NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
lib.h File Reference

API for encryption/signing of emails. More...

#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
+ Include dependency graph for lib.h:

Go to the source code of this file.

Macros

#define SEC_NO_FLAGS   0
 No flags are set. More...
 
#define SEC_ENCRYPT   (1 << 0)
 Email is encrypted. More...
 
#define SEC_SIGN   (1 << 1)
 Email is signed. More...
 
#define SEC_GOODSIGN   (1 << 2)
 Email has a valid signature. More...
 
#define SEC_BADSIGN   (1 << 3)
 Email has a bad signature. More...
 
#define SEC_PARTSIGN   (1 << 4)
 Not all parts of the email is signed. More...
 
#define SEC_SIGNOPAQUE   (1 << 5)
 Email has an opaque signature (encrypted) More...
 
#define SEC_KEYBLOCK   (1 << 6)
 Email has a key attached. More...
 
#define SEC_INLINE   (1 << 7)
 Email has an inline signature. More...
 
#define SEC_OPPENCRYPT   (1 << 8)
 Opportunistic encrypt mode. More...
 
#define SEC_AUTOCRYPT   (1 << 9)
 (Autocrypt) Message will be, or was Autocrypt encrypt+signed More...
 
#define SEC_AUTOCRYPT_OVERRIDE   (1 << 10)
 (Autocrypt) Indicates manual set/unset of encryption More...
 
#define APPLICATION_PGP   (1 << 11)
 Use PGP to encrypt/sign. More...
 
#define APPLICATION_SMIME   (1 << 12)
 Use SMIME to encrypt/sign. More...
 
#define PGP_TRADITIONAL_CHECKED   (1 << 13)
 Email has a traditional (inline) signature. More...
 
#define SEC_ALL_FLAGS   ((1 << 14) - 1)
 
#define PGP_ENCRYPT   (APPLICATION_PGP | SEC_ENCRYPT)
 
#define PGP_SIGN   (APPLICATION_PGP | SEC_SIGN)
 
#define PGP_GOODSIGN   (APPLICATION_PGP | SEC_GOODSIGN)
 
#define PGP_KEY   (APPLICATION_PGP | SEC_KEYBLOCK)
 
#define PGP_INLINE   (APPLICATION_PGP | SEC_INLINE)
 
#define SMIME_ENCRYPT   (APPLICATION_SMIME | SEC_ENCRYPT)
 
#define SMIME_SIGN   (APPLICATION_SMIME | SEC_SIGN)
 
#define SMIME_GOODSIGN   (APPLICATION_SMIME | SEC_GOODSIGN)
 
#define SMIME_BADSIGN   (APPLICATION_SMIME | SEC_BADSIGN)
 
#define SMIME_OPAQUE   (APPLICATION_SMIME | SEC_SIGNOPAQUE)
 
#define WithCrypto   (APPLICATION_PGP | APPLICATION_SMIME)
 
#define KEYFLAG_NO_FLAGS   0
 No flags are set. More...
 
#define KEYFLAG_CANSIGN   (1 << 0)
 Key is suitable for signing. More...
 
#define KEYFLAG_CANENCRYPT   (1 << 1)
 Key is suitable for encryption. More...
 
#define KEYFLAG_ISX509   (1 << 2)
 Key is an X.509 key. More...
 
#define KEYFLAG_SECRET   (1 << 7)
 Key is a secret key. More...
 
#define KEYFLAG_EXPIRED   (1 << 8)
 Key is expired. More...
 
#define KEYFLAG_REVOKED   (1 << 9)
 Key is revoked. More...
 
#define KEYFLAG_DISABLED   (1 << 10)
 Key is marked disabled. More...
 
#define KEYFLAG_SUBKEY   (1 << 11)
 Key is a subkey. More...
 
#define KEYFLAG_CRITICAL   (1 << 12)
 Key is marked critical. More...
 
#define KEYFLAG_PREFER_ENCRYPTION   (1 << 13)
 Key's owner prefers encryption. More...
 
#define KEYFLAG_PREFER_SIGNING   (1 << 14)
 Key's owner prefers signing. More...
 
#define KEYFLAG_CANTUSE   (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
 
#define KEYFLAG_RESTRICTIONS   (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
 
#define KEYFLAG_ABILITIES   (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
 

Typedefs

typedef uint16_t SecurityFlags
 Flags, e.g. SEC_ENCRYPT. More...
 
typedef uint16_t KeyFlags
 Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN. More...
 

Functions

void crypt_extract_keys_from_messages (struct Mailbox *m, struct EmailList *el)
 Extract keys from a message. More...
 
void crypt_forget_passphrase (void)
 Forget a passphrase and display a message. More...
 
int crypt_get_keys (struct Mailbox *m, struct Email *e, char **keylist, bool oppenc_mode)
 Check we have all the keys we need. More...
 
void crypt_opportunistic_encrypt (struct Mailbox *m, struct Email *e)
 Can all recipients be determined. More...
 
SecurityFlags crypt_query (struct Body *b)
 Check out the type of encryption used. More...
 
bool crypt_valid_passphrase (SecurityFlags flags)
 Check that we have a usable passphrase, ask if not. More...
 
SecurityFlags mutt_is_application_pgp (struct Body *b)
 Does the message use PGP? More...
 
SecurityFlags mutt_is_application_smime (struct Body *b)
 Does the message use S/MIME? More...
 
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted (struct Body *b)
 Check for malformed layout. More...
 
SecurityFlags mutt_is_multipart_encrypted (struct Body *b)
 Does the message have encrypted parts? More...
 
SecurityFlags mutt_is_multipart_signed (struct Body *b)
 Is a message signed? More...
 
int mutt_is_valid_multipart_pgp_encrypted (struct Body *b)
 Is this a valid multi-part encrypted message? More...
 
int mutt_protect (struct Mailbox *m, struct Email *e, char *keylist, bool postpone)
 Encrypt and/or sign a message. More...
 
int mutt_protected_headers_handler (struct Body *b, struct State *s)
 Process a protected header - Implements handler_t. More...
 
bool mutt_should_hide_protected_subject (struct Email *e)
 Should NeoMutt hide the protected subject? More...
 
int mutt_signed_handler (struct Body *b, struct State *s)
 Verify a "multipart/signed" body - Implements handler_t. More...
 
void crypt_cleanup (void)
 Clean up backend. More...
 
bool crypt_has_module_backend (SecurityFlags type)
 Is there a crypto backend for a given type? More...
 
void crypt_init (void)
 Initialise the crypto backends. More...
 
void crypt_invoke_message (SecurityFlags type)
 Display an informative message. More...
 
int crypt_pgp_application_handler (struct Body *m, struct State *s)
 Wrapper for CryptModuleSpecs::application_handler() More...
 
bool crypt_pgp_check_traditional (FILE *fp, struct Body *b, bool just_one)
 Wrapper for CryptModuleSpecs::pgp_check_traditional() More...
 
int crypt_pgp_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
 Wrapper for CryptModuleSpecs::decrypt_mime() More...
 
int crypt_pgp_encrypted_handler (struct Body *a, struct State *s)
 Wrapper for CryptModuleSpecs::encrypted_handler() More...
 
void crypt_pgp_extract_key_from_attachment (FILE *fp, struct Body *top)
 Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment() More...
 
void crypt_pgp_invoke_getkeys (struct Address *addr)
 Wrapper for CryptModuleSpecs::pgp_invoke_getkeys() More...
 
struct Bodycrypt_pgp_make_key_attachment (void)
 Wrapper for CryptModuleSpecs::pgp_make_key_attachment() More...
 
SecurityFlags crypt_pgp_send_menu (struct Mailbox *m, struct Email *e)
 Wrapper for CryptModuleSpecs::send_menu() More...
 
int crypt_smime_application_handler (struct Body *m, struct State *s)
 Wrapper for CryptModuleSpecs::application_handler() More...
 
int crypt_smime_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
 Wrapper for CryptModuleSpecs::decrypt_mime() More...
 
void crypt_smime_getkeys (struct Envelope *env)
 Wrapper for CryptModuleSpecs::smime_getkeys() More...
 
SecurityFlags crypt_smime_send_menu (struct Mailbox *m, struct Email *e)
 Wrapper for CryptModuleSpecs::send_menu() More...
 
int crypt_smime_verify_sender (struct Mailbox *m, struct Email *e, struct Message *msg)
 Wrapper for CryptModuleSpecs::smime_verify_sender() More...
 
void crypto_module_free (void)
 Clean up the crypto modules. More...
 
void pgp_gpgme_init (void)
 Implements CryptModuleSpecs::init() -. More...
 
int mutt_gpgme_select_secret_key (struct Buffer *keyid)
 Select a private Autocrypt key for a new account. More...
 
const char * mutt_gpgme_print_version (void)
 Get version of GPGME. More...
 

Detailed Description

API for encryption/signing of emails.

Authors
  • Werner Koch
  • g10code GmbH
  • Pietro Cerutti

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file lib.h.

Macro Definition Documentation

◆ SEC_NO_FLAGS

#define SEC_NO_FLAGS   0

No flags are set.

Definition at line 74 of file lib.h.

◆ SEC_ENCRYPT

#define SEC_ENCRYPT   (1 << 0)

Email is encrypted.

Definition at line 75 of file lib.h.

◆ SEC_SIGN

#define SEC_SIGN   (1 << 1)

Email is signed.

Definition at line 76 of file lib.h.

◆ SEC_GOODSIGN

#define SEC_GOODSIGN   (1 << 2)

Email has a valid signature.

Definition at line 77 of file lib.h.

◆ SEC_BADSIGN

#define SEC_BADSIGN   (1 << 3)

Email has a bad signature.

Definition at line 78 of file lib.h.

◆ SEC_PARTSIGN

#define SEC_PARTSIGN   (1 << 4)

Not all parts of the email is signed.

