1245
1265
state_attach_puts (txt, s);
1268
static void print_smime_keyinfo (const char* msg, gpgme_signature_t sig,
1269
gpgme_key_t key, STATE *s)
1272
gpgme_user_id_t uids = NULL;
1275
state_attach_puts (msg, s);
1276
state_attach_puts (" ", s);
1277
for (uids = key->uids; uids; uids = uids->next)
1283
msglen = mutt_strlen (msg) - 4;
1284
for (i = 0; i < msglen; i++)
1285
state_attach_puts(" ", s);
1286
state_attach_puts(_("aka: "), s);
1288
state_attach_puts (uids->uid, s);
1289
state_attach_puts ("\n", s);
1294
msglen = mutt_strlen (msg) - 8;
1295
for (i = 0; i < msglen; i++)
1296
state_attach_puts(" ", s);
1297
state_attach_puts (_("created: "), s);
1298
print_time (sig->timestamp, s);
1299
state_attach_puts ("\n", s);
1248
1302
/* Show information about one signature. This fucntion is called with
1249
1303
the context CTX of a sucessful verification operation and the
1250
1304
enumerator IDX which should start at 0 and incremete for each
1308
1359
; /* No state information so no way to print anything. */
1311
state_attach_puts (_("Error getting key information: "), s);
1312
state_attach_puts ( gpg_strerror (err), s );
1313
state_attach_puts ("\n", s);
1362
state_attach_puts (_("Error getting key information: "), s);
1363
state_attach_puts ( gpg_strerror (err), s );
1364
state_attach_puts ("\n", s);
1316
1367
else if ((sum & GPGME_SIGSUM_GREEN))
1318
state_attach_puts (_("Good signature from: "), s);
1319
state_attach_puts (uid, s);
1320
state_attach_puts ("\n", s);
1321
for (i = 1, uids = key->uids; uids; i++, uids = uids->next)
1324
/* Skip primary UID. */
1328
state_attach_puts (_(" aka: "), s);
1329
state_attach_puts (uids->uid, s);
1330
state_attach_puts ("\n", s);
1332
state_attach_puts (_(" created: "), s);
1333
print_time (created, s);
1334
state_attach_puts ("\n", s);
1335
if (show_sig_summary (sum, ctx, key, idx, s, sig))
1337
show_one_sig_validity (ctx, idx, s);
1369
print_smime_keyinfo (_("Good signature from:"), sig, key, s);
1370
if (show_sig_summary (sum, ctx, key, idx, s, sig))
1372
show_one_sig_validity (ctx, idx, s);
1339
1374
else if ((sum & GPGME_SIGSUM_RED))
1341
state_attach_puts (_("*BAD* signature claimed to be from: "), s);
1342
state_attach_puts (uid, s);
1343
state_attach_puts ("\n", s);
1344
show_sig_summary (sum, ctx, key, idx, s, sig);
1376
print_smime_keyinfo (_("*BAD* signature from:"), sig, key, s);
1377
show_sig_summary (sum, ctx, key, idx, s, sig);
1346
1379
else if (!anybad && key && (key->protocol == GPGME_PROTOCOL_OpenPGP))
1347
{ /* We can't decide (yellow) but this is a PGP key with a good
1348
signature, so we display what a PGP user expects: The name,
1349
fingerprint and the key validity (which is neither fully or
1351
state_attach_puts (_("Good signature from: "), s);
1352
state_attach_puts (uid, s);
1353
state_attach_puts ("\n", s);
1354
state_attach_puts (_(" created: "), s);
1355
print_time (created, s);
1356
state_attach_puts ("\n", s);
1357
show_one_sig_validity (ctx, idx, s);
1358
show_fingerprint (key,s);
1359
if (show_sig_summary (sum, ctx, key, idx, s, sig))
1380
{ /* We can't decide (yellow) but this is a PGP key with a good
1381
signature, so we display what a PGP user expects: The name,
1382
fingerprint and the key validity (which is neither fully or
1384
print_smime_keyinfo (_("Good signature from:"), sig, key, s);
1385
show_one_sig_validity (ctx, idx, s);
1386
show_fingerprint (key,s);
1387
if (show_sig_summary (sum, ctx, key, idx, s, sig))
1362
1390
else /* can't decide (yellow) */
1364
state_attach_puts (_("Error checking signature"), s);
1365
state_attach_puts ("\n", s);
1366
show_sig_summary (sum, ctx, key, idx, s, sig);
1392
print_smime_keyinfo (_("Problem signature from:"), sig, key, s);
1393
state_attach_puts (_(" expires: "), s);
1394
print_time (sig->exp_timestamp, s);
1395
state_attach_puts ("\n", s);
1396
show_sig_summary (sum, ctx, key, idx, s, sig);
1369
1400
if (key != signature_key)
1370
1401
gpgme_key_release (key);
1820
1851
return *cur? 0:-1;
1854
static int pgp_gpgme_extract_keys (gpgme_data_t keydata, FILE** fp, int dryrun)
1856
/* there's no side-effect free way to view key data in GPGME,
1857
* so we import the key into a temporary keyring */
1858
char tmpdir[_POSIX_PATH_MAX];
1859
char tmpfile[_POSIX_PATH_MAX];
1862
gpgme_engine_info_t engineinfo;
1864
gpgme_user_id_t uid;
1865
gpgme_subkey_t subkey;
1866
const char* shortid;
1872
if ((err = gpgme_new (&tmpctx)) != GPG_ERR_NO_ERROR)
1874
dprint (1, (debugfile, "Error creating GPGME context\n"));
1880
snprintf (tmpdir, sizeof(tmpdir), "%s/mutt-gpgme-XXXXXX", Tempdir);
1881
if (!mkdtemp (tmpdir))
1883
dprint (1, (debugfile, "Error creating temporary GPGME home\n"));
1887
engineinfo = gpgme_ctx_get_engine_info (tmpctx);
1888
while (engineinfo && engineinfo->protocol != GPGME_PROTOCOL_OpenPGP)
1889
engineinfo = engineinfo->next;
1892
dprint (1, (debugfile, "Error finding GPGME PGP engine\n"));
1896
err = gpgme_ctx_set_engine_info (tmpctx, GPGME_PROTOCOL_OpenPGP,
1897
engineinfo->file_name, tmpdir);
1898
if (err != GPG_ERR_NO_ERROR)
1900
dprint (1, (debugfile, "Error setting GPGME context home\n"));
1905
if ((err = gpgme_op_import (tmpctx, keydata)) != GPG_ERR_NO_ERROR)
1907
dprint (1, (debugfile, "Error importing key\n"));
1911
mutt_mktemp (tmpfile);
1912
*fp = safe_fopen (tmpfile, "w+");
1915
mutt_perror (tmpfile);
1920
err = gpgme_op_keylist_start (tmpctx, NULL, 0);
1923
if ((err = gpgme_op_keylist_next (tmpctx, &key)))
1926
subkey = key->subkeys;
1930
shortid = subkey->keyid;
1931
len = mutt_strlen (subkey->keyid);
1934
strftime (date, sizeof (date), "%Y-%m-%d", localtime (&subkey->timestamp));
1937
fprintf (*fp, "%s %5.5s %d/%8s %s %s\n", more ? "sub" : "pub",
1938
gpgme_pubkey_algo_name (subkey->pubkey_algo), subkey->length,
1939
shortid, date, uid->uid);
1941
fprintf (*fp, "%s %5.5s %d/%8s %s\n", more ? "sub" : "pub",
1942
gpgme_pubkey_algo_name (subkey->pubkey_algo), subkey->length,
1944
subkey = subkey->next;
1947
gpgme_key_release (key);
1949
if (gpg_err_code (err) != GPG_ERR_EOF)
1951
dprint (1, (debugfile, "Error listing keys\n"));
1962
mutt_rmtree (tmpdir);
1964
gpgme_release (tmpctx);
1825
1970
* Implementation of `pgp_check_traditional'.
2051
/* TODO: looks like this won't work and we'll have to fully parse the
2052
* message file. GPGME makes life hard yet again. */
2053
void pgp_gpgme_invoke_import (const char *fname)
2055
gpgme_data_t keydata;
2061
if (!(in = safe_fopen (fname, "r")))
2063
if ((err = gpgme_data_new_from_stream (&keydata, in)) != GPG_ERR_NO_ERROR)
2065
dprint (1, (debugfile, "error converting key file into data object\n"));
2070
if (!pgp_gpgme_extract_keys (keydata, &out, 0))
2072
/* display import results */
2073
outlen = ftell (out);
2074
fseek (out, 0, SEEK_SET);
2075
mutt_copy_bytes (out, stdout, outlen);
2079
printf (_("Error extracting key data!\n"));
1908
2084
* Implementation of `application_handler'.