# include "config.h"
#endif
+#include <lib-lib/str.h>
+#include <lib-lib/file.h>
+#include <lib-lib/ascii.h>
+#include <lib-lib/mem.h>
+#include <lib-lib/macros.h>
+
+#include <lib-mime/mime.h>
+
#include "mutt.h"
+#include "handler.h"
#include "mutt_curses.h"
-#include "mime.h"
#include "copy.h"
#include "mutt_crypt.h"
#include "pgp.h"
-#include "lib/mem.h"
-#include "lib/intl.h"
-#include "lib/str.h"
#include <sys/wait.h>
#include <string.h>
/* print the current time to avoid spoofing of the signature output */
-void crypt_current_time (STATE * s, char *app_name)
+void crypt_current_time (STATE * s, const char *app_name)
{
time_t t;
char p[STRING], tmp[STRING];
- if (!WithCrypto)
- return;
-
if (option (OPTCRYPTTIMESTAMP)) {
t = time (NULL);
setlocale (LC_TIME, "");
void crypt_forget_passphrase (void)
{
- if ((WithCrypto & APPLICATION_PGP))
crypt_pgp_void_passphrase ();
-
- if ((WithCrypto & APPLICATION_SMIME))
crypt_smime_void_passphrase ();
-
- if (WithCrypto)
mutt_message _("Passphrase(s) forgotten.");
}
disable_coredumps ();
# endif
- if ((WithCrypto & APPLICATION_PGP) && (flags & APPLICATION_PGP))
+ if (flags & APPLICATION_PGP)
ret = crypt_pgp_valid_passphrase ();
- if ((WithCrypto & APPLICATION_SMIME) && (flags & APPLICATION_SMIME))
+ if (flags & APPLICATION_SMIME)
ret = crypt_smime_valid_passphrase ();
return ret;
BODY *pbody = NULL, *tmp_pbody = NULL;
BODY *tmp_smime_pbody = NULL;
BODY *tmp_pgp_pbody = NULL;
- int flags = (WithCrypto & APPLICATION_PGP) ? msg->security : 0;
+ int flags = msg->security;
int i;
- if (!WithCrypto)
- return -1;
-
if ((msg->security & SIGN) && !crypt_valid_passphrase (msg->security))
return (-1);
- if ((WithCrypto & APPLICATION_PGP)
- && ((msg->security & PGPINLINE) == PGPINLINE)) {
+ if ((msg->security & PGPINLINE) == PGPINLINE) {
/* they really want to send it inline... go for it */
if (!isendwin ())
mutt_endwin _("Invoking PGP...");
if (!isendwin ())
mutt_endwin (NULL);
- if ((WithCrypto & APPLICATION_SMIME))
- tmp_smime_pbody = msg->content;
- if ((WithCrypto & APPLICATION_PGP))
- tmp_pgp_pbody = msg->content;
+ tmp_smime_pbody = msg->content;
+ tmp_pgp_pbody = msg->content;
if (msg->security & SIGN) {
- if ((WithCrypto & APPLICATION_SMIME)
- && (msg->security & APPLICATION_SMIME)) {
+ if (msg->security & APPLICATION_SMIME) {
if (!(tmp_pbody = crypt_smime_sign_message (msg->content)))
return -1;
pbody = tmp_smime_pbody = tmp_pbody;
}
- if ((WithCrypto & APPLICATION_PGP)
- && (msg->security & APPLICATION_PGP)
+ if ((msg->security & APPLICATION_PGP)
&& (!(flags & ENCRYPT) || option (OPTPGPRETAINABLESIG))) {
if (!(tmp_pbody = crypt_pgp_sign_message (msg->content)))
return -1;
pbody = tmp_pgp_pbody = tmp_pbody;
}
- if (WithCrypto && (msg->security & APPLICATION_SMIME)
+ if ((msg->security & APPLICATION_SMIME)
&& (msg->security & APPLICATION_PGP)) {
/* here comes the draft ;-) */
}
if (msg->security & ENCRYPT) {
- if ((WithCrypto & APPLICATION_SMIME)
- && (msg->security & APPLICATION_SMIME)) {
+ if ((msg->security & APPLICATION_SMIME)) {
if (!(tmp_pbody = crypt_smime_build_smime_entity (tmp_smime_pbody,
keylist))) {
/* signed ? free it! */
pbody = tmp_pbody;
}
- if ((WithCrypto & APPLICATION_PGP)
- && (msg->security & APPLICATION_PGP)) {
+ if ((msg->security & APPLICATION_PGP)) {
if (!(pbody = crypt_pgp_encrypt_message (tmp_pgp_pbody, keylist,
flags & SIGN))) {
if (!(ascii_strcasecmp (p, "multipart/mixed")))
return SIGN;
- if ((WithCrypto & APPLICATION_PGP)
- && !(ascii_strcasecmp (p, "application/pgp-signature")))
+ if (!(ascii_strcasecmp (p, "application/pgp-signature")))
return PGPSIGN;
- if ((WithCrypto & APPLICATION_SMIME)
- && !(ascii_strcasecmp (p, "application/x-pkcs7-signature")))
+ if (!(ascii_strcasecmp (p, "application/x-pkcs7-signature")))
return SMIMESIGN;
- if ((WithCrypto & APPLICATION_SMIME)
- && !(ascii_strcasecmp (p, "application/pkcs7-signature")))
+ if (!(ascii_strcasecmp (p, "application/pkcs7-signature")))
return SMIMESIGN;
return 0;
int mutt_is_multipart_encrypted (BODY * b)
{
- if ((WithCrypto & APPLICATION_PGP)) {
- char *p;
-
- if (!b || b->type != TYPEMULTIPART ||
- !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") ||
- !(p = mutt_get_parameter ("protocol", b->parameter)) ||
- ascii_strcasecmp (p, "application/pgp-encrypted"))
- return 0;
+ char *p;
- return PGPENCRYPT;
- }
+ if (!b || b->type != TYPEMULTIPART ||
+ !b->subtype || ascii_strcasecmp (b->subtype, "encrypted") ||
+ !(p = mutt_get_parameter ("protocol", b->parameter)) ||
+ ascii_strcasecmp (p, "application/pgp-encrypted"))
+ return 0;
- return 0;
+ return PGPENCRYPT;
}
/* no .p7c, .p10 support yet. */
- len = mutt_strlen (t) - 4;
+ len = m_strlen(t) - 4;
if (len > 0 && *(t + len) == '.') {
len++;
if (!ascii_strcasecmp ((t + len), "p7m"))
{
int t = 0;
- if (!WithCrypto)
- return 0;
-
if (!m)
return 0;
if (m->type == TYPEAPPLICATION) {
- if ((WithCrypto & APPLICATION_PGP))
- t |= mutt_is_application_pgp (m);
-
- if ((WithCrypto & APPLICATION_SMIME)) {
- t |= mutt_is_application_smime (m);
- if (t && m->goodsig)
- t |= GOODSIGN;
- if (t && m->badsig)
- t |= BADSIGN;
- }
+ t |= mutt_is_application_pgp (m);
+
+ t |= mutt_is_application_smime (m);
+ if (t && m->goodsig)
+ t |= GOODSIGN;
+ if (t && m->badsig)
+ t |= BADSIGN;
}
- else if ((WithCrypto & APPLICATION_PGP) && m->type == TYPETEXT) {
+ else if (m->type == TYPETEXT) {
t |= mutt_is_application_pgp (m);
if (t && m->goodsig)
t |= GOODSIGN;
short hadcr;
size_t bytes;
- if (!WithCrypto)
- return -1;
-
if (!(fp = safe_fopen (tempfile, "w"))) {
mutt_perror (tempfile);
return -1;
}
- fseek (s->fpin, a->hdr_offset, 0);
+ fseeko (s->fpin, a->hdr_offset, 0);
bytes = a->length + a->offset - a->hdr_offset;
hadcr = 0;
while (bytes > 0) {
void convert_to_7bit (BODY * a)
{
- if (!WithCrypto)
- return;
-
while (a) {
if (a->type == TYPEMULTIPART) {
if (a->encoding != ENC7BIT) {
a->encoding = ENC7BIT;
convert_to_7bit (a->parts);
}
- else if ((WithCrypto & APPLICATION_PGP) && option (OPTPGPSTRICTENC))
+ else if (option (OPTPGPSTRICTENC))
convert_to_7bit (a->parts);
}
else if (a->type == TYPEMESSAGE &&
- mutt_strcasecmp (a->subtype, "delivery-status")) {
+ m_strcasecmp(a->subtype, "delivery-status")) {
if (a->encoding != ENC7BIT)
mutt_message_to_7bit (a, NULL);
}
{
int i;
char tempfname[_POSIX_PATH_MAX], *mbox;
- ADDRESS *tmp = NULL;
+ address_t *tmp = NULL;
FILE *fpout;
- if (!WithCrypto)
- return;
-
mutt_mktemp (tempfname);
if (!(fpout = safe_fopen (tempfname, "w"))) {
mutt_perror (tempfname);
return;
}
- if ((WithCrypto & APPLICATION_PGP))
- set_option (OPTDONTHANDLEPGPKEYS);
+ set_option (OPTDONTHANDLEPGPKEYS);
if (!h) {
for (i = 0; i < Context->vcount; i++) {
break;
}
- if ((WithCrypto & APPLICATION_PGP)
- && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP)) {
+ if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_PGP) {
mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
M_CM_DECODE | M_CM_CHARCONV, 0);
fflush (fpout);
crypt_pgp_invoke_import (tempfname);
}
- if ((WithCrypto & APPLICATION_SMIME)
- && (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME)) {
+ if (Context->hdrs[Context->v2r[i]]->security & APPLICATION_SMIME) {
if (Context->hdrs[Context->v2r[i]]->security & ENCRYPT)
mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]],
M_CM_NOHEADER | M_CM_DECODE_CRYPT
else {
mutt_parse_mime_message (Context, h);
if (!(h->security & ENCRYPT && !crypt_valid_passphrase (h->security))) {
- if ((WithCrypto & APPLICATION_PGP)
- && (h->security & APPLICATION_PGP)) {
+ if (h->security & APPLICATION_PGP) {
mutt_copy_message (fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0);
fflush (fpout);
mutt_endwin (_("Trying to extract PGP keys...\n"));
crypt_pgp_invoke_import (tempfname);
}
- if ((WithCrypto & APPLICATION_SMIME)
- && (h->security & APPLICATION_SMIME)) {
+ if (h->security & APPLICATION_SMIME) {
if (h->security & ENCRYPT)
mutt_copy_message (fpout, Context, h, M_CM_NOHEADER
| M_CM_DECODE_CRYPT | M_CM_DECODE_SMIME, 0);
mutt_unlink (tempfname);
- if ((WithCrypto & APPLICATION_PGP))
- unset_option (OPTDONTHANDLEPGPKEYS);
+ unset_option (OPTDONTHANDLEPGPKEYS);
}
* keys if the user has requested this service.
*/
- if (!WithCrypto)
- return 0;
-
- if ((WithCrypto & APPLICATION_PGP))
- set_option (OPTPGPCHECKTRUST);
+ set_option (OPTPGPCHECKTRUST);
*keylist = NULL;
if (msg->security & ENCRYPT) {
- if ((WithCrypto & APPLICATION_PGP)
- && (msg->security & APPLICATION_PGP)) {
+ if (msg->security & APPLICATION_PGP) {
if ((*keylist = crypt_pgp_findkeys (msg->env->to, msg->env->cc,
msg->env->bcc)) == NULL)
return (-1);
unset_option (OPTPGPCHECKTRUST);
}
- if ((WithCrypto & APPLICATION_SMIME)
- && (msg->security & APPLICATION_SMIME)) {
+ if (msg->security & APPLICATION_SMIME) {
if ((*keylist = crypt_smime_findkeys (msg->env->to, msg->env->cc,
msg->env->bcc)) == NULL)
return (-1);
-static void crypt_fetch_signatures (BODY *** signatures, BODY * a, int *n)
+static void crypt_fetch_signatures (BODY ***signatures, BODY * a, int *n)
{
- if (!WithCrypto)
- return;
-
for (; a; a = a->next) {
if (a->type == TYPEMULTIPART)
crypt_fetch_signatures (signatures, a->parts, n);
else {
if ((*n % 5) == 0)
- safe_realloc (signatures, (*n + 6) * sizeof (BODY **));
+ p_realloc(signatures, *n + 6);
(*signatures)[(*n)++] = a;
}
* This routine verifies a "multipart/signed" body.
*/
-void mutt_signed_handler (BODY * a, STATE * s)
+int mutt_signed_handler (BODY * a, STATE * s)
{
char tempfile[_POSIX_PATH_MAX];
char *protocol;
int sigcnt = 0;
int i;
short goodsig = 1;
-
- if (!WithCrypto)
- return;
+ int rc = 0;
protocol = mutt_get_parameter ("protocol", a->parameter);
a = a->parts;
if ((protocol_minor = strchr (protocol, '/')))
protocol_minor++;
- strfcpy (major, protocol, sizeof (major));
+ m_strcpy(major, sizeof(major), protocol);
if ((t = strchr (major, '/')))
*t = '\0';
/* consistency check */
if (!(a && a->next && a->next->type == protocol_major &&
- !mutt_strcasecmp (a->next->subtype, protocol_minor))) {
+ !m_strcasecmp(a->next->subtype, protocol_minor))) {
state_attach_puts (_("[-- Error: "
"Inconsistent multipart/signed structure! --]\n\n"),
s);
- mutt_body_handler (a, s);
- return;
+ return mutt_body_handler (a, s);
}
- if ((WithCrypto & APPLICATION_PGP)
- && protocol_major == TYPEAPPLICATION
- && !mutt_strcasecmp (protocol_minor, "pgp-signature"));
- else if ((WithCrypto & APPLICATION_SMIME)
- && protocol_major == TYPEAPPLICATION
- && !(mutt_strcasecmp (protocol_minor, "x-pkcs7-signature")
- && mutt_strcasecmp (protocol_minor, "pkcs7-signature")));
+ if (protocol_major == TYPEAPPLICATION
+ && !m_strcasecmp(protocol_minor, "pgp-signature"));
+ else if (protocol_major == TYPEAPPLICATION
+ && !(m_strcasecmp(protocol_minor, "x-pkcs7-signature")
+ && m_strcasecmp(protocol_minor, "pkcs7-signature")));
else if (protocol_major == TYPEMULTIPART
- && !mutt_strcasecmp (protocol_minor, "mixed"));
+ && !m_strcasecmp(protocol_minor, "mixed"));
else {
state_printf (s, _("[-- Error: "
"Unknown multipart/signed protocol %s! --]\n\n"),
protocol);
- mutt_body_handler (a, s);
- return;
+ return mutt_body_handler (a, s);
}
if (s->flags & M_DISPLAY) {
mutt_mktemp (tempfile);
if (crypt_write_signed (a, s, tempfile) == 0) {
for (i = 0; i < sigcnt; i++) {
- if ((WithCrypto & APPLICATION_PGP)
- && signatures[i]->type == TYPEAPPLICATION
- && !mutt_strcasecmp (signatures[i]->subtype, "pgp-signature")) {
+ if (signatures[i]->type == TYPEAPPLICATION
+ && !m_strcasecmp(signatures[i]->subtype, "pgp-signature")) {
if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0)
goodsig = 0;
continue;
}
- if ((WithCrypto & APPLICATION_SMIME)
- && signatures[i]->type == TYPEAPPLICATION
- &&
- (!mutt_strcasecmp (signatures[i]->subtype, "x-pkcs7-signature")
- || !mutt_strcasecmp (signatures[i]->subtype,
- "pkcs7-signature"))) {
+ if (signatures[i]->type == TYPEAPPLICATION
+ && (!m_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature")
+ || !m_strcasecmp(signatures[i]->subtype, "pkcs7-signature")))
+ {
if (crypt_smime_verify_one (signatures[i], s, tempfile) != 0)
goodsig = 0;
state_attach_puts (_("[-- The following data is signed --]\n\n"), s);
- FREE (&signatures);
+ p_delete(&signatures);
}
else
state_attach_puts (_("[-- Warning: Can't find any signatures. --]\n\n"),
s);
}
- mutt_body_handler (a, s);
+ rc = mutt_body_handler (a, s);
if (s->flags & M_DISPLAY && sigcnt)
state_attach_puts (_("\n[-- End of signed data --]\n"), s);
+
+ return (rc);
}