diff options
-rw-r--r-- | camel/ChangeLog | 9 | ||||
-rw-r--r-- | camel/camel-cipher-context.h | 3 | ||||
-rw-r--r-- | camel/camel-pgp-context.c | 137 | ||||
-rw-r--r-- | camel/camel-pgp-mime.c | 3 |
4 files changed, 100 insertions, 52 deletions
diff --git a/camel/ChangeLog b/camel/ChangeLog index b11dd5310b..d1d41fd8fb 100644 --- a/camel/ChangeLog +++ b/camel/ChangeLog @@ -1,5 +1,14 @@ 2002-03-07 Jeffrey Stedfast <fejj@ximian.com> + * camel-pgp-mime.c (camel_pgp_mime_part_sign): Add support for + hash type RIPEMD160. + + * camel-cipher-context.h: Add RIPEMD160 hash type. + + * camel-pgp-context.c (pgp_sign): Updated to consider hash + function for pgp5 and pgp6. + (pgp_clearsign): Same. + * camel-tcp-stream-openssl.c (stream_read): Add a timeout on the select. (stream_write): Same. diff --git a/camel/camel-cipher-context.h b/camel/camel-cipher-context.h index 80f07f2a43..5147cc5ebc 100644 --- a/camel/camel-cipher-context.h +++ b/camel/camel-cipher-context.h @@ -43,7 +43,8 @@ typedef enum { CAMEL_CIPHER_HASH_DEFAULT, CAMEL_CIPHER_HASH_MD2, CAMEL_CIPHER_HASH_MD5, - CAMEL_CIPHER_HASH_SHA1 + CAMEL_CIPHER_HASH_SHA1, + CAMEL_CIPHER_HASH_RIPEMD160 } CamelCipherHash; typedef struct _CamelCipherContext { diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c index 85354dca7f..29a948e881 100644 --- a/camel/camel-pgp-context.c +++ b/camel/camel-pgp-context.c @@ -540,6 +540,53 @@ crypto_exec_with_passwd (const char *path, char *argv[], const char *input, int * Public crypto functions *----------------------------------------------------------------------*/ +static char * +hash_string (CamelPgpContext *ctx, CamelCipherHash hash) +{ + if (hash == CAMEL_CIPHER_HASH_DEFAULT) + return NULL; + + switch (ctx->priv->type) { + case CAMEL_PGP_TYPE_GPG: + switch (hash) { + case CAMEL_CIPHER_HASH_MD2: + return "MD2"; + case CAMEL_CIPHER_HASH_MD5: + return "MD5"; + case CAMEL_CIPHER_HASH_SHA1: + return "SHA1"; + case CAMEL_CIPHER_HASH_RIPEMD160: + return "RIPEMD160"; + default: + g_assert_not_reached (); + } + break; + case CAMEL_PGP_TYPE_PGP2: + /* FIXME: find a way to specify a hash algorithm for pgp2 */ + return NULL; + case CAMEL_PGP_TYPE_PGP5: + case CAMEL_PGP_TYPE_PGP6: + switch (hash) { + case CAMEL_CIPHER_HASH_MD2: + return "+hashnum=5"; + case CAMEL_CIPHER_HASH_MD5: + return "+hashnum=1"; + case CAMEL_CIPHER_HASH_SHA1: + return "+hashnum=2"; + case CAMEL_CIPHER_HASH_RIPEMD160: + return "+hashnum=3"; + default: + g_assert_not_reached (); + } + break; + default: + g_assert_not_reached (); + break; + } + + return NULL; +} + static int pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, CamelStream *istream, CamelStream *ostream, CamelException *ex) @@ -590,20 +637,7 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, goto exception; } - switch (hash) { - case CAMEL_CIPHER_HASH_DEFAULT: - hash_str = NULL; - break; - case CAMEL_CIPHER_HASH_MD5: - hash_str = "MD5"; - break; - case CAMEL_CIPHER_HASH_SHA1: - hash_str = "SHA1"; - break; - default: - g_assert_not_reached (); - break; - } + hash_str = hash_string (context, hash); i = 0; switch (context->priv->type) { @@ -639,38 +673,44 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash, argv[i++] = passwd_fd; break; case CAMEL_PGP_TYPE_PGP5: - /* FIXME: respect hash */ argv[i++] = "pgps"; + if (hash_str) + argv[i++] = hash_str; + if (userid) { argv[i++] = "-u"; argv[i++] = (char *) userid; } - argv[i++] = "-b"; - argv[i++] = "-f"; - argv[i++] = "-z"; - argv[i++] = "-a"; - argv[i++] = "-o"; - argv[i++] = "-"; /* output to stdout */ + argv[i++] = "-b"; /* -b means break off (detach) the signature */ + argv[i++] = "-f"; /* -f means act as a unix-style filter */ + argv[i++] = "-v"; /* -v means verbose diagnostic messages */ + argv[i++] = "-z"; /* FIXME: do we want this option!? */ + argv[i++] = "-a"; /* -a means ascii armor */ + argv[i++] = "-o"; /* -o specifies an output stream */ + argv[i++] = "-"; /* ...in this case, stdout */ sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); putenv (passwd_fd); break; case CAMEL_PGP_TYPE_PGP2: case CAMEL_PGP_TYPE_PGP6: - /* FIXME: respect hash */ argv[i++] = "pgp"; + if (hash_str) + argv[i++] = hash_str; + if (userid) { argv[i++] = "-u"; argv[i++] = (char *) userid; } - argv[i++] = "-f"; - argv[i++] = "-a"; - argv[i++] = "-o"; - argv[i++] = "-"; + argv[i++] = "-f"; /* -f means act as a unix-style filter */ + argv[i++] = "-l"; /* -l means show longer more descriptive diagnostic messages */ + argv[i++] = "-a"; /* -a means ascii armor */ + argv[i++] = "-o"; /* -o specifies an output stream */ + argv[i++] = "-"; /* ...in this case, stdout */ argv[i++] = "-sb"; /* create a detached signature */ sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); @@ -771,20 +811,7 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash goto exception; } - switch (hash) { - case CAMEL_CIPHER_HASH_DEFAULT: - hash_str = NULL; - break; - case CAMEL_CIPHER_HASH_MD5: - hash_str = "MD5"; - break; - case CAMEL_CIPHER_HASH_SHA1: - hash_str = "SHA1"; - break; - default: - g_assert_not_reached (); - break; - } + hash_str = hash_string (context, hash); i = 0; switch (context->priv->type) { @@ -820,37 +847,43 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash argv[i++] = passwd_fd; break; case CAMEL_PGP_TYPE_PGP5: - /* FIXME: modify to respect hash */ argv[i++] = "pgps"; + if (hash_str) + argv[i++] = hash_str; + if (userid) { argv[i++] = "-u"; argv[i++] = (char *) userid; } - argv[i++] = "-f"; - argv[i++] = "-z"; - argv[i++] = "-a"; - argv[i++] = "-o"; - argv[i++] = "-"; /* output to stdout */ + argv[i++] = "-f"; /* -f means act as a unix-style filter */ + argv[i++] = "-v"; /* -v means verbose diagnostic messages */ + argv[i++] = "-z"; /* FIXME: do we want this option!? */ + argv[i++] = "-a"; /* -a means ascii armor */ + argv[i++] = "-o"; /* -o specifies an output stream */ + argv[i++] = "-"; /* ...in this case, stdout */ sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); putenv (passwd_fd); break; case CAMEL_PGP_TYPE_PGP2: case CAMEL_PGP_TYPE_PGP6: - /* FIXME: modify to respect hash */ argv[i++] = "pgp"; + if (hash_str) + argv[i++] = hash_str; + if (userid) { argv[i++] = "-u"; argv[i++] = (char *) userid; } - argv[i++] = "-f"; - argv[i++] = "-a"; - argv[i++] = "-o"; - argv[i++] = "-"; + argv[i++] = "-f"; /* -f means act as a unix-style filter */ + argv[i++] = "-l"; /* -l means show longer more descriptive diagnostic messages */ + argv[i++] = "-a"; /* -a means ascii armor */ + argv[i++] = "-o"; /* -o specifies an output stream */ + argv[i++] = "-"; /* ...in this case, stdout */ argv[i++] = "-st"; sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); @@ -1383,6 +1416,7 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream, break; case CAMEL_PGP_TYPE_PGP5: argv[i++] = "pgpv"; + argv[i++] = "-f"; argv[i++] = "+batchmode=1"; @@ -1392,6 +1426,7 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream, case CAMEL_PGP_TYPE_PGP2: case CAMEL_PGP_TYPE_PGP6: argv[i++] = "pgp"; + argv[i++] = "-f"; sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); diff --git a/camel/camel-pgp-mime.c b/camel/camel-pgp-mime.c index 4e3eee7cba..47458803a5 100644 --- a/camel/camel-pgp-mime.c +++ b/camel/camel-pgp-mime.c @@ -294,6 +294,9 @@ camel_pgp_mime_part_sign (CamelPgpContext *context, CamelMimePart **mime_part, c case CAMEL_CIPHER_HASH_SHA1: hash_type = "pgp-sha1"; break; + case CAMEL_CIPHER_HASH_RIPEMD160: + hash_type = "pgp-ripemd160"; + break; default: /* set a reasonable default */ hash = CAMEL_CIPHER_HASH_SHA1; |