static void unlock_token(struct securid_token *t, int get_pin, char **ret_pass) { char devid[BUFLEN] = { 0 }, pass[BUFLEN] = { 0 }, pin[BUFLEN]; int rc; if (securid_devid_required(t)) request_devid(t, devid); if (securid_pass_required(t)) request_pass("Enter password to decrypt token: ", t, pass, devid); rc = securid_decrypt_seed(t, pass, devid); if (rc != ERR_NONE) die("error: can't decrypt token: %s\n", stoken_errstr[rc]); if (t->enc_pin_str) if (securid_decrypt_pin(t->enc_pin_str, pass, t->pin) != ERR_NONE) warn("warning: can't decrypt PIN\n"); if (ret_pass && strlen(pass)) *ret_pass = xstrdup(pass); /* always allow --pin to override .stokenrc */ if (get_pin && securid_pin_required(t) && (!strlen(t->pin) || opt_pin)) { request_pin("Enter PIN:", pin); strncpy(t->pin, pin, MAX_PIN + 1); } }
int main(int argc, char **argv) { GtkWidget *window; char *cmd; gtk_init(&argc, &argv); gtk_window_set_default_icon_from_file( DATA_DIR "/pixmaps/stoken-gui.png", NULL); cmd = parse_cmdline(argc, argv, IS_GUI); /* check for a couple of error conditions */ if (common_init(cmd)) error_dialog("Application error", "Unable to initialize crypto library."); if (!current_token) error_dialog("Missing token", "Please use 'stoken import' to add a new seed."); if (securid_devid_required(current_token)) error_dialog("Unsupported token", "Please use 'stoken' to handle tokens encrypted with a device ID."); /* check for token expiration */ token_days_left = securid_check_exp(current_token, time(NULL)); if (!opt_force && !opt_small) { if (token_days_left < 0) error_dialog("Token expired", "Please obtain a new token from your administrator."); if (token_days_left < EXP_WARN_DAYS) { char msg[BUFLEN]; sprintf(msg, "This token will expire in %d day%s.", token_days_left, token_days_left == 1 ? "" : "s"); warning_dialog(NULL, "Expiration warning", msg); } } /* request password / PIN, if missing */ if (request_credentials(current_token) != ERR_NONE) return 1; token_interval = securid_token_interval(current_token); token_uses_pin = securid_pin_required(current_token); window = opt_small ? create_small_app_window() : create_app_window(); update_tokencode(NULL); gtk_widget_show_all(window); g_timeout_add(250, update_tokencode, NULL); gtk_main(); return 0; }