📄 crypt-gpgme.c
字号:
gpgme_verify_result_t verify_result; verify_result = gpgme_op_verify_result (ctx); if (verify_result->signatures) sig_stat = 1; } have_any_sigs = 0; maybe_goodsig = 0; if ((s->flags & M_DISPLAY) && sig_stat) { int res, idx; int anybad = 0; int anywarn = 0; state_attach_puts (_("[-- Begin signature " "information --]\n"), s); have_any_sigs = 1; for(idx=0; (res = show_one_sig_status (ctx, idx, s)) != -1; idx++) { if (res == 1) anybad = 1; else if (res == 2) anywarn = 1; } if (!anybad && idx) maybe_goodsig = 1; state_attach_puts (_("[-- End signature " "information --]\n\n"), s); } tmpfname = data_object_to_tempfile (plaintext, &pgpout); if (!tmpfname) { pgpout = NULL; state_attach_puts (_("Error: copy data failed\n"), s); } else { unlink (tmpfname); FREE (&tmpfname); } } gpgme_release (ctx); } /* * Now, copy cleartext to the screen. NOTE - we expect that PGP * outputs utf-8 cleartext. This may not always be true, but it * seems to be a reasonable guess. */ if(s->flags & M_DISPLAY) { if (needpass) state_attach_puts (_("[-- BEGIN PGP MESSAGE --]\n\n"), s); else if (pgp_keyblock) state_attach_puts (_("[-- BEGIN PGP PUBLIC KEY BLOCK --]\n"), s); else state_attach_puts (_("[-- BEGIN PGP SIGNED MESSAGE --]\n\n"), s); } if (clearsign) { copy_clearsigned (armored_data, s, body_charset); } else if (pgpout) { FGETCONV *fc; int c; rewind (pgpout); fc = fgetconv_open (pgpout, "utf-8", Charset, 0); while ((c = fgetconv (fc)) != EOF) { state_putc (c, s); if (c == '\n' && s->prefix) state_puts (s->prefix, s); } fgetconv_close (&fc); } if (s->flags & M_DISPLAY) { state_putc ('\n', s); if (needpass) state_attach_puts (_("[-- END PGP MESSAGE --]\n"), s); else if (pgp_keyblock) state_attach_puts (_("[-- END PGP PUBLIC KEY BLOCK --]\n"), s); else state_attach_puts (_("[-- END PGP SIGNED MESSAGE --]\n"), s); } if (pgpout) { safe_fclose (&pgpout); } } else { /* XXX - we may wish to recode here */ if (s->prefix) state_puts (s->prefix, s); state_puts (buf, s); } } m->goodsig = (maybe_goodsig && have_any_sigs); if (needpass == -1) { state_attach_puts (_("[-- Error: could not find beginning" " of PGP message! --]\n\n"), s); return -1; } dprint (2, (debugfile, "Leaving pgp_application_pgp handler\n")); return err;}/* * Implementation of `encrypted_handler'. *//* MIME handler for pgp/mime encrypted messages. */int pgp_gpgme_encrypted_handler (BODY *a, STATE *s){ char tempfile[_POSIX_PATH_MAX]; FILE *fpout; BODY *tattach; BODY *orig_body = a; int is_signed; int rc = 0; dprint (2, (debugfile, "Entering pgp_encrypted handler\n")); a = a->parts; if (!a || a->type != TYPEAPPLICATION || !a->subtype || ascii_strcasecmp ("pgp-encrypted", a->subtype) || !a->next || a->next->type != TYPEAPPLICATION || !a->next->subtype || ascii_strcasecmp ("octet-stream", a->next->subtype) ) { if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: malformed PGP/MIME message! --]\n\n"), s); return -1; } /* Move forward to the application/pgp-encrypted body. */ a = a->next; mutt_mktemp (tempfile); if (!(fpout = safe_fopen (tempfile, "w+"))) { if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: could not create temporary file! " "--]\n"), s); return -1; } tattach = decrypt_part (a, s, fpout, 0, &is_signed); if (tattach) { tattach->goodsig = is_signed > 0; if (s->flags & M_DISPLAY) state_attach_puts (is_signed? _("[-- The following data is PGP/MIME signed and encrypted --]\n\n"): _("[-- The following data is PGP/MIME encrypted --]\n\n"), s); { FILE *savefp = s->fpin; s->fpin = fpout; rc = mutt_body_handler (tattach, s); s->fpin = savefp; } /* * if a multipart/signed is the _only_ sub-part of a * multipart/encrypted, cache signature verification * status. */ if (mutt_is_multipart_signed (tattach) && !tattach->next) orig_body->goodsig |= tattach->goodsig; if (s->flags & M_DISPLAY) { state_puts ("\n", s); state_attach_puts (is_signed? _("[-- End of PGP/MIME signed and encrypted data --]\n"): _("[-- End of PGP/MIME encrypted data --]\n"), s); } mutt_free_body (&tattach); } fclose (fpout); mutt_unlink(tempfile); dprint (2, (debugfile, "Leaving pgp_encrypted handler\n")); return rc;}/* Support for application/smime */int smime_gpgme_application_handler (BODY *a, STATE *s){ char tempfile[_POSIX_PATH_MAX]; FILE *fpout; BODY *tattach; int is_signed; int rc = 0; dprint (2, (debugfile, "Entering smime_encrypted handler\n")); a->warnsig = 0; mutt_mktemp (tempfile); if (!(fpout = safe_fopen (tempfile, "w+"))) { if (s->flags & M_DISPLAY) state_attach_puts (_("[-- Error: could not create temporary file! " "--]\n"), s); return -1; } tattach = decrypt_part (a, s, fpout, 1, &is_signed); if (tattach) { tattach->goodsig = is_signed > 0; if (s->flags & M_DISPLAY) state_attach_puts (is_signed? _("[-- The following data is S/MIME signed --]\n\n"): _("[-- The following data is S/MIME encrypted --]\n\n"), s); { FILE *savefp = s->fpin; s->fpin = fpout; rc = mutt_body_handler (tattach, s); s->fpin = savefp; } /* * if a multipart/signed is the _only_ sub-part of a * multipart/encrypted, cache signature verification * status. */ if (mutt_is_multipart_signed (tattach) && !tattach->next) { if (!(a->goodsig = tattach->goodsig)) a->warnsig = tattach->warnsig; } else if (tattach->goodsig) { a->goodsig = 1; a->warnsig = tattach->warnsig; } if (s->flags & M_DISPLAY) { state_puts ("\n", s); state_attach_puts (is_signed? _("[-- End of S/MIME signed data --]\n"): _("[-- End of S/MIME encrypted data --]\n"), s); } mutt_free_body (&tattach); } fclose (fpout); mutt_unlink(tempfile); dprint (2, (debugfile, "Leaving smime_encrypted handler\n")); return rc;}/* * Format an entry on the CRYPT key selection menu. * * %n number * %k key id %K key id of the principal key * %u user id * %a algorithm %A algorithm of the princ. key * %l length %L length of the princ. key * %f flags %F flags of the princ. key * %c capabilities %C capabilities of the princ. key * %t trust/validity of the key-uid association * %p protocol * %[...] date of key using strftime(3) */static const char *crypt_entry_fmt (char *dest, size_t destlen, char op, const char *src, const char *prefix, const char *ifstring, const char *elsestring, unsigned long data, format_flag flags){ char fmt[16]; crypt_entry_t *entry; crypt_key_t *key; int kflags = 0; int optional = (flags & M_FORMAT_OPTIONAL); const char *s = NULL; unsigned long val; entry = (crypt_entry_t *) data; key = entry->key;/* if (isupper ((unsigned char) op)) *//* key = pkey; */ kflags = (key->flags /*| (pkey->flags & KEYFLAG_RESTRICTIONS) | uid->flags*/); switch (ascii_tolower (op)) { case '[': { const char *cp; char buf2[SHORT_STRING], *p; int do_locales; struct tm *tm; size_t len; p = dest; cp = src; if (*cp == '!') { do_locales = 0; cp++; } else do_locales = 1; len = destlen - 1; while (len > 0 && *cp != ']') { if (*cp == '%') { cp++; if (len >= 2) { *p++ = '%'; *p++ = *cp; len -= 2; } else break; /* not enough space */ cp++; } else { *p++ = *cp++; len--; } } *p = 0; if (do_locales && Locale) setlocale (LC_TIME, Locale); { time_t tt = 0; if (key->kobj->subkeys && (key->kobj->subkeys->timestamp > 0)) tt = key->kobj->subkeys->timestamp; tm = localtime (&tt); } strftime (buf2, sizeof (buf2), dest, tm); if (do_locales) setlocale (LC_TIME, "C"); snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, buf2); if (len > 0) src = cp + 1; } break; case 'n': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sd", prefix); snprintf (dest, destlen, fmt, entry->num); } break; case 'k': if (!optional) { /* fixme: we need a way to distinguish between main and subkeys. Store the idx in entry? */ snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, crypt_keyid (key)); } break; case 'u': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, key->uid); } break; case 'a': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%s.3s", prefix); if (key->kobj->subkeys) s = gpgme_pubkey_algo_name (key->kobj->subkeys->pubkey_algo); else s = "?"; snprintf (dest, destlen, fmt, s); } break; case 'l': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%slu", prefix); if (key->kobj->subkeys) val = key->kobj->subkeys->length; else val = 0; snprintf (dest, destlen, fmt, val); } break; case 'f': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%sc", prefix); snprintf (dest, destlen, fmt, crypt_flags (kflags)); } else if (!(kflags & (KEYFLAG_RESTRICTIONS))) optional = 0; break; case 'c': if (!optional) { snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, crypt_key_abilities (kflags)); } else if (!(kflags & (KEYFLAG_ABILITIES))) optional = 0; break; case 't': if ((kflags & KEYFLAG_ISX509)) s = "x"; else { gpgme_user_id_t uid = NULL; unsigned int i = 0; for (i = 0, uid = key->kobj->uids; uid && (i < key->idx); i++, uid = uid->next) ; if (uid) switch (uid->validity) { case GPGME_VALIDITY_UNDEFINED: s = "q"; break; case GPGME_VALIDITY_NEVER: s = "n"; break; case GPGME_VALIDITY_MARGINAL: s = "m"; break; case GPGME_VALIDITY_FULL: s = "f"; break; case GPGME_VALIDITY_ULTIMATE: s = "u"; break; case GPGME_VALIDITY_UNKNOWN: default: s = "?"; break; } } snprintf (fmt, sizeof (fmt), "%%%sc", prefix); snprintf (dest, destlen, fmt, s? *s: 'B'); break; case 'p': snprintf (fmt, sizeof (fmt), "%%%ss", prefix); snprintf (dest, destlen, fmt, gpgme_get_protocol_name (key->kobj->protocol)); break; default: *dest = '\0'; } if (optiona
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -