aboutsummaryrefslogtreecommitdiffstats
path: root/camel
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2002-06-25 14:21:17 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2002-06-25 14:21:17 +0800
commitb62bbc149b31f928ea0f7c6c60e28a72555bb88f (patch)
treedeb5f57d73b749775ac1820115f332a790bd7248 /camel
parent0b6f593b29ad4ff7e7c06d9f0b2b46b629830098 (diff)
downloadgsoc2013-evolution-b62bbc149b31f928ea0f7c6c60e28a72555bb88f.tar.gz
gsoc2013-evolution-b62bbc149b31f928ea0f7c6c60e28a72555bb88f.tar.zst
gsoc2013-evolution-b62bbc149b31f928ea0f7c6c60e28a72555bb88f.zip
Return the option as --digest-algo=<micalg> (gpg_ctx_parse_status): Decode
2002-06-25 Jeffrey Stedfast <fejj@ximian.com> * camel-gpg-context.c (gpg_hash_str): Return the option as --digest-algo=<micalg> (gpg_ctx_parse_status): Decode more status information and keep track of trust and such. (gpg_ctx_op_complete): Make sure we aren't waiting for gpg to write data to stdout (such as encrypted/decrypted data or a signature). (gpg_encrypt): Remove the fejj@stampede.org hard-coded value (which had only meant to be for testing). svn path=/trunk/; revision=17271
Diffstat (limited to 'camel')
-rw-r--r--camel/ChangeLog12
-rw-r--r--camel/camel-gpg-context.c90
2 files changed, 82 insertions, 20 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog
index bf05be0b7c..c8c04ef5c4 100644
--- a/camel/ChangeLog
+++ b/camel/ChangeLog
@@ -1,3 +1,15 @@
+2002-06-25 Jeffrey Stedfast <fejj@ximian.com>
+
+ * camel-gpg-context.c (gpg_hash_str): Return the option as
+ --digest-algo=<micalg>
+ (gpg_ctx_parse_status): Decode more status information and keep
+ track of trust and such.
+ (gpg_ctx_op_complete): Make sure we aren't waiting for gpg to
+ write data to stdout (such as encrypted/decrypted data or a
+ signature).
+ (gpg_encrypt): Remove the fejj@stampede.org hard-coded value
+ (which had only meant to be for testing).
+
2002-06-24 Jeffrey Stedfast <fejj@ximian.com>
* camel-gpg-context.c (gpg_ctx_get_argv): Use --command-fd rather
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 608bb42dc8..1cea8fbe37 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -213,6 +213,14 @@ enum _GpgCtxMode {
GPG_CTX_MODE_DECRYPT,
};
+enum _GpgTrustMetric {
+ GPG_TRUST_UNKNOWN,
+ GPG_TRUST_NEVER,
+ GPG_TRUST_MARGINAL,
+ GPG_TRUST_FULLY,
+ GPG_TRUST_ULTIMATE
+};
+
struct _GpgCtx {
enum _GpgCtxMode mode;
CamelSession *session;
@@ -244,6 +252,7 @@ struct _GpgCtx {
GByteArray *diagnostics;
unsigned int complete:1;
+ unsigned int await_read:1;
unsigned int reading:1;
unsigned int always_trust:1;
unsigned int armor:1;
@@ -252,7 +261,10 @@ struct _GpgCtx {
unsigned int bad_passwds:2;
- unsigned int padding:24;
+ unsigned int validsig:1;
+ unsigned int trust:3;
+
+ unsigned int padding:19;
};
static struct _GpgCtx *
@@ -266,6 +278,7 @@ gpg_ctx_new (CamelSession *session, const char *path)
camel_object_ref (CAMEL_OBJECT (session));
gpg->userid_hint = g_hash_table_new (g_str_hash, g_str_equal);
gpg->complete = FALSE;
+ gpg->await_read = FALSE;
gpg->reading = FALSE;
gpg->pid = (pid_t) -1;
@@ -292,6 +305,9 @@ gpg_ctx_new (CamelSession *session, const char *path)
gpg->send_passwd = FALSE;
gpg->passwd = NULL;
+ gpg->validsig = FALSE;
+ gpg->trust = GPG_TRUST_UNKNOWN;
+
gpg->istream = NULL;
gpg->ostream = NULL;
@@ -438,13 +454,13 @@ gpg_hash_str (CamelCipherHash hash)
{
switch (hash) {
case CAMEL_CIPHER_HASH_MD2:
- return "MD2";
+ return "--digest-algo=MD2";
case CAMEL_CIPHER_HASH_MD5:
- return "MD5";
+ return "--digest-algo=MD5";
case CAMEL_CIPHER_HASH_SHA1:
- return "SHA1";
+ return "--digest-algo=SHA1";
case CAMEL_CIPHER_HASH_RIPEMD160:
- return "RIPEMD160";
+ return "--digest-algo=RIPEMD160";
default:
return NULL;
}
@@ -487,10 +503,8 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, char **sfd, int passwd_fd,
if (gpg->armor)
g_ptr_array_add (argv, "--armor");
hash_str = gpg_hash_str (gpg->hash);
- if (hash_str) {
- g_ptr_array_add (argv, "--digest-algo");
+ if (hash_str)
g_ptr_array_add (argv, (char *) hash_str);
- }
if (gpg->userid) {
g_ptr_array_add (argv, "-u");
g_ptr_array_add (argv, (char *) gpg->userid);
@@ -532,6 +546,10 @@ gpg_ctx_get_argv (struct _GpgCtx *gpg, int status_fd, char **sfd, int passwd_fd,
break;
}
+ for (i = 0; i < argv->len; i++)
+ printf ("%s ", argv->pdata[i]);
+ printf ("\n");
+
g_ptr_array_add (argv, NULL);
return argv;
@@ -742,9 +760,9 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
g_free (passwd);
gpg->send_passwd = TRUE;
- } else if (!strncmp (status, "GOOD_PASSPHRASE ", 16)) {
+ } else if (!strncmp (status, "GOOD_PASSPHRASE", 15)) {
gpg->bad_passwds = 0;
- } else if (!strncmp (status, "BAD_PASSPHRASE ", 15)) {
+ } else if (!strncmp (status, "BAD_PASSPHRASE", 14)) {
gpg->bad_passwds++;
camel_session_forget_password (gpg->session, NULL, gpg->userid, ex);
@@ -764,24 +782,54 @@ gpg_ctx_parse_status (struct _GpgCtx *gpg, CamelException *ex)
/* check to see if we are complete */
switch (gpg->mode) {
case GPG_CTX_MODE_SIGN:
- if (!strncmp (status, "SIG_CREATED ", 12))
+ if (!strncmp (status, "SIG_CREATED ", 12)) {
gpg->complete = TRUE;
+ gpg->await_read = TRUE;
+ }
break;
case GPG_CTX_MODE_VERIFY:
- /* FIXME: we should save this so we can present it to the user? */
- /* Note: NO_PUBKEY often comes after an ERRSIG, but do we really care? */
- if (!strncmp (status, "TRUST_", 6) ||
- !strncmp (status, "BADSIG", 6) ||
- !strncmp (status, "ERRSIG", 6))
+ if (!strncmp (status, "TRUST_", 6)) {
+ status += 6;
+ if (!strncmp (status, "NEVER", 5)) {
+ gpg->trust = GPG_TRUST_NEVER;
+ } else if (!strncmp (status, "MARGINAL", 8)) {
+ gpg->trust = GPG_TRUST_MARGINAL;
+ } else if (!strncmp (status, "FULLY", 5)) {
+ gpg->trust = GPG_TRUST_FULLY;
+ } else if (!strncmp (status, "ULTIMATE", 8)) {
+ gpg->trust = GPG_TRUST_ULTIMATE;
+ }
+
+ gpg->complete = TRUE;
+ } else if (!strncmp (status, "VALIDSIG", 8)) {
+ gpg->validsig = TRUE;
gpg->complete = TRUE;
+ } else if (!strncmp (status, "BADSIG", 6)) {
+ gpg->validsig = FALSE;
+ gpg->complete = TRUE;
+ } else if (!strncmp (status, "ERRSIG", 6)) {
+ /* Note: NO_PUBKEY often comes after an ERRSIG, but do we really care? */
+ gpg->validsig = FALSE;
+ gpg->complete = TRUE;
+ }
break;
case GPG_CTX_MODE_ENCRYPT:
- if (!strncmp (status, "END_ENCRYPTION", 14))
+ if (!strncmp (status, "BEGIN_ENCRYPTION", 16)) {
+ gpg->await_read = TRUE;
+ } else if (!strncmp (status, "END_ENCRYPTION", 14)) {
gpg->complete = TRUE;
+ } else if (!strncmp (status, "NO_RECP", 7)) {
+ camel_exception_set (ex, CAMEL_EXCEPTION_SYSTEM,
+ _("Failed to encrypt: No valid recipients specified."));
+ return -1;
+ }
break;
case GPG_CTX_MODE_DECRYPT:
- if (!strncmp (status, "END_DECRYPTION", 14))
+ if (!strncmp (status, "BEGIN_DECRYPTION", 16)) {
+ gpg->await_read = TRUE;
+ } else if (!strncmp (status, "END_DECRYPTION", 14)) {
gpg->complete = TRUE;
+ }
break;
}
@@ -913,6 +961,8 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
if (camel_stream_write (gpg->ostream, buffer, (size_t) nread) == -1)
goto exception;
+ gpg->await_read = FALSE;
+
/* make sure we don't exit before reading all the data... */
gpg->reading = TRUE;
}
@@ -1030,7 +1080,7 @@ gpg_ctx_op_step (struct _GpgCtx *gpg, CamelException *ex)
static gboolean
gpg_ctx_op_complete (struct _GpgCtx *gpg)
{
- return gpg->complete && !gpg->reading;
+ return gpg->complete && !gpg->await_read && !gpg->reading;
}
static void
@@ -1282,7 +1332,7 @@ gpg_encrypt (CamelCipherContext *context, gboolean sign, const char *userid,
gpg = gpg_ctx_new (context->session, ctx->path);
gpg_ctx_set_mode (gpg, GPG_CTX_MODE_ENCRYPT);
gpg_ctx_set_armor (gpg, TRUE);
- gpg_ctx_set_userid (gpg, "fejj@stampede.org");
+ gpg_ctx_set_userid (gpg, userid);
gpg_ctx_set_istream (gpg, istream);
gpg_ctx_set_ostream (gpg, ostream);
gpg_ctx_set_always_trust (gpg, ctx->always_trust);