+2006-08-14 [cleroy] 2.4.0cvs50
+
+ * src/gtk/pluginwindow.c
+ New layout (maybe to be changed?)
+ * src/gtk/gtkutils.c
+ Fix a bit label_window
+ * src/plugins/pgpcore/passphrase.c
+ * src/plugins/pgpcore/passphrase.h
+ * src/plugins/pgpcore/plugin.c
+ * src/plugins/pgpcore/prefs_gpg.c
+ * src/plugins/pgpcore/prefs_gpg.h
+ * src/plugins/pgpcore/sgpgme.c
+ * src/plugins/pgpcore/sgpgme.h
+ Allow to create a PGP private key via the GUI
+
2006-08-14 [wwp] 2.4.0cvs49
* src/addressbook_foldersel.c
( cvs diff -u -r 1.16.2.19 -r 1.16.2.20 src/prefs_display_header.c; ) > 2.4.0cvs47.patchset
( cvs diff -u -r 1.12.2.26 -r 1.12.2.27 src/gtk/prefswindow.c; ) > 2.4.0cvs48.patchset
( cvs diff -u -r 1.1.2.1 -r 1.1.2.2 src/addressbook_foldersel.c; ) > 2.4.0cvs49.patchset
+( cvs diff -u -r 1.5.2.35 -r 1.5.2.36 src/gtk/gtkutils.c; cvs diff -u -r 1.5.2.31 -r 1.5.2.32 src/gtk/pluginwindow.c; cvs diff -u -r 1.1.2.15 -r 1.1.2.16 src/plugins/pgpcore/passphrase.c; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/pgpcore/passphrase.h; cvs diff -u -r 1.1.2.8 -r 1.1.2.9 src/plugins/pgpcore/plugin.c; cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/plugins/pgpcore/prefs_gpg.c; cvs diff -u -r 1.1.2.3 -r 1.1.2.4 src/plugins/pgpcore/prefs_gpg.h; cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/plugins/pgpcore/sgpgme.c; cvs diff -u -r 1.1.2.4 -r 1.1.2.5 src/plugins/pgpcore/sgpgme.h; ) > 2.4.0cvs50.patchset
MICRO_VERSION=0
INTERFACE_AGE=0
BINARY_AGE=0
-EXTRA_VERSION=49
+EXTRA_VERSION=50
EXTRA_RELEASE=
EXTRA_GTK2_VERSION=
label = gtk_label_new(str);
gtk_container_add(GTK_CONTAINER(window), label);
+ gtk_label_set_line_wrap(label, TRUE);
gtk_widget_show(label);
gtk_widget_show_now(window);
+
+ GTK_EVENTS_FLUSH();
return window;
}
GtkWidget *unload_btn;
GtkWidget *close_btn;
GtkWidget *get_more_btn;
+ GtkWidget *desc_lbl;
static GdkGeometry geometry;
debug_print("Creating plugins window...\n");
vbox1 = gtk_vbox_new(FALSE, 4);
gtk_widget_show(vbox1);
gtk_container_add(GTK_CONTAINER(window), vbox1);
+ gtk_box_set_homogeneous(GTK_BOX(vbox1), FALSE);
+ gtk_widget_realize(window);
+
+ desc_lbl = gtk_label_new(_("Plugins are a way to greatly extend Sylpheed-Claws' capabilities."));
+ gtk_misc_set_alignment(GTK_MISC(desc_lbl), 0, 0.5);
+ gtk_widget_show(desc_lbl);
+ gtk_box_pack_start(GTK_BOX(vbox1), desc_lbl, FALSE, FALSE, 0);
+
+ get_more_btn = gtkut_get_link_btn(window, PLUGINS_URI, _("Get more..."));
+ gtk_misc_set_alignment(GTK_MISC(GTK_BIN(get_more_btn)->child), 0, 0.5);
+ gtk_widget_show(get_more_btn);
+ gtk_box_pack_start(GTK_BOX(vbox1), get_more_btn, FALSE, FALSE, 0);
hbox2 = gtk_hbox_new(FALSE, 8);
gtk_widget_show(hbox2);
hbuttonbox1 = gtk_hbutton_box_new();
gtk_widget_show(hbuttonbox1);
- gtk_widget_realize(window);
- get_more_btn = gtkut_get_link_btn(window, PLUGINS_URI, _("Get more..."));
- gtk_misc_set_alignment(GTK_MISC(GTK_BIN(get_more_btn)->child), 0, 0.5);
- gtk_widget_show(get_more_btn);
-
- gtk_box_pack_start(GTK_BOX(hbox3), get_more_btn, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox3), hbuttonbox1, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox1), hbox3, FALSE, FALSE, 0);
renderer = gtk_cell_renderer_text_new();
column = gtk_tree_view_column_new_with_attributes
- (_("Plugins"),
+ (_("Loaded plugins"),
renderer,
"text", PLUGINWINDOW_NAME,
"style", PLUGINWINDOW_STYLE,
gpointer data);
static gboolean passphrase_key_pressed(GtkWidget *widget, GdkEventKey *event,
gpointer data);
-static gchar* passphrase_mbox(const gchar *uid_hint, const gchar *pass_hint,
- gint prev_bad);
static GtkWidget *create_description(const gchar *uid_hint,
- const gchar *pass_hint, gint prev_bad);
+ const gchar *pass_hint, gint prev_bad, gint new_key);
void
gpgmegtk_set_passphrase_grab(gint yes)
grab_all = yes;
}
-static gchar*
-passphrase_mbox(const gchar *uid_hint, const gchar *pass_hint, gint prev_bad)
+gchar*
+passphrase_mbox(const gchar *uid_hint, const gchar *pass_hint, gint prev_bad, gint new_key)
{
gchar *the_passphrase = NULL;
GtkWidget *vbox, *hbox;
if (uid_hint || pass_hint) {
GtkWidget *label, *icon;
- label = create_description (uid_hint, pass_hint, prev_bad);
+ label = create_description (uid_hint, pass_hint, prev_bad, new_key);
icon = gtk_image_new_from_stock(GTK_STOCK_DIALOG_AUTHENTICATION,
GTK_ICON_SIZE_DIALOG);
}
static GtkWidget *
-create_description(const gchar *uid_hint, const gchar *pass_hint, gint prev_bad)
+create_description(const gchar *uid_hint, const gchar *pass_hint, gint prev_bad, gint new_key)
{
const gchar *uid = NULL, *info = NULL;
gchar *buf;
while (strchr(my_uid, '>'))
*(strchr(my_uid, '>')) = ')';
- buf = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">%sPlease enter the passphrase for:</span>\n\n"
+ if (new_key == 1) {
+ buf = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">%sPlease enter the passphrase for the new key:</span>\n\n"
+ "%.*s\n"),
+ prev_bad ?
+ _("Passphrases did not match.\n") : "",
+ linelen (my_uid), my_uid);
+ } else if (new_key == 2) {
+ buf = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">Please re-enter the passphrase for the new key:</span>\n\n"
+ "%.*s\n"),
+ linelen (my_uid), my_uid);
+ } else {
+ buf = g_strdup_printf (_("<span weight=\"bold\" size=\"larger\">%sPlease enter the passphrase for:</span>\n\n"
"%.*s\n"),
prev_bad ?
_("Bad passphrase.\n") : "",
linelen (my_uid), my_uid);
+ }
g_free(my_uid);
label = gtk_label_new (buf);
gtk_label_set_use_markup(GTK_LABEL (label), TRUE);
else {
gpgmegtk_set_passphrase_grab (prefs_gpg_get_config()->passphrase_grab);
debug_print ("%% requesting passphrase for '%s'\n ", uid_hint);
- pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad);
+ pass = passphrase_mbox (uid_hint, passphrase_hint, prev_bad, FALSE);
gpgmegtk_free_passphrase();
if (!pass) {
debug_print ("%% cancel passphrase entry\n");
gpgme_error_t gpgmegtk_passphrase_cb(void *opaque, const char *uid_hint,
const char *passphrase_info, int prev_bad, int fd);
void gpgmegtk_free_passphrase();
+gchar* passphrase_mbox(const gchar *uid_hint, const gchar *pass_hint,
+ gint prev_bad, gint new_key);
#endif /* GPGMEGTK_PASSPHRASE_H */
sgpgme_init();
prefs_gpg_init();
-
+ sgpgme_check_create_key();
return 0;
}
#include "prefs.h"
#include "prefs_gtk.h"
#include "prefs_gpg.h"
+#include "sgpgme.h"
struct GPGConfig prefs_gpg;
NULL, NULL, NULL},
{"gpg_warning", "TRUE", &prefs_gpg.gpg_warning, P_BOOL,
NULL, NULL, NULL},
+ {"gpg_ask_create_key", "TRUE", &prefs_gpg.gpg_ask_create_key, P_BOOL,
+ NULL, NULL, NULL},
{NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
};
GtkWidget *key_custom;
GtkWidget *keyid;
GtkWidget *keyid_label;
+ GtkWidget *new_key_label;
+ GtkWidget *new_key_btn;
+ GtkWidget *new_key_box;
PrefsAccount *account;
};
gtk_editable_delete_text(GTK_EDITABLE(page->keyid), 0, -1);
}
+static void new_key_clicked(GtkWidget *widget, gpointer user_data)
+{
+ struct GPGAccountPage *page = (struct GPGAccountPage *) user_data;
+ sgpgme_create_secret_key(page->account);
+}
+
static void prefs_gpg_account_create_widget_func(PrefsPage *_page,
GtkWindow *window,
gpointer data)
GtkWidget *key_custom;
GtkWidget *keyid_label;
GtkWidget *keyid;
+ GtkWidget *image;
+ GtkWidget *new_key_label;
+ GtkWidget *new_key_btn;
+ GtkWidget *new_key_box;
vbox = gtk_vbox_new(FALSE, VSPACING);
gtk_container_set_border_width (GTK_CONTAINER (vbox), VBOX_BORDER);
break;
}
+ new_key_box = gtk_hbox_new(FALSE, 6);
+
+ image = gtk_image_new_from_stock(GTK_STOCK_DIALOG_WARNING,
+ GTK_ICON_SIZE_SMALL_TOOLBAR);
+
+ gtk_box_pack_start(GTK_BOX(new_key_box), image, FALSE, FALSE, 0);
+ new_key_label = gtk_label_new(
+ _("No secret key found."));
+ gtk_box_pack_start(GTK_BOX(new_key_box), new_key_label, FALSE, FALSE, 0);
+ new_key_btn = gtk_button_new_with_label(_("Generate new secret key"));
+ gtk_box_pack_start(GTK_BOX(new_key_box), new_key_btn, FALSE, FALSE, 0);
+
+ gtk_box_pack_start(GTK_BOX(vbox2), new_key_box, FALSE, FALSE, 0);
+
+ gtk_widget_show_all(new_key_box);
+
+ if (sgpgme_has_secret_key())
+ gtk_widget_hide(new_key_box);
+
if (config->sign_key_id != NULL)
gtk_entry_set_text(GTK_ENTRY(keyid), config->sign_key_id);
g_signal_connect(G_OBJECT(key_custom), "toggled", G_CALLBACK(key_custom_toggled), page);
+ g_signal_connect(G_OBJECT(new_key_btn), "clicked", G_CALLBACK(new_key_clicked), page);
page->key_default = key_default;
page->key_by_from = key_by_from;
gint store_passphrase_timeout;
gboolean passphrase_grab;
gboolean gpg_warning;
+ gboolean gpg_ask_create_key;
};
struct GPGAccountConfig
#include <glib/gi18n.h>
#include <stdio.h>
#include <errno.h>
+#ifndef G_OS_WIN32
+#include <sys/mman.h>
+#endif
#if HAVE_LOCALE_H
# include <locale.h>
#endif
#include "alertpanel.h"
#include "passphrase.h"
#include "prefs_gpg.h"
+#include "account.h"
#include "select-keys.h"
static void sgpgme_disable_all(void)
gpgmegtk_free_passphrase();
}
+void sgpgme_create_secret_key(PrefsAccount *account)
+{
+ AlertValue val = alertpanel(_("No PGP key found"),
+ _("Sylpheed-Claws did not find a secret PGP key, "
+ "which means that you won't be able to sign "
+ "emails or receive encrypted emails.\n"
+ "Do you want to create a secret key now?"),
+ GTK_STOCK_NO, "+" GTK_STOCK_YES, NULL);
+ gchar *key_parms = NULL;
+ gchar *name = NULL;
+ gchar *email = NULL;
+ gchar *passphrase = NULL, *passphrase_second = NULL;
+ gint prev_bad = 0;
+ gchar *tmp = NULL;
+ gpgme_error_t err = 0;
+ gpgme_ctx_t ctx;
+ GtkWidget *window = NULL;
+ gpgme_genkey_result_t key;
+
+ if (account == NULL)
+ account = account_get_default();
+
+ if (val == G_ALERTDEFAULT) {
+ prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
+ prefs_gpg_save_config();
+ return;
+ }
+
+ if (account->name) {
+ name = g_strdup(account->name);
+ } else {
+ name = g_strdup(account->address);
+ }
+ email = g_strdup(account->address);
+ tmp = g_strdup_printf("%s <%s>", account->name?account->name:account->address, account->address);
+again:
+ passphrase = passphrase_mbox(tmp, NULL, prev_bad, 1);
+ if (passphrase == NULL) {
+ g_free(tmp);
+ g_free(email);
+ g_free(name);
+ return;
+ }
+ passphrase_second = passphrase_mbox(tmp, NULL, 0, 2);
+ if (passphrase_second == NULL) {
+ g_free(tmp);
+ g_free(email);
+ g_free(passphrase);
+ g_free(name);
+ return;
+ }
+ if (strcmp(passphrase, passphrase_second)) {
+ g_free(passphrase);
+ g_free(passphrase_second);
+ prev_bad = 1;
+ goto again;
+ }
+
+ key_parms = g_strdup_printf("<GnupgKeyParms format=\"internal\">\n"
+ "Key-Type: DSA\n"
+ "Key-Length: 1024\n"
+ "Subkey-Type: ELG-E\n"
+ "Subkey-Length: 2048\n"
+ "Name-Real: %s\n"
+ "Name-Email: %s\n"
+ "Expire-Date: 0\n"
+ "Passphrase: %s\n"
+ "</GnupgKeyParms>\n",
+ name, email, passphrase);
+#ifndef G_PLATFORM_WIN32
+ if (mlock(passphrase, strlen(passphrase)) == -1)
+ debug_print("couldn't lock passphrase\n");
+ if (mlock(passphrase_second, strlen(passphrase_second)) == -1)
+ debug_print("couldn't lock passphrase2\n");
+#endif
+ g_free(tmp);
+ g_free(email);
+ g_free(name);
+ g_free(passphrase_second);
+ g_free(passphrase);
+
+ err = gpgme_new (&ctx);
+ if (err) {
+ alertpanel_error(_("Couldn't generate new key: %s"), gpgme_strerror(err));
+ g_free(key_parms);
+ return;
+ }
+
+
+ window = label_window_create(_("Generating your new key... Please move the mouse "
+ "around to help generate entropy..."));
+
+ err = gpgme_op_genkey(ctx, key_parms, NULL, NULL);
+ g_free(key_parms);
+
+ gtk_widget_destroy(window);
+
+ if (err) {
+ alertpanel_error(_("Couldn't generate new key: %s"), gpgme_strerror(err));
+ gpgme_release(ctx);
+ return;
+ }
+ key = gpgme_op_genkey_result(ctx);
+ if (key == NULL) {
+ alertpanel_error(_("Couldn't generate new key: unknown error"));
+ gpgme_release(ctx);
+ return;
+ } else {
+ alertpanel_notice(_("Your secret key has been generated. "
+ "Its fingerprint is:\n%s"),
+ key->fpr ? key->fpr:"null");
+ }
+ prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
+ prefs_gpg_save_config();
+ gpgme_release(ctx);
+}
+
+gboolean sgpgme_has_secret_key(void)
+{
+ gpgme_error_t err = 0;
+ gpgme_ctx_t ctx;
+ gpgme_key_t key;
+
+ err = gpgme_new (&ctx);
+ if (err) {
+ debug_print("err : %s\n", gpgme_strerror(err));
+ return TRUE;
+ }
+ err = gpgme_op_keylist_start(ctx, NULL, TRUE);
+ if (!err)
+ err = gpgme_op_keylist_next(ctx, &key);
+ gpgme_op_keylist_end(ctx);
+ gpgme_release(ctx);
+ if (gpg_err_code(err) == GPG_ERR_EOF)
+ return FALSE;
+ else
+ return TRUE;
+}
+
+void sgpgme_check_create_key(void)
+{
+ if (prefs_gpg_get_config()->gpg_ask_create_key &&
+ !sgpgme_has_secret_key()) {
+ sgpgme_create_secret_key(NULL);
+ } else {
+ prefs_gpg_get_config()->gpg_ask_create_key = FALSE;
+ prefs_gpg_save_config();
+ }
+}
#endif /* USE_GPGME */
gchar *sgpgme_get_encrypt_data (GSList *recp_names,
gpgme_protocol_t proto);
gboolean sgpgme_setup_signers(gpgme_ctx_t ctx, PrefsAccount *account);
-
+void sgpgme_check_create_key(void);
+gboolean sgpgme_has_secret_key(void);
+void sgpgme_create_secret_key(PrefsAccount *account);
#endif /* SGPGME_H */