X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=crypt.c;h=bc44714e942486822fd2fdf2d53c46c86e668b74;hp=c0c64ad4ab46d6edc3552251d4c3722ef2df23b9;hb=10b7d54ecaa5c54622bf1239b57fa2e3359db0e1;hpb=51c07577bff89fde3038940cc06ac01bc28557b9 diff --git a/crypt.c b/crypt.c index c0c64ad..bc44714 100644 --- a/crypt.c +++ b/crypt.c @@ -59,9 +59,6 @@ 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, ""); @@ -80,13 +77,8 @@ void crypt_current_time (STATE * s, const char *app_name) 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."); } @@ -115,10 +107,10 @@ int crypt_valid_passphrase (int flags) 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; @@ -131,17 +123,13 @@ int mutt_protect (HEADER * msg, char *keylist) 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..."); @@ -169,21 +157,17 @@ int mutt_protect (HEADER * msg, char *keylist) 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; @@ -192,7 +176,7 @@ int mutt_protect (HEADER * msg, char *keylist) 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 ;-) */ } @@ -200,8 +184,7 @@ int mutt_protect (HEADER * msg, char *keylist) 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! */ @@ -218,8 +201,7 @@ int mutt_protect (HEADER * msg, char *keylist) 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))) { @@ -268,15 +250,12 @@ int mutt_is_multipart_signed (BODY * b) 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; @@ -285,19 +264,15 @@ int mutt_is_multipart_signed (BODY * b) 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; } @@ -419,25 +394,19 @@ int crypt_query (BODY * m) { 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; @@ -482,9 +451,6 @@ int crypt_write_signed (BODY * a, STATE * s, const char *tempfile) short hadcr; size_t bytes; - if (!WithCrypto) - return -1; - if (!(fp = safe_fopen (tempfile, "w"))) { mutt_perror (tempfile); return -1; @@ -520,16 +486,13 @@ int crypt_write_signed (BODY * a, STATE * s, const char *tempfile) 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 && @@ -559,17 +522,13 @@ void crypt_extract_keys_from_messages (HEADER * h) 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++) { @@ -582,8 +541,7 @@ void crypt_extract_keys_from_messages (HEADER * h) 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); @@ -592,8 +550,7 @@ void crypt_extract_keys_from_messages (HEADER * h) 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 @@ -623,16 +580,14 @@ void crypt_extract_keys_from_messages (HEADER * h) 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); @@ -659,8 +614,7 @@ void crypt_extract_keys_from_messages (HEADER * h) mutt_unlink (tempfname); - if ((WithCrypto & APPLICATION_PGP)) - unset_option (OPTDONTHANDLEPGPKEYS); + unset_option (OPTDONTHANDLEPGPKEYS); } @@ -671,24 +625,18 @@ int crypt_get_keys (HEADER * msg, char **keylist) * 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); @@ -702,9 +650,6 @@ int crypt_get_keys (HEADER * msg, char **keylist) 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); @@ -736,9 +681,6 @@ int mutt_signed_handler (BODY * a, STATE * s) short goodsig = 1; int rc = 0; - if (!WithCrypto) - return (-1); - protocol = mutt_get_parameter ("protocol", a->parameter); a = a->parts; @@ -769,11 +711,9 @@ int mutt_signed_handler (BODY * a, STATE * s) } - if ((WithCrypto & APPLICATION_PGP) - && protocol_major == TYPEAPPLICATION + if (protocol_major == TYPEAPPLICATION && !m_strcasecmp(protocol_minor, "pgp-signature")); - else if ((WithCrypto & APPLICATION_SMIME) - && protocol_major == TYPEAPPLICATION + else if (protocol_major == TYPEAPPLICATION && !(m_strcasecmp(protocol_minor, "x-pkcs7-signature") && m_strcasecmp(protocol_minor, "pkcs7-signature"))); else if (protocol_major == TYPEMULTIPART @@ -793,8 +733,7 @@ int mutt_signed_handler (BODY * a, STATE * s) 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 + if (signatures[i]->type == TYPEAPPLICATION && !m_strcasecmp(signatures[i]->subtype, "pgp-signature")) { if (crypt_pgp_verify_one (signatures[i], s, tempfile) != 0) goodsig = 0; @@ -802,12 +741,10 @@ int mutt_signed_handler (BODY * a, STATE * s) continue; } - if ((WithCrypto & APPLICATION_SMIME) - && signatures[i]->type == TYPEAPPLICATION - && - (!m_strcasecmp(signatures[i]->subtype, "x-pkcs7-signature") - || !m_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;