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.c155
1 files changed, 59 insertions, 96 deletions
diff --git a/camel/camel-pgp-context.c b/camel/camel-pgp-context.c
index e6ef1a7820..16b3ea72b7 100644
--- a/camel/camel-pgp-context.c
+++ b/camel/camel-pgp-context.c
@@ -422,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;
}
@@ -539,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)
@@ -636,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) {
@@ -659,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";
@@ -672,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]);
@@ -767,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;
@@ -810,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) {
@@ -833,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";
@@ -846,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]);
@@ -1215,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");
@@ -1415,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";
@@ -1425,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]);