46 #include <gpg-error.h>
85 #define CRYPT_KV_VALID (1 << 0)
86 #define CRYPT_KV_ADDR (1 << 1)
87 #define CRYPT_KV_STRING (1 << 2)
88 #define CRYPT_KV_STRONGID (1 << 3)
89 #define CRYPT_KV_MATCH (CRYPT_KV_ADDR | CRYPT_KV_STRING)
106 #define PKA_NOTATION_NAME "pka-address@gnupg.org"
108 #define _LINE_COMPARE(_x, _y) line_compare(_x, sizeof(_x) - 1, _y)
109 #define MESSAGE(_y) _LINE_COMPARE("MESSAGE-----", _y)
110 #define SIGNED_MESSAGE(_y) _LINE_COMPARE("SIGNED MESSAGE-----", _y)
111 #define PUBLIC_KEY_BLOCK(_y) _LINE_COMPARE("PUBLIC KEY BLOCK-----", _y)
112 #define BEGIN_PGP_SIGNATURE(_y) \
113 _LINE_COMPARE("-----BEGIN PGP SIGNATURE-----", _y)
131 #if (GPGME_VERSION_NUMBER < 0x010800)
137 const char *s = gpgme_get_ctx_flag(ctx,
"redraw");
145 #if (GPGRT_VERSION_NUMBER >= 0x012100)
164 static int cmp_version_strings(const char *a, const char *b, int level)
166 return gpgrt_cmp_version(a, b, level);
168 #elif (GPGME_VERSION_NUMBER >= 0x010900)
182 static const char *parse_version_number(
const char *s,
int *number)
186 if ((*s ==
'0') && isdigit(s[1]))
188 for (; isdigit(s[0]); s++)
194 return (val < 0) ? NULL : s;
215 static const char *parse_version_string(
const char *s,
int *major,
int *minor,
int *micro)
217 s = parse_version_number(s, major);
225 s = parse_version_number(s, minor);
233 s = parse_version_number(s, micro);
260 static int cmp_version_strings(
const char *a,
const char *b,
int level)
262 int a_major, a_minor, a_micro;
263 int b_major, b_minor, b_micro;
264 const char *a_plvl = NULL, *b_plvl = NULL;
267 int positive, negative;
280 if ((ignore_plvl = (level > 9)))
283 a_major = a_minor = a_micro = 0;
284 a_plvl = parse_version_string(a, &a_major, (level > 1) ? &a_minor : NULL,
285 (level > 2) ? &a_micro : NULL);
287 a_major = a_minor = a_micro = 0;
289 b_major = b_minor = b_micro = 0;
290 b_plvl = parse_version_string(b, &b_major, (level > 1) ? &b_minor : NULL,
291 (level > 2) ? &b_micro : NULL);
293 b_major = b_minor = b_micro = 0;
297 if (!a_plvl && !b_plvl)
299 if (a_plvl && !b_plvl)
301 if (!a_plvl && b_plvl)
305 if (a_major > b_major)
307 if (a_major < b_major)
310 if (a_minor > b_minor)
312 if (a_minor < b_minor)
315 if (a_micro > b_micro)
317 if (a_micro < b_micro)
323 for (; *a_plvl && *b_plvl; a_plvl++, b_plvl++)
325 if ((*a_plvl ==
'.') && (*b_plvl ==
'.'))
327 r = strcmp(a_plvl, b_plvl);
338 if (*a_plvl != *b_plvl)
341 if (*a_plvl == *b_plvl)
343 if ((*(
signed char *) a_plvl - *(
signed char *) b_plvl) > 0)
359 const char *s =
"????????";
363 s = k->
kobj->subkeys->keyid;
365 if ((!c_pgp_long_ids) && (strlen(s) == 16))
384 const char *s =
"????????????????";
388 s = k->
kobj->subkeys->keyid;
401 const char *s =
"????????";
405 s = k->
kobj->subkeys->keyid;
423 s = k->
kobj->subkeys->fpr;
435 const char *s =
"????????????????";
439 if (k->
kobj->subkeys->fpr)
440 s = k->
kobj->subkeys->fpr;
442 s = k->
kobj->subkeys->keyid;
459 gpgme_key_ref(key->
kobj);
482 *keylist = (*keylist)->
next;
484 gpgme_key_unref(k->
kobj);
499 bool is_strong =
false;
506 case GPGME_VALIDITY_MARGINAL:
507 case GPGME_VALIDITY_NEVER:
508 case GPGME_VALIDITY_UNDEFINED:
509 case GPGME_VALIDITY_UNKNOWN:
513 case GPGME_VALIDITY_FULL:
514 case GPGME_VALIDITY_ULTIMATE:
583 gpgme_ctx_t ctx = NULL;
585 gpgme_error_t err = gpgme_new(&ctx);
590 err = gpgme_ctx_set_engine_info(ctx, GPGME_PROTOCOL_OpenPGP, NULL, c_autocrypt_dir);
595 mutt_error(
_(
"error creating GPGME context: %s"), gpgme_strerror(err));
601 err = gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
604 mutt_error(
_(
"error enabling CMS protocol: %s"), gpgme_strerror(err));
622 gpgme_data_t data = NULL;
624 gpgme_error_t err = gpgme_data_new(&data);
627 mutt_error(
_(
"error creating GPGME data object: %s"), gpgme_strerror(err));
633 #if (GPGME_VERSION_NUMBER >= 0x010900)
641 static bool have_gpg_version(const char *version)
643 static char *engine_version = NULL;
647 gpgme_ctx_t ctx = NULL;
648 gpgme_engine_info_t engineinfo = NULL;
651 engineinfo = gpgme_ctx_get_engine_info(ctx);
652 while (engineinfo && (engineinfo->protocol != GPGME_PROTOCOL_OpenPGP))
653 engineinfo = engineinfo->next;
666 return cmp_version_strings(engine_version, version, 3) >= 0;
679 gpgme_data_t data = NULL;
697 unsigned char buf[1];
701 while ((c = fgetc(fp_tmp)) != EOF)
707 if ((c ==
'\n') && !hadcr)
710 gpgme_data_write(
data, buf, 1);
717 gpgme_data_write(
data, buf, 1);
720 gpgme_data_seek(
data, 0, SEEK_SET);
728 mutt_error(
_(
"error allocating data object: %s"), gpgme_strerror(err));
729 gpgme_data_release(
data);
750 gpgme_data_t
data = NULL;
752 int err = gpgme_data_new_from_filepart(&
data, NULL, fp, offset, length);
755 mutt_error(
_(
"error allocating data object: %s"), gpgme_strerror(err));
774 int err = ((gpgme_data_seek(
data, 0, SEEK_SET) == -1) ? gpgme_error_from_errno(errno) : 0);
777 mutt_error(
_(
"error rewinding data object: %s"), gpgme_strerror(err));
781 while ((nread = gpgme_data_read(
data, buf,
sizeof(buf))) > 0)
785 for (
char *p = buf; nread; p++, nread--)
799 mutt_error(
_(
"error reading data object: %s"), strerror(errno));
831 int err = ((gpgme_data_seek(
data, 0, SEEK_SET) == -1) ? gpgme_error_from_errno(errno) : 0);
836 while ((nread = gpgme_data_read(
data, buf,
sizeof(buf))) > 0)
838 if (fwrite(buf, nread, 1, fp) != 1)
853 mutt_error(
_(
"error reading data object: %s"), gpgme_strerror(err));
867 #if (GPGME_VERSION_NUMBER >= 0x010b00)
874 static void create_recipient_string(const char *keylist, struct Buffer *recpstring, int use_smime)
878 const char *s = keylist;
894 while ((*s !=
'\0') && (*s !=
' '))
897 }
while (*s !=
'\0');
907 gpgme_key_t *rset = NULL;
918 gpgme_key_t k = *rset;
935 const char *s = NULL;
937 gpgme_key_t *rset = NULL;
938 unsigned int rset_n = 0;
939 gpgme_key_t key = NULL;
948 for (i = 0; *s && *s !=
' ' && i <
sizeof(buf) - 1;)
953 if ((i > 1) && (buf[i - 1] ==
'!'))
958 err = gpgme_get_key(context, buf, &key, 0);
960 key->uids->validity = GPGME_VALIDITY_FULL;
964 err = gpgme_get_key(context, buf, &key, 0);
967 rset[rset_n++] = key;
970 mutt_error(
_(
"error adding recipient '%s': %s"), buf, gpgme_strerror(err));
973 gpgme_release(context);
981 rset[rset_n++] = NULL;
983 gpgme_release(context);
1000 gpgme_key_t key = NULL, key2 = NULL;
1002 err = gpgme_op_keylist_start(listctx, address, 1);
1004 err = gpgme_op_keylist_next(listctx, &key);
1007 gpgme_release(listctx);
1008 mutt_error(
_(
"secret key '%s' not found: %s"), address, gpgme_strerror(err));
1014 fpr = key->subkeys->fpr ? key->subkeys->fpr : key->subkeys->keyid;
1015 while (gpgme_op_keylist_next(listctx, &key2) == 0)
1017 char *fpr2 =
"fpr2";
1019 fpr2 = key2->subkeys->fpr ? key2->subkeys->fpr : key2->subkeys->keyid;
1022 gpgme_key_unref(key);
1023 gpgme_key_unref(key2);
1024 gpgme_release(listctx);
1025 mutt_error(
_(
"ambiguous specification of secret key '%s'"), address);
1030 gpgme_key_unref(key2);
1033 gpgme_op_keylist_end(listctx);
1034 gpgme_release(listctx);
1036 gpgme_signers_clear(ctx);
1037 err = gpgme_signers_add(ctx, key);
1038 gpgme_key_unref(key);
1041 mutt_error(
_(
"error setting secret key '%s': %s"), address, gpgme_strerror(err));
1055 static int set_signer(gpgme_ctx_t ctx,
const struct AddressList *al,
bool for_smime)
1057 const char *signid = NULL;
1064 signid = c_smime_sign_as ? c_smime_sign_as : c_smime_default_key;
1065 #ifdef USE_AUTOCRYPT
1070 signid = c_pgp_sign_as ? c_pgp_sign_as : c_pgp_default_key;
1091 return (!signid && !al) ? 0 : -1;
1104 mutt_error(
_(
"error setting PKA signature notation: %s"), gpgme_strerror(err));
1120 bool combined_signed,
const struct AddressList *from)
1123 gpgme_ctx_t ctx = NULL;
1124 gpgme_data_t ciphertext = NULL;
1125 char *outfile = NULL;
1127 #if (GPGME_VERSION_NUMBER >= 0x010b00)
1129 create_recipient_string(keylist, recpstring, use_smime);
1143 gpgme_set_armor(ctx, 1);
1147 if (combined_signed)
1153 if (c_crypt_use_pka)
1160 #if (GPGME_VERSION_NUMBER >= 0x010b00)
1162 GPGME_ENCRYPT_ALWAYS_TRUST, plaintext, ciphertext);
1164 err = gpgme_op_encrypt_sign(ctx, rset, GPGME_ENCRYPT_ALWAYS_TRUST, plaintext, ciphertext);
1169 #if (GPGME_VERSION_NUMBER >= 0x010b00)
1171 GPGME_ENCRYPT_ALWAYS_TRUST, plaintext, ciphertext);
1173 err = gpgme_op_encrypt(ctx, rset, GPGME_ENCRYPT_ALWAYS_TRUST, plaintext, ciphertext);
1180 mutt_error(
_(
"error encrypting data: %s"), gpgme_strerror(err));
1187 #if (GPGME_VERSION_NUMBER >= 0x010b00)
1193 gpgme_data_release(ciphertext);
1209 static int get_micalg(gpgme_ctx_t ctx,
int use_smime,
char *buf,
size_t buflen)
1211 gpgme_sign_result_t result = NULL;
1212 const char *algorithm_name = NULL;
1218 result = gpgme_op_sign_result(ctx);
1219 if (result && result->signatures)
1221 algorithm_name = gpgme_hash_algo_name(result->signatures->hash_algo);
1227 snprintf(buf, buflen,
"%s", algorithm_name);
1233 snprintf(buf, buflen,
"pgp-%s", algorithm_name);
1239 return (buf[0] !=
'\0') ? 0 : -1;
1264 struct Body *t = NULL;
1265 char *sigfile = NULL;
1268 gpgme_ctx_t ctx = NULL;
1269 gpgme_data_t message = NULL, signature = NULL;
1270 gpgme_sign_result_t sigres = NULL;
1281 gpgme_set_armor(ctx, 1);
1285 gpgme_data_release(signature);
1286 gpgme_data_release(message);
1292 if (c_crypt_use_pka)
1297 gpgme_data_release(signature);
1298 gpgme_data_release(message);
1304 err = gpgme_op_sign(ctx, message, signature, GPGME_SIG_MODE_DETACH);
1306 gpgme_data_release(message);
1309 gpgme_data_release(signature);
1311 mutt_error(
_(
"error signing data: %s"), gpgme_strerror(err));
1316 sigres = gpgme_op_sign_result(ctx);
1317 if (!sigres->signatures)
1319 gpgme_data_release(signature);
1321 mutt_error(
_(
"$pgp_sign_as unset and no default key specified in ~/.gnupg/gpg.conf"));
1326 gpgme_data_release(signature);
1342 use_smime ?
"application/pkcs7-signature" :
"application/pgp-signature");
1345 if (
get_micalg(ctx, use_smime, buf,
sizeof(buf)) == 0)
1400 const struct AddressList *from)
1409 gpgme_data_release(plaintext);
1455 gpgme_data_release(plaintext);
1490 int idx,
struct State *s, gpgme_signature_t sig)
1495 bool severe =
false;
1497 if ((sum & GPGME_SIGSUM_KEY_REVOKED))
1499 state_puts(s,
_(
"Warning: One of the keys has been revoked\n"));
1503 if ((sum & GPGME_SIGSUM_KEY_EXPIRED))
1505 time_t at = key->subkeys->expires ? key->subkeys->expires : 0;
1508 state_puts(s,
_(
"Warning: The key used to create the signature expired at: "));
1514 state_puts(s,
_(
"Warning: At least one certification key has expired\n"));
1518 if ((sum & GPGME_SIGSUM_SIG_EXPIRED))
1520 gpgme_signature_t sig2 = NULL;
1523 gpgme_verify_result_t result = gpgme_op_verify_result(ctx);
1525 for (sig2 = result->signatures, i = 0; sig2 && (i < idx); sig2 = sig2->next, i++)
1528 state_puts(s,
_(
"Warning: The signature expired at: "));
1529 print_time(sig2 ? sig2->exp_timestamp : 0, s);
1533 if ((sum & GPGME_SIGSUM_KEY_MISSING))
1535 state_puts(s,
_(
"Can't verify due to a missing key or certificate\n"));
1538 if ((sum & GPGME_SIGSUM_CRL_MISSING))
1544 if ((sum & GPGME_SIGSUM_CRL_TOO_OLD))
1550 if ((sum & GPGME_SIGSUM_BAD_POLICY))
1551 state_puts(s,
_(
"A policy requirement was not met\n"));
1553 if ((sum & GPGME_SIGSUM_SYS_ERROR))
1555 const char *t0 = NULL, *t1 = NULL;
1556 gpgme_verify_result_t result = NULL;
1557 gpgme_signature_t sig2 = NULL;
1563 result = gpgme_op_verify_result(ctx);
1564 for (sig2 = result->signatures, i = 0; sig2 && (i < idx); sig2 = sig2->next, i++)
1570 t1 = sig2->wrong_key_usage ?
"Wrong_Key_Usage" :
"";
1578 if (t1 && !(t0 && (strcmp(t0, t1) == 0)))
1589 if (c_crypt_use_pka)
1591 if ((sig->pka_trust == 1) && sig->pka_address)
1593 state_puts(s,
_(
"WARNING: PKA entry does not match signer's address: "));
1597 else if ((sig->pka_trust == 2) && sig->pka_address)
1599 state_puts(s,
_(
"PKA verified signer's address is: "));
1618 const char *prefix =
_(
"Fingerprint: ");
1620 const char *s = key->subkeys ? key->subkeys->fpr : NULL;
1623 bool is_pgp = (key->protocol == GPGME_PROTOCOL_OpenPGP);
1626 strcpy(buf, prefix);
1627 char *p = buf + strlen(buf);
1628 if (is_pgp && (strlen(s) == 40))
1630 for (
int i = 0; *s && s[1] && s[2] && s[3] && s[4]; s += 4, i++)
1643 for (
int i = 0; *s && s[1] && s[2]; s += 2, i++)
1647 *p++ = is_pgp ?
' ' :
':';
1648 if (is_pgp && (i == 7))
1670 gpgme_signature_t sig = NULL;
1671 const char *txt = NULL;
1673 gpgme_verify_result_t result = gpgme_op_verify_result(ctx);
1675 for (sig = result->signatures; sig && (idx > 0); sig = sig->next, idx--)
1678 switch (sig ? sig->validity : 0)
1680 case GPGME_VALIDITY_UNKNOWN:
1681 txt =
_(
"WARNING: We have NO indication whether the key belongs to the person named as shown above\n");
1683 case GPGME_VALIDITY_UNDEFINED:
1685 case GPGME_VALIDITY_NEVER:
1686 txt =
_(
"WARNING: The key does NOT BELONG to the person named as shown above\n");
1688 case GPGME_VALIDITY_MARGINAL:
1689 txt =
_(
"WARNING: It is NOT certain that the key belongs to the person named as shown above\n");
1691 case GPGME_VALIDITY_FULL:
1692 case GPGME_VALIDITY_ULTIMATE:
1708 gpgme_key_t key,
struct State *s)
1718 for (gpgme_user_id_t uids = key->uids; uids; uids = uids->next)
1727 for (
int i = 0; i < msgwid; i++)
1748 state_puts(s,
_(
"no signature fingerprint available"));
1760 for (
int i = 0; i < msgwid; i++)
1782 const char *fpr = NULL;
1783 gpgme_key_t key = NULL;
1784 bool anybad =
false, anywarn =
false;
1785 gpgme_signature_t sig = NULL;
1786 gpgme_error_t err = GPG_ERR_NO_ERROR;
1788 gpgme_verify_result_t result = gpgme_op_verify_result(ctx);
1795 for (i = 0, sig = result->signatures; sig && (i < idx); i++, sig = sig->next)
1808 const unsigned int sum = sig->summary;
1810 if (gpg_err_code(sig->status) != GPG_ERR_NO_ERROR)
1813 if (gpg_err_code(sig->status) != GPG_ERR_NO_PUBKEY)
1815 err = gpgme_get_key(ctx, fpr, &key, 0);
1837 snprintf(buf,
sizeof(buf),
_(
"Error getting key information for KeyID %s: %s\n"),
1838 fpr, gpgme_strerror(err));
1842 else if ((sum & GPGME_SIGSUM_GREEN))
1849 else if ((sum & GPGME_SIGSUM_RED))
1854 else if (!anybad && key && (key->protocol == GPGME_PROTOCOL_OpenPGP))
1869 if (sig->exp_timestamp)
1882 gpgme_key_unref(key);
1885 return anybad ? 1 : anywarn ? 2 : 0;
1905 gpgme_ctx_t ctx = NULL;
1906 gpgme_data_t message = NULL;
1915 gpgme_data_set_encoding(signature, GPGME_DATA_ENCODING_BASE64);
1917 int err = gpgme_data_new_from_file(&message, tempfile, 1);
1920 gpgme_data_release(signature);
1921 mutt_error(
_(
"error allocating data object: %s"), gpgme_strerror(err));
1930 err = gpgme_op_verify(ctx, signature, message, NULL);
1931 gpgme_data_release(message);
1932 gpgme_data_release(signature);
1939 snprintf(buf,
sizeof(buf) - 1,
_(
"Error: verification failed: %s\n"),
1940 gpgme_strerror(err));
1945 gpgme_verify_result_t verify_result = NULL;
1953 verify_result = gpgme_op_verify_result(ctx);
1954 if (verify_result && verify_result->signatures)
1956 bool anybad =
false;
1972 gpgme_verify_result_t result = NULL;
1973 gpgme_sig_notation_t notation = NULL;
1974 gpgme_signature_t sig = NULL;
1976 result = gpgme_op_verify_result(ctx);
1979 for (sig = result->signatures; sig; sig = sig->next)
1981 int non_pka_notations = 0;
1982 for (notation = sig->notations; notation; notation = notation->next)
1984 non_pka_notations++;
1986 if (non_pka_notations)
1989 snprintf(buf,
sizeof(buf),
1990 _(
"*** Begin Notation (signature by: %s) ***\n"), sig->fpr);
1992 for (notation = sig->notations; notation; notation = notation->next)
2002 if (notation->value)
2005 if (!(*notation->value && (notation->value[strlen(notation->value) - 1] ==
'\n')))
2020 return badsig ? 1 : anywarn ? 2 : 0;
2028 return verify_one(sigbdy, s, tempfile,
false);
2036 return verify_one(sigbdy, s, tempfile,
true);
2053 bool is_smime,
int *r_is_signed)
2055 if (!a || !s || !fp_out)
2058 struct Body *tattach = NULL;
2060 gpgme_data_t ciphertext = NULL, plaintext = NULL;
2061 bool maybe_signed =
false;
2062 bool anywarn =
false;
2068 gpgme_ctx_t ctx = NULL;
2081 if ((!is_smime) || maybe_signed)
2084 err = gpgme_op_decrypt_verify(ctx, ciphertext, plaintext);
2085 else if (maybe_signed)
2086 err = gpgme_op_verify(ctx, ciphertext, NULL, plaintext);
2088 if (err == GPG_ERR_NO_ERROR)
2091 gpgme_verify_result_t verify_result = gpgme_op_verify_result(ctx);
2092 if (verify_result->signatures)
2097 err = gpgme_op_decrypt(ctx, ciphertext, plaintext);
2098 gpgme_data_release(ciphertext);
2102 #ifdef USE_AUTOCRYPT
2108 if (is_smime && !maybe_signed && (gpg_err_code(err) == GPG_ERR_NO_DATA))
2114 gpgme_decrypt_result_t result;
2116 result = gpgme_op_decrypt_result(ctx);
2117 if (!result->unsupported_algorithm)
2119 maybe_signed =
true;
2120 gpgme_data_release(plaintext);
2133 snprintf(buf,
sizeof(buf) - 1,
2134 _(
"[-- Error: decryption failed: %s --]\n\n"), gpgme_strerror(err));
2147 gpgme_data_release(plaintext);
2169 if (!anybad && idx && r_is_signed && *r_is_signed)
2170 *r_is_signed = anywarn ? 2 : 1;
2200 gpgme_data_release(ciphertext);
2201 gpgme_data_release(plaintext);
2212 struct State s = { 0 };
2213 struct Body *first_part = b;
2215 bool need_decode =
false;
2216 LOFF_T saved_offset = 0;
2217 size_t saved_length = 0;
2218 FILE *fp_decoded = NULL;
2243 saved_offset = b->
offset;
2244 saved_length = b->
length;
2263 b->
length = ftello(fp_decoded);
2266 s.
fp_in = fp_decoded;
2278 *cur =
decrypt_part(b, &s, *fp_out,
false, &is_signed);
2294 b->
length = saved_length;
2295 b->
offset = saved_offset;
2307 struct State s = { 0 };
2309 LOFF_T saved_b_offset;
2310 size_t saved_b_length;
2322 saved_b_offset = b->
offset;
2323 saved_b_length = b->
length;
2343 memset(&s, 0,
sizeof(s));
2355 (*cur)->goodsig = is_signed > 0;
2356 b->
length = saved_b_length;
2357 b->
offset = saved_b_offset;
2369 struct Body *bb = *cur;
2371 saved_b_offset = bb->
offset;
2372 saved_b_length = bb->
length;
2373 memset(&s, 0,
sizeof(s));
2394 memset(&s, 0,
sizeof(s));
2406 b_tmp->
goodsig = is_signed > 0;
2407 bb->
length = saved_b_length;
2408 bb->
offset = saved_b_offset;
2414 return *cur ? 0 : -1;
2430 struct Buffer *tmpdir = NULL;
2431 gpgme_ctx_t tmpctx = NULL;
2433 gpgme_engine_info_t engineinfo = NULL;
2434 gpgme_key_t key = NULL;
2435 gpgme_user_id_t uid = NULL;
2436 gpgme_subkey_t subkey = NULL;
2437 const char *shortid = NULL;
2444 #if (GPGME_VERSION_NUMBER >= 0x010900)
2445 legacy_api = !have_gpg_version(
"2.1.14");
2457 if (!mkdtemp(tmpdir->
data))
2463 engineinfo = gpgme_ctx_get_engine_info(tmpctx);
2464 while (engineinfo && (engineinfo->protocol != GPGME_PROTOCOL_OpenPGP))
2465 engineinfo = engineinfo->next;
2472 err = gpgme_ctx_set_engine_info(tmpctx, GPGME_PROTOCOL_OpenPGP, engineinfo->file_name,
2474 if (err != GPG_ERR_NO_ERROR)
2488 #if (GPGME_VERSION_NUMBER >= 0x010900)
2490 err = gpgme_op_keylist_from_data_start(tmpctx, keydata, 0);
2494 err = gpgme_op_keylist_start(tmpctx, NULL, 0);
2498 err = gpgme_op_keylist_next(tmpctx, &key);
2502 subkey = key->subkeys;
2506 shortid = subkey->keyid;
2510 tt = subkey->timestamp;
2515 fprintf(*fp,
"sub %5.5s %u/%8s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo),
2516 subkey->length, shortid, date);
2520 fprintf(*fp,
"pub %5.5s %u/%8s %s %s\n", gpgme_pubkey_algo_name(subkey->pubkey_algo),
2521 subkey->length, shortid, date, (uid ? uid->uid :
""));
2523 subkey = subkey->next;
2526 gpgme_key_unref(key);
2528 if (gpg_err_code(err) != GPG_ERR_EOF)
2543 gpgme_release(tmpctx);
2566 if ((b[n] ==
'\n') || ((b[n] ==
'\r') && (b[n + 1] ==
'\n')))
2606 while (fgets(buf,
sizeof(buf), fp_tmp))
2647 for (; b; b = b->
next)
2672 gpgme_data_t keydata = NULL;
2673 gpgme_import_result_t impres;
2674 gpgme_import_status_t st;
2685 gpgme_error_t err = gpgme_data_new_from_stream(&keydata, fp_in);
2686 if (err != GPG_ERR_NO_ERROR)
2688 mutt_error(
_(
"error allocating data object: %s"), gpgme_strerror(err));
2692 err = gpgme_op_import(ctx, keydata);
2695 mutt_error(
_(
"Error importing key: %s"), gpgme_strerror(err));
2700 impres = gpgme_op_import_result(ctx);
2703 fputs(
"oops: no import result returned\n", stdout);
2707 for (st = impres->imports; st; st = st->next)
2711 printf(
"key %s imported (",
NONULL(st->fpr));
2715 if (st->status & GPGME_IMPORT_SECRET)
2717 printf(
"secret parts");
2720 if ((st->status & GPGME_IMPORT_NEW))
2722 printf(
"%snew key", any ?
", " :
"");
2725 if ((st->status & GPGME_IMPORT_UID))
2727 printf(
"%snew uid", any ?
", " :
"");
2730 if ((st->status & GPGME_IMPORT_SIG))
2732 printf(
"%snew sig", any ?
", " :
"");
2735 if ((st->status & GPGME_IMPORT_SUBKEY))
2737 printf(
"%snew subkey", any ?
", " :
"");
2740 printf(
"%s)\n", any ?
"" :
"not changed");
2749 for (st = impres->imports; st; st = st->next)
2751 if (st->result == 0)
2753 printf(
"key %s import failed: %s\n",
NONULL(st->fpr), gpgme_strerror(st->result));
2759 gpgme_data_release(keydata);
2781 bool complete, armor_header;
2799 for (complete =
true, armor_header =
true;
2815 armor_header =
false;
2822 if ((buf[0] ==
'-') && (buf[1] ==
' '))
2838 bool pgp_keyblock =
false;
2839 bool clearsign =
false;
2843 FILE *fp_out = NULL;
2845 gpgme_error_t err = 0;
2846 gpgme_data_t armored_data = NULL;
2848 bool maybe_goodsig =
true;
2849 bool have_any_sigs =
false;
2851 char body_charset[256];
2858 mutt_str_copy(body_charset,
"iso-8859-1",
sizeof(body_charset));
2866 for (bytes = m->
length; bytes > 0;)
2868 if (!fgets(buf,
sizeof(buf), s->
fp_in))
2871 LOFF_T offset = ftello(s->
fp_in);
2872 bytes -= (offset - last_pos);
2890 pgp_keyblock =
true;
2901 have_any_sigs = (have_any_sigs || (clearsign && (s->
flags &
MUTT_VERIFY)));
2916 err = gpgme_op_verify(ctx, armored_data, NULL, plaintext);
2919 err = gpgme_op_decrypt_verify(ctx, armored_data, plaintext);
2920 if (gpg_err_code(err) == GPG_ERR_NO_DATA)
2923 gpgme_data_seek(armored_data, 0, SEEK_SET);
2925 gpgme_data_release(plaintext);
2927 err = gpgme_op_verify(ctx, armored_data, NULL, plaintext);
2936 snprintf(errbuf,
sizeof(errbuf) - 1,
2937 _(
"Error: decryption/verification failed: %s\n"), gpgme_strerror(err));
2946 bool sig_stat =
false;
2947 char *tmpfname = NULL;
2951 gpgme_verify_result_t verify_result = gpgme_op_verify_result(ctx);
2952 if (verify_result->signatures)
2956 have_any_sigs =
false;
2957 maybe_goodsig =
false;
2961 bool anybad =
false;
2964 have_any_sigs =
true;
2971 maybe_goodsig =
true;
2988 gpgme_data_release(plaintext);
2999 else if (pgp_keyblock)
3019 if ((c ==
'\n') && s->
prefix)
3030 else if (pgp_keyblock)
3036 gpgme_data_release(armored_data);
3049 m->
goodsig = (maybe_goodsig && have_any_sigs);
3053 state_attach_puts(s,
_(
"[-- Error: could not find beginning of PGP message --]\n\n"));
3088 tattach->
goodsig = is_signed > 0;
3093 _(
"[-- The following data is PGP/MIME signed and encrypted --]\n\n") :
3094 _(
"[-- The following data is PGP/MIME encrypted --]\n\n"));
3107 FILE *fp_save = s->
fp_in;
3132 state_attach_puts(s, is_signed ?
_(
"[-- End of PGP/MIME signed and encrypted data --]\n") :
3133 _(
"[-- End of PGP/MIME encrypted data --]\n"));
3141 #ifdef USE_AUTOCRYPT
3183 tattach->
goodsig = is_signed > 0;
3188 _(
"[-- The following data is S/MIME signed --]\n\n") :
3189 _(
"[-- The following data is S/MIME encrypted --]\n\n"));
3202 FILE *fp_save = s->
fp_in;
3236 _(
"[-- End of S/MIME encrypted data --]\n"));
3256 unsigned int rc = 0;
3261 rc = key->can_encrypt;
3264 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
3266 rc = subkey->can_encrypt;
3276 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
3278 rc = subkey->can_sign;
3285 rc = key->can_certify;
3288 for (gpgme_subkey_t subkey = key->subkeys; subkey; subkey = subkey->next)
3290 rc = subkey->can_certify;
3312 char *pattern = NULL, *p = NULL;
3313 const char *s = NULL;
3320 for (s = np->
data; *s; s++)
3322 if ((*s ==
'%') || (*s ==
'+'))
3338 for (s = np->
data; *s; s++)
3375 struct CryptKeyInfo *db = NULL, *k = NULL, **kend = NULL;
3377 gpgme_ctx_t ctx = NULL;
3378 gpgme_key_t key = NULL;
3380 gpgme_user_id_t
uid = NULL;
3413 err = gpgme_op_keylist_ext_start(ctx, (
const char **) patarr, secret, 0);
3414 for (n = 0; patarr[n]; n++)
3419 mutt_error(
_(
"gpgme_op_keylist_start failed: %s"), gpgme_strerror(err));
3425 while ((err = gpgme_op_keylist_next(ctx, &key)) == 0)
3441 for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
3445 gpgme_key_ref(k->kobj);
3451 k->validity = uid->validity;
3455 gpgme_key_unref(key);
3457 if (gpg_err_code(err) != GPG_ERR_EOF)
3458 mutt_error(
_(
"gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
3459 gpgme_op_keylist_end(ctx);
3466 gpgme_set_protocol(ctx, GPGME_PROTOCOL_CMS);
3467 err = gpgme_op_keylist_start(ctx, pattern, 0);
3470 mutt_error(
_(
"gpgme_op_keylist_start failed: %s"), gpgme_strerror(err));
3476 while ((err = gpgme_op_keylist_next(ctx, &key)) == 0)
3492 for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
3496 gpgme_key_ref(k->kobj);
3502 k->validity = uid->validity;
3506 gpgme_key_unref(key);
3508 if (gpg_err_code(err) != GPG_ERR_EOF)
3509 mutt_error(
_(
"gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
3510 gpgme_op_keylist_end(ctx);
3532 for (
char *t = strtok(scratch,
" ,.:\"()<>\n"); t; t = strtok(NULL,
" ,.:\"()<>\n"))
3551 KeyFlags abilities,
unsigned int app,
3552 bool *forced_valid,
bool oppenc_mode)
3557 int this_key_has_strong =
false;
3558 int this_key_has_addr_match =
false;
3584 for (k = keys; k; k = k->
next)
3588 if (abilities && !(k->flags & abilities))
3594 this_key_has_strong =
false;
3595 this_key_has_addr_match =
false;
3613 if (the_strong_valid_key && (the_strong_valid_key->
kobj != k->kobj))
3615 this_key_has_strong =
true;
3618 this_key_has_addr_match =
true;
3627 *matches_endp = tmp;
3628 matches_endp = &tmp->
next;
3630 if (this_key_has_strong)
3631 the_strong_valid_key = tmp;
3632 else if (this_key_has_addr_match)
3633 a_valid_addrmatch_key = tmp;
3643 const bool c_crypt_opportunistic_encrypt_strong_keys =
3645 if (the_strong_valid_key)
3647 else if (a_valid_addrmatch_key && !c_crypt_opportunistic_encrypt_strong_keys)
3652 else if (the_strong_valid_key && !multi)
3681 unsigned int app,
bool *forced_valid)
3687 const char *ps = NULL, *pl = NULL, *phint = NULL;
3702 for (k = keys; k; k = k->
next)
3704 if (abilities && !(k->
flags & abilities))
3717 *matches_endp = tmp;
3718 matches_endp = &tmp->
next;
3752 unsigned int app,
bool *forced_valid)
3817 static char *
find_keys(
const struct AddressList *addrlist,
unsigned int app,
bool oppenc_mode)
3820 struct ListNode *crypt_hook = NULL;
3821 const char *keyid = NULL;
3822 char *keylist = NULL;
3823 size_t keylist_size = 0;
3824 size_t keylist_used = 0;
3829 bool forced_valid =
false;
3836 key_selected =
false;
3842 forced_valid =
false;
3847 keyid = crypt_hook->
data;
3850 if (!oppenc_mode && c_crypt_confirm_hook)
3852 snprintf(buf,
sizeof(buf),
_(
"Use keyID = \"%s\" for %s?"), keyid, p->
mailbox);
3861 goto bypass_selection;
3871 else if (!oppenc_mode)
3878 if (key_selected ||
STAILQ_NEXT(crypt_hook, entries))
3898 if (!k_info && !oppenc_mode)
3900 snprintf(buf,
sizeof(buf),
_(
"Enter keyID for %s: "), p->
mailbox);
3918 sprintf(keylist + keylist_used,
"%s0x%s%s", keylist_used ?
" " :
"",
3919 keyid, forced_valid ?
"!" :
"");
3922 key_selected =
true;
3930 }
while (crypt_hook);
3953 #ifdef USE_AUTOCRYPT
3970 gpgme_key_t key = NULL;
3971 gpgme_user_id_t uid = NULL;
3979 if (gpgme_op_keylist_start(ctx, NULL, 1))
3984 while (!(err = gpgme_op_keylist_next(ctx, &key)))
4005 gpgme_key_ref(k->kobj);
4011 k->validity =
uid->validity;
4015 gpgme_key_unref(key);
4017 if (gpg_err_code(err) != GPG_ERR_EOF)
4018 mutt_error(
_(
"gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
4019 gpgme_op_keylist_end(ctx);
4030 if (!(choice && choice->
kobj && choice->
kobj->subkeys && choice->
kobj->subkeys->fpr))
4049 #ifdef HAVE_GPGME_OP_EXPORT_KEYS
4050 gpgme_ctx_t context = NULL;
4051 gpgme_key_t export_keys[2] = { 0 };
4052 gpgme_data_t keydata = NULL;
4054 struct Body *att = NULL;
4063 export_keys[0] = key->
kobj;
4064 export_keys[1] = NULL;
4067 gpgme_set_armor(context, 1);
4069 err = gpgme_op_export_keys(context, export_keys, 0, keydata);
4070 if (err != GPG_ERR_NO_ERROR)
4072 mutt_error(
_(
"Error exporting key: %s"), gpgme_strerror(err));
4090 snprintf(buf,
sizeof(buf),
_(
"PGP Key 0x%s"),
crypt_keyid(key));
4098 gpgme_data_release(keydata);
4099 gpgme_release(context);
4103 mutt_error(
"gpgme_op_export_keys not supported");
4115 static bool has_run =
false;
4119 gpgme_check_version(NULL);
4120 gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
4122 gpgme_set_locale(NULL, LC_MESSAGES, setlocale(LC_MESSAGES, NULL));
4132 if (gpgme_engine_check_version(GPGME_PROTOCOL_OpenPGP) != GPG_ERR_NO_ERROR)
4134 mutt_error(
_(
"GPGME: OpenPGP protocol not available"));
4143 if (gpgme_engine_check_version(GPGME_PROTOCOL_CMS) != GPG_ERR_NO_ERROR)
4145 mutt_error(
_(
"GPGME: CMS protocol not available"));
4176 const char *prompt = NULL;
4177 const char *letters = NULL;
4178 const char *choices = NULL;
4196 prompt =
_(
"S/MIME (s)ign, sign (a)s, (p)gp, (c)lear, or (o)ppenc mode off?");
4198 letters =
_(
"sapco");
4204 prompt =
_(
"PGP (s)ign, sign (a)s, s/(m)ime, (c)lear, or (o)ppenc mode off?");
4206 letters =
_(
"samco");
4211 else if (c_crypt_opportunistic_encrypt)
4216 prompt =
_(
"S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (p)gp, (c)lear, or (o)ppenc mode?");
4218 letters =
_(
"esabpco");
4219 choices =
"esabpcO";
4224 prompt =
_(
"PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, s/(m)ime, (c)lear, or (o)ppenc mode?");
4226 letters =
_(
"esabmco");
4227 choices =
"esabmcO";
4236 prompt =
_(
"S/MIME (e)ncrypt, (s)ign, sign (a)s, (b)oth, (p)gp or (c)lear?");
4238 letters =
_(
"esabpc");
4244 prompt =
_(
"PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, s/(m)ime or (c)lear?");
4246 letters =
_(
"esabmc");
4254 switch (choices[choice - 1])
4261 char input_signas[128];
4294 is_smime = !is_smime;
4354 struct Address *sender = NULL;
4373 gpgme_user_id_t uid = NULL;
4374 int sender_length = strlen(sender->
mailbox);
4375 for (uid = key->uids; uid && rc; uid = uid->next)
4377 int uid_length = strlen(uid->email);
4378 if ((uid->email[0] ==
'<') && (uid->email[uid_length - 1] ==
'>') &&
4379 (uid_length == (sender_length + 2)))
4381 const char *at_sign = strchr(uid->email + 1,
'@');
4387 const char *tmp_email = uid->email + 1;
4388 const char *tmp_sender = sender->
mailbox;
4390 int mailbox_length = at_sign - tmp_email + 1;
4391 int domainname_length = sender_length - mailbox_length;
4392 int mailbox_match, domainname_match;
4394 mailbox_match =
mutt_strn_equal(tmp_email, tmp_sender, mailbox_length);
4395 tmp_email += mailbox_length;
4396 tmp_sender += mailbox_length;
4397 domainname_match = (
mutt_istrn_cmp(tmp_email, tmp_sender, domainname_length) == 0);
4398 if (mailbox_match && domainname_match)
4448 return GPGME_VERSION;
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
int mutt_addrlist_parse(struct AddressList *al, const char *s)
Parse a list of email addresses.
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
GUI display the mailboxes in a side panel.
char * AutocryptSignAs
Autocrypt Key id to sign as.
Autocrypt end-to-end encryption.
bool mutt_buffer_is_empty(const struct Buffer *buf)
Is the Buffer empty?
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
size_t mutt_buffer_addstr(struct Buffer *buf, const char *s)
Add a string to a Buffer.
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Convenience wrapper for the config headers.
Convenience wrapper for the core headers.
const char * crypt_get_fingerprint_or_id(const char *p, const char **pphint, const char **ppl, const char **pps)
Get the fingerprint or long key ID.
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
bool crypt_is_numerical_keyid(const char *s)
Is this a numerical keyid.
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
void crypt_convert_to_7bit(struct Body *a)
Convert an email to 7bit encoding.
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Signing/encryption multiplexor.
static struct Body * decrypt_part(struct Body *a, struct State *s, FILE *fp_out, bool is_smime, int *r_is_signed)
Decrypt a PGP or SMIME message.
static gpgme_error_t set_pka_sig_notation(gpgme_ctx_t ctx)
Set the signature notation.
static struct CryptKeyInfo * crypt_getkeybyaddr(struct Address *a, KeyFlags abilities, unsigned int app, bool *forced_valid, bool oppenc_mode)
Find a key by email address.
static bool verify_sender(struct Email *e)
Verify the sender of a message.
static int show_sig_summary(unsigned long sum, gpgme_ctx_t ctx, gpgme_key_t key, int idx, struct State *s, gpgme_signature_t sig)
Show a signature summary.
static void init_common(void)
Initialise code common to PGP and SMIME parts of GPGME.
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
static const char * crypt_short_keyid(struct CryptKeyInfo *k)
Get the short keyID for a key.
static gpgme_key_t * create_recipient_set(const char *keylist, bool use_smime)
Create a GpgmeRecipientSet from a string of keys.
int crypt_id_is_valid(struct CryptKeyInfo *key)
Is key ID valid.
static gpgme_data_t create_gpgme_data(void)
Create a new GPGME data object.
static struct CryptCache * id_defaults
static int verify_one(struct Body *sigbdy, struct State *s, const char *tempfile, bool is_smime)
Do the actual verification step.
static void print_smime_keyinfo(const char *msg, gpgme_signature_t sig, gpgme_key_t key, struct State *s)
Print key info about an SMIME key.
static char * current_sender
static void show_fingerprint(gpgme_key_t key, struct State *state)
Write a key's fingerprint.
gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
static gpgme_data_t body_to_data_object(struct Body *a, bool convert)
Create GPGME object from the mail body.
static int crypt_id_matches_addr(struct Address *addr, struct Address *u_addr, struct CryptKeyInfo *key)
Does the key ID match the address.
bool crypt_id_is_strong(struct CryptKeyInfo *key)
Is the key strong.
static void crypt_add_string_to_hints(const char *str, struct ListHead *hints)
Split a string and add the parts to a List.
static void print_time(time_t t, struct State *s)
Print the date/time according to the locale.
static char * list_to_pattern(struct ListHead *list)
Convert STailQ to GPGME-compatible pattern.
const char * mutt_gpgme_print_version(void)
Get version of GPGME.
#define BEGIN_PGP_SIGNATURE(_y)
#define SIGNED_MESSAGE(_y)
#define PKA_NOTATION_NAME
static char * find_keys(const struct AddressList *addrlist, unsigned int app, bool oppenc_mode)
Find keys of the recipients of the message.
static int get_micalg(gpgme_ctx_t ctx, int use_smime, char *buf, size_t buflen)
Find the "micalg" parameter from the last GPGME operation.
static int data_object_to_stream(gpgme_data_t data, FILE *fp)
Write a GPGME data object to a file.
static int pgp_check_traditional_one_body(FILE *fp, struct Body *b)
Check one inline PGP body part.
static void show_one_sig_validity(gpgme_ctx_t ctx, int idx, struct State *s)
Show the validity of a key used for one signature.
#define CRYPT_KV_STRONGID
static int show_one_sig_status(gpgme_ctx_t ctx, int idx, struct State *s)
Show information about one signature.
static struct Body * sign_message(struct Body *a, const struct AddressList *from, bool use_smime)
Sign a message.
static gpgme_data_t file_to_data_object(FILE *fp, long offset, size_t length)
Create GPGME data object from file.
struct CryptKeyInfo * crypt_copy_key(struct CryptKeyInfo *key)
Return a copy of KEY.
#define PUBLIC_KEY_BLOCK(_y)
static gpgme_key_t signature_key
static int set_signer(gpgme_ctx_t ctx, const struct AddressList *al, bool for_smime)
Make sure that the correct signer is set.
static void init_smime(void)
Initialise the SMIME crypto backend.
static const char * crypt_fpr(struct CryptKeyInfo *k)
Get the hexstring fingerprint from a key.
static struct CryptKeyInfo * crypt_ask_for_key(char *tag, char *whatfor, KeyFlags abilities, unsigned int app, bool *forced_valid)
Ask the user for a key.
static void copy_clearsigned(gpgme_data_t data, struct State *s, char *charset)
Copy a clearsigned message.
const char * crypt_keyid(struct CryptKeyInfo *k)
Find the ID for the key.
unsigned int key_check_cap(gpgme_key_t key, enum KeyCap cap)
Check the capabilities of a key.
static SecurityFlags gpgme_send_menu(struct Email *e, bool is_smime)
Show the user the encryption/signing menu.
static bool is_pka_notation(gpgme_sig_notation_t notation)
Is this the standard pka email address.
static void redraw_if_needed(gpgme_ctx_t ctx)
Accommodate for a redraw if needed.
static int pgp_gpgme_extract_keys(gpgme_data_t keydata, FILE **fp)
Write PGP keys to a file.
static int line_compare(const char *a, size_t n, const char *b)
Compare two strings ignore line endings.
static void crypt_key_free(struct CryptKeyInfo **keylist)
Release all the keys in a list.
static struct CryptKeyInfo * crypt_getkeybystr(const char *p, KeyFlags abilities, unsigned int app, bool *forced_valid)
Find a key by string.
static void recipient_set_free(gpgme_key_t **p_rset)
Free a set of recipients.
static bool set_signer_from_address(gpgme_ctx_t ctx, const char *address, bool for_smime)
Try to set the context's signer from the address.
static char * encrypt_gpgme_object(gpgme_data_t plaintext, char *keylist, bool use_smime, bool combined_signed, const struct AddressList *from)
Encrypt the GPGPME data object.
static char * data_object_to_tempfile(gpgme_data_t data, FILE **fp_ret)
Copy a data object to a temporary file.
static const char * crypt_long_keyid(struct CryptKeyInfo *k)
Find the Long ID for the key.
static void init_pgp(void)
Initialise the PGP crypto backend.
static struct CryptKeyInfo * get_candidates(struct ListHead *hints, SecurityFlags app, int secret)
Get a list of keys which are candidates for the selection.
const char * crypt_fpr_or_lkeyid(struct CryptKeyInfo *k)
Find the fingerprint of a key.
Wrapper for PGP/SMIME calls to GPGME.
KeyCap
PGP/SMIME Key Capabilities.
@ KEY_CAP_CAN_CERTIFY
Key can be used to certify.
@ KEY_CAP_CAN_ENCRYPT
Key can be used for encryption.
@ KEY_CAP_CAN_SIGN
Key can be used for signing.
int mutt_buffer_get_field(const char *field, struct Buffer *buf, CompletionFlags complete, bool multiple, struct Mailbox *m, char ***files, int *numfiles)
Ask the user for a string.
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
void mutt_need_hard_redraw(void)
Force a hard refresh.
size_t mutt_strwidth(const char *s)
Measure a string's width in screen cells.
size_t mutt_date_localtime_format(char *buf, size_t buflen, const char *format, time_t t)
Format localtime.
struct CryptKeyInfo * dlg_select_gpgme_key(struct CryptKeyInfo *keys, struct Address *p, const char *s, unsigned int app, bool *forced_valid)
Get the user to select a key.
void mutt_body_free(struct Body **ptr)
Free a Body.
char * mutt_body_get_charset(struct Body *b, char *buf, size_t buflen)
Get a body's character set.
struct Body * mutt_body_new(void)
Create a new Body.
Structs that make up an email.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
bool mutt_file_seek(FILE *fp, LOFF_T offset, int whence)
Wrapper for fseeko with error handling.
long mutt_file_get_size(const char *path)
Get the size of a file.
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
int mutt_file_rmtree(const char *path)
Recursively remove a directory.
#define mutt_file_mkstemp()
int smime_gpgme_application_handler(struct Body *a, struct State *s)
Implements CryptModuleSpecs::application_handler() -.
int pgp_gpgme_application_handler(struct Body *m, struct State *s)
Implements CryptModuleSpecs::application_handler() -.
int pgp_gpgme_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Implements CryptModuleSpecs::decrypt_mime() -.
int smime_gpgme_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Implements CryptModuleSpecs::decrypt_mime() -.
int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s)
Implements CryptModuleSpecs::encrypted_handler() -.
char * smime_gpgme_find_keys(const struct AddressList *addrlist, bool oppenc_mode)
Implements CryptModuleSpecs::find_keys() -.
char * pgp_gpgme_find_keys(const struct AddressList *addrlist, bool oppenc_mode)
Implements CryptModuleSpecs::find_keys() -.
void smime_gpgme_init(void)
Implements CryptModuleSpecs::init() -.
void pgp_gpgme_init(void)
Implements CryptModuleSpecs::init() -.
bool pgp_gpgme_check_traditional(FILE *fp, struct Body *b, bool just_one)
Implements CryptModuleSpecs::pgp_check_traditional() -.
struct Body * pgp_gpgme_encrypt_message(struct Body *a, char *keylist, bool sign, const struct AddressList *from)
Implements CryptModuleSpecs::pgp_encrypt_message() -.
void pgp_gpgme_invoke_import(const char *fname)
Implements CryptModuleSpecs::pgp_invoke_import() -.
struct Body * pgp_gpgme_make_key_attachment(void)
Implements CryptModuleSpecs::pgp_make_key_attachment() -.
void pgp_gpgme_set_sender(const char *sender)
Implements CryptModuleSpecs::set_sender() -.
struct Body * smime_gpgme_sign_message(struct Body *a, const struct AddressList *from)
Implements CryptModuleSpecs::sign_message() -.
struct Body * pgp_gpgme_sign_message(struct Body *a, const struct AddressList *from)
Implements CryptModuleSpecs::sign_message() -.
struct Body * smime_gpgme_build_smime_entity(struct Body *a, char *keylist)
Implements CryptModuleSpecs::smime_build_smime_entity() -.
int smime_gpgme_verify_sender(struct Email *e, struct Message *msg)
Implements CryptModuleSpecs::smime_verify_sender() -.
int pgp_gpgme_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile)
Implements CryptModuleSpecs::verify_one() -.
int smime_gpgme_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile)
Implements CryptModuleSpecs::verify_one() -.
int mutt_protected_headers_handler(struct Body *b, struct State *s)
Process a protected header - Implements handler_t -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
Convenience wrapper for the gui headers.
void mutt_decode_attachment(struct Body *b, struct State *s)
Decode an email's attachment.
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Decide how to display email content.
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
void mutt_crypt_hook(struct ListHead *list, struct Address *addr)
Find crypto hooks for an Address.
Parse and execute user-defined hooks.
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
@ LL_DEBUG5
Log at debug level 5.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
void mutt_exit(int code)
Leave NeoMutt NOW.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
@ ENC_BASE64
Base-64 encoded text.
@ TYPE_MULTIPART
Type: 'multipart/*'.
@ TYPE_APPLICATION
Type: 'application/*'.
@ TYPE_TEXT
Type: 'text/*'.
@ DISP_ATTACH
Content is attached.
@ DISP_INLINE
Content is inline.
@ DISP_NONE
No preferred disposition.
#define is_multipart(body)
void mutt_generate_boundary(struct ParameterList *pl)
Create a unique boundary id for a MIME part.
void mutt_ch_fgetconv_close(struct FgetConv **fc)
Close an fgetconv handle.
struct FgetConv * mutt_ch_fgetconv_open(FILE *fp, const char *from, const char *to, uint8_t flags)
Prepare a file for charset conversion.
int mutt_ch_fgetconv(struct FgetConv *fc)
Convert a file's character set.
char * mutt_ch_fgetconvs(char *buf, size_t buflen, struct FgetConv *fc)
Convert a file's charset into a string buffer.
#define MUTT_ICONV_HOOK_FROM
apply charset-hooks to fromcode
#define MUTT_ICONV_NO_FLAGS
No flags are set.
Convenience wrapper for the library headers.
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
#define state_puts(STATE, STR)
#define MUTT_VERIFY
Perform signature verification.
#define state_putc(STATE, STR)
#define MUTT_DISPLAY
Output is displayed to the user.
int mutt_istrn_cmp(const char *a, const char *b, size_t num)
Compare two strings ignoring case (to a maximum), safely.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
const char * mutt_istr_find(const char *haystack, const char *needle)
Find first occurrence of string (ignoring case)
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
char * mutt_str_lower(char *str)
Convert all characters in the string to lowercase.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Many unsorted constants and some structs.
#define MUTT_COMP_NO_FLAGS
No flags are set.
int mutt_decode_save_attachment(FILE *fp, struct Body *m, const char *path, int displaying, enum SaveAttach opt)
Decode, then save an attachment.
@ MUTT_SAVE_NO_FLAGS
No flags set.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
Some miscellaneous functions.
#define mutt_buffer_mktemp(buf)
#define KEYFLAG_EXPIRED
Key is expired.
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
#define KEYFLAG_ISX509
Key is an X.509 key.
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
#define APPLICATION_PGP
Use PGP to encrypt/sign.
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
#define KEYFLAG_NO_FLAGS
No flags are set.
#define SEC_NO_FLAGS
No flags are set.
#define KEYFLAG_DISABLED
Key is marked disabled.
#define SEC_ENCRYPT
Email is encrypted.
#define KEYFLAG_REVOKED
Key is revoked.
#define SEC_SIGN
Email is signed.
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Handling of global boolean variables.
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
bool OptPgpCheckTrust
(pseudo) used by dlg_select_pgp_key()
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
struct Body * mutt_read_mime_header(FILE *fp, bool digest)
Parse a MIME header.
static size_t plen
Length of cached packet.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
QuadOption
Possible values for a quad-option.
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
@ MUTT_NO
User answered 'No', or assume 'No'.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
int mutt_multi_choice(const char *prompt, const char *letters)
Offer the user a multiple choice question.
#define TAILQ_FOREACH(var, head, field)
#define STAILQ_HEAD_INITIALIZER(head)
#define STAILQ_FIRST(head)
#define STAILQ_FOREACH(var, head, field)
#define TAILQ_FIRST(head)
#define TAILQ_HEAD_INITIALIZER(head)
#define TAILQ_EMPTY(head)
#define STAILQ_NEXT(elm, field)
int mutt_write_mime_body(struct Body *a, FILE *fp, struct ConfigSubset *sub)
Write a MIME part.
Convenience wrapper for the send headers.
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
void mutt_update_encoding(struct Body *a, struct ConfigSubset *sub)
Update the encoding type.
char * mailbox
Mailbox and host address.
char * personal
Real name of address.
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
struct Body * parts
parts of a multipart or message/rfc822
LOFF_T offset
offset where the actual data begins
bool unlink
If true, filename should be unlink()ed before free()ing this structure.
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
struct Envelope * mime_headers
Memory hole protected headers.
LOFF_T length
length (in bytes) of attachment
struct ParameterList parameter
Parameters of the content-type.
bool use_disp
Content-Disposition uses filename= ?
char * description
content-description
unsigned int disposition
content-disposition, ContentDisposition
struct Body * next
next attachment in the list
char * subtype
content-type subtype
unsigned int encoding
content-transfer-encoding, ContentEncoding
bool goodsig
Good cryptographic signature.
bool warnsig
Maybe good signature.
unsigned int type
content-type primary type, ContentType
char * filename
When sending a message, this is the file to which this structure refers.
String manipulation buffer.
char * data
Pointer to data.
Internal cache for GPGME.
gpgme_validity_t validity
uid validity (cached for convenience)
KeyFlags flags
global and per uid flags (for convenience)
int idx
and the user ID at this index
struct CryptKeyInfo * next
Linked list.
const char * uid
and for convenience point to this user ID
The envelope/body of an email.
struct Envelope * env
Envelope information.
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
struct AddressList sender
Email's sender.
struct AddressList from
Email's 'From' list.
Cursor for converting a file's encoding.
A local copy of an email.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
Keep track when processing files.
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
FILE * fp_out
File to write to.
char * prefix
String to add to the beginning of each output line.
FILE * fp_in
File to read from.
int cs_subset_str_string_set(const struct ConfigSubset *sub, const char *name, const char *value, struct Buffer *err)
Set a config item by string.