Definition at line 79 of file lib.h.

◆ SEC_SIGNOPAQUE

#define SEC_SIGNOPAQUE   (1 << 5)

Email has an opaque signature (encrypted)

Definition at line 80 of file lib.h.

◆ SEC_KEYBLOCK

#define SEC_KEYBLOCK   (1 << 6)

Email has a key attached.

Definition at line 81 of file lib.h.

◆ SEC_INLINE

#define SEC_INLINE   (1 << 7)

Email has an inline signature.

Definition at line 82 of file lib.h.

◆ SEC_OPPENCRYPT

#define SEC_OPPENCRYPT   (1 << 8)

Opportunistic encrypt mode.

Definition at line 83 of file lib.h.

◆ SEC_AUTOCRYPT

#define SEC_AUTOCRYPT   (1 << 9)

(Autocrypt) Message will be, or was Autocrypt encrypt+signed

Definition at line 84 of file lib.h.

◆ SEC_AUTOCRYPT_OVERRIDE

#define SEC_AUTOCRYPT_OVERRIDE   (1 << 10)

(Autocrypt) Indicates manual set/unset of encryption

Definition at line 85 of file lib.h.

◆ APPLICATION_PGP

#define APPLICATION_PGP   (1 << 11)

Use PGP to encrypt/sign.

Definition at line 87 of file lib.h.

◆ APPLICATION_SMIME

#define APPLICATION_SMIME   (1 << 12)

Use SMIME to encrypt/sign.

Definition at line 88 of file lib.h.

◆ PGP_TRADITIONAL_CHECKED

#define PGP_TRADITIONAL_CHECKED   (1 << 13)

Email has a traditional (inline) signature.

Definition at line 89 of file lib.h.

◆ SEC_ALL_FLAGS

#define SEC_ALL_FLAGS   ((1 << 14) - 1)

Definition at line 91 of file lib.h.

◆ PGP_ENCRYPT

#define PGP_ENCRYPT   (APPLICATION_PGP | SEC_ENCRYPT)

Definition at line 93 of file lib.h.

◆ PGP_SIGN

#define PGP_SIGN   (APPLICATION_PGP | SEC_SIGN)

Definition at line 94 of file lib.h.

◆ PGP_GOODSIGN

#define PGP_GOODSIGN   (APPLICATION_PGP | SEC_GOODSIGN)

Definition at line 95 of file lib.h.

◆ PGP_KEY

#define PGP_KEY   (APPLICATION_PGP | SEC_KEYBLOCK)

Definition at line 96 of file lib.h.

◆ PGP_INLINE

#define PGP_INLINE   (APPLICATION_PGP | SEC_INLINE)

Definition at line 97 of file lib.h.

◆ SMIME_ENCRYPT

#define SMIME_ENCRYPT   (APPLICATION_SMIME | SEC_ENCRYPT)

Definition at line 99 of file lib.h.

◆ SMIME_SIGN

#define SMIME_SIGN   (APPLICATION_SMIME | SEC_SIGN)

Definition at line 100 of file lib.h.

◆ SMIME_GOODSIGN

#define SMIME_GOODSIGN   (APPLICATION_SMIME | SEC_GOODSIGN)

Definition at line 101 of file lib.h.

◆ SMIME_BADSIGN

#define SMIME_BADSIGN   (APPLICATION_SMIME | SEC_BADSIGN)

Definition at line 102 of file lib.h.

◆ SMIME_OPAQUE

#define SMIME_OPAQUE   (APPLICATION_SMIME | SEC_SIGNOPAQUE)

Definition at line 103 of file lib.h.

◆ WithCrypto

#define WithCrypto   (APPLICATION_PGP | APPLICATION_SMIME)

Definition at line 113 of file lib.h.

◆ KEYFLAG_NO_FLAGS

#define KEYFLAG_NO_FLAGS   0

No flags are set.

Definition at line 123 of file lib.h.

◆ KEYFLAG_CANSIGN

#define KEYFLAG_CANSIGN   (1 << 0)

Key is suitable for signing.

Definition at line 124 of file lib.h.

◆ KEYFLAG_CANENCRYPT

#define KEYFLAG_CANENCRYPT   (1 << 1)

Key is suitable for encryption.

Definition at line 125 of file lib.h.

◆ KEYFLAG_ISX509

#define KEYFLAG_ISX509   (1 << 2)

Key is an X.509 key.

Definition at line 126 of file lib.h.

◆ KEYFLAG_SECRET

#define KEYFLAG_SECRET   (1 << 7)

Key is a secret key.

Definition at line 127 of file lib.h.

◆ KEYFLAG_EXPIRED

#define KEYFLAG_EXPIRED   (1 << 8)

Key is expired.

Definition at line 128 of file lib.h.

◆ KEYFLAG_REVOKED

#define KEYFLAG_REVOKED   (1 << 9)

Key is revoked.

Definition at line 129 of file lib.h.

◆ KEYFLAG_DISABLED

#define KEYFLAG_DISABLED   (1 << 10)

Key is marked disabled.

Definition at line 130 of file lib.h.

◆ KEYFLAG_SUBKEY

#define KEYFLAG_SUBKEY   (1 << 11)

Key is a subkey.

Definition at line 131 of file lib.h.

◆ KEYFLAG_CRITICAL

#define KEYFLAG_CRITICAL   (1 << 12)

Key is marked critical.

Definition at line 132 of file lib.h.

◆ KEYFLAG_PREFER_ENCRYPTION

#define KEYFLAG_PREFER_ENCRYPTION   (1 << 13)

Key's owner prefers encryption.

Definition at line 133 of file lib.h.

◆ KEYFLAG_PREFER_SIGNING

#define KEYFLAG_PREFER_SIGNING   (1 << 14)

Key's owner prefers signing.

Definition at line 134 of file lib.h.

◆ KEYFLAG_CANTUSE

#define KEYFLAG_CANTUSE   (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)

Definition at line 136 of file lib.h.

◆ KEYFLAG_RESTRICTIONS

#define KEYFLAG_RESTRICTIONS   (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)

Definition at line 137 of file lib.h.

◆ KEYFLAG_ABILITIES

Definition at line 139 of file lib.h.

Typedef Documentation

◆ SecurityFlags

typedef uint16_t SecurityFlags

Flags, e.g. SEC_ENCRYPT.

Definition at line 71 of file lib.h.

◆ KeyFlags

typedef uint16_t KeyFlags

Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.

Definition at line 122 of file lib.h.

Function Documentation

◆ crypt_extract_keys_from_messages()

void crypt_extract_keys_from_messages ( struct Mailbox m,
struct EmailList *  el 
)

Extract keys from a message.

Parameters
mMailbox
elList of Emails to process

The extracted keys will be added to the user's keyring.

Definition at line 858 of file crypt.c.

859 {
860  if (!WithCrypto)
861  return;
862 
863  struct Buffer *tempfname = mutt_buffer_pool_get();
864  mutt_buffer_mktemp(tempfname);
865  FILE *fp_out = mutt_file_fopen(mutt_buffer_string(tempfname), "w");
866  if (!fp_out)
867  {
868  mutt_perror(mutt_buffer_string(tempfname));
869  goto cleanup;
870  }
871 
873  OptDontHandlePgpKeys = true;
874 
875  struct EmailNode *en = NULL;
876  STAILQ_FOREACH(en, el, entries)
877  {
878  struct Email *e = en->email;
879  struct Message *msg = mx_msg_open(m, e->msgno);
880  if (!msg)
881  {
882  continue;
883  }
884  mutt_parse_mime_message(m, e, msg->fp);
886  {
887  mx_msg_close(m, &msg);
888  mutt_file_fclose(&fp_out);
889  break;
890  }
891 
892  if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
893  {
895  CH_NO_FLAGS, 0);
896  fflush(fp_out);
897 
898  mutt_endwin();
899  puts(_("Trying to extract PGP keys...\n"));
901  }
902 
903  if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME))
904  {
905  const bool encrypt = e->security & SEC_ENCRYPT;
906  mutt_copy_message(fp_out, m, e, msg,
909  CH_NO_FLAGS, 0);
910  fflush(fp_out);
911 
912  char *mbox = NULL;
913  if (!TAILQ_EMPTY(&e->env->from))
914  {
916  mbox = TAILQ_FIRST(&e->env->from)->mailbox;
917  }
918  else if (!TAILQ_EMPTY(&e->env->sender))
919  {
921  mbox = TAILQ_FIRST(&e->env->sender)->mailbox;
922  }
923  if (mbox)
924  {
925  mutt_endwin();
926  puts(_("Trying to extract S/MIME certificates..."));
928  }
929  }
930  mx_msg_close(m, &msg);
931 
932  rewind(fp_out);
933  }
934 
935  mutt_file_fclose(&fp_out);
936  if (isendwin())
938 
940 
941  if (WithCrypto & APPLICATION_PGP)
942  OptDontHandlePgpKeys = false;
943 
944 cleanup:
945  mutt_buffer_pool_release(&tempfname);
946 }
#define MUTT_CM_DECODE_CRYPT
Definition: copy.h:48
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:591
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
#define WithCrypto
Definition: lib.h:113
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:300
The envelope/body of an email.
Definition: email.h:37
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:195
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:35
#define mutt_perror(...)
Definition: logging.h:89
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1186
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:135
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
struct Envelope * env
Envelope information.
Definition: email.h:90
WHERE bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
Definition: options.h:35
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
A local copy of an email.
Definition: mxapi.h:41
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:422
void crypt_pgp_invoke_import(const char *fname)
Wrapper for CryptModuleSpecs::pgp_invoke_import()
Definition: cryptglue.c:370
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:51
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:38
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:42
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
Definition: copy.h:46
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:455
void crypt_smime_invoke_import(const char *infile, const char *mailbox)
Wrapper for CryptModuleSpecs::smime_invoke_import()
Definition: cryptglue.c:516
struct Email * email
Email in the list.
Definition: email.h:131
FILE * fp
pointer to the message data
Definition: mxapi.h:43
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:853
struct AddressList sender
Email&#39;s sender.
Definition: envelope.h:61
List of Emails.
Definition: email.h:129
#define TAILQ_EMPTY(head)
Definition: queue.h:721
#define MUTT_CM_NOHEADER
Don&#39;t copy the message header.
Definition: copy.h:36
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:589
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1140
int msgno
Number displayed to the user.
Definition: email.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_forget_passphrase()

