diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-08-06 14:34:14 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-08-06 14:34:14 +0800 |
commit | 43e3ba9da9a44b1f0ad6a5f78a27927f5cc8b531 (patch) | |
tree | 18a2fddb1ded7ce680f329473dc8576282466676 /mail | |
parent | c115cff69df04b7580fd8a50e087c7bd53614cec (diff) | |
download | gsoc2013-evolution-43e3ba9da9a44b1f0ad6a5f78a27927f5cc8b531.tar.gz gsoc2013-evolution-43e3ba9da9a44b1f0ad6a5f78a27927f5cc8b531.tar.zst gsoc2013-evolution-43e3ba9da9a44b1f0ad6a5f78a27927f5cc8b531.zip |
Added support for encrypting with GnuPG. Support for PGP5 and PGP2 are
2000-08-06 Jeffrey Stedfast <fejj@helixcode.com>
* mail-crypto.c (mail_crypto_openpgp_encrypt): Added support for
encrypting with GnuPG. Support for PGP5 and PGP2 are still in
progress.
svn path=/trunk/; revision=4557
Diffstat (limited to 'mail')
-rw-r--r-- | mail/ChangeLog | 6 | ||||
-rw-r--r-- | mail/mail-crypto.c | 109 | ||||
-rw-r--r-- | mail/mail.h | 6 |
3 files changed, 120 insertions, 1 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 2bc98fcc11..222df97211 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,9 @@ +2000-08-06 Jeffrey Stedfast <fejj@helixcode.com> + + * mail-crypto.c (mail_crypto_openpgp_encrypt): Added support for + encrypting with GnuPG. Support for PGP5 and PGP2 are still in + progress. + 2000-08-05 Dan Winship <danw@helixcode.com> * folder-browser-factory.c (control_activate): Remove bonobo 0.15 diff --git a/mail/mail-crypto.c b/mail/mail-crypto.c index 4db4357b44..7f8c22af12 100644 --- a/mail/mail-crypto.c +++ b/mail/mail-crypto.c @@ -10,6 +10,7 @@ * Authors: * Nathan Thompson-Amato <ndt@jps.net> * Dan Winship <danw@helixcode.com> + * Jeffrey Stedfast <fejj@helixcode.com> * * Copyright 2000, Helix Code, Inc. (http://www.helixcode.com) * Copyright 2000, Nathan Thompson-Amato @@ -339,7 +340,7 @@ mail_crypto_openpgp_decrypt (const char *ciphertext, const char *passphrase, #ifndef PGP_PROGRAM camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, - "No GPG/PGP program available."); + _("No GPG/PGP program available.")); return NULL; #endif @@ -402,4 +403,110 @@ mail_crypto_openpgp_decrypt (const char *ciphertext, const char *passphrase, return plaintext; } +char * +mail_crypto_openpgp_encrypt (const char *plaintext, const GPtrArray *recipients, const char *passphrase, + gboolean sign, CamelException *ex) +{ + GPtrArray *recipient_list = NULL; + int retval; + char *path, *argv[12]; + int i, r; + char *cyphertext = NULL; + char *diagnostics = NULL; + int passwd_fds[2]; + char passwd_fd[32]; + +#ifndef PGP_PROGRAM + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("No GPG/PGP program available.")); + return NULL; +#endif + + if (pipe (passwd_fds) < 0) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + _("Couldn't create pipe to GPG/PGP: %s"), + g_strerror (errno)); + return NULL; + } + + i = 0; +#if defined(GPG_PATH) + path = GPG_PATH; + + recipient_list = g_ptr_array_new (); + for (r = 0; r < recipients->len; r++) { + char *buf, *recipient; + + recipient = recipients->pdata[i]; + buf = g_strdup_printf ("-r %s", recipient); + g_ptr_array_add (recipient_list, buf); + } + + argv[i++] = "gpg"; + argv[i++] = "--verbose"; + argv[i++] = "--yes"; + argv[i++] = "--batch"; + + argv[i++] = "--armor"; + + for (r = 0; r < recipient_list->len; r++) + argv[i++] = recipient_list->pdata[r]; + + argv[i++] = "--output"; + argv[i++] = "-"; /* output to stdout */ + + argv[i++] = "--encrypt"; + + if (sign) { + argv[i++] = "--sign"; + + argv[i++] = "--passphrase-fd"; + sprintf (passwd_fd, "%d", passwd_fds[0]); + argv[i++] = passwd_fd; + } +#elif defined(PGP5_PATH) /* FIXME: from here down needs to be modified to work correctly */ + path = PGP5_PATH; + + argv[i++] = "pgpe"; + argv[i++] = "-f"; + argv[i++] = "-z"; + argv[i++] = "-a"; + + if (sign) + argv[i++] = "-s"; + + sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); + putenv (passwd_fd); +#else + path = PGP_PATH; + + argv[i++] = "pgp"; + argv[i++] = "-f"; + + sprintf (passwd_fd, "PGPPASSFD=%d", passwd_fds[0]); + putenv (passwd_fd); +#endif + argv[i++] = NULL; + + retval = crypto_exec_with_passwd (path, argv, plaintext, passwd_fds, + passphrase, &cyphertext, + &diagnostics); + + if (retval != 0 || !*cyphertext) { + camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM, + "%s", diagnostics); + g_free (cyphertext); + cyphertext = NULL; + } + + if (recipient_list) { + for (r = 0; r < recipient_list->len; r++) + g_free (recipient_list->pdata[r]); + g_ptr_array_free (recipient_list, TRUE); + } + + g_free (diagnostics); + return cyphertext; +} + #endif /* PGP_PROGRAM */ diff --git a/mail/mail.h b/mail/mail.h index 83f5001605..6247ae5d24 100644 --- a/mail/mail.h +++ b/mail/mail.h @@ -36,6 +36,12 @@ CamelFolder *mail_uri_to_folder (const char *uri); char *mail_crypto_openpgp_decrypt (const char *ciphertext, const char *passphrase, CamelException *ex); + +char *mail_crypto_openpgp_encrypt (const char *plaintext, + const GPtrArray *recipients, + const char *passphrase, + gboolean sign, + CamelException *ex); /* FIXME: add encryption & signing functions */ /* mail-format */ |