diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-03-08 04:11:35 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-03-08 04:11:35 +0800 |
commit | 2d62db45411f0d7ffa18bf2d5ef904445844ae8c (patch) | |
tree | b7ccb191b5fd82edc8caa9dc08448e7dce1749f4 /camel/camel-pgp-context.c | |
parent | 17fd352c3b2ccbc9dcfc9d199e7363fe40cd379f (diff) | |
download | gsoc2013-evolution-2d62db45411f0d7ffa18bf2d5ef904445844ae8c.tar.gz gsoc2013-evolution-2d62db45411f0d7ffa18bf2d5ef904445844ae8c.tar.zst gsoc2013-evolution-2d62db45411f0d7ffa18bf2d5ef904445844ae8c.zip |
Add support for hash type RIPEMD160.
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.
svn path=/trunk/; revision=15969
Diffstat (limited to 'camel/camel-pgp-context.c')
-rw-r--r-- | camel/camel-pgp-context.c | 137 |
1 files changed, 86 insertions, 51 deletions
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]); |