gboolean gkd_gpg_agent_ops_getpass (GkdGpgAgentCall *call, gchar *args) { gchar *id; gchar *errmsg; gchar *prompt; gchar *description; GckSession *session; gchar *password; gchar *encoded; guint32 flags; /* We don't answer this unless it's from the right terminal */ if (!call->terminal_ok) { g_message ("received passphrase request from wrong terminal"); return gkd_gpg_agent_send_reply (call, FALSE, "113 Server Resource Problem"); } split_arguments (args, &flags, &id, &errmsg, &prompt, &description, NULL); if (!id || !errmsg || !prompt || !description) { g_message ("received invalid passphrase request"); return gkd_gpg_agent_send_reply (call, FALSE, "105 parameter error"); } if (is_null_argument (id)) id = NULL; if (is_null_argument (errmsg)) errmsg = NULL; if (is_null_argument (prompt)) prompt = NULL; if (is_null_argument (description)) description = NULL; session = gkd_gpg_agent_checkout_main_session (); g_return_val_if_fail (session, FALSE); password = do_get_password (session, id, errmsg, prompt, description, flags & GKD_GPG_AGENT_REPEAT); gkd_gpg_agent_checkin_main_session (session); if (password == NULL) { gkd_gpg_agent_send_reply (call, FALSE, "111 cancelled"); } else if (flags & GKD_GPG_AGENT_PASS_AS_DATA) { encoded = uri_encode_password (password); gkd_gpg_agent_send_data (call, encoded); gkd_gpg_agent_send_reply (call, TRUE, NULL); egg_secure_strfree (encoded); } else { encoded = hex_encode_password (password); gkd_gpg_agent_send_reply (call, TRUE, encoded); egg_secure_strfree (encoded); } egg_secure_strfree (password); return TRUE; }
void show_export_crl_dialog(FRONTEND * fe) { /* export dialog -> * dialog (OK, cancel), * filename entry & browse, * format choice (DER, text) */ GtkWidget *dlg; GtkEntry *filename_entry; GtkButton *browse_button; GtkRadioButton *rb_text, *rb_der; GtkBox *box; gint result; dlg = gtk_dialog_new_with_buttons("Export CRL", GTK_WINDOW(fe->mainWindow), GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); box = GTK_BOX(gtk_hbox_new(0, 5)); gtk_box_pack_start(box, gtk_label_new("Export to"), FALSE, FALSE, 0); filename_entry = GTK_ENTRY(gtk_entry_new()); gtk_box_pack_start(box, GTK_WIDGET(filename_entry), FALSE, FALSE, 0); browse_button = GTK_BUTTON(gtk_button_new_with_mnemonic("_Browse...")); gtk_box_pack_start(box, GTK_WIDGET(browse_button), FALSE, FALSE, 0); g_signal_connect(G_OBJECT(browse_button), "clicked", G_CALLBACK(on_browse_button_clicked), dlg); /* don't ref the entry -- same lifetime */ g_object_set_data_full(G_OBJECT(browse_button), "entry", filename_entry, NULL); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), GTK_WIDGET(box), FALSE, FALSE, 0); rb_der = GTK_RADIO_BUTTON(gtk_radio_button_new_with_mnemonic (NULL, "_DER (Binary)")); rb_text = GTK_RADIO_BUTTON(gtk_radio_button_new_with_mnemonic_from_widget (rb_der, "_PEM (Text)")); box = GTK_BOX(gtk_hbox_new(0, 5)); gtk_box_pack_start(box, gtk_label_new("Format:"), FALSE, FALSE, 0); gtk_box_pack_start(box, GTK_WIDGET(rb_der), FALSE, FALSE, 0); gtk_box_pack_start(box, GTK_WIDGET(rb_text), FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dlg)->vbox), GTK_WIDGET(box), FALSE, FALSE, 0); gtk_widget_show_all(GTK_WIDGET(GTK_DIALOG(dlg)->vbox)); result = gtk_dialog_run(GTK_DIALOG(dlg)); if (result == GTK_RESPONSE_ACCEPT) { void *buf; int status; int len; gboolean text_format; CRYPT_CERTFORMAT_TYPE fmt; FILE *f; gchar *filename; CRYPT_CERTIFICATE crl; CRYPT_CONTEXT key; gchar *password; /* get password */ password = do_get_password(GTK_WINDOW(dlg)); if (password == NULL) { /* cancelled? */ goto cleanup; } /* sign */ status = lmz_ca_get_signing_key(fe->db, password, &key); g_free(password); /* dynamic */ if (status == CRYPT_ERROR_WRONGKEY) { show_error_dialog(GTK_WINDOW(dlg), "Wrong password"); goto cleanup; } else if (!cryptStatusOK(status)) { show_error_dialog(GTK_WINDOW(dlg), "Error getting signing key (cryptlib error %d)", status); goto cleanup; } status = lmz_ca_gen_crl(fe->db, &crl); if (cryptStatusOK(status)) { /* sign it */ status = cryptSignCert(crl, key); if (cryptStatusOK(status)) { text_format = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(rb_text)); fmt = text_format ? CRYPT_CERTFORMAT_TEXT_CERTIFICATE : CRYPT_CERTFORMAT_CERTIFICATE; status = cryptExportCert(NULL, 0, &len, fmt, crl); buf = malloc(len); status = cryptExportCert(buf, len, &len, fmt, crl); if (cryptStatusOK(status)) { filename = g_filename_from_utf8(gtk_entry_get_text(filename_entry), -1, NULL, NULL, NULL); if (filename != NULL) { f = fopen(filename, "w"); if (f != NULL) { if (fwrite(buf, len, 1, f) != 1) { show_error_dialog(NULL, "error fully writing data"); } fclose(f); } else { show_error_dialog(NULL, "error opening file for writing"); } g_free(filename); } else { show_error_dialog(NULL, "filename conversion error"); } free(buf); } } else { show_error_dialog(NULL, "error signing crl (cl error %d)", status); } cryptDestroyCert(crl); } else { show_error_dialog(NULL, "error generating crl (cl error %d)", status); } cryptDestroyContext(key); } cleanup: gtk_widget_destroy(dlg); }