int main(int argc, char **argv) { GtkWidget *window; int days_left; 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 */ days_left = securid_check_exp(current_token, time(NULL)); if (!opt_force) { if (days_left < 0) error_dialog("Token expired", "Please obtain a new token from your administrator."); if (days_left < 14) { char msg[BUFLEN]; sprintf(msg, "This token will expire in %d day%s.", days_left, days_left == 1 ? "" : "s"); warning_dialog(NULL, "Expiration warning", msg); } } /* request password + PIN, if missing */ if (do_password_dialog(current_token) != ERR_NONE) return 1; interval = securid_token_interval(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; }
static int request_credentials(struct securid_token *t) { int rc, pass_required = 0, pin_required = 0; if (securid_pass_required(t)) { pass_required = 1; if (opt_password) { rc = securid_decrypt_seed(t, opt_password, NULL); if (rc == ERR_DECRYPT_FAILED) warn("warning: --password parameter is incorrect\n"); else if (rc != ERR_NONE) error_dialog("Token decrypt error", stoken_errstr[rc]); else pass_required = 0; } } else { rc = securid_decrypt_seed(t, opt_password, NULL); if (rc != ERR_NONE) error_dialog("Token decrypt error", stoken_errstr[rc]); } while (pass_required) { const char *pass = do_password_dialog(UIDIR "/password-dialog.ui"); if (!pass) return ERR_MISSING_PASSWORD; rc = securid_decrypt_seed(t, pass, NULL); if (rc == ERR_NONE) { if (t->enc_pin_str) { rc = securid_decrypt_pin(t->enc_pin_str, pass, t->pin); if (rc != ERR_NONE) error_dialog("PIN decrypt error", stoken_errstr[rc]); } pass_required = 0; } else if (rc == ERR_DECRYPT_FAILED) warning_dialog(NULL, "Bad password", "Please enter the correct password for this seed."); else error_dialog("Token decrypt error", stoken_errstr[rc]); } if (securid_pin_required(t)) { pin_required = 1; if (opt_pin) { if (securid_pin_format_ok(opt_pin) == ERR_NONE) { xstrncpy(t->pin, opt_pin, MAX_PIN + 1); pin_required = 0; } else warn("warning: --pin argument is invalid\n"); } else if (strlen(t->pin) || t->enc_pin_str) pin_required = 0; } while (pin_required) { const char *pin = do_password_dialog(UIDIR "/pin-dialog.ui"); if (!pin) { skipped_pin = 1; xstrncpy(t->pin, "0000", MAX_PIN + 1); break; } if (securid_pin_format_ok(pin) != ERR_NONE) { warning_dialog(NULL, "Bad PIN", "Please enter 4-8 digits, or click Skip for no PIN."); } else { xstrncpy(t->pin, pin, MAX_PIN + 1); break; } } return ERR_NONE; }