void crypt_forget_passphrase ( void  )

Forget a passphrase and display a message.

Definition at line 93 of file crypt.c.

94 {
97 
100 
101  if (WithCrypto)
102  {
103  /* L10N: Due to the implementation details (e.g. some passwords are managed
104  by gpg-agent) we can't know whether we forgot zero, 1, 12, ...
105  passwords. So in English we use "Passphrases". Your language might
106  have other means to express this. */
107  mutt_message(_("Passphrases forgotten"));
108  }
109 }
#define WithCrypto
Definition: lib.h:113
void crypt_pgp_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
Definition: cryptglue.c:192
#define _(a)
Definition: message.h:28
void crypt_smime_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
Definition: cryptglue.c:419
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
#define mutt_message(...)
Definition: logging.h:87
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_get_keys()

int crypt_get_keys ( struct Mailbox m,
struct Email e,
char **  keylist,
bool  oppenc_mode 
)

Check we have all the keys we need.

Parameters
[in]mCurrent Mailbox
[in]eEmail with addresses to match
[out]keylistKeys needed
[in]oppenc_modeIf true, use opportunistic encryption
Return values
0Success
-1Error

Do a quick check to make sure that we can find all of the encryption keys if the user has requested this service. Return the list of keys in KEYLIST. If oppenc_mode is true, only keys that can be determined without prompting will be used.

Definition at line 963 of file crypt.c.

964 {
965  if (!WithCrypto)
966  return 0;
967 
968  struct AddressList addrlist = TAILQ_HEAD_INITIALIZER(addrlist);
969  const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
970  const char *self_encrypt = NULL;
971 
972  /* Do a quick check to make sure that we can find all of the encryption
973  * keys if the user has requested this service. */
974 
975  *keylist = NULL;
976 
977 #ifdef USE_AUTOCRYPT
978  if (!oppenc_mode && (e->security & SEC_AUTOCRYPT))
979  {
981  return -1;
982  return 0;
983  }
984 #endif
985 
987  OptPgpCheckTrust = true;
988 
989  mutt_addrlist_copy(&addrlist, &e->env->to, false);
990  mutt_addrlist_copy(&addrlist, &e->env->cc, false);
991  mutt_addrlist_copy(&addrlist, &e->env->bcc, false);
992  mutt_addrlist_qualify(&addrlist, fqdn);
993  mutt_addrlist_dedupe(&addrlist);
994 
995  if (oppenc_mode || (e->security & SEC_ENCRYPT))
996  {
997  if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
998  {
999  *keylist = crypt_pgp_find_keys(&addrlist, oppenc_mode);
1000  if (!*keylist)
1001  {
1002  mutt_addrlist_clear(&addrlist);
1003  return -1;
1004  }
1005  OptPgpCheckTrust = false;
1006  const bool c_pgp_self_encrypt =
1007  cs_subset_bool(NeoMutt->sub, "pgp_self_encrypt");
1008  const char *const c_pgp_default_key =
1009  cs_subset_string(NeoMutt->sub, "pgp_default_key");
1010  const enum QuadOption c_pgp_encrypt_self =
1011  cs_subset_quad(NeoMutt->sub, "pgp_encrypt_self");
1012  if (c_pgp_self_encrypt || (c_pgp_encrypt_self == MUTT_YES))
1013  self_encrypt = c_pgp_default_key;
1014  }
1015  if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME))
1016  {
1017  *keylist = crypt_smime_find_keys(&addrlist, oppenc_mode);
1018  if (!*keylist)
1019  {
1020  mutt_addrlist_clear(&addrlist);
1021  return -1;
1022  }
1023  const bool c_smime_self_encrypt =
1024  cs_subset_bool(NeoMutt->sub, "smime_self_encrypt");
1025  const char *const c_smime_default_key =
1026  cs_subset_string(NeoMutt->sub, "smime_default_key");
1027  const enum QuadOption c_smime_encrypt_self =
1028  cs_subset_quad(NeoMutt->sub, "smime_encrypt_self");
1029  if (c_smime_self_encrypt || (c_smime_encrypt_self == MUTT_YES))
1030  self_encrypt = c_smime_default_key;
1031  }
1032  }
1033 
1034  if (!oppenc_mode && self_encrypt)
1035  {
1036  const size_t keylist_size = mutt_str_len(*keylist);
1037  mutt_mem_realloc(keylist, keylist_size + mutt_str_len(self_encrypt) + 2);
1038  sprintf(*keylist + keylist_size, " %s", self_encrypt);
1039  }
1040 
1041  mutt_addrlist_clear(&addrlist);
1042 
1043  return 0;
1044 }
enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Mailbox *m, struct Email *e, char **keylist)
Get the recommended action for an Email.
Definition: autocrypt.c:575
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define WithCrypto
Definition: lib.h:113
char * crypt_smime_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:483
struct AddressList bcc
Email&#39;s &#39;Bcc&#39; list.
Definition: envelope.h:60
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1470
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:737
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:84
Container for Accounts, Notifications.
Definition: neomutt.h:36
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
Do no use Autocrypt.
Definition: lib.h:157
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
Definition: address.c:1407
struct Envelope * env
Envelope information.
Definition: email.h:90
struct AddressList cc
Email&#39;s &#39;Cc&#39; list.
Definition: envelope.h:59
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
WHERE bool OptPgpCheckTrust
(pseudo) used by dlg_select_pgp_key()
Definition: options.h:48
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:650
char * crypt_pgp_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:321
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:1187
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_opportunistic_encrypt()

void crypt_opportunistic_encrypt ( struct Mailbox m,
struct Email e 
)

Can all recipients be determined.

Parameters
mCurrent Mailbox
eEmail

Check if all recipients keys can be automatically determined. Enable encryption if they can, otherwise disable encryption.

Definition at line 1054 of file crypt.c.

