[Gpa-commits] r929 - trunk/src
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Sun Jan 11 15:44:42 CET 2009
Author: moritzs
Date: 2009-01-11 15:44:40 +0100 (Sun, 11 Jan 2009)
New Revision: 929
Modified:
trunk/src/ChangeLog
trunk/src/gpagenkeycardop.c
trunk/src/gpgmeedit.c
trunk/src/gpgmeedit.h
Log:
2009-01-11 Moritz <moritz at gnu.org>
* gpagenkeycardop.c (gpa_gen_key_card_operation_done_cb): Do not
use gpgme_op_genkey_result to retrieve result information about
the generated key.
(gpa_gen_key_card_operation_idle_cb): Call
gpa_gpgme_card_edit_genkey_start.
Include "gpgmeedit.h".
* gpgmeedit.h: Declare gpa_gpgme_card_genkey_start.
* gpgmeedit.c (struct genkey_parms_s): New struct.
(card_edit_genkey_fnc_action, card_edit_genkey_fnc_transit)
(card_edit_genkey_parms_release, calculate_expiration_day)
(card_edit_genkey_parms_new, gpa_gpgme_card_edit_genkey_start): New functions.
Include <assert.h>.
Added several new CARD_... symbols in enum.
Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog 2009-01-08 18:30:07 UTC (rev 928)
+++ trunk/src/ChangeLog 2009-01-11 14:44:40 UTC (rev 929)
@@ -1,3 +1,20 @@
+2009-01-11 Moritz <moritz at gnu.org>
+
+ * gpagenkeycardop.c (gpa_gen_key_card_operation_done_cb): Do not
+ use gpgme_op_genkey_result to retrieve result information about
+ the generated key.
+ (gpa_gen_key_card_operation_idle_cb): Call
+ gpa_gpgme_card_edit_genkey_start.
+ Include "gpgmeedit.h".
+
+ * gpgmeedit.h: Declare gpa_gpgme_card_genkey_start.
+ * gpgmeedit.c (struct genkey_parms_s): New struct.
+ (card_edit_genkey_fnc_action, card_edit_genkey_fnc_transit)
+ (card_edit_genkey_parms_release, calculate_expiration_day)
+ (card_edit_genkey_parms_new, gpa_gpgme_card_edit_genkey_start): New functions.
+ Include <assert.h>.
+ Added several new CARD_... symbols in enum.
+
2009-01-08 Marcus Brinkmann <marcus at g10code.de>
* cardman.c (struct _GpaCardManager): New members status_label,
Modified: trunk/src/gpagenkeycardop.c
===================================================================
--- trunk/src/gpagenkeycardop.c 2009-01-08 18:30:07 UTC (rev 928)
+++ trunk/src/gpagenkeycardop.c 2009-01-11 14:44:40 UTC (rev 929)
@@ -1,6 +1,6 @@
/* gpagenkeycardop.c - The GpaGenKeyCardOperation object.
* Copyright (C) 2003 Miguel Coca.
- * Copyright (C) 2008 g10 Code GmbH
+ * Copyright (C) 2008, 2009 g10 Code GmbH
*
* This file is part of GPA
*
@@ -27,6 +27,7 @@
#include "gtktools.h"
#include "gpagenkeycardop.h"
#include "keygendlg.h"
+#include "gpgmeedit.h"
static GObjectClass *parent_class = NULL;
@@ -155,12 +156,11 @@
GPAKeyGenParameters *parms;
parms = gpa_key_gen_run_dialog (GPA_OPERATION (op)->window, 1);
-#if 0
if (!parms)
g_signal_emit_by_name (op, "completed", gpg_error (GPG_ERR_CANCELED));
else
{
- err = gpa_generate_key_start (GPA_OPERATION (op)->context->ctx, parms);
+ err = gpa_gpgme_card_edit_genkey_start (GPA_OPERATION (op)->context, parms);
if (err)
{
gpa_gpgme_warning (err);
@@ -169,23 +169,21 @@
else
gtk_widget_show_all (op->progress_dialog);
}
-#else
- g_signal_emit_by_name (op, "completed", gpg_error (GPG_ERR_CANCELED));
-#endif
-
return FALSE;
}
static void
gpa_gen_key_card_operation_done_cb (GpaContext *context,
- gpg_error_t err,
- GpaGenKeyCardOperation *op)
+ gpg_error_t err,
+ GpaGenKeyCardOperation *op)
{
if (! err)
{
- gpgme_genkey_result_t result = gpgme_op_genkey_result (context->ctx);
- g_signal_emit_by_name (op, "generated_key", result->fpr);
+ /* This is not a gpgme_op_genkey operation, thus we cannot use
+ gpgme_op_genkey_result to retrieve result information about
+ the generated key. */
+ g_signal_emit_by_name (op, "generated_key", NULL);
}
g_signal_emit_by_name (op, "completed", err);
}
@@ -193,8 +191,8 @@
static void
gpa_gen_key_card_operation_done_error_cb (GpaContext *context,
- gpg_error_t err,
- GpaGenKeyCardOperation *op)
+ gpg_error_t err,
+ GpaGenKeyCardOperation *op)
{
switch (gpg_err_code (err))
{
Modified: trunk/src/gpgmeedit.c
===================================================================
--- trunk/src/gpgmeedit.c 2009-01-08 18:30:07 UTC (rev 928)
+++ trunk/src/gpgmeedit.c 2009-01-11 14:44:40 UTC (rev 929)
@@ -1,6 +1,6 @@
/* gpgmetools.c - The GNU Privacy Assistant
* Copyright (C) 2002 Miguel Coca.
- * Copyright (C) 2008 g10 Code GmbH.
+ * Copyright (C) 2008, 2009 g10 Code GmbH.
*
* This file is part of GPA
*
@@ -22,6 +22,8 @@
# include <config.h>
#endif
+#include <assert.h>
+
#include "gpgmeedit.h"
#include "passwddlg.h"
@@ -42,7 +44,7 @@
*/
/* Define this macro to 1 to enable debugging of the FSM. */
-#define DEBUG_FSM 0
+#define DEBUG_FSM 1
/* Prototype of the action function. Returns the error if there is one */
@@ -128,6 +130,13 @@
CARD_ADMIN_COMMAND,
CARD_QUIT,
CARD_QUERY_LOGIN,
+ CARD_GENERATE_BACKUP,
+ CARD_GENERATE_REPLACE_KEYS,
+ CARD_GENERATE_VALIDITY,
+ CARD_GENERATE_NAME,
+ CARD_GENERATE_EMAIL,
+ CARD_GENERATE_COMMENT,
+ CARD_GENERATE_DONE,
CARD_ERROR
};
@@ -1210,7 +1219,302 @@
return err;
}
+/*
+ * GENKEY
+ */
+struct genkey_parms_s
+{
+ char expiration_day[11]; /* "YYYY-MM-DD". */
+ char *name;
+ char *email;
+ char *comment;
+};
+
+static gpg_error_t
+card_edit_genkey_fnc_action (int state, void *opaque, char **result)
+{
+ struct genkey_parms_s *parms = opaque;
+
+ switch (state)
+ {
+ case CARD_COMMAND:
+ *result = "admin";
+ break;
+
+ case CARD_ADMIN_COMMAND:
+ *result = "generate";
+ break;
+
+ case CARD_GENERATE_BACKUP:
+ /* FIXME: disable encryption key backup functionality for
+ now. -mo */
+ *result = "N";
+ break;
+
+ case CARD_GENERATE_REPLACE_KEYS:
+ /* FIXME: simply replace existing keys for now. -mo */
+ *result = "Y";
+ break;
+
+ case CARD_GENERATE_VALIDITY:
+ *result = parms->expiration_day;
+ break;
+
+ case CARD_GENERATE_NAME:
+ *result = parms->name;
+ break;
+
+ case CARD_GENERATE_EMAIL:
+ *result = parms->email;
+ break;
+
+ case CARD_GENERATE_COMMENT:
+ *result = parms->comment;
+ break;
+
+ case CARD_GENERATE_DONE:
+ *result = NULL;
+ break;
+
+ case CARD_QUIT:
+ *result = "quit";
+ break;
+ }
+
+ return 0; /* FIXME? */
+}
+
+static int
+card_edit_genkey_fnc_transit (int current_state, gpgme_status_code_t status,
+ const char *args, void *opaque, gpg_error_t *err)
+{
+ int next_state;
+
+ switch (current_state)
+ {
+ case CARD_START:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "cardedit.prompt"))
+ next_state = CARD_COMMAND;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_COMMAND:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "cardedit.prompt"))
+ next_state = CARD_ADMIN_COMMAND;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_ADMIN_COMMAND:
+ if (status == GPGME_STATUS_GET_BOOL &&
+ g_str_equal (args, "cardedit.genkeys.backup_enc"))
+ next_state = CARD_GENERATE_BACKUP;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_BACKUP:
+ if (status == GPGME_STATUS_GET_BOOL &&
+ g_str_equal (args, "cardedit.genkeys.replace_keys"))
+ next_state = CARD_GENERATE_REPLACE_KEYS;
+ else if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "keygen.valid"))
+ next_state = CARD_GENERATE_VALIDITY;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_REPLACE_KEYS:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "keygen.valid"))
+ next_state = CARD_GENERATE_VALIDITY;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_VALIDITY:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "keygen.name"))
+ next_state = CARD_GENERATE_NAME;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_NAME:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "keygen.email"))
+ next_state = CARD_GENERATE_EMAIL;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_EMAIL:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "keygen.comment"))
+ next_state = CARD_GENERATE_COMMENT;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_COMMENT:
+ if (status == GPGME_STATUS_KEY_CREATED)
+ next_state = CARD_GENERATE_DONE;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ case CARD_GENERATE_DONE:
+ if (status == GPGME_STATUS_GET_LINE &&
+ g_str_equal (args, "cardedit.prompt"))
+ next_state = CARD_QUIT;
+ else
+ {
+ next_state = CARD_ERROR;
+ *err = gpg_error (GPG_ERR_GENERAL);
+ }
+ break;
+
+ }
+
+ return next_state;
+}
+
+static void
+card_edit_genkey_parms_release (GpaContext *ctx, gpg_error_t err,
+ struct edit_parms_s *parms)
+{
+ gpgme_data_release (parms->out);
+ if (parms->signal_id != 0)
+ {
+ /* Don't run this signal handler again if the context is reused */
+ g_signal_handler_disconnect (ctx, parms->signal_id);
+ }
+ g_free (parms->opaque);
+ g_free (parms);
+}
+
+static void
+calculate_expiration_day (GPAKeyGenParameters *parms, char *expiration_day, size_t length)
+{
+ assert (length >= 11);
+
+ if (parms->expiryDate)
+ g_date_strftime (expiration_day, length, "%Y-%m-%d", parms->expiryDate);
+ else if (parms->interval)
+ {
+ GDate *date = g_date_new ();
+ g_date_set_time_t (date, time (NULL));
+
+ assert ((parms->unit == 'd') || (parms->unit == 'w')
+ || (parms->unit == 'm') || (parms->unit == 'y'));
+
+ switch (parms->unit)
+ {
+ case 'd':
+ g_date_add_days (date, parms->interval);
+ break;
+ case 'w':
+ g_date_add_days (date, parms->interval * 7);
+ break;
+ case 'm':
+ g_date_add_months (date, parms->interval);
+ break;
+ case 'y':
+ g_date_add_years (date, parms->interval);
+ break;
+ }
+
+ g_date_strftime (expiration_day, length, "%Y-%m-%d", date);
+ g_date_free (date);
+ }
+ else
+ /* Never expire. */
+ strcpy (expiration_day, "0");
+}
+
+/* Generate the edit parameters needed for setting owner trust. */
+static struct edit_parms_s *
+card_edit_genkey_parms_new (GpaContext *ctx, GPAKeyGenParameters *parms, gpgme_data_t out)
+{
+ struct edit_parms_s *edit_parms = g_malloc (sizeof (struct edit_parms_s));
+ struct genkey_parms_s *genkey_parms = g_malloc (sizeof (struct genkey_parms_s));
+
+ edit_parms->state = CARD_START;
+ edit_parms->err = 0;
+ edit_parms->action = card_edit_genkey_fnc_action;
+ edit_parms->transit = card_edit_genkey_fnc_transit;
+ edit_parms->signal_id = 0;
+ edit_parms->out = out;
+ edit_parms->opaque = genkey_parms;
+
+ calculate_expiration_day (parms, genkey_parms->expiration_day,
+ sizeof (genkey_parms->expiration_day));
+ genkey_parms->name = parms->userID;
+ genkey_parms->email = parms->email;
+ genkey_parms->comment = parms->comment;
+
+ /* Make sure the cleanup is run when the edit completes */
+ edit_parms->signal_id =
+ g_signal_connect (G_OBJECT (ctx), "done",
+ G_CALLBACK (card_edit_genkey_parms_release),
+ edit_parms);
+
+ return edit_parms;
+}
+
+gpg_error_t
+gpa_gpgme_card_edit_genkey_start (GpaContext *ctx, GPAKeyGenParameters *genkey_parms)
+{
+ struct edit_parms_s *edit_parms;
+ gpgme_data_t out = NULL;
+ gpg_error_t err;
+
+ err = gpgme_data_new (&out);
+ if (gpg_err_code (err) != GPG_ERR_NO_ERROR)
+ {
+ return err;
+ }
+
+ edit_parms = card_edit_genkey_parms_new (ctx, genkey_parms, out);
+
+ err = gpgme_op_card_edit_start (ctx->ctx, NULL, edit_fnc, edit_parms, out);
+
+ return err;
+}
+
+
+
#if 0 /* DISABLED */
/* Modify. */
Modified: trunk/src/gpgmeedit.h
===================================================================
--- trunk/src/gpgmeedit.h 2009-01-08 18:30:07 UTC (rev 928)
+++ trunk/src/gpgmeedit.h 2009-01-11 14:44:40 UTC (rev 929)
@@ -1,5 +1,6 @@
/* gpgmeedit.h - The GNU Privacy Assistant
* Copyright (C) 2002, Miguel Coca.
+ * Copyright (C) 2008, 2009 g10 Code GmbH.
*
* This file is part of GPA
*
@@ -51,8 +52,9 @@
output. */
gpg_error_t gpa_gpgme_card_edit_list_start (GpaContext *ctx, gpgme_data_t out);
+gpg_error_t gpa_gpgme_card_edit_genkey_start (GpaContext *ctx, GPAKeyGenParameters *parms);
+
#if 0
-gpg_error_t gpa_gpgme_card_edit_genkey_start (GpaContext *ctx, ...);
gpg_error_t gpa_gpgme_card_edit_modify_start (GpaContext *ctx, const gchar *login);
#endif
More information about the Gpa-commits
mailing list