diff options
-rw-r--r-- | camel/ChangeLog | 11 | ||||
-rw-r--r-- | camel/camel-pgp-context.c | 41 | ||||
-rw-r--r-- | camel/camel-pgp-context.h | 2 |
3 files changed, 30 insertions, 24 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index 75b16e3e4b..958d1c262f 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,3 +1,14 @@ +2001-09-25 Jeffrey Stedfast <fejj@ximian.com> + + * camel-pgp-context.c (camel_pgp_context_new): No longer takes a + remember argument. + (pgp_sign): Only uncache the passphrase on failure. + (pgp_clearsign): Same. + (pgp_encrypt): Here too. + (pgp_decrypt): And here. + (pass_free): New function to zero the passphrase before freeing + it. + 2001-09-25 Ettore Perazzoli <ettore@ximian.com> [Patch for Automake 1.5 compatibility pointed out by Richard diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c index db87a0dd6c..5983dd71bb 100644 --- a/camel/camel-pgp-context.c +++ b/camel/camel-pgp-context.c @@ -58,7 +58,6 @@ struct _CamelPgpContextPrivate { CamelPgpType type; char *path; - gboolean remember; }; static int pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, @@ -141,7 +140,7 @@ camel_pgp_context_get_type (void) * Return value: the new CamelPgpContext **/ CamelPgpContext * -camel_pgp_context_new (CamelSession *session, CamelPgpType type, const char *path, gboolean remember) +camel_pgp_context_new (CamelSession *session, CamelPgpType type, const char *path) { CamelPgpContext *context; @@ -156,7 +155,6 @@ camel_pgp_context_new (CamelSession *session, CamelPgpType type, const char *pat context->priv->type = type; context->priv->path = g_strdup (path); - context->priv->remember = remember; return context; } @@ -216,6 +214,15 @@ pgp_forget_passphrase (CamelSession *session, CamelPgpType pgp_type, char *useri camel_session_forget_password (session, NULL, userid ? userid : type, NULL); } +static void +pass_free (char *passphrase) +{ + if (passphrase) { + memset (passphrase, 0, strlen (passphrase)); + g_free (passphrase); + } +} + static int cleanup_child (pid_t child) { @@ -630,7 +637,7 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, &diagnostics); g_byte_array_free (plaintext, TRUE); - g_free (passphrase); + pass_free (passphrase); if (retval != 0 || !*ciphertext) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, @@ -642,9 +649,6 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, return -1; } - if (!context->priv->remember) - pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); - g_free (diagnostics); camel_stream_write (ostream, ciphertext, strlen (ciphertext)); @@ -658,7 +662,7 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, if (passphrase) { pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); - g_free (passphrase); + pass_free (passphrase); } return -1; @@ -804,7 +808,7 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash &diagnostics); g_byte_array_free (plaintext, TRUE); - g_free (passphrase); + pass_free (passphrase); if (retval != 0 || !*ciphertext) { camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, @@ -814,9 +818,6 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); } - if (!context->priv->remember) - pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); - g_free (diagnostics); camel_stream_write (ostream, ciphertext, strlen (ciphertext)); @@ -830,7 +831,7 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash if (passphrase) { pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); - g_free (passphrase); + pass_free (passphrase); } return -1; @@ -1192,7 +1193,7 @@ pgp_encrypt (CamelCipherContext *ctx, gboolean sign, const char *userid, GPtrArr g_byte_array_free (plaintext, TRUE); - g_free (passphrase); + pass_free (passphrase); g_ptr_array_free (argv, TRUE); if (retval != 0 || !*ciphertext) { @@ -1207,9 +1208,6 @@ pgp_encrypt (CamelCipherContext *ctx, gboolean sign, const char *userid, GPtrArr return -1; } - if (!context->priv->remember) - pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); - g_free (diagnostics); camel_stream_write (ostream, ciphertext, strlen (ciphertext)); @@ -1222,7 +1220,7 @@ pgp_encrypt (CamelCipherContext *ctx, gboolean sign, const char *userid, GPtrArr g_byte_array_free (plaintext, TRUE); if (sign) { - g_free (passphrase); + pass_free (passphrase); pgp_forget_passphrase (ctx->session, context->priv->type, (char *) userid); } @@ -1326,7 +1324,7 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream, &diagnostics); g_byte_array_free (ciphertext, TRUE); - g_free (passphrase); + pass_free (passphrase); /* gpg returns '1' if it succeedes in decrypting but can't verify the signature */ if (retval != 0 || (context->priv->type == CAMEL_PGP_TYPE_GPG && retval == 1) || !*plaintext) { @@ -1340,9 +1338,6 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream, return -1; } - if (!context->priv->remember) - pgp_forget_passphrase (ctx->session, context->priv->type, NULL); - g_free (diagnostics); camel_stream_write (ostream, plaintext, plainlen); @@ -1356,7 +1351,7 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream, if (passphrase) { pgp_forget_passphrase (ctx->session, context->priv->type, NULL); - g_free (passphrase); + pass_free (passphrase); } return -1; diff --git a/camel/camel-pgp-context.h b/camel/camel-pgp-context.h index 79149d60d4..4cf72b6174 100644 --- a/camel/camel-pgp-context.h +++ b/camel/camel-pgp-context.h @@ -61,7 +61,7 @@ typedef struct _CamelPgpContextClass { CamelType camel_pgp_context_get_type (void); CamelPgpContext *camel_pgp_context_new (CamelSession *session, CamelPgpType type, - const char *path, gboolean remember); + const char *path); /* PGP routines */ #define camel_pgp_sign(c, u, h, i, o, e) camel_cipher_sign (CAMEL_CIPHER_CONTEXT (c), u, h, i, o, e) |