1055 {
1056  if (!WithCrypto)
1057  return;
1058 
1059  const bool c_crypt_opportunistic_encrypt =
1060  cs_subset_bool(NeoMutt->sub, "crypt_opportunistic_encrypt");
1061  if (!(c_crypt_opportunistic_encrypt && (e->security & SEC_OPPENCRYPT)))
1062  return;
1063 
1064  char *pgpkeylist = NULL;
1065 
1066  crypt_get_keys(m, e, &pgpkeylist, 1);
1067  if (pgpkeylist)
1068  {
1069  e->security |= SEC_ENCRYPT;
1070  FREE(&pgpkeylist);
1071  }
1072  else
1073  {
1074  e->security &= ~SEC_ENCRYPT;
1075  }
1076 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define WithCrypto
Definition: lib.h:113
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
Container for Accounts, Notifications.
Definition: neomutt.h:36
int crypt_get_keys(struct Mailbox *m, struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:963
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:83
#define FREE(x)
Definition: memory.h:40
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_query()

SecurityFlags crypt_query ( struct Body b)

Check out the type of encryption used.

Parameters
bBody of email
Return values
numFlags, see SecurityFlags
0Error (SEC_NO_FLAGS)

Set the cached status values if there are any.

Definition at line 698 of file crypt.c.

699 {
700  if (!WithCrypto || !b)
701  return SEC_NO_FLAGS;
702 
704 
705  if (b->type == TYPE_APPLICATION)
706  {
708  rc |= mutt_is_application_pgp(b);
709 
711  {
712  rc |= mutt_is_application_smime(b);
713  if (rc && b->goodsig)
714  rc |= SEC_GOODSIGN;
715  if (rc && b->badsig)
716  rc |= SEC_BADSIGN;
717  }
718  }
719  else if (((WithCrypto & APPLICATION_PGP) != 0) && (b->type == TYPE_TEXT))
720  {
721  rc |= mutt_is_application_pgp(b);
722  if (rc && b->goodsig)
723  rc |= SEC_GOODSIGN;
724  }
725 
726  if (b->type == TYPE_MULTIPART)
727  {
729  rc |= mutt_is_multipart_signed(b);
731 
732  if (rc && b->goodsig)
733  rc |= SEC_GOODSIGN;
734 #ifdef USE_AUTOCRYPT
735  if (rc && b->is_autocrypt)
736  rc |= SEC_AUTOCRYPT;
737 #endif
738  }
739 
740  if ((b->type == TYPE_MULTIPART) || (b->type == TYPE_MESSAGE))
741  {
742  SecurityFlags u = b->parts ? SEC_ALL_FLAGS : SEC_NO_FLAGS; /* Bits set in all parts */
743  SecurityFlags w = SEC_NO_FLAGS; /* Bits set in any part */
744 
745  for (b = b->parts; b; b = b->next)
746  {
747  const SecurityFlags v = crypt_query(b);
748  u &= v;
749  w |= v;
750  }
751  rc |= u | (w & ~SEC_GOODSIGN);
752 
753  if ((w & SEC_GOODSIGN) && !(u & SEC_GOODSIGN))
754  rc |= SEC_PARTSIGN;
755  }
756 
757  return rc;
758 }
#define WithCrypto
Definition: lib.h:113
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:623
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:80
struct Body * next
next attachment in the list
Definition: body.h:53
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:84
#define SEC_ALL_FLAGS
Definition: lib.h:91
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:71
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:460
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
Definition: body.h:78
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:420
bool goodsig
Good cryptographic signature.
Definition: body.h:76
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
Type: &#39;text/*&#39;.
Definition: mime.h:38
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:521
#define SEC_BADSIGN
Email has a bad signature.
Definition: lib.h:78
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;message/*&#39;.
Definition: mime.h:35
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
Definition: crypt.c:565
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:698
#define SEC_GOODSIGN
Email has a valid signature.
Definition: lib.h:77
#define SEC_PARTSIGN
Not all parts of the email is signed.
Definition: lib.h:79
Type: &#39;application/*&#39;.
Definition: mime.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_valid_passphrase()

bool crypt_valid_passphrase ( SecurityFlags  flags)

Check that we have a usable passphrase, ask if not.

Parameters
flagsFlags, see SecurityFlags
Return values
trueSuccess
falseFailed

Definition at line 135 of file crypt.c.

136 {
137  bool rc = false;
138 
139 #ifndef DEBUG
140  disable_coredumps();
141 #endif
142 
143  if (((WithCrypto & APPLICATION_PGP) != 0) && (flags & APPLICATION_PGP))
145 
146  if (((WithCrypto & APPLICATION_SMIME) != 0) && (flags & APPLICATION_SMIME))
148 
149  return rc;
150 }
#define WithCrypto
Definition: lib.h:113
bool crypt_smime_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
Definition: cryptglue.c:428
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
bool crypt_pgp_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
Definition: cryptglue.c:201
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_application_pgp()

SecurityFlags mutt_is_application_pgp ( struct Body b)

Does the message use PGP?

Parameters
bBody of email
Return values
>0Message uses PGP, e.g. PGP_ENCRYPT
0Message doesn't use PGP, (SEC_NO_FLAGS)

Definition at line 565 of file crypt.c.

566 {
568  char *p = NULL;
569 
570  if (b->type == TYPE_APPLICATION)
571  {
572  if (mutt_istr_equal(b->subtype, "pgp") ||
573  mutt_istr_equal(b->subtype, "x-pgp-message"))
574  {
575  p = mutt_param_get(&b->parameter, "x-action");
576  if (p && (mutt_istr_equal(p, "sign") || mutt_istr_equal(p, "signclear")))
577  {
578  t |= PGP_SIGN;
579  }
580 
581  p = mutt_param_get(&b->parameter, "format");
582  if (p && mutt_istr_equal(p, "keys-only"))
583  {
584  t |= PGP_KEY;
585  }
586 
587  if (t == SEC_NO_FLAGS)
588  t |= PGP_ENCRYPT; /* not necessarily correct, but... */
589  }
590 
591  if (mutt_istr_equal(b->subtype, "pgp-signed"))
592  t |= PGP_SIGN;
593 
594  if (mutt_istr_equal(b->subtype, "pgp-keys"))
595  t |= PGP_KEY;
596  }
597  else if ((b->type == TYPE_TEXT) && mutt_istr_equal("plain", b->subtype))
598  {
599  if (((p = mutt_param_get(&b->parameter, "x-mutt-action")) ||
600  (p = mutt_param_get(&b->parameter, "x-action")) ||
601  (p = mutt_param_get(&b->parameter, "action"))) &&
602  mutt_istr_startswith(p, "pgp-sign"))
603  {
604  t |= PGP_SIGN;
605  }
606  else if (p && mutt_istr_startswith(p, "pgp-encrypt"))
607  t |= PGP_ENCRYPT;
608  else if (p && mutt_istr_startswith(p, "pgp-keys"))
609  t |= PGP_KEY;
610  }
611  if (t)
612  t |= PGP_INLINE;
613 
614  return t;
615 }
#define PGP_INLINE
Definition: lib.h:97
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define PGP_ENCRYPT
Definition: lib.h:93
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:71
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
Type: &#39;text/*&#39;.
Definition: mime.h:38
#define PGP_SIGN
Definition: lib.h:94
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
#define PGP_KEY
Definition: lib.h:96
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
Type: &#39;application/*&#39;.
Definition: mime.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_application_smime()

SecurityFlags mutt_is_application_smime ( struct Body b)

Does the message use S/MIME?

Parameters
bBody of email
Return values
>0Message uses S/MIME, e.g. SMIME_ENCRYPT
0Message doesn't use S/MIME, (SEC_NO_FLAGS)

Definition at line 623 of file crypt.c.

624 {
625  if (!b)
626  return SEC_NO_FLAGS;
627 
628  if (((b->type & TYPE_APPLICATION) == 0) || !b->subtype)
629  return SEC_NO_FLAGS;
630 
631  char *t = NULL;
632  bool complain = false;
633  /* S/MIME MIME types don't need x- anymore, see RFC2311 */
634  if (mutt_istr_equal(b->subtype, "x-pkcs7-mime") || mutt_istr_equal(b->subtype, "pkcs7-mime"))
635  {
636  t = mutt_param_get(&b->parameter, "smime-type");
637  if (t)
638  {
639  if (mutt_istr_equal(t, "enveloped-data"))
640  return SMIME_ENCRYPT;
641  if (mutt_istr_equal(t, "signed-data"))
642  return SMIME_SIGN | SMIME_OPAQUE;
643  return SEC_NO_FLAGS;
644  }
645  /* Netscape 4.7 uses
646  * Content-Description: S/MIME Encrypted Message
647  * instead of Content-Type parameter */
648  if (mutt_istr_equal(b->description, "S/MIME Encrypted Message"))
649  return SMIME_ENCRYPT;
650  complain = true;
651  }
652  else if (!mutt_istr_equal(b->subtype, "octet-stream"))
653  return SEC_NO_FLAGS;
654 
655  t = mutt_param_get(&b->parameter, "name");
656 
657  if (!t)
658  t = b->d_filename;
659  if (!t)
660  t = b->filename;
661  if (!t)
662  {
663  if (complain)
664  {
665  mutt_message(
666  _("S/MIME messages with no hints on content are unsupported"));
667  }
668  return SEC_NO_FLAGS;
669  }
670 
671  /* no .p7c, .p10 support yet. */
672 
673  int len = mutt_str_len(t) - 4;
674  if ((len > 0) && (*(t + len) == '.'))
675  {
676  len++;
677  if (mutt_istr_equal((t + len), "p7m"))
678  {
679  /* Not sure if this is the correct thing to do, but
680  * it's required for compatibility with Outlook */
681  return SMIME_SIGN | SMIME_OPAQUE;
682  }
683  else if (mutt_istr_equal((t + len), "p7s"))
684  return SMIME_SIGN | SMIME_OPAQUE;
685  }
686 
687  return SEC_NO_FLAGS;
688 }
#define SMIME_OPAQUE
Definition: lib.h:103
char * filename
when sending a message, this is the file to which this structure refers
Definition: body.h:46
#define SMIME_SIGN
Definition: lib.h:100
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define SMIME_ENCRYPT
Definition: lib.h:99
#define _(a)
Definition: message.h:28
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
char * description
content-description
Definition: body.h:40
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:664
#define mutt_message(...)
Definition: logging.h:87
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
char * d_filename
filename to be used for the content-disposition header.
Definition: body.h:47
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
Type: &#39;application/*&#39;.
Definition: mime.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_malformed_multipart_pgp_encrypted()

SecurityFlags mutt_is_malformed_multipart_pgp_encrypted ( struct Body b)

Check for malformed layout.

Parameters
bBody of email
Return values
numSuccess, see SecurityFlags
0Error, (SEC_NO_FLAGS)

This checks for the malformed layout caused by MS Exchange in some cases:

<multipart/mixed>
<text/plain>
<application/pgp-encrypted> [BASE64-encoded]
<application/octet-stream> [BASE64-encoded]

Definition at line 521 of file crypt.c.

522 {
523  if (!(WithCrypto & APPLICATION_PGP))
524  return SEC_NO_FLAGS;
525 
526  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype || !mutt_istr_equal(b->subtype, "mixed"))
527  {
528  return SEC_NO_FLAGS;
529  }
530 
531  b = b->parts;
532  if (!b || (b->type != TYPE_TEXT) || !b->subtype ||
533  !mutt_istr_equal(b->subtype, "plain") || (b->length != 0))
534  {
535  return SEC_NO_FLAGS;
536  }
537 
538  b = b->next;
539  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
540  !mutt_istr_equal(b->subtype, "pgp-encrypted"))
541  {
542  return SEC_NO_FLAGS;
543  }
544 
545  b = b->next;
546  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
547  !mutt_istr_equal(b->subtype, "octet-stream"))
548  {
549  return SEC_NO_FLAGS;
550  }
551 
552  b = b->next;
553  if (b)
554  return SEC_NO_FLAGS;
555 
556  return PGP_ENCRYPT;
557 }
#define WithCrypto
Definition: lib.h:113
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define PGP_ENCRYPT
Definition: lib.h:93
struct Body * next
next attachment in the list
Definition: body.h:53
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
Type: &#39;text/*&#39;.
Definition: mime.h:38
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
Type: &#39;application/*&#39;.
Definition: mime.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_multipart_encrypted()

SecurityFlags mutt_is_multipart_encrypted ( struct Body b)

Does the message have encrypted parts?

Parameters
bBody of email
Return values
numMessage has got encrypted parts, see SecurityFlags
0Message hasn't got encrypted parts (SEC_NO_FLAGS)

Definition at line 460 of file crypt.c.

461 {
462  if ((WithCrypto & APPLICATION_PGP) == 0)
463  return SEC_NO_FLAGS;
464 
465  char *p = NULL;
466 
467  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype ||
468  !mutt_istr_equal(b->subtype, "encrypted") ||
469  !(p = mutt_param_get(&b->parameter, "protocol")) ||
470  !mutt_istr_equal(p, "application/pgp-encrypted"))
471  {
472  return SEC_NO_FLAGS;
473  }
474 
475  return PGP_ENCRYPT;
476 }
#define WithCrypto
Definition: lib.h:113
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define PGP_ENCRYPT
Definition: lib.h:93
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_multipart_signed()

SecurityFlags mutt_is_multipart_signed ( struct Body b)

Is a message signed?

Parameters
bBody of email
Return values
numMessage is signed, see SecurityFlags
0Message is not signed (SEC_NO_FLAGS)

Definition at line 420 of file crypt.c.

421 {
422  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype || !mutt_istr_equal(b->subtype, "signed"))
423  {
424  return SEC_NO_FLAGS;
425  }
426 
427  char *p = mutt_param_get(&b->parameter, "protocol");
428  if (!p)
429  return SEC_NO_FLAGS;
430 
431  if (mutt_istr_equal(p, "multipart/mixed"))
432  return SEC_SIGN;
433 
434  if (((WithCrypto & APPLICATION_PGP) != 0) &&
435  mutt_istr_equal(p, "application/pgp-signature"))
436  {
437  return PGP_SIGN;
438  }
439 
440  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
441  mutt_istr_equal(p, "application/x-pkcs7-signature"))
442  {
443  return SMIME_SIGN;
444  }
445  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
446  mutt_istr_equal(p, "application/pkcs7-signature"))
447  {
448  return SMIME_SIGN;
449  }
450 
451  return SEC_NO_FLAGS;
452 }
#define SMIME_SIGN
Definition: lib.h:100
#define WithCrypto
Definition: lib.h:113
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
#define PGP_SIGN
Definition: lib.h:94
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
#define SEC_SIGN
Email is signed.
Definition: lib.h:76
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_valid_multipart_pgp_encrypted()

int mutt_is_valid_multipart_pgp_encrypted ( struct Body b)

Is this a valid multi-part encrypted message?

Parameters
bBody of email
Return values
>0Message is valid, with encrypted parts, e.g. PGP_ENCRYPT
0Message hasn't got encrypted parts

Definition at line 484 of file crypt.c.

485 {
487  return 0;
488 
489  b = b->parts;
490  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
491  !mutt_istr_equal(b->subtype, "pgp-encrypted"))
492  {
493  return 0;
494  }
495 
496  b = b->next;
497  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
498  !mutt_istr_equal(b->subtype, "octet-stream"))
499  {
500  return 0;
501  }
502 
503  return PGP_ENCRYPT;
504 }
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define PGP_ENCRYPT
Definition: lib.h:93
struct Body * next
next attachment in the list
Definition: body.h:53
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:460
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;application/*&#39;.
Definition: mime.h:33
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_protect()

int mutt_protect ( struct Mailbox m,
struct Email e,
char *  keylist,
bool  postpone 
)

Encrypt and/or sign a message.

Parameters
mCurrent Mailbox
eEmail
keylistList of keys to encrypt to (space-separated)
postponeWhen true, signing is automatically disabled
Return values
0Success
-1Error

Definition at line 161 of file crypt.c.

162 {
163  struct Body *pbody = NULL, *tmp_pbody = NULL;
164  struct Body *tmp_smime_pbody = NULL;
165  struct Body *tmp_pgp_pbody = NULL;
166  bool has_retainable_sig = false;
167 
168  if (!WithCrypto)
169  return -1;
170 
171  SecurityFlags security = e->security;
172  int sign = security & (SEC_AUTOCRYPT | SEC_SIGN);
173  if (postpone)
174  {
175  sign = SEC_NO_FLAGS;
176  security &= ~SEC_SIGN;
177  }
178 
179  if (!(security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) && !sign)
180  return 0;
181 
182  if (sign && !(security & SEC_AUTOCRYPT) && !crypt_valid_passphrase(security))
183  return -1;
184 
185  if (((WithCrypto & APPLICATION_PGP) != 0) && !(security & SEC_AUTOCRYPT) &&
186  ((security & PGP_INLINE) == PGP_INLINE))
187  {
188  const enum QuadOption c_pgp_mime_auto =
189  cs_subset_quad(NeoMutt->sub, "pgp_mime_auto");
190  if ((e->body->type != TYPE_TEXT) ||
191  !mutt_istr_equal(e->body->subtype, "plain"))
192  {
193  if (query_quadoption(c_pgp_mime_auto,
194  _("Inline PGP can't be used with attachments. "
195  "Revert to PGP/MIME?")) != MUTT_YES)
196  {
197  mutt_error(
198  _("Mail not sent: inline PGP can't be used with attachments"));
199  return -1;
200  }
201  }
202  else if (mutt_istr_equal("flowed",
203  mutt_param_get(&e->body->parameter, "format")))
204  {
205  if ((query_quadoption(c_pgp_mime_auto,
206  _("Inline PGP can't be used with format=flowed. "
207  "Revert to PGP/MIME?"))) != MUTT_YES)
208  {
209  mutt_error(
210  _("Mail not sent: inline PGP can't be used with format=flowed"));
211  return -1;
212  }
213  }
214  else
215  {
216  /* they really want to send it inline... go for it */
217  if (!isendwin())
218  {
219  mutt_endwin();
220  puts(_("Invoking PGP..."));
221  }
222  pbody = crypt_pgp_traditional_encryptsign(e->body, security, keylist);
223  if (pbody)
224  {
225  e->body = pbody;
226  return 0;
227  }
228 
229  /* otherwise inline won't work...ask for revert */
230  if (query_quadoption(
231  c_pgp_mime_auto,
232  _("Message can't be sent inline. Revert to using PGP/MIME?")) != MUTT_YES)
233  {
234  mutt_error(_("Mail not sent"));
235  return -1;
236  }
237  }
238 
239  /* go ahead with PGP/MIME */
240  }
241 
242  if (!isendwin())
243  mutt_endwin();
244 
246  tmp_smime_pbody = e->body;
247  if (WithCrypto & APPLICATION_PGP)
248  tmp_pgp_pbody = e->body;
249 
250 #ifdef CRYPT_BACKEND_GPGME
251  const bool c_crypt_use_pka = cs_subset_bool(NeoMutt->sub, "crypt_use_pka");
252  if (sign && c_crypt_use_pka)
253 #else
254  if (sign)
255 #endif
256  {
257  /* Set sender (necessary for e.g. PKA). */
258  const char *mailbox = NULL;
259  struct Address *from = TAILQ_FIRST(&e->env->from);
260  bool free_from = false;
261 
262  if (!from)
263  {
264  free_from = true;
265  from = mutt_default_from(NeoMutt->sub);
266  }
267 
268  mailbox = from->mailbox;
269  const struct Address *c_envelope_from_address =
270  cs_subset_address(NeoMutt->sub, "envelope_from_address");
271  if (!mailbox && c_envelope_from_address)
272  mailbox = c_envelope_from_address->mailbox;
273 
274  if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
275  crypt_smime_set_sender(mailbox);
276  else if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP))
277  crypt_pgp_set_sender(mailbox);
278 
279  if (free_from)
280  mutt_addr_free(&from);
281  }
282 
283  const bool c_crypt_protected_headers_write =
284  cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_write");
285  if (c_crypt_protected_headers_write)
286  {
287  struct Envelope *protected_headers = mutt_env_new();
288  mutt_str_replace(&protected_headers->subject, e->env->subject);
289  /* Note: if other headers get added, such as to, cc, then a call to
290  * mutt_env_to_intl() will need to be added here too. */
291  mutt_prepare_envelope(protected_headers, 0, NeoMutt->sub);
292 
294  e->body->mime_headers = protected_headers;
295  /* Optional part of the draft RFC, but required by Enigmail */
296  mutt_param_set(&e->body->parameter, "protected-headers", "v1");
297  }
298  else
299  {
300  mutt_param_delete(&e->body->parameter, "protected-headers");
301  }
302 
303 #ifdef USE_AUTOCRYPT
304  /* A note about e->body->mime_headers. If postpone or send
305  * fails, the mime_headers is cleared out before returning to the
306  * compose menu. So despite the "robustness" code above and in the
307  * gen_gossip_list function below, mime_headers will not be set when
308  * entering mutt_protect().
309  *
310  * This is important to note because the user could toggle
311  * $crypt_protected_headers_write or $autocrypt off back in the
312  * compose menu. We don't want mutt_write_rfc822_header() to write
313  * stale data from one option if the other is set.
314  */
315  const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
316  if (c_autocrypt && !postpone && (security & SEC_AUTOCRYPT))
317  {
319  }
320 #endif
321 
322  if (sign)
323  {
324  if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
325  {
326  tmp_pbody = crypt_smime_sign_message(e->body, &e->env->from);
327  if (!tmp_pbody)
328  goto bail;
329  pbody = tmp_pbody;
330  tmp_smime_pbody = tmp_pbody;
331  }
332 
333  const bool c_pgp_retainable_sigs =
334  cs_subset_bool(NeoMutt->sub, "pgp_retainable_sigs");
335  if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP) &&
336  (!(security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) || c_pgp_retainable_sigs))
337  {
338  tmp_pbody = crypt_pgp_sign_message(e->body, &e->env->from);
339  if (!tmp_pbody)
340  goto bail;
341 
342  has_retainable_sig = true;
343  sign = SEC_NO_FLAGS;
344  pbody = tmp_pbody;
345  tmp_pgp_pbody = tmp_pbody;
346  }
347 
348  if ((WithCrypto != 0) && (security & APPLICATION_SMIME) && (security & APPLICATION_PGP))
349  {
350  /* here comes the draft ;-) */
351  }
352  }
353 
354  if (security & (SEC_ENCRYPT | SEC_AUTOCRYPT))
355  {
356  if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
357  {
358  tmp_pbody = crypt_smime_build_smime_entity(tmp_smime_pbody, keylist);
359  if (!tmp_pbody)
360  {
361  /* signed ? free it! */
362  goto bail;
363  }
364  /* free tmp_body if messages was signed AND encrypted ... */
365  if ((tmp_smime_pbody != e->body) && (tmp_smime_pbody != tmp_pbody))
366  {
367  /* detach and don't delete e->body,
368  * which tmp_smime_pbody->parts after signing. */
369  tmp_smime_pbody->parts = tmp_smime_pbody->parts->next;
370  e->body->next = NULL;
371  mutt_body_free(&tmp_smime_pbody);
372  }
373  pbody = tmp_pbody;
374  }
375 
376  if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP))
377  {
378  pbody =
379  crypt_pgp_encrypt_message(m, e, tmp_pgp_pbody, keylist, sign, &e->env->from);
380  if (!pbody)
381  {
382  /* did we perform a retainable signature? */
383  if (has_retainable_sig)
384  {
385  /* remove the outer multipart layer */
386  tmp_pgp_pbody = mutt_remove_multipart(tmp_pgp_pbody);
387  /* get rid of the signature */
388  mutt_body_free(&tmp_pgp_pbody->next);
389  }
390 
391  goto bail;
392  }
393 
394  // destroy temporary signature envelope when doing retainable signatures.
395  if (has_retainable_sig)
396  {
397  tmp_pgp_pbody = mutt_remove_multipart(tmp_pgp_pbody);
398  mutt_body_free(&tmp_pgp_pbody->next);
399  }
400  }
401  }
402 
403  if (pbody)
404  {
405  e->body = pbody;
406  return 0;
407  }
408 
409 bail:
411  return -1;
412 }
#define PGP_INLINE
Definition: lib.h:97
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define WithCrypto
Definition: lib.h:113
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
int mutt_autocrypt_generate_gossip_list(struct Mailbox *m, struct Email *e)
Create the gossip list headers.
Definition: autocrypt.c:841
#define TAILQ_FIRST(head)
Definition: queue.h:723
struct Body * body
List of MIME parts.
Definition: email.h:91
#define mutt_error(...)
Definition: logging.h:88
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
void crypt_pgp_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
Definition: cryptglue.c:410
#define _(a)
Definition: message.h:28
struct Body * next
next attachment in the list
Definition: body.h:53
An email address.
Definition: address.h:35
char * mailbox
Mailbox and host address.
Definition: address.h:38
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:84
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:71
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:42
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: helpers.c:49
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:440
Container for Accounts, Notifications.
Definition: neomutt.h:36
The body of an email.
Definition: body.h:34
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
void crypt_smime_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
Definition: cryptglue.c:547
struct Body * crypt_smime_sign_message(struct Body *a, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
Definition: cryptglue.c:494
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:135
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition: sendlib.c:1243
struct AddressList from
Email&#39;s &#39;From&#39; list.
Definition: envelope.h:57
struct Envelope * env
Envelope information.
Definition: email.h:90
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: question.c:347
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:142
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: multipart.c:126
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:422
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default &#39;from&#39; Address.
Definition: send.c:1454
Type: &#39;text/*&#39;.
Definition: mime.h:38
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
#define SEC_SIGN
Email is signed.
Definition: lib.h:76
struct Body * crypt_smime_build_smime_entity(struct Body *a, char *certlist)
Wrapper for CryptModuleSpecs::smime_build_smime_entity()
Definition: cryptglue.c:505
char * subject
Email&#39;s subject.
Definition: envelope.h:66
struct Body * crypt_pgp_encrypt_message(struct Mailbox *m, struct Email *e, struct Body *a, char *keylist, int sign, const struct AddressList *from)
Wrapper for CryptModuleSpecs::pgp_encrypt_message()
Definition: cryptglue.c:343
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
struct Body * crypt_pgp_sign_message(struct Body *a, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
Definition: cryptglue.c:332
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:110
The header of an Email.
Definition: envelope.h:54
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
struct Body * crypt_pgp_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist)
Wrapper for CryptModuleSpecs::pgp_traditional_encryptsign()
Definition: cryptglue.c:299
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_protected_headers_handler()

int mutt_protected_headers_handler ( struct Body b,
struct State s 
)

Process a protected header - Implements handler_t.

Definition at line 1126 of file crypt.c.

1127 {
1128  const bool c_crypt_protected_headers_read =
1129  cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_read");
1130  if (c_crypt_protected_headers_read && b->mime_headers)
1131  {
1132  if (b->mime_headers->subject)
1133  {
1134  const bool display = (s->flags & MUTT_DISPLAY);
1135 
1136  const bool c_weed = cs_subset_bool(NeoMutt->sub, "weed");
1137  if (display && c_weed && mutt_matches_ignore("subject"))
1138  return 0;
1139 
1141  const short c_wrap = cs_subset_number(NeoMutt->sub, "wrap");
1142  int wraplen = display ? mutt_window_wrap_cols(s->wraplen, c_wrap) : 0;
1143 
1144  mutt_write_one_header(s->fp_out, "Subject", b->mime_headers->subject, s->prefix,
1145  wraplen, display ? CH_DISPLAY : CH_NO_FLAGS, NeoMutt->sub);
1146  state_puts(s, "\n");
1147  }
1148  }
1149 
1150  return 0;
1151 }
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
Definition: parse.c:316
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:63
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define state_puts(STATE, STR)
Definition: state.h:55
char * prefix
String to add to the beginning of each output line.
Definition: state.h:48
FILE * fp_out
File to write to.
Definition: state.h:47
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
Container for Accounts, Notifications.
Definition: neomutt.h:36
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
int wraplen
Width to wrap lines to (when flags & MUTT_DISPLAY)
Definition: state.h:50
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:51
#define CH_DISPLAY
Display result to user.
Definition: copy.h:70
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
Definition: mutt_window.c:386
void state_mark_protected_header(struct State *s)
Write a unique marker around protected headers.
Definition: state.c:89
char * subject
Email&#39;s subject.
Definition: envelope.h:66
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
int mutt_write_one_header(FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, CopyHeaderFlags chflags, struct ConfigSubset *sub)
Write one header line to a file.
Definition: header.c:420
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_should_hide_protected_subject()

bool mutt_should_hide_protected_subject ( struct Email e)

Should NeoMutt hide the protected subject?

Parameters
eEmail to test
Return values
trueThe subject should be protected

Definition at line 1108 of file crypt.c.

1109 {
1110  const bool c_crypt_protected_headers_write =
1111  cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_write");
1112  const char *const c_crypt_protected_headers_subject =
1113  cs_subset_string(NeoMutt->sub, "crypt_protected_headers_subject");
1114  if (c_crypt_protected_headers_write && (e->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) &&
1115  !(e->security & SEC_INLINE) && c_crypt_protected_headers_subject)
1116  {
1117  return true;
1118  }
1119 
1120  return false;
1121 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:84
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:82
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_signed_handler()

int mutt_signed_handler ( struct Body b,
struct State s 
)

Verify a "multipart/signed" body - Implements handler_t.

Definition at line 1156 of file crypt.c.

1157 {
1158  if (!WithCrypto)
1159  return -1;
1160 
1161  bool inconsistent = false;
1162  struct Body *top = b;
1163  struct Body **signatures = NULL;
1164  int sigcnt = 0;
1165  int rc = 0;
1166  struct Buffer *tempfile = NULL;
1167 
1168  b = b->parts;
1169  SecurityFlags signed_type = mutt_is_multipart_signed(top);
1170  if (signed_type == SEC_NO_FLAGS)
1171  {
1172  /* A null protocol value is already checked for in mutt_body_handler() */
1173  state_printf(s,
1174  _("[-- Error: "
1175  "Unknown multipart/signed protocol %s --]\n\n"),
1176  mutt_param_get(&top->parameter, "protocol"));
1177  return mutt_body_handler(b, s);
1178  }
1179 
1180  if (!(b && b->next))
1181  inconsistent = true;
1182  else
1183  {
1184  switch (signed_type)
1185  {
1186  case SEC_SIGN:
1187  if ((b->next->type != TYPE_MULTIPART) || !mutt_istr_equal(b->next->subtype, "mixed"))
1188  {
1189  inconsistent = true;
1190  }
1191  break;
1192  case PGP_SIGN:
1193  if ((b->next->type != TYPE_APPLICATION) ||
1194  !mutt_istr_equal(b->next->subtype, "pgp-signature"))
1195  {
1196  inconsistent = true;
1197  }
1198  break;
1199  case SMIME_SIGN:
1200  if ((b->next->type != TYPE_APPLICATION) ||
1201  (!mutt_istr_equal(b->next->subtype, "x-pkcs7-signature") &&
1202  !mutt_istr_equal(b->next->subtype, "pkcs7-signature")))
1203  {
1204  inconsistent = true;
1205  }
1206  break;
1207  default:
1208  inconsistent = true;
1209  }
1210  }
1211  if (inconsistent)
1212  {
1213  state_attach_puts(s, _("[-- Error: Missing or bad-format multipart/signed "
1214  "signature --]\n\n"));
1215  return mutt_body_handler(b, s);
1216  }
1217 
1218  if (s->flags & MUTT_DISPLAY)
1219  {
1220  crypt_fetch_signatures(&signatures, b->next, &sigcnt);
1221 
1222  if (sigcnt != 0)
1223  {
1224  tempfile = mutt_buffer_pool_get();
1225  mutt_buffer_mktemp(tempfile);
1226  bool goodsig = true;
1227  if (crypt_write_signed(b, s, mutt_buffer_string(tempfile)) == 0)
1228  {
1229  for (int i = 0; i < sigcnt; i++)
1230  {
1231  if (((WithCrypto & APPLICATION_PGP) != 0) &&
1232  (signatures[i]->type == TYPE_APPLICATION) &&
1233  mutt_istr_equal(signatures[i]->subtype, "pgp-signature"))
1234  {
1235  if (crypt_pgp_verify_one(signatures[i], s, mutt_buffer_string(tempfile)) != 0)
1236  goodsig = false;
1237 
1238  continue;
1239  }
1240 
1241  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
1242  (signatures[i]->type == TYPE_APPLICATION) &&
1243  (mutt_istr_equal(signatures[i]->subtype, "x-pkcs7-signature") ||
1244  mutt_istr_equal(signatures[i]->subtype, "pkcs7-signature")))
1245  {
1246  if (crypt_smime_verify_one(signatures[i], s, mutt_buffer_string(tempfile)) != 0)
1247  goodsig = false;
1248 
1249  continue;
1250  }
1251 
1252  state_printf(s,
1253  _("[-- Warning: "
1254  "We can't verify %s/%s signatures. --]\n\n"),
1255  TYPE(signatures[i]), signatures[i]->subtype);
1256  }
1257  }
1258 
1260  mutt_buffer_pool_release(&tempfile);
1261 
1262  top->goodsig = goodsig;
1263  top->badsig = !goodsig;
1264 
1265  /* Now display the signed body */
1266  state_attach_puts(s, _("[-- The following data is signed --]\n\n"));
1267 
1269 
1270  FREE(&signatures);
1271  }
1272  else
1273  {
1275  _("[-- Warning: Can't find any signatures. --]\n\n"));
1276  }
1277  }
1278 
1279  rc = mutt_body_handler(b, s);
1280 
1281  if ((s->flags & MUTT_DISPLAY) && (sigcnt != 0))
1282  state_attach_puts(s, _("\n[-- End of signed data --]\n"));
1283 
1284  return rc;
1285 }
int state_printf(struct State *s, const char *fmt,...)
Write a formatted string to the State.
Definition: state.c:187
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:74
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define SMIME_SIGN
Definition: lib.h:100
#define WithCrypto
Definition: lib.h:113
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:74
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:195
String manipulation buffer.
Definition: buffer.h:33
#define _(a)
Definition: message.h:28
struct Body * next
next attachment in the list
Definition: body.h:53
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:71
int crypt_write_signed(struct Body *a, struct State *s, const char *tempfile)
Write the message body/part.
Definition: crypt.c:770
The body of an email.
Definition: body.h:34
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:77
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
Definition: body.h:78
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:420
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
int mutt_protected_headers_handler(struct Body *b, struct State *s)
Process a protected header - Implements handler_t.
Definition: crypt.c:1126
bool goodsig
Good cryptographic signature.
Definition: body.h:76
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
#define PGP_SIGN
Definition: lib.h:94
static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, int *n)
Create an array of an emails parts.
Definition: crypt.c:1084
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
#define SEC_SIGN
Email is signed.
Definition: lib.h:76
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
Definition: state.c:104
#define TYPE(body)
Definition: mime.h:89
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
#define FREE(x)
Definition: memory.h:40
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:84
int crypt_smime_verify_one(struct Body *sigbdy, struct State *s, const char *tempf)
Wrapper for CryptModuleSpecs::verify_one()
Definition: cryptglue.c:525
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Definition: handler.c:1604
struct ParameterList parameter
parameters of the content-type
Definition: body.h:39
Type: &#39;application/*&#39;.
Definition: mime.h:33
int crypt_pgp_verify_one(struct Body *sigbdy, struct State *s, const char *tempf)
Wrapper for CryptModuleSpecs::verify_one()
Definition: cryptglue.c:379
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_cleanup()

void crypt_cleanup ( void  )

Clean up backend.

Definition at line 143 of file cryptglue.c.

144 {
145  if (CRYPT_MOD_CALL_CHECK(PGP, cleanup))
146  (CRYPT_MOD_CALL(PGP, cleanup))();
147 
148  if (CRYPT_MOD_CALL_CHECK(SMIME, cleanup))
149  (CRYPT_MOD_CALL(SMIME, cleanup))();
150 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_has_module_backend()

bool crypt_has_module_backend ( SecurityFlags  type)

Is there a crypto backend for a given type?

Parameters
typeCrypto type, see SecurityFlags
Return values
trueBackend is present
falseBackend is not present

Definition at line 172 of file cryptglue.c.

173 {
174  if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP) &&
175  crypto_module_lookup(APPLICATION_PGP))
176  {
177  return true;
178  }
179 
180  if (((WithCrypto & APPLICATION_SMIME) != 0) && (type & APPLICATION_SMIME) &&
181  crypto_module_lookup(APPLICATION_SMIME))
182  {
183  return true;
184  }
185 
186  return false;
187 }
#define WithCrypto
Definition: lib.h:113
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
struct CryptModuleSpecs * crypto_module_lookup(int identifier)
Lookup a crypto module by name.
Definition: crypt_mod.c:65
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_init()

void crypt_init ( void  )

Initialise the crypto backends.

This calls CryptModuleSpecs::init()

Definition at line 94 of file cryptglue.c.

95 {
96 #ifdef CRYPT_BACKEND_GPGME
97  const bool c_crypt_use_gpgme =
98  cs_subset_bool(NeoMutt->sub, "crypt_use_gpgme");
99 #endif
100 #ifdef CRYPT_BACKEND_CLASSIC_PGP
101  if (
102 #ifdef CRYPT_BACKEND_GPGME
103  (!c_crypt_use_gpgme)
104 #else
105  1
106 #endif
107  )
109 #endif
110 
111 #ifdef CRYPT_BACKEND_CLASSIC_SMIME
112  if (
113 #ifdef CRYPT_BACKEND_GPGME
114  (!c_crypt_use_gpgme)
115 #else
116  1
117 #endif
118  )
120 #endif
121 
122 #ifdef CRYPT_BACKEND_GPGME
123  if (c_crypt_use_gpgme)
124  {
127  }
128 #endif
129 
130 #if defined(CRYPT_BACKEND_CLASSIC_PGP) || \
131  defined(CRYPT_BACKEND_CLASSIC_SMIME) || defined(CRYPT_BACKEND_GPGME)
132  if (CRYPT_MOD_CALL_CHECK(PGP, init))
133  CRYPT_MOD_CALL(PGP, init)();
134 
135  if (CRYPT_MOD_CALL_CHECK(SMIME, init))
136  CRYPT_MOD_CALL(SMIME, init)();
137 #endif
138 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
void crypto_module_register(struct CryptModuleSpecs *specs)
Register a new crypto module.
Definition: crypt_mod.c:51
Container for Accounts, Notifications.
Definition: neomutt.h:36
struct CryptModuleSpecs CryptModSmimeClassic
CLI SMIME - Implements CryptModuleSpecs.
struct CryptModuleSpecs CryptModPgpClassic
CLI PGP - Implements CryptModuleSpecs.
struct CryptModuleSpecs CryptModPgpGpgme
GPGME PGP - Implements CryptModuleSpecs.
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
struct CryptModuleSpecs CryptModSmimeGpgme
GPGME SMIME - Implements CryptModuleSpecs.
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_invoke_message()

void crypt_invoke_message ( SecurityFlags  type)

Display an informative message.

Parameters
typeCrypto type, see SecurityFlags

Show a message that a backend will be invoked.

Definition at line 158 of file cryptglue.c.

159 {
160  if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP))
161  mutt_message(_("Invoking PGP..."));
162  else if (((WithCrypto & APPLICATION_SMIME) != 0) && (type & APPLICATION_SMIME))
163  mutt_message(_("Invoking S/MIME..."));
164 }
#define WithCrypto
Definition: lib.h:113
#define _(a)
Definition: message.h:28
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
#define mutt_message(...)
Definition: logging.h:87
+ Here is the caller graph for this function:

◆ crypt_pgp_application_handler()

int crypt_pgp_application_handler ( struct Body b,
struct State s 
)

Wrapper for CryptModuleSpecs::application_handler()

Implements handler_t

Definition at line 240 of file cryptglue.c.

241 {
242  if (CRYPT_MOD_CALL_CHECK(PGP, application_handler))
243  return CRYPT_MOD_CALL(PGP, application_handler)(b, s);
244 
245  return -1;
246 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_pgp_check_traditional()

bool crypt_pgp_check_traditional ( FILE *  fp,
struct Body b,
bool  just_one 
)

Wrapper for CryptModuleSpecs::pgp_check_traditional()

Definition at line 288 of file cryptglue.c.

289 {
290  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_check_traditional))
291  return CRYPT_MOD_CALL(PGP, pgp_check_traditional)(fp, b, just_one);
292 
293  return false;
294 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_pgp_decrypt_mime()

int crypt_pgp_decrypt_mime ( FILE *  fp_in,
FILE **  fp_out,
struct Body b,
struct Body **  cur 
)

Wrapper for CryptModuleSpecs::decrypt_mime()

Definition at line 212 of file cryptglue.c.

213 {
214 #ifdef USE_AUTOCRYPT
215  const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
216  if (c_autocrypt)
217  {
218  OptAutocryptGpgme = true;
219  int result = pgp_gpgme_decrypt_mime(fp_in, fp_out, b, cur);
220  OptAutocryptGpgme = false;
221  if (result == 0)
222  {
223  b->is_autocrypt = true;
224  return result;
225  }
226  }
227 #endif
228 
229  if (CRYPT_MOD_CALL_CHECK(PGP, decrypt_mime))
230  return CRYPT_MOD_CALL(PGP, decrypt_mime)(fp_in, fp_out, b, cur);
231 
232  return -1;
233 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
int pgp_gpgme_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Implements CryptModuleSpecs::decrypt_mime() -.
Definition: crypt_gpgme.c:2208
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:80
WHERE bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: options.h:33
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_pgp_encrypted_handler()

int crypt_pgp_encrypted_handler ( struct Body b,
struct State s 
)

Wrapper for CryptModuleSpecs::encrypted_handler()

Implements handler_t

Definition at line 253 of file cryptglue.c.

254 {
255 #ifdef USE_AUTOCRYPT
256  const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
257  if (c_autocrypt)
258  {
259  OptAutocryptGpgme = true;
260  int result = pgp_gpgme_encrypted_handler(b, s);
261  OptAutocryptGpgme = false;
262  if (result == 0)
263  {
264  b->is_autocrypt = true;
265  return result;
266  }
267  }
268 #endif
269 
270  if (CRYPT_MOD_CALL_CHECK(PGP, encrypted_handler))
271  return CRYPT_MOD_CALL(PGP, encrypted_handler)(b, s);
272 
273  return -1;
274 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s)
Implements CryptModuleSpecs::encrypted_handler() -This handler is passed the application/octet-stream...
Definition: crypt_gpgme.c:3061
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:80
WHERE bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: options.h:33
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
Container for Accounts, Notifications.
Definition: neomutt.h:36
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_pgp_extract_key_from_attachment()

void crypt_pgp_extract_key_from_attachment ( FILE *  fp,
struct Body top 
)

Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()

Definition at line 401 of file cryptglue.c.

402 {
403  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_extract_key_from_attachment))
404  CRYPT_MOD_CALL(PGP, pgp_extract_key_from_attachment)(fp, top);
405 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_pgp_invoke_getkeys()

void crypt_pgp_invoke_getkeys ( struct Address addr)

Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()

Definition at line 279 of file cryptglue.c.

280 {
281  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_invoke_getkeys))
282  CRYPT_MOD_CALL(PGP, pgp_invoke_getkeys)(addr);
283 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_pgp_make_key_attachment()

struct Body* crypt_pgp_make_key_attachment ( void  )

Wrapper for CryptModuleSpecs::pgp_make_key_attachment()

Definition at line 310 of file cryptglue.c.

311 {
312  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_make_key_attachment))
313  return CRYPT_MOD_CALL(PGP, pgp_make_key_attachment)();
314 
315  return NULL;
316 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_pgp_send_menu()

SecurityFlags crypt_pgp_send_menu ( struct Mailbox m,
struct Email e 
)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 390 of file cryptglue.c.

391 {
392  if (CRYPT_MOD_CALL_CHECK(PGP, send_menu))
393  return CRYPT_MOD_CALL(PGP, send_menu)(m, e);
394 
395  return 0;
396 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_smime_application_handler()

int crypt_smime_application_handler ( struct Body b,
struct State s 
)

Wrapper for CryptModuleSpecs::application_handler()

Implements handler_t

Definition at line 452 of file cryptglue.c.

453 {
454  if (CRYPT_MOD_CALL_CHECK(SMIME, application_handler))
455  return CRYPT_MOD_CALL(SMIME, application_handler)(b, s);
456 
457  return -1;
458 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_smime_decrypt_mime()

int crypt_smime_decrypt_mime ( FILE *  fp_in,
FILE **  fp_out,
struct Body b,
struct Body **  cur 
)

Wrapper for CryptModuleSpecs::decrypt_mime()

Definition at line 439 of file cryptglue.c.

440 {
441  if (CRYPT_MOD_CALL_CHECK(SMIME, decrypt_mime))
442  return CRYPT_MOD_CALL(SMIME, decrypt_mime)(fp_in, fp_out, b, cur);
443 
444  return -1;
445 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_smime_getkeys()

void crypt_smime_getkeys ( struct Envelope env)

Wrapper for CryptModuleSpecs::smime_getkeys()

Definition at line 463 of file cryptglue.c.

464 {
465  if (CRYPT_MOD_CALL_CHECK(SMIME, smime_getkeys))
466  CRYPT_MOD_CALL(SMIME, smime_getkeys)(env);
467 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_smime_send_menu()

SecurityFlags crypt_smime_send_menu ( struct Mailbox m,
struct Email e 
)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 536 of file cryptglue.c.

537 {
538  if (CRYPT_MOD_CALL_CHECK(SMIME, send_menu))
539  return CRYPT_MOD_CALL(SMIME, send_menu)(m, e);
540 
541  return 0;
542 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypt_smime_verify_sender()

int crypt_smime_verify_sender ( struct Mailbox m,
struct Email e,
struct Message msg 
)

Wrapper for CryptModuleSpecs::smime_verify_sender()

Definition at line 472 of file cryptglue.c.

473 {
474  if (CRYPT_MOD_CALL_CHECK(SMIME, smime_verify_sender))
475  return CRYPT_MOD_CALL(SMIME, smime_verify_sender)(m, e, msg);
476 
477  return 1;
478 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:86
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:80
+ Here is the caller graph for this function:

◆ crypto_module_free()

void crypto_module_free ( void  )

Clean up the crypto modules.

Definition at line 81 of file crypt_mod.c.

82 {
83  struct CryptModule *np = NULL, *tmp = NULL;
84  STAILQ_FOREACH_SAFE(np, &CryptModules, entries, tmp)
85  {
86  STAILQ_REMOVE(&CryptModules, np, CryptModule, entries);
87  FREE(&np);
88  }
89 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
A crypto plugin module.
Definition: crypt_mod.c:38
static struct CryptModuleList CryptModules
Definition: crypt_mod.c:45
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ mutt_gpgme_select_secret_key()

int mutt_gpgme_select_secret_key ( struct Buffer keyid)

Select a private Autocrypt key for a new account.

Parameters
keyidAutocrypt Key id
Return values
0Success
-1Error

Unfortunately, the internal ncrypt/crypt_gpgme.c functions use CryptKeyInfo, and so aren't exportable.

This function queries all private keys, provides the crypt_select_keys() menu, and returns the selected key fingerprint in keyid.

Definition at line 3976 of file crypt_gpgme.c.

3977 {
3978  int rc = -1, junk;
3979  gpgme_error_t err;
3980  gpgme_key_t key = NULL;
3981  gpgme_user_id_t uid = NULL;
3982  struct CryptKeyInfo *results = NULL, *k = NULL;
3983  struct CryptKeyInfo **kend = NULL;
3984  struct CryptKeyInfo *choice = NULL;
3985 
3986  gpgme_ctx_t ctx = create_gpgme_context(false);
3987 
3988  /* list all secret keys */
3989  if (gpgme_op_keylist_start(ctx, NULL, 1))
3990  goto cleanup;
3991 
3992  kend = &results;
3993 
3994  while (!(err = gpgme_op_keylist_next(ctx, &key)))
3995  {
3997 
3999  flags |= KEYFLAG_CANENCRYPT;
4000  if (key_check_cap(key, KEY_CAP_CAN_SIGN))
4001  flags |= KEYFLAG_CANSIGN;
4002 
4003  if (key->revoked)
4004  flags |= KEYFLAG_REVOKED;
4005  if (key->expired)
4006  flags |= KEYFLAG_EXPIRED;
4007  if (key->disabled)
4008  flags |= KEYFLAG_DISABLED;
4009 
4010  int idx;
4011  for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
4012  {
4013  k = mutt_mem_calloc(1, sizeof(*k));
4014  k->kobj = key;
4015  gpgme_key_ref(k->kobj);
4016  k->idx = idx;
4017  k->uid = uid->uid;
4018  k->flags = flags;
4019  if (uid->revoked)
4020  k->flags |= KEYFLAG_REVOKED;
4021  k->validity = uid->validity;
4022  *kend = k;
4023  kend = &k->next;
4024  }
4025  gpgme_key_unref(key);
4026  }
4027  if (gpg_err_code(err) != GPG_ERR_EOF)
4028  mutt_error(_("gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
4029  gpgme_op_keylist_end(ctx);
4030 
4031  if (!results)
4032  {
4033  /* L10N: mutt_gpgme_select_secret_key() tries to list all secret keys to choose
4034  from. This error is displayed if no results were found. */
4035  mutt_error(_("No secret keys found"));
4036  goto cleanup;
4037  }
4038 
4039  choice = dlg_select_gpgme_key(results, NULL, "*", APPLICATION_PGP, &junk);
4040  if (!(choice && choice->kobj && choice->kobj->subkeys && choice->kobj->subkeys->fpr))
4041  goto cleanup;
4042  mutt_buffer_strcpy(keyid, choice->kobj->subkeys->fpr);
4043 
4044  rc = 0;
4045 
4046 cleanup:
4047  crypt_key_free(&choice);
4048  crypt_key_free(&results);
4049  gpgme_release(ctx);
4050  return rc;
4051 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
static void crypt_key_free(struct CryptKeyInfo **keylist)
Release all the keys in a list.
Definition: crypt_gpgme.c:462
#define mutt_error(...)
Definition: logging.h:88
struct CryptKeyInfo * dlg_select_gpgme_key(struct CryptKeyInfo *keys, struct Address *p, const char *s, unsigned int app, int *forced_valid)
Get the user to select a key.
Definition: dlggpgme.c:1317
size_t idx
Definition: mailbox.c:257
#define _(a)
Definition: message.h:28
Key can be used for encryption.
Definition: crypt_gpgme.h:77
Key can be used for signing.
Definition: crypt_gpgme.h:78
struct CryptKeyInfo * next
Definition: crypt_gpgme.h:46
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:125
A stored PGP key.
Definition: crypt_gpgme.h:44
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:128
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
#define KEYFLAG_NO_FLAGS
No flags are set.
Definition: lib.h:123
gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
Definition: crypt_gpgme.c:571
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:122
gpgme_key_t kobj
Definition: crypt_gpgme.h:47
unsigned int key_check_cap(gpgme_key_t key, enum KeyCap cap)
Check the capabilities of a key.
Definition: crypt_gpgme.c:3256
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:130
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:124
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
KeyFlags flags
global and per uid flags (for convenience)
Definition: crypt_gpgme.h:50
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:129
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_gpgme_print_version()

const char* mutt_gpgme_print_version ( void  )

Get version of GPGME.

Return values
ptrGPGME version string

Definition at line 4467 of file crypt_gpgme.c.

4468 {
4469  return GPGME_VERSION;
4470 }
+ Here is the caller graph for this function: