Commit d6f1de34 authored by Stefan Walter's avatar Stefan Walter

Progress dialog while generating key. Patch from Jim Pharis. Bug #159083

    * libseahorse/seahorse-pgp-key-op.c:
    * libseahorse/seahorse-pgp-key-op.h:
    * src/seahorse-generate-adv.c:
    * src/seahorse-generate-druid.c: Progress dialog while generating key.
    Patch from Jim Pharis. Bug #159083
parent e31065dc
2006-04-09 Nate Nielsen <nielsen@memberwebs.com>
* libseahorse/seahorse-pgp-key-op.c:
* libseahorse/seahorse-pgp-key-op.h:
* src/seahorse-generate-adv.c:
* src/seahorse-generate-druid.c: Progress dialog while generating key.
Patch from Jim Pharis. Bug #159083
2006-04-06 Nate Nielsen <nielsen@memberwebs.com>
* src/seahorse-key-properties.c:
......
......@@ -29,6 +29,7 @@
#include "seahorse-pgp-key-op.h"
#include "seahorse-util.h"
#include "seahorse-libdialogs.h"
#include "seahorse-pgp-operation.h"
#define PROMPT "keyedit.prompt"
#define QUIT "quit"
......@@ -65,84 +66,84 @@
* @type: Key type. Supported types are #DSA_ELGAMAL, #DSA, and #RSA_SIGN
* @length: Length of key, must be within the range of @type specified by #SeahorseKeyLength
* @expires: Expiration date of key
*
* @err: Catches errors in the params
*
* Tries to generate a new key based on given parameters.
* The generation operation is done with a new GPGME context
* If the generation is successful, seahorse_key_source_refresh() will be
* called with @sksrc.
*
* Returns: gpgme_error_t
* Returns: SeahorseOperation*
**/
gpgme_error_t
SeahorseOperation*
seahorse_pgp_key_op_generate (SeahorsePGPSource *psrc, const gchar *name,
const gchar *email, const gchar *comment,
const gchar *passphrase, const SeahorseKeyEncType type,
const guint length, const time_t expires)
const gchar *email, const gchar *comment,
const gchar *passphrase, const SeahorseKeyEncType type,
const guint length, const time_t expires, gpgme_error_t *err)
{
gchar *common, *key_type, *start, *parms, *expires_date;
gpgme_error_t err;
gpgme_ctx_t new_ctx;
g_return_val_if_fail (strlen (name) >= 5, GPG_E (GPG_ERR_INV_VALUE));
/* Check lengths for each type */
switch (type) {
case DSA_ELGAMAL:
g_return_val_if_fail (length >= ELGAMAL_MIN && length <= LENGTH_MAX, GPG_E (GPG_ERR_INV_VALUE));
break;
case DSA:
g_return_val_if_fail (length >= DSA_MIN && length <= DSA_MAX, GPG_E (GPG_ERR_INV_VALUE));
break;
case RSA_SIGN:
g_return_val_if_fail (length >= RSA_MIN && length <= LENGTH_MAX, GPG_E (GPG_ERR_INV_VALUE));
break;
default:
g_return_val_if_reached (GPG_E (GPG_ERR_INV_VALUE));
break;
}
if (expires != 0)
expires_date = seahorse_util_get_date_string (expires);
else
expires_date = "0";
/* Common xml */
common = g_strdup_printf ("Name-Real: %s\nExpire-Date: %s\nPassphrase: %s\n"
"</GnupgKeyParms>", name, expires_date, passphrase);
if (email != NULL && strlen (email) > 0)
common = g_strdup_printf ("Name-Email: %s\n%s", email, common);
if (comment != NULL && strlen (comment) > 0)
common = g_strdup_printf ("Name-Comment: %s\n%s", comment, common);
if (type == RSA_SIGN)
key_type = "Key-Type: RSA";
else
key_type = "Key-Type: DSA";
start = g_strdup_printf ("<GnupgKeyParms format=\"internal\">\n%s\nKey-Length: ", key_type);
/* Subkey xml */
if (type == DSA_ELGAMAL)
parms = g_strdup_printf ("%s%d\nSubkey-Type: ELG-E\nSubkey-Length: %d\n%s",
start, DSA_MAX, length, common);
else
parms = g_strdup_printf ("%s%d\n%s", start, length, common);
new_ctx = seahorse_pgp_source_new_context ();
g_return_val_if_fail (new_ctx != NULL, GPG_E (GPG_ERR_GENERAL));
SeahorsePGPOperation *pop = NULL;
gchar *common, *key_type, *start, *expires_date;
const gchar *parms;
err = gpgme_op_genkey (new_ctx, parms, NULL, NULL);
gpgme_release (new_ctx);
if (GPG_IS_OK (err))
seahorse_key_source_load_async (SEAHORSE_KEY_SOURCE (psrc), SKSRC_LOAD_NEW, NULL);
/* Free xmls */
g_free (parms);
g_free (start);
g_free (common);
return err;
*err = GPG_OK;
if (strlen (name) < 5)
*err = GPG_E (GPG_ERR_INV_VALUE);
/* Check lengths for each type */
switch (type) {
case DSA_ELGAMAL:
if (length < ELGAMAL_MIN || length > LENGTH_MAX)
*err = GPG_E (GPG_ERR_INV_VALUE);
break;
case DSA:
if (length < DSA_MIN || length > DSA_MAX)
*err = GPG_E (GPG_ERR_INV_VALUE);
break;
case RSA_SIGN:
if (length < RSA_MIN || length > LENGTH_MAX)
*err = GPG_E (GPG_ERR_INV_VALUE);
break;
default:
*err = GPG_E (GPG_ERR_INV_VALUE);
break;
}
if (0 != expires)
expires_date = seahorse_util_get_date_string (expires);
else
expires_date = g_strdup ("0");
/* Common xml */
common = g_strdup_printf ("Name-Real: %s\nExpire-Date: %s\nPassphrase: %s\n"
"</GnupgKeyParms>", name, expires_date, passphrase);
if (email != NULL && strlen (email) > 0)
common = g_strdup_printf ("Name-Email: %s\n%s", email, common);
if (comment != NULL && strlen (comment) > 0)
common = g_strdup_printf ("Name-Comment: %s\n%s", comment, common);
if (type == RSA_SIGN)
key_type = "Key-Type: RSA";
else
key_type = "Key-Type: DSA";
start = g_strdup_printf ("<GnupgKeyParms format=\"internal\">\n%s\nKey-Length: ", key_type);
/* Subkey xml */
if (type == DSA_ELGAMAL)
parms = g_strdup_printf ("%s%d\nSubkey-Type: ELG-E\nSubkey-Length: %d\n%s",
start, DSA_MAX, length, common);
else
parms = g_strdup_printf ("%s%d\n%s", start, length, common);
if (GPG_IS_OK (*err)) {
pop = seahorse_pgp_operation_new (NULL);
*err = gpgme_op_genkey_start (pop->gctx, parms, NULL, NULL);
}
/* Free xmls */
g_free (start);
g_free (common);
g_free (expires_date);
return pop ? SEAHORSE_OPERATION (pop) : NULL;
}
/* helper function for deleting @skey */
......
......@@ -29,6 +29,7 @@
#include "seahorse-pgp-source.h"
#include "seahorse-pgp-key.h"
#include "seahorse-gpgmex.h"
#include "seahorse-operation.h"
/* Key type options. */
typedef enum {
......@@ -102,14 +103,15 @@ typedef enum {
REVOKE_NOT_USED = 3
} SeahorseRevokeReason;
gpgme_error_t seahorse_pgp_key_op_generate (SeahorsePGPSource *sksrc,
const gchar *name,
const gchar *email,
const gchar *comment,
const gchar *passphrase,
SeahorseKeyEncType type,
guint length,
time_t expires);
SeahorseOperation* seahorse_pgp_key_op_generate (SeahorsePGPSource *sksrc,
const gchar *name,
const gchar *email,
const gchar *comment,
const gchar *passphrase,
SeahorseKeyEncType type,
guint length,
time_t expires,
gpgme_error_t *err);
gpgme_error_t seahorse_pgp_key_op_delete (SeahorsePGPKey *pkey);
......
......@@ -25,6 +25,8 @@
#include "seahorse-widget.h"
#include "seahorse-util.h"
#include "seahorse-pgp-key-op.h"
#include "seahorse-progress.h"
#include "seahorse-operation.h"
#define LENGTH "length"
#define EXPIRES "expires"
......@@ -90,7 +92,8 @@ never_expires_toggled (GtkToggleButton *togglebutton, SeahorseWidget *swidget)
static void
ok_clicked (GtkButton *button, SeahorseWidget *swidget)
{
SeahorseKeySource *sksrc;
SeahorseKeySource *sksrc;
SeahorseOperation *op;
const gchar *name, *email, *comment, *pass;
gint history, length;
SeahorseKeyEncType type;
......@@ -98,6 +101,8 @@ ok_clicked (GtkButton *button, SeahorseWidget *swidget)
GtkWidget *widget;
gpgme_error_t err;
err = GPG_OK;
name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, NAME)));
email = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, "email")));
comment = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, "comment")));
......@@ -130,18 +135,20 @@ ok_clicked (GtkButton *button, SeahorseWidget *swidget)
widget = glade_xml_get_widget (swidget->xml, swidget->name);
gtk_widget_hide (widget);
/* When we update to support S/MIME this will need to change */
sksrc = seahorse_context_find_key_source (SCTX_APP (), SKEY_PGP, SKEY_LOC_LOCAL);
g_return_if_fail (sksrc && SEAHORSE_IS_PGP_SOURCE (sksrc));
/* When we update to support S/MIME this will need to change */
sksrc = seahorse_context_find_key_source (SCTX_APP (), SKEY_PGP, SKEY_LOC_LOCAL);
g_return_if_fail (sksrc && SEAHORSE_IS_PGP_SOURCE (sksrc));
err = seahorse_pgp_key_op_generate (SEAHORSE_PGP_SOURCE (sksrc), name, email, comment,
pass, type, length, expires);
if (!GPG_IS_OK (err)) {
gtk_widget_show (widget);
op = seahorse_pgp_key_op_generate (SEAHORSE_PGP_SOURCE (sksrc), name, email, comment,
pass, type, length, expires, &err);
if (GPG_IS_OK (err))
seahorse_progress_show (op, _("Generating key"), TRUE);
else
seahorse_util_handle_gpgme (err, _("Couldn't generate key"));
}
else
seahorse_widget_destroy (swidget);
gtk_widget_destroy (widget);
seahorse_widget_destroy (swidget);
}
void
......
......@@ -26,6 +26,8 @@
#include "seahorse-util.h"
#include "seahorse-key-source.h"
#include "seahorse-pgp-key-op.h"
#include "seahorse-progress.h"
#include "seahorse-operation.h"
#define EXPIRES "expiration_date"
#define LOW_SECURITY 768
......@@ -121,21 +123,22 @@ on_druidpagepassphrase_next (GnomeDruidPage *gnomedruidpage, GtkWidget *widget,
void
on_druid_finish (GnomeDruidPage *gnomedruidpage, GtkWidget *widget, SeahorseWidget *swidget)
{
SeahorseKeySource *sksrc;
SeahorseKeySource *sksrc;
SeahorseOperation *op;
const gchar *name, *email, *comment, *pass;
gint length;
SeahorseKeyEncType type;
time_t expires;
GtkWidget *widget2;
gpgme_error_t err;
err = GPG_OK;
name = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, NAME)));
email = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, EMAIL)));
comment = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, COMMENT)));
pass = gtk_entry_get_text (GTK_ENTRY (glade_xml_get_widget (swidget->xml, PASS)));
if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (glade_xml_get_widget (swidget->xml, RM_SECURITY)))){
length = MED_SECURITY;
}else if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON (glade_xml_get_widget (swidget->xml, RH_SECURITY)))){
......@@ -156,19 +159,18 @@ on_druid_finish (GnomeDruidPage *gnomedruidpage, GtkWidget *widget, SeahorseWidg
widget2 = glade_xml_get_widget (swidget->xml, swidget->name);
gtk_widget_hide (widget2);
/* When we update to support S/MIME this will need to change */
sksrc = seahorse_context_find_key_source (SCTX_APP(), SKEY_PGP, SKEY_LOC_LOCAL);
g_return_if_fail (sksrc && SEAHORSE_IS_PGP_SOURCE (sksrc));
/* When we update to support S/MIME this will need to change */
sksrc = seahorse_context_find_key_source (SCTX_APP(), SKEY_PGP, SKEY_LOC_LOCAL);
g_return_if_fail (sksrc && SEAHORSE_IS_PGP_SOURCE (sksrc));
err = seahorse_pgp_key_op_generate (SEAHORSE_PGP_SOURCE (sksrc), name, email, comment,
pass, type, length, expires);
if (!GPG_IS_OK (err)) {
gtk_widget_show (widget2);
seahorse_util_handle_gpgme (err, _("Couldn't generate key"));
}
op = seahorse_pgp_key_op_generate (SEAHORSE_PGP_SOURCE (sksrc), name, email, comment,
pass, type, length, expires, &err);
if (GPG_IS_OK (err))
seahorse_progress_show (op, _("Generating Key"), TRUE);
else
gtk_widget_destroy (widget2);
seahorse_util_handle_gpgme (err, _("Couldn't generate key"));
gtk_widget_destroy (widget2);
}
gboolean
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment