aboutsummaryrefslogtreecommitdiffstats
path: root/camel/camel-pgp-context.c
diff options
context:
space:
mode:
Diffstat (limited to 'camel/camel-pgp-context.c')
-rw-r--r--camel/camel-pgp-context.c210
1 files changed, 59 insertions, 151 deletions
diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c
index 246b35d691..16b3ea72b7 100644
--- a/camel/camel-pgp-context.c
+++ b/camel/camel-pgp-context.c
@@ -43,8 +43,6 @@
#include <sys/types.h>
#include <dirent.h>
-#include <ctype.h>
-
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/time.h>
@@ -53,8 +51,6 @@
#include <termios.h>
#include <unistd.h>
-#include <ctype.h>
-
#include <iconv.h>
#include <gal/unicode/gunicode.h>
#include <gal/util/e-iconv.h>
@@ -80,19 +76,12 @@ static int pgp_encrypt (CamelCipherContext *context, gboolean s
static int pgp_decrypt (CamelCipherContext *context, CamelStream *istream,
CamelStream *ostream, CamelException *ex);
-static const char *pgp_hash_to_id(CamelCipherContext *context, CamelCipherHash hash);
-static CamelCipherHash pgp_id_to_hash(CamelCipherContext *context, const char *id);
-
static CamelCipherContextClass *parent_class;
static void
camel_pgp_context_init (CamelPgpContext *context)
{
- CamelCipherContext *ciph = (CamelCipherContext *)context;
-
context->priv = g_new0 (struct _CamelPgpContextPrivate, 1);
-
- ciph->protocol = "application/pgp-signature";
}
static void
@@ -118,8 +107,6 @@ camel_pgp_context_class_init (CamelPgpContextClass *camel_pgp_context_class)
camel_cipher_context_class->verify = pgp_verify;
camel_cipher_context_class->encrypt = pgp_encrypt;
camel_cipher_context_class->decrypt = pgp_decrypt;
- camel_cipher_context_class->hash_to_id = pgp_hash_to_id;
- camel_cipher_context_class->id_to_hash = pgp_id_to_hash;
}
CamelType
@@ -435,17 +422,18 @@ crypto_exec_with_passwd (const char *path, char *argv[], const char *input, int
select_result = select (max + 1, &fdset, &write_fdset,
NULL, &timeout);
+ if (cancel_fd != -1 && FD_ISSET (cancel_fd, &fdset)) {
+ /* user-cancelled */
+ break;
+ }
+
if (select_result < 0) {
if (errno == EINTR)
continue;
break;
- } else if (select_result == 0) {
- /* timeout */
- break;
}
-
- if (cancel_fd != -1 && FD_ISSET (cancel_fd, &fdset)) {
- /* user-cancelled */
+ if (select_result == 0) {
+ /* timeout */
break;
}
@@ -552,53 +540,6 @@ 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)
@@ -649,7 +590,20 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash,
goto exception;
}
- hash_str = hash_string (context, hash);
+ 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;
+ }
i = 0;
switch (context->priv->type) {
@@ -672,7 +626,6 @@ pgp_sign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash,
argv[i++] = "--no-secmem-warning";
argv[i++] = "--no-greeting";
argv[i++] = "--yes";
- argv[i++] = "--always-trust";
argv[i++] = "--batch";
argv[i++] = "--armor";
@@ -685,44 +638,38 @@ 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"; /* -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 */
+ argv[i++] = "-b";
+ argv[i++] = "-f";
+ argv[i++] = "-z";
+ argv[i++] = "-a";
+ argv[i++] = "-o";
+ argv[i++] = "-"; /* output to 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"; /* -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++] = "-f";
+ argv[i++] = "-a";
+ argv[i++] = "-o";
+ argv[i++] = "-";
argv[i++] = "-sb"; /* create a detached signature */
sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]);
@@ -780,7 +727,7 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash
CamelPgpContext *context = CAMEL_PGP_CONTEXT (ctx);
GByteArray *plaintext;
CamelStream *stream;
- char *argv[20];
+ char *argv[15];
char *ciphertext = NULL;
char *diagnostics = NULL;
char *passphrase = NULL;
@@ -823,7 +770,20 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash
goto exception;
}
- hash_str = hash_string (context, hash);
+ 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;
+ }
i = 0;
switch (context->priv->type) {
@@ -846,7 +806,6 @@ pgp_clearsign (CamelCipherContext *ctx, const char *userid, CamelCipherHash hash
argv[i++] = "--no-secmem-warning";
argv[i++] = "--no-greeting";
argv[i++] = "--yes";
- argv[i++] = "--always-trust";
argv[i++] = "--batch";
argv[i++] = "--armor";
@@ -859,43 +818,37 @@ 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"; /* -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 */
+ argv[i++] = "-f";
+ argv[i++] = "-z";
+ argv[i++] = "-a";
+ argv[i++] = "-o";
+ argv[i++] = "-"; /* output to 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"; /* -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++] = "-f";
+ argv[i++] = "-a";
+ argv[i++] = "-o";
+ argv[i++] = "-";
argv[i++] = "-st";
sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]);
@@ -1228,7 +1181,6 @@ pgp_encrypt (CamelCipherContext *ctx, gboolean sign, const char *userid, GPtrArr
g_ptr_array_add (argv, "--no-secmem-warning");
g_ptr_array_add (argv, "--no-greeting");
g_ptr_array_add (argv, "--yes");
- g_ptr_array_add (argv, "--always-trust");
g_ptr_array_add (argv, "--batch");
g_ptr_array_add (argv, "--armor");
@@ -1428,7 +1380,6 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream,
break;
case CAMEL_PGP_TYPE_PGP5:
argv[i++] = "pgpv";
-
argv[i++] = "-f";
argv[i++] = "+batchmode=1";
@@ -1438,7 +1389,6 @@ 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]);
@@ -1489,45 +1439,3 @@ pgp_decrypt (CamelCipherContext *ctx, CamelStream *istream,
return -1;
}
-
-/* this has a 1:1 relationship to CamelCipherHash */
-static char *name_table[] = {
- "pgp-sha1", /* we use sha1 as the 'default' */
- "pgp-md2",
- "pgp-md5",
- "pgp-sha1",
- "pgp-ripemd160",
-};
-
-static const char *pgp_hash_to_id(CamelCipherContext *context, CamelCipherHash hash)
-{
- /* if we dont know, just use default? */
- if (hash > sizeof(name_table)/sizeof(name_table[0]))
- hash = CAMEL_CIPHER_HASH_DEFAULT;
-
- return name_table[hash];
-}
-
-static CamelCipherHash pgp_id_to_hash(CamelCipherContext *context, const char *id)
-{
- int i;
- unsigned char *tmpid, *o;
- const char *in;
- unsigned char c;
-
- if (id == NULL)
- return CAMEL_CIPHER_HASH_DEFAULT;
-
- tmpid = alloca(strlen(id)+1);
- in = id;
- o = tmpid;
- while ((c = (unsigned char)*in++))
- *o++ = tolower(c);
-
- for (i=1;i<sizeof(name_table)/sizeof(name_table[0]);i++) {
- if (!strcmp(name_table[i], tmpid))
- return i;
- }
-
- return CAMEL_CIPHER_HASH_DEFAULT;
-}