NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
encrypted_handler()

Manage a PGP or S/MIME encrypted MIME part. More...

+ Collaboration diagram for encrypted_handler():

Functions

int pgp_gpgme_encrypted_handler (struct Body *a, struct State *s)
 Implements CryptModuleSpecs::encrypted_handler() -. More...
 
int pgp_class_encrypted_handler (struct Body *a, struct State *s)
 Implements CryptModuleSpecs::encrypted_handler() -. More...
 

Detailed Description

Manage a PGP or S/MIME encrypted MIME part.

Parameters
mBody of the email
sState of text being processed
Return values
0Success
-1Error

Function Documentation

◆ pgp_gpgme_encrypted_handler()

int pgp_gpgme_encrypted_handler ( struct Body a,
struct State s 
)

Implements CryptModuleSpecs::encrypted_handler() -.

This handler is passed the application/octet-stream directly. The caller must propagate a->goodsig to its parent.

Definition at line 2650 of file crypt_gpgme.c.

2651{
2652 int is_signed;
2653 int rc = 0;
2654
2655 mutt_debug(LL_DEBUG2, "Entering handler\n");
2656
2657 FILE *fp_out = mutt_file_mkstemp();
2658 if (!fp_out)
2659 {
2660 mutt_perror(_("Can't create temporary file"));
2661 if (s->flags & MUTT_DISPLAY)
2662 {
2663 state_attach_puts(s, _("[-- Error: could not create temporary file --]\n"));
2664 }
2665 return -1;
2666 }
2667
2668 struct Body *tattach = decrypt_part(a, s, fp_out, false, &is_signed);
2669 if (tattach)
2670 {
2671 tattach->goodsig = is_signed > 0;
2672
2673 if (s->flags & MUTT_DISPLAY)
2674 {
2675 state_attach_puts(s, is_signed ?
2676 _("[-- The following data is PGP/MIME signed and encrypted --]\n\n") :
2677 _("[-- The following data is PGP/MIME encrypted --]\n\n"));
2679 }
2680
2681 /* Store any protected headers in the parent so they can be
2682 * accessed for index updates after the handler recursion is done.
2683 * This is done before the handler to prevent a nested encrypted
2684 * handler from freeing the headers. */
2686 a->mime_headers = tattach->mime_headers;
2687 tattach->mime_headers = NULL;
2688
2689 {
2690 FILE *fp_save = s->fp_in;
2691 s->fp_in = fp_out;
2692 rc = mutt_body_handler(tattach, s);
2693 s->fp_in = fp_save;
2694 }
2695
2696 /* Embedded multipart signed protected headers override the
2697 * encrypted headers. We need to do this after the handler so
2698 * they can be printed in the pager. */
2699 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
2700 {
2702 a->mime_headers = tattach->parts->mime_headers;
2703 tattach->parts->mime_headers = NULL;
2704 }
2705
2706 /* if a multipart/signed is the _only_ sub-part of a
2707 * multipart/encrypted, cache signature verification
2708 * status. */
2709 if (mutt_is_multipart_signed(tattach) && !tattach->next)
2710 a->goodsig |= tattach->goodsig;
2711
2712 if (s->flags & MUTT_DISPLAY)
2713 {
2714 state_puts(s, "\n");
2715 state_attach_puts(s, is_signed ? _("[-- End of PGP/MIME signed and encrypted data --]\n") :
2716 _("[-- End of PGP/MIME encrypted data --]\n"));
2717 }
2718
2719 mutt_body_free(&tattach);
2720 mutt_message(_("PGP message successfully decrypted"));
2721 }
2722 else
2723 {
2724#ifdef USE_AUTOCRYPT
2725 if (!OptAutocryptGpgme)
2726#endif
2727 {
2728 mutt_error(_("Could not decrypt PGP message"));
2729 }
2730 rc = -1;
2731 }
2732
2733 mutt_file_fclose(&fp_out);
2734 mutt_debug(LL_DEBUG2, "Leaving handler\n");
2735
2736 return rc;
2737}
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:402
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.
Definition: crypt_gpgme.c:1688
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:97
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define mutt_file_mkstemp()
Definition: file.h:112
int mutt_protected_headers_handler(struct Body *b, struct State *s)
Process a protected header - Implements handler_t -.
Definition: crypt.c:1095
#define mutt_error(...)
Definition: logging.h:87
#define mutt_message(...)
Definition: logging.h:86
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
#define mutt_perror(...)
Definition: logging.h:88
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Definition: handler.c:1597
@ LL_DEBUG2
Log at debug level 2.
Definition: logging.h:41
#define _(a)
Definition: message.h:28
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
Definition: state.c:100
#define state_puts(STATE, STR)
Definition: state.h:56
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: options.h:39
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
struct Body * next
next attachment in the list
Definition: body.h:71
bool goodsig
Good cryptographic signature.
Definition: body.h:45
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:50
FILE * fp_in
File to read from.
Definition: state.h:47
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ pgp_class_encrypted_handler()

int pgp_class_encrypted_handler ( struct Body a,
struct State s 
)

Implements CryptModuleSpecs::encrypted_handler() -.

Definition at line 1227 of file pgp.c.

1228{
1229 FILE *fp_in = NULL;
1230 struct Body *tattach = NULL;
1231 int rc = 0;
1232
1233 FILE *fp_out = mutt_file_mkstemp();
1234 if (!fp_out)
1235 {
1236 mutt_perror(_("Can't create temporary file"));
1237 if (s->flags & MUTT_DISPLAY)
1238 {
1239 state_attach_puts(s, _("[-- Error: could not create temporary file --]\n"));
1240 }
1241 return -1;
1242 }
1243
1244 if (s->flags & MUTT_DISPLAY)
1245 crypt_current_time(s, "PGP");
1246
1247 tattach = pgp_decrypt_part(a, s, fp_out, a);
1248 if (tattach)
1249 {
1250 if (s->flags & MUTT_DISPLAY)
1251 {
1252 state_attach_puts(s, _("[-- The following data is PGP/MIME encrypted --]\n\n"));
1254 }
1255
1256 /* Store any protected headers in the parent so they can be
1257 * accessed for index updates after the handler recursion is done.
1258 * This is done before the handler to prevent a nested encrypted
1259 * handler from freeing the headers. */
1261 a->mime_headers = tattach->mime_headers;
1262 tattach->mime_headers = NULL;
1263
1264 fp_in = s->fp_in;
1265 s->fp_in = fp_out;
1266 rc = mutt_body_handler(tattach, s);
1267 s->fp_in = fp_in;
1268
1269 /* Embedded multipart signed protected headers override the
1270 * encrypted headers. We need to do this after the handler so
1271 * they can be printed in the pager. */
1272 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
1273 {
1275 a->mime_headers = tattach->parts->mime_headers;
1276 tattach->parts->mime_headers = NULL;
1277 }
1278
1279 /* if a multipart/signed is the _only_ sub-part of a
1280 * multipart/encrypted, cache signature verification
1281 * status. */
1282 if (mutt_is_multipart_signed(tattach) && !tattach->next)
1283 a->goodsig |= tattach->goodsig;
1284
1285 if (s->flags & MUTT_DISPLAY)
1286 {
1287 state_puts(s, "\n");
1288 state_attach_puts(s, _("[-- End of PGP/MIME encrypted data --]\n"));
1289 }
1290
1291 mutt_body_free(&tattach);
1292 /* clear 'Invoking...' message, since there's no error */
1293 mutt_message(_("PGP message successfully decrypted"));
1294 }
1295 else
1296 {
1297 mutt_error(_("Could not decrypt PGP message"));
1298 /* void the passphrase, even if it's not necessarily the problem */
1300 rc = -1;
1301 }
1302
1303 mutt_file_fclose(&fp_out);
1304
1305 return rc;
1306}
void crypt_current_time(struct State *s, const char *app_name)
Print the current time.
Definition: crypt.c:70
void pgp_class_void_passphrase(void)
Implements CryptModuleSpecs::void_passphrase() -.
Definition: pgp.c:75
static struct Body * pgp_decrypt_part(struct Body *a, struct State *s, FILE *fp_out, struct Body *p)
Decrypt part of a PGP message.
Definition: pgp.c:1008
+ Here is the call graph for this function: