NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
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 *b, struct State *state)
 Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.
 
int pgp_class_encrypted_handler (struct Body *b, struct State *state)
 Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.
 

Detailed Description

Manage a PGP or S/MIME encrypted MIME part.

Parameters
bBody of the email
stateState of text being processed
Return values
0Success
-1Error

Function Documentation

◆ pgp_gpgme_encrypted_handler()

int pgp_gpgme_encrypted_handler ( struct Body b,
struct State state 
)

Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.

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

Definition at line 2718 of file crypt_gpgme.c.

2719{
2720 int is_signed;
2721 int rc = 0;
2722
2723 mutt_debug(LL_DEBUG2, "Entering handler\n");
2724
2725 FILE *fp_out = mutt_file_mkstemp();
2726 if (!fp_out)
2727 {
2728 mutt_perror(_("Can't create temporary file"));
2729 if (state->flags & STATE_DISPLAY)
2730 {
2731 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
2732 }
2733 return -1;
2734 }
2735
2736 struct Body *tattach = decrypt_part(b, state, fp_out, false, &is_signed);
2737 if (tattach)
2738 {
2739 tattach->goodsig = is_signed > 0;
2740
2741 if (state->flags & STATE_DISPLAY)
2742 {
2743 state_attach_puts(state, is_signed ?
2744 _("[-- The following data is PGP/MIME signed and encrypted --]\n\n") :
2745 _("[-- The following data is PGP/MIME encrypted --]\n\n"));
2746 mutt_protected_headers_handler(tattach, state);
2747 }
2748
2749 /* Store any protected headers in the parent so they can be
2750 * accessed for index updates after the handler recursion is done.
2751 * This is done before the handler to prevent a nested encrypted
2752 * handler from freeing the headers. */
2754 b->mime_headers = tattach->mime_headers;
2755 tattach->mime_headers = NULL;
2756
2757 FILE *fp_save = state->fp_in;
2758 state->fp_in = fp_out;
2759 rc = mutt_body_handler(tattach, state);
2760 state->fp_in = fp_save;
2761
2762 /* Embedded multipart signed protected headers override the
2763 * encrypted headers. We need to do this after the handler so
2764 * they can be printed in the pager. */
2765 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
2766 {
2768 b->mime_headers = tattach->parts->mime_headers;
2769 tattach->parts->mime_headers = NULL;
2770 }
2771
2772 /* if a multipart/signed is the _only_ sub-part of a
2773 * multipart/encrypted, cache signature verification
2774 * status. */
2775 if (mutt_is_multipart_signed(tattach) && !tattach->next)
2776 b->goodsig |= tattach->goodsig;
2777
2778 if (state->flags & STATE_DISPLAY)
2779 {
2780 state_puts(state, "\n");
2781 state_attach_puts(state, is_signed ?
2782 _("[-- End of PGP/MIME signed and encrypted data --]\n") :
2783 _("[-- End of PGP/MIME encrypted data --]\n"));
2784 }
2785
2786 mutt_body_free(&tattach);
2787 mutt_message(_("PGP message successfully decrypted"));
2788 }
2789 else
2790 {
2791#ifdef USE_AUTOCRYPT
2792 if (!OptAutocryptGpgme)
2793#endif
2794 {
2795 mutt_error(_("Could not decrypt PGP message"));
2796 }
2797 rc = -1;
2798 }
2799
2800 mutt_file_fclose(&fp_out);
2801 mutt_debug(LL_DEBUG2, "Leaving handler\n");
2802
2803 return rc;
2804}
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:394
static struct Body * decrypt_part(struct Body *b, struct State *state, FILE *fp_out, bool is_smime, int *r_is_signed)
Decrypt a PGP or SMIME message.
Definition: crypt_gpgme.c:1693
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
#define mutt_file_fclose(FP)
Definition: file.h:147
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: globals.c:62
int mutt_protected_headers_handler(struct Body *b_email, struct State *state)
Handler for protected headers - Implements handler_t -.
Definition: crypt.c:1103
#define mutt_error(...)
Definition: logging2.h:92
#define mutt_message(...)
Definition: logging2.h:91
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
#define mutt_perror(...)
Definition: logging2.h:93
int mutt_body_handler(struct Body *b, struct State *state)
Handler for the Body of an email.
Definition: handler.c:1631
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define _(a)
Definition: message.h:28
void state_attach_puts(struct State *state, const char *t)
Write a string to the state.
Definition: state.c:103
#define state_puts(STATE, STR)
Definition: state.h:58
#define STATE_DISPLAY
Output is displayed to the user.
Definition: state.h:33
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. STATE_DISPLAY.
Definition: state.h:52
FILE * fp_in
File to read from.
Definition: state.h:49
#define mutt_file_mkstemp()
Definition: tmp.h:36
+ 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 b,
struct State state 
)

Manage a PGP or S/MIME encrypted MIME part - Implements CryptModuleSpecs::encrypted_handler() -.

Definition at line 1247 of file pgp.c.

1248{
1249 FILE *fp_in = NULL;
1250 struct Body *tattach = NULL;
1251 int rc = 0;
1252
1253 FILE *fp_out = mutt_file_mkstemp();
1254 if (!fp_out)
1255 {
1256 mutt_perror(_("Can't create temporary file"));
1257 if (state->flags & STATE_DISPLAY)
1258 {
1259 state_attach_puts(state, _("[-- Error: could not create temporary file --]\n"));
1260 }
1261 return -1;
1262 }
1263
1264 if (state->flags & STATE_DISPLAY)
1265 crypt_current_time(state, "PGP");
1266
1267 tattach = pgp_decrypt_part(b, state, fp_out, b);
1268 if (tattach)
1269 {
1270 if (state->flags & STATE_DISPLAY)
1271 {
1272 state_attach_puts(state, _("[-- The following data is PGP/MIME encrypted --]\n\n"));
1273 mutt_protected_headers_handler(tattach, state);
1274 }
1275
1276 /* Store any protected headers in the parent so they can be
1277 * accessed for index updates after the handler recursion is done.
1278 * This is done before the handler to prevent a nested encrypted
1279 * handler from freeing the headers. */
1281 b->mime_headers = tattach->mime_headers;
1282 tattach->mime_headers = NULL;
1283
1284 fp_in = state->fp_in;
1285 state->fp_in = fp_out;
1286 rc = mutt_body_handler(tattach, state);
1287 state->fp_in = fp_in;
1288
1289 /* Embedded multipart signed protected headers override the
1290 * encrypted headers. We need to do this after the handler so
1291 * they can be printed in the pager. */
1292 if (mutt_is_multipart_signed(tattach) && tattach->parts && tattach->parts->mime_headers)
1293 {
1295 b->mime_headers = tattach->parts->mime_headers;
1296 tattach->parts->mime_headers = NULL;
1297 }
1298
1299 /* if a multipart/signed is the _only_ sub-part of a
1300 * multipart/encrypted, cache signature verification
1301 * status. */
1302 if (mutt_is_multipart_signed(tattach) && !tattach->next)
1303 b->goodsig |= tattach->goodsig;
1304
1305 if (state->flags & STATE_DISPLAY)
1306 {
1307 state_puts(state, "\n");
1308 state_attach_puts(state, _("[-- End of PGP/MIME encrypted data --]\n"));
1309 }
1310
1311 mutt_body_free(&tattach);
1312 /* clear 'Invoking...' message, since there's no error */
1313 mutt_message(_("PGP message successfully decrypted"));
1314 }
1315 else
1316 {
1317 mutt_error(_("Could not decrypt PGP message"));
1318 /* void the passphrase, even if it's not necessarily the problem */
1320 rc = -1;
1321 }
1322
1323 mutt_file_fclose(&fp_out);
1324
1325 return rc;
1326}
void crypt_current_time(struct State *state, const char *app_name)
Print the current time.
Definition: crypt.c:65
void pgp_class_void_passphrase(void)
Forget the cached passphrase - Implements CryptModuleSpecs::void_passphrase() -.
Definition: pgp.c:76
static struct Body * pgp_decrypt_part(struct Body *a, struct State *state, FILE *fp_out, struct Body *p)
Decrypt part of a PGP message.
Definition: pgp.c:1026
+ Here is the call graph for this function: