NeoMutt  2020-04-24
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:
+ This graph shows which files directly or indirectly include this file:

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 Email *e, char **keylist, bool oppenc_mode)
 Check we have all the keys we need. More...
 
void crypt_opportunistic_encrypt (struct Email *e)
 Can all recipients be determined. More...
 
SecurityFlags crypt_query (struct Body *m)
 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 *m)
 Does the message use PGP? More...
 
SecurityFlags mutt_is_application_smime (struct Body *m)
 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 Email *e, char *keylist, bool postpone)
 Encrypt and/or sign a message. More...
 
int mutt_protected_headers_handler (struct Body *m, 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 *a, 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...
 
int 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...
 
int crypt_pgp_send_menu (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...
 
int crypt_smime_send_menu (struct Email *e)
 Wrapper for CryptModuleSpecs::send_menu() More...
 
int crypt_smime_verify_sender (struct Mailbox *m, struct Email *e)
 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...
 

Variables

bool C_CryptTimestamp
 Config: Add a timestamp to PGP or SMIME output to prevent spoofing. More...
 
unsigned char C_PgpEncryptSelf
 Deprecated, see C_PgpSelfEncrypt. More...
 
unsigned char C_PgpMimeAuto
 Config: Prompt the user to use MIME if inline PGP fails. More...
 
bool C_PgpRetainableSigs
 Config: Create nested multipart/signed or encrypted messages. More...
 
bool C_PgpSelfEncrypt
 Config: Encrypted messages will also be encrypted to C_PgpDefaultKey too. More...
 
bool C_PgpStrictEnc
 Config: Encode PGP signed messages with quoted-printable (don't unset) More...
 
unsigned char C_SmimeEncryptSelf
 Deprecated, see C_SmimeSelfEncrypt. More...
 
bool C_SmimeSelfEncrypt
 Config: Encrypted messages will also be encrypt to C_SmimeDefaultKey too. More...
 
bool C_CryptUseGpgme
 Config: Use GPGME crypto backend. More...
 
bool C_PgpCheckExit
 Config: Check the exit code of PGP subprocess. More...
 
bool C_PgpCheckGpgDecryptStatusFd
 Config: File descriptor used for status info. More...
 
struct RegexC_PgpDecryptionOkay
 Config: Text indicating a successful decryption. More...
 
struct RegexC_PgpGoodSign
 Config: Text indicating a good signature. More...
 
long C_PgpTimeout
 Config: Time in seconds to cache a passphrase. More...
 
bool C_PgpUseGpgAgent
 Config: Use a PGP agent for caching passwords. More...
 
char * C_PgpClearsignCommand
 Config: (pgp) External command to inline-sign a message. More...
 
char * C_PgpDecodeCommand
 Config: (pgp) External command to decode a PGP attachment. More...
 
char * C_PgpDecryptCommand
 Config: (pgp) External command to decrypt a PGP message. More...
 
char * C_PgpEncryptOnlyCommand
 Config: (pgp) External command to encrypt, but not sign a message. More...
 
char * C_PgpEncryptSignCommand
 Config: (pgp) External command to encrypt and sign a message. More...
 
char * C_PgpExportCommand
 Config: (pgp) External command to export a public key from the user's keyring. More...
 
char * C_PgpGetkeysCommand
 Config: (pgp) External command to download a key for an email address. More...
 
char * C_PgpImportCommand
 Config: (pgp) External command to import a key into the user's keyring. More...
 
char * C_PgpListPubringCommand
 Config: (pgp) External command to list the public keys in a user's keyring. More...
 
char * C_PgpListSecringCommand
 Config: (pgp) External command to list the private keys in a user's keyring. More...
 
char * C_PgpSignCommand
 Config: (pgp) External command to create a detached PGP signature. More...
 
char * C_PgpVerifyCommand
 Config: (pgp) External command to verify PGP signatures. More...
 
char * C_PgpVerifyKeyCommand
 Config: (pgp) External command to verify key information. More...
 
bool C_SmimeAskCertLabel
 Config: Prompt the user for a label for SMIME certificates. More...
 
char * C_SmimeCaLocation
 Config: File containing trusted certificates. More...
 
char * C_SmimeCertificates
 Config: File containing user's public certificates. More...
 
char * C_SmimeDecryptCommand
 Config: (smime) External command to decrypt an SMIME message. More...
 
bool C_SmimeDecryptUseDefaultKey
 Config: Use the default key for decryption. More...
 
char * C_SmimeEncryptCommand
 Config: (smime) External command to encrypt a message. More...
 
char * C_SmimeGetCertCommand
 Config: (smime) External command to extract a certificate from a message. More...
 
char * C_SmimeGetCertEmailCommand
 Config: (smime) External command to get a certificate for an email. More...
 
char * C_SmimeGetSignerCertCommand
 Config: (smime) External command to extract a certificate from an email. More...
 
char * C_SmimeImportCertCommand
 Config: (smime) External command to import a certificate. More...
 
char * C_SmimeKeys
 Config: File containing user's private certificates. More...
 
char * C_SmimePk7outCommand
 Config: (smime) External command to extract a public certificate. More...
 
char * C_SmimeSignCommand
 Config: (smime) External command to sign a message. More...
 
char * C_SmimeSignDigestAlg
 Config: Digest algorithm. More...
 
long C_SmimeTimeout
 Config: Time in seconds to cache a passphrase. More...
 
char * C_SmimeVerifyCommand
 Config: (smime) External command to verify a signed message. More...
 
char * C_SmimeVerifyOpaqueCommand
 Config: (smime) External command to verify a signature. 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 124 of file lib.h.

◆ SEC_ENCRYPT

#define SEC_ENCRYPT   (1 << 0)

Email is encrypted.

Definition at line 125 of file lib.h.

◆ SEC_SIGN

#define SEC_SIGN   (1 << 1)

Email is signed.

Definition at line 126 of file lib.h.

◆ SEC_GOODSIGN

#define SEC_GOODSIGN   (1 << 2)

Email has a valid signature.

Definition at line 127 of file lib.h.

◆ SEC_BADSIGN

#define SEC_BADSIGN   (1 << 3)

Email has a bad signature.

Definition at line 128 of file lib.h.

◆ SEC_PARTSIGN

#define SEC_PARTSIGN   (1 << 4)

Not all parts of the email is signed.

Definition at line 129 of file lib.h.

◆ SEC_SIGNOPAQUE

#define SEC_SIGNOPAQUE   (1 << 5)

Email has an opaque signature (encrypted)

Definition at line 130 of file lib.h.

◆ SEC_KEYBLOCK

#define SEC_KEYBLOCK   (1 << 6)

Email has a key attached.

Definition at line 131 of file lib.h.

◆ SEC_INLINE

#define SEC_INLINE   (1 << 7)

Email has an inline signature.

Definition at line 132 of file lib.h.

◆ SEC_OPPENCRYPT

#define SEC_OPPENCRYPT   (1 << 8)

Opportunistic encrypt mode.

Definition at line 133 of file lib.h.

◆ SEC_AUTOCRYPT

#define SEC_AUTOCRYPT   (1 << 9)

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

Definition at line 134 of file lib.h.

◆ SEC_AUTOCRYPT_OVERRIDE

#define SEC_AUTOCRYPT_OVERRIDE   (1 << 10)

(Autocrypt) Indicates manual set/unset of encryption

Definition at line 135 of file lib.h.

◆ APPLICATION_PGP

#define APPLICATION_PGP   (1 << 11)

Use PGP to encrypt/sign.

Definition at line 137 of file lib.h.

◆ APPLICATION_SMIME

#define APPLICATION_SMIME   (1 << 12)

Use SMIME to encrypt/sign.

Definition at line 138 of file lib.h.

◆ PGP_TRADITIONAL_CHECKED

#define PGP_TRADITIONAL_CHECKED   (1 << 13)

Email has a traditional (inline) signature.

Definition at line 139 of file lib.h.

◆ SEC_ALL_FLAGS

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

Definition at line 141 of file lib.h.

◆ PGP_ENCRYPT

#define PGP_ENCRYPT   (APPLICATION_PGP | SEC_ENCRYPT)

Definition at line 143 of file lib.h.

◆ PGP_SIGN

#define PGP_SIGN   (APPLICATION_PGP | SEC_SIGN)

Definition at line 144 of file lib.h.

◆ PGP_GOODSIGN

#define PGP_GOODSIGN   (APPLICATION_PGP | SEC_GOODSIGN)

Definition at line 145 of file lib.h.

◆ PGP_KEY

#define PGP_KEY   (APPLICATION_PGP | SEC_KEYBLOCK)

Definition at line 146 of file lib.h.

◆ PGP_INLINE

#define PGP_INLINE   (APPLICATION_PGP | SEC_INLINE)

Definition at line 147 of file lib.h.

◆ SMIME_ENCRYPT

#define SMIME_ENCRYPT   (APPLICATION_SMIME | SEC_ENCRYPT)

Definition at line 149 of file lib.h.

◆ SMIME_SIGN

#define SMIME_SIGN   (APPLICATION_SMIME | SEC_SIGN)

Definition at line 150 of file lib.h.

◆ SMIME_GOODSIGN

#define SMIME_GOODSIGN   (APPLICATION_SMIME | SEC_GOODSIGN)

Definition at line 151 of file lib.h.

◆ SMIME_BADSIGN

#define SMIME_BADSIGN   (APPLICATION_SMIME | SEC_BADSIGN)

Definition at line 152 of file lib.h.

◆ SMIME_OPAQUE

#define SMIME_OPAQUE   (APPLICATION_SMIME | SEC_SIGNOPAQUE)

Definition at line 153 of file lib.h.

◆ WithCrypto

#define WithCrypto   (APPLICATION_PGP | APPLICATION_SMIME)

Definition at line 163 of file lib.h.

◆ KEYFLAG_NO_FLAGS

#define KEYFLAG_NO_FLAGS   0

No flags are set.

Definition at line 173 of file lib.h.

◆ KEYFLAG_CANSIGN

#define KEYFLAG_CANSIGN   (1 << 0)

Key is suitable for signing.

Definition at line 174 of file lib.h.

◆ KEYFLAG_CANENCRYPT

#define KEYFLAG_CANENCRYPT   (1 << 1)

Key is suitable for encryption.

Definition at line 175 of file lib.h.

◆ KEYFLAG_ISX509

#define KEYFLAG_ISX509   (1 << 2)

Key is an X.509 key.

Definition at line 176 of file lib.h.

◆ KEYFLAG_SECRET

#define KEYFLAG_SECRET   (1 << 7)

Key is a secret key.

Definition at line 177 of file lib.h.

◆ KEYFLAG_EXPIRED

#define KEYFLAG_EXPIRED   (1 << 8)

Key is expired.

Definition at line 178 of file lib.h.

◆ KEYFLAG_REVOKED

#define KEYFLAG_REVOKED   (1 << 9)

Key is revoked.

Definition at line 179 of file lib.h.

◆ KEYFLAG_DISABLED

#define KEYFLAG_DISABLED   (1 << 10)

Key is marked disabled.

Definition at line 180 of file lib.h.

◆ KEYFLAG_SUBKEY

#define KEYFLAG_SUBKEY   (1 << 11)

Key is a subkey.

Definition at line 181 of file lib.h.

◆ KEYFLAG_CRITICAL

#define KEYFLAG_CRITICAL   (1 << 12)

Key is marked critical.

Definition at line 182 of file lib.h.

◆ KEYFLAG_PREFER_ENCRYPTION

#define KEYFLAG_PREFER_ENCRYPTION   (1 << 13)

Key's owner prefers encryption.

Definition at line 183 of file lib.h.

◆ KEYFLAG_PREFER_SIGNING

#define KEYFLAG_PREFER_SIGNING   (1 << 14)

Key's owner prefers signing.

Definition at line 184 of file lib.h.

◆ KEYFLAG_CANTUSE

#define KEYFLAG_CANTUSE   (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)

Definition at line 186 of file lib.h.

◆ KEYFLAG_RESTRICTIONS

#define KEYFLAG_RESTRICTIONS   (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)

Definition at line 187 of file lib.h.

◆ KEYFLAG_ABILITIES

Definition at line 189 of file lib.h.

Typedef Documentation

◆ SecurityFlags

typedef uint16_t SecurityFlags

Flags, e.g. SEC_ENCRYPT.

Definition at line 123 of file lib.h.

◆ KeyFlags

typedef uint16_t KeyFlags

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

Definition at line 172 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 859 of file crypt.c.

860 {
861  if (!WithCrypto)
862  return;
863 
864  struct Buffer *tempfname = mutt_buffer_pool_get();
865  mutt_buffer_mktemp(tempfname);
866  FILE *fp_out = mutt_file_fopen(mutt_b2s(tempfname), "w");
867  if (!fp_out)
868  {
869  mutt_perror(mutt_b2s(tempfname));
870  goto cleanup;
871  }
872 
874  OptDontHandlePgpKeys = true;
875 
876  struct EmailNode *en = NULL;
877  STAILQ_FOREACH(en, el, entries)
878  {
879  struct Email *e = en->email;
880 
883  {
884  mutt_file_fclose(&fp_out);
885  break;
886  }
887 
888  if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
889  {
891  fflush(fp_out);
892 
893  mutt_endwin();
894  puts(_("Trying to extract PGP keys...\n"));
895  crypt_pgp_invoke_import(mutt_b2s(tempfname));
896  }
897 
898  if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME))
899  {
900  if (e->security & SEC_ENCRYPT)
901  {
903  CH_NO_FLAGS, 0);
904  }
905  else
907  fflush(fp_out);
908 
909  char *mbox = NULL;
910  if (!TAILQ_EMPTY(&e->env->from))
911  {
913  mbox = TAILQ_FIRST(&e->env->from)->mailbox;
914  }
915  else if (!TAILQ_EMPTY(&e->env->sender))
916  {
918  mbox = TAILQ_FIRST(&e->env->sender)->mailbox;
919  }
920  if (mbox)
921  {
922  mutt_endwin();
923  puts(_("Trying to extract S/MIME certificates..."));
924  crypt_smime_invoke_import(mutt_b2s(tempfname), mbox);
925  }
926  }
927 
928  rewind(fp_out);
929  }
930 
931  mutt_file_fclose(&fp_out);
932  if (isendwin())
934 
935  mutt_file_unlink(mutt_b2s(tempfname));
936 
937  if (WithCrypto & APPLICATION_PGP)
938  OptDontHandlePgpKeys = false;
939 
940 cleanup:
941  mutt_buffer_pool_release(&tempfname);
942 }
#define MUTT_CM_DECODE_CRYPT
Definition: copy.h:47
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:81
#define WithCrypto
Definition: lib.h:163
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:303
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:716
#define mutt_perror(...)
Definition: logging.h:85
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:125
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
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e)
Parse a MIME email.
Definition: mutt_parse.c:48
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:812
#define _(a)
Definition: message.h:28
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:34
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:146
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:89
WHERE bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
Definition: options.h:36
#define mutt_b2s(buf)
Definition: buffer.h:41
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:546
void crypt_pgp_invoke_import(const char *fname)
Wrapper for CryptModuleSpecs::pgp_invoke_import()
Definition: cryptglue.c:367
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:50
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:37
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:41
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
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:45
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:579
void crypt_smime_invoke_import(const char *infile, const char *mailbox)
Wrapper for CryptModuleSpecs::smime_invoke_import()
Definition: cryptglue.c:513
struct Email * email
Email in the list.
Definition: email.h:116
struct AddressList sender
Email&#39;s sender.
Definition: envelope.h:61
List of Emails.
Definition: email.h:114
#define TAILQ_EMPTY(head)
Definition: queue.h:714
#define MUTT_CM_NOHEADER
Don&#39;t copy the message header.
Definition: copy.h:35
FILE * mutt_file_fopen(const char *path, const char *mode)
Call fopen() safely.
Definition: file.c:588
+ 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 104 of file crypt.c.

105 {
108 
111 
112  if (WithCrypto)
113  {
114  /* L10N: Due to the implementation details (e.g. some passwords are managed
115  by gpg-agent) we can't know whether we forgot zero, 1, 12, ...
116  passwords. So in English we use "Passphrases". Your language might
117  have other means to express this. */
118  mutt_message(_("Passphrases forgotten"));
119  }
120 }
#define WithCrypto
Definition: lib.h:163
#define mutt_message(...)
Definition: logging.h:83
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:416
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_get_keys()

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

Check we have all the keys we need.

Parameters
[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 958 of file crypt.c.

959 {
960  if (!WithCrypto)
961  return 0;
962 
963  struct AddressList addrlist = TAILQ_HEAD_INITIALIZER(addrlist);
964  const char *fqdn = mutt_fqdn(true);
965  char *self_encrypt = NULL;
966 
967  /* Do a quick check to make sure that we can find all of the encryption
968  * keys if the user has requested this service. */
969 
970  *keylist = NULL;
971 
972 #ifdef USE_AUTOCRYPT
973  if (!oppenc_mode && (e->security & SEC_AUTOCRYPT))
974  {
976  return -1;
977  return 0;
978  }
979 #endif
980 
982  OptPgpCheckTrust = true;
983 
984  mutt_addrlist_copy(&addrlist, &e->env->to, false);
985  mutt_addrlist_copy(&addrlist, &e->env->cc, false);
986  mutt_addrlist_copy(&addrlist, &e->env->bcc, false);
987  mutt_addrlist_qualify(&addrlist, fqdn);
988  mutt_addrlist_dedupe(&addrlist);
989 
990  if (oppenc_mode || (e->security & SEC_ENCRYPT))
991  {
992  if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
993  {
994  *keylist = crypt_pgp_find_keys(&addrlist, oppenc_mode);
995  if (!*keylist)
996  {
997  mutt_addrlist_clear(&addrlist);
998  return -1;
999  }
1000  OptPgpCheckTrust = false;
1002  self_encrypt = C_PgpDefaultKey;
1003  }
1004  if (((WithCrypto & APPLICATION_SMIME) != 0) && (e->security & APPLICATION_SMIME))
1005  {
1006  *keylist = crypt_smime_find_keys(&addrlist, oppenc_mode);
1007  if (!*keylist)
1008  {
1009  mutt_addrlist_clear(&addrlist);
1010  return -1;
1011  }
1013  self_encrypt = C_SmimeDefaultKey;
1014  }
1015  }
1016 
1017  if (!oppenc_mode && self_encrypt)
1018  {
1019  const size_t keylist_size = mutt_str_strlen(*keylist);
1020  mutt_mem_realloc(keylist, keylist_size + mutt_str_strlen(self_encrypt) + 2);
1021  sprintf(*keylist + keylist_size, " %s", self_encrypt);
1022  }
1023 
1024  mutt_addrlist_clear(&addrlist);
1025 
1026  return 0;
1027 }
#define WithCrypto
Definition: lib.h:163
char * crypt_smime_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:480
WHERE char * C_SmimeDefaultKey
Config: Default key for SMIME operations.
Definition: globals.h:164
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:40
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:1412
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:125
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:734
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:134
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:692
bool C_PgpSelfEncrypt
Config: Encrypted messages will also be encrypted to C_PgpDefaultKey too.
Definition: crypt.c:71
Do no use Autocrypt.
Definition: lib.h:155
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
Definition: address.c:1349
unsigned char C_PgpEncryptSelf
Deprecated, see C_PgpSelfEncrypt.
Definition: crypt.c:68
struct Envelope * env
Envelope information.
Definition: email.h:89
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
bool C_SmimeSelfEncrypt
Config: Encrypted messages will also be encrypt to C_SmimeDefaultKey too.
Definition: crypt.c:74
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
unsigned char C_SmimeEncryptSelf
Deprecated, see C_SmimeSelfEncrypt.
Definition: crypt.c:73
WHERE bool OptPgpCheckTrust
(pseudo) used by pgp_select_key()
Definition: options.h:50
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
const char * mutt_fqdn(bool may_hide_host)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:2531
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:647
char * crypt_pgp_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:319
enum AutocryptRec mutt_autocrypt_ui_recommendation(struct Email *e, char **keylist)
Get the recommended action for an Email.
Definition: autocrypt.c:552
WHERE char * C_PgpDefaultKey
Config: Default key to use for PGP operations.
Definition: globals.h:160
struct AddressList to
Email&#39;s &#39;To&#39; list.
Definition: envelope.h:58
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:630
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_opportunistic_encrypt()

void crypt_opportunistic_encrypt ( struct Email e)

Can all recipients be determined.

Parameters
eEmail

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

Definition at line 1036 of file crypt.c.

1037 {
1038  if (!WithCrypto)
1039  return;
1040 
1042  return;
1043 
1044  char *pgpkeylist = NULL;
1045 
1046  crypt_get_keys(e, &pgpkeylist, 1);
1047  if (pgpkeylist)
1048  {
1049  e->security |= SEC_ENCRYPT;
1050  FREE(&pgpkeylist);
1051  }
1052  else
1053  {
1054  e->security &= ~SEC_ENCRYPT;
1055  }
1056 }
#define WithCrypto
Definition: lib.h:163
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:125
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:958
WHERE bool C_CryptOpportunisticEncrypt
Config: Enable encryption when the recipient&#39;s key is available.
Definition: globals.h:268
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:133
#define FREE(x)
Definition: memory.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_query()

SecurityFlags crypt_query ( struct Body m)

Check out the type of encryption used.

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

Set the cached status values if there are any.

Definition at line 700 of file crypt.c.

701 {
702  if (!WithCrypto || !m)
703  return SEC_NO_FLAGS;
704 
706 
707  if (m->type == TYPE_APPLICATION)
708  {
710  rc |= mutt_is_application_pgp(m);
711 
713  {
714  rc |= mutt_is_application_smime(m);
715  if (rc && m->goodsig)
716  rc |= SEC_GOODSIGN;
717  if (rc && m->badsig)
718  rc |= SEC_BADSIGN;
719  }
720  }
721  else if (((WithCrypto & APPLICATION_PGP) != 0) && (m->type == TYPE_TEXT))
722  {
723  rc |= mutt_is_application_pgp(m);
724  if (rc && m->goodsig)
725  rc |= SEC_GOODSIGN;
726  }
727 
728  if (m->type == TYPE_MULTIPART)
729  {
731  rc |= mutt_is_multipart_signed(m);
733 
734  if (rc && m->goodsig)
735  rc |= SEC_GOODSIGN;
736 #ifdef USE_AUTOCRYPT
737  if (rc && m->is_autocrypt)
738  rc |= SEC_AUTOCRYPT;
739 #endif
740  }
741 
742  if ((m->type == TYPE_MULTIPART) || (m->type == TYPE_MESSAGE))
743  {
744  SecurityFlags u = m->parts ? SEC_ALL_FLAGS : SEC_NO_FLAGS; /* Bits set in all parts */
745  SecurityFlags w = SEC_NO_FLAGS; /* Bits set in any part */
746 
747  for (struct Body *b = m->parts; b; b = b->next)
748  {
749  const SecurityFlags v = crypt_query(b);
750  u &= v;
751  w |= v;
752  }
753  rc |= u | (w & ~SEC_GOODSIGN);
754 
755  if ((w & SEC_GOODSIGN) && !(u & SEC_GOODSIGN))
756  rc |= SEC_PARTSIGN;
757  }
758 
759  return rc;
760 }
#define WithCrypto
Definition: lib.h:163
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:79
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:134
#define SEC_ALL_FLAGS
Definition: lib.h:141
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:123
The body of an email.
Definition: body.h:34
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:459
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
Definition: body.h:77
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:418
bool goodsig
Good cryptographic signature.
Definition: body.h:75
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
SecurityFlags mutt_is_application_pgp(struct Body *m)
Does the message use PGP?
Definition: crypt.c:565
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
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:520
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:624
#define SEC_BADSIGN
Email has a bad signature.
Definition: lib.h:128
unsigned int type
content-type primary type
Definition: body.h:65
Type: &#39;message/*&#39;.
Definition: mime.h:35
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:700
#define SEC_GOODSIGN
Email has a valid signature.
Definition: lib.h:127
#define SEC_PARTSIGN
Not all parts of the email is signed.
Definition: lib.h:129
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 146 of file crypt.c.

147 {
148  bool rc = false;
149 
150 #ifndef DEBUG
151  disable_coredumps();
152 #endif
153 
154  if (((WithCrypto & APPLICATION_PGP) != 0) && (flags & APPLICATION_PGP))
156 
157  if (((WithCrypto & APPLICATION_SMIME) != 0) && (flags & APPLICATION_SMIME))
159 
160  return rc;
161 }
#define WithCrypto
Definition: lib.h:163
bool crypt_smime_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
Definition: cryptglue.c:425
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
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 m)

Does the message use PGP?

Parameters
mBody 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 (m->type == TYPE_APPLICATION)
571  {
572  if ((mutt_str_strcasecmp(m->subtype, "pgp") == 0) ||
573  (mutt_str_strcasecmp(m->subtype, "x-pgp-message") == 0))
574  {
575  p = mutt_param_get(&m->parameter, "x-action");
576  if (p && ((mutt_str_strcasecmp(p, "sign") == 0) ||
577  (mutt_str_strcasecmp(p, "signclear") == 0)))
578  {
579  t |= PGP_SIGN;
580  }
581 
582  p = mutt_param_get(&m->parameter, "format");
583  if (p && (mutt_str_strcasecmp(p, "keys-only") == 0))
584  {
585  t |= PGP_KEY;
586  }
587 
588  if (t == SEC_NO_FLAGS)
589  t |= PGP_ENCRYPT; /* not necessarily correct, but... */
590  }
591 
592  if (mutt_str_strcasecmp(m->subtype, "pgp-signed") == 0)
593  t |= PGP_SIGN;
594 
595  if (mutt_str_strcasecmp(m->subtype, "pgp-keys") == 0)
596  t |= PGP_KEY;
597  }
598  else if ((m->type == TYPE_TEXT) && (mutt_str_strcasecmp("plain", m->subtype) == 0))
599  {
600  if (((p = mutt_param_get(&m->parameter, "x-mutt-action")) ||
601  (p = mutt_param_get(&m->parameter, "x-action")) ||
602  (p = mutt_param_get(&m->parameter, "action"))) &&
603  mutt_str_startswith(p, "pgp-sign", CASE_IGNORE))
604  {
605  t |= PGP_SIGN;
606  }
607  else if (p && mutt_str_startswith(p, "pgp-encrypt", CASE_IGNORE))
608  t |= PGP_ENCRYPT;
609  else if (p && mutt_str_startswith(p, "pgp-keys", CASE_IGNORE))
610  t |= PGP_KEY;
611  }
612  if (t)
613  t |= PGP_INLINE;
614 
615  return t;
616 }
#define PGP_INLINE
Definition: lib.h:147
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
#define PGP_ENCRYPT
Definition: lib.h:143
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:123
char * subtype
content-type subtype
Definition: body.h:37
Type: &#39;text/*&#39;.
Definition: mime.h:38
#define PGP_SIGN
Definition: lib.h:144
Ignore case when comparing strings.
Definition: string2.h:68
unsigned int type
content-type primary type
Definition: body.h:65
size_t mutt_str_startswith(const char *str, const char *prefix, enum CaseSensitivity cs)
Check whether a string starts with a prefix.
Definition: string.c:168
#define PGP_KEY
Definition: lib.h:146
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 m)

Does the message use S/MIME?

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

Definition at line 624 of file crypt.c.

625 {
626  if (!m)
627  return SEC_NO_FLAGS;
628 
629  if (((m->type & TYPE_APPLICATION) == 0) || !m->subtype)
630  return SEC_NO_FLAGS;
631 
632  char *t = NULL;
633  bool complain = false;
634  /* S/MIME MIME types don't need x- anymore, see RFC2311 */
635  if ((mutt_str_strcasecmp(m->subtype, "x-pkcs7-mime") == 0) ||
636  (mutt_str_strcasecmp(m->subtype, "pkcs7-mime") == 0))
637  {
638  t = mutt_param_get(&m->parameter, "smime-type");
639  if (t)
640  {
641  if (mutt_str_strcasecmp(t, "enveloped-data") == 0)
642  return SMIME_ENCRYPT;
643  if (mutt_str_strcasecmp(t, "signed-data") == 0)
644  return SMIME_SIGN | SMIME_OPAQUE;
645  return SEC_NO_FLAGS;
646  }
647  /* Netscape 4.7 uses
648  * Content-Description: S/MIME Encrypted Message
649  * instead of Content-Type parameter */
650  if (mutt_str_strcasecmp(m->description, "S/MIME Encrypted Message") == 0)
651  return SMIME_ENCRYPT;
652  complain = true;
653  }
654  else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0)
655  return SEC_NO_FLAGS;
656 
657  t = mutt_param_get(&m->parameter, "name");
658 
659  if (!t)
660  t = m->d_filename;
661  if (!t)
662  t = m->filename;
663  if (!t)
664  {
665  if (complain)
666  {
667  mutt_message(
668  _("S/MIME messages with no hints on content are unsupported"));
669  }
670  return SEC_NO_FLAGS;
671  }
672 
673  /* no .p7c, .p10 support yet. */
674 
675  int len = mutt_str_strlen(t) - 4;
676  if ((len > 0) && (*(t + len) == '.'))
677  {
678  len++;
679  if (mutt_str_strcasecmp((t + len), "p7m") == 0)
680  {
681  /* Not sure if this is the correct thing to do, but
682  * it's required for compatibility with Outlook */
683  return SMIME_SIGN | SMIME_OPAQUE;
684  }
685  else if (mutt_str_strcasecmp((t + len), "p7s") == 0)
686  return SMIME_SIGN | SMIME_OPAQUE;
687  }
688 
689  return SEC_NO_FLAGS;
690 }
#define SMIME_OPAQUE
Definition: lib.h:153
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:150
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
#define mutt_message(...)
Definition: logging.h:83
#define SMIME_ENCRYPT
Definition: lib.h:149
#define _(a)
Definition: message.h:28
size_t mutt_str_strlen(const char *a)
Calculate the length of a string, safely.
Definition: string.c:692
char * subtype
content-type subtype
Definition: body.h:37
char * description
content-description
Definition: body.h:40
unsigned int type
content-type primary type
Definition: body.h:65
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 520 of file crypt.c.

521 {
522  if (!(WithCrypto & APPLICATION_PGP))
523  return SEC_NO_FLAGS;
524 
525  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype ||
526  (mutt_str_strcasecmp(b->subtype, "mixed") != 0))
527  {
528  return SEC_NO_FLAGS;
529  }
530 
531  b = b->parts;
532  if (!b || (b->type != TYPE_TEXT) || !b->subtype ||
533  (mutt_str_strcasecmp(b->subtype, "plain") != 0) || (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_str_strcasecmp(b->subtype, "pgp-encrypted") != 0))
541  {
542  return SEC_NO_FLAGS;
543  }
544 
545  b = b->next;
546  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
547  (mutt_str_strcasecmp(b->subtype, "octet-stream") != 0))
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:163
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
#define PGP_ENCRYPT
Definition: lib.h:143
struct Body * next
next attachment in the list
Definition: body.h:53
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
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
Definition: body.h:65
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 459 of file crypt.c.

460 {
461  if ((WithCrypto & APPLICATION_PGP) == 0)
462  return SEC_NO_FLAGS;
463 
464  char *p = NULL;
465 
466  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype ||
467  (mutt_str_strcasecmp(b->subtype, "encrypted") != 0) ||
468  !(p = mutt_param_get(&b->parameter, "protocol")) ||
469  (mutt_str_strcasecmp(p, "application/pgp-encrypted") != 0))
470  {
471  return SEC_NO_FLAGS;
472  }
473 
474  return PGP_ENCRYPT;
475 }
#define WithCrypto
Definition: lib.h:163
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
#define PGP_ENCRYPT
Definition: lib.h:143
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
unsigned int type
content-type primary type
Definition: body.h:65
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 418 of file crypt.c.

419 {
420  if (!b || (b->type != TYPE_MULTIPART) || !b->subtype ||
421  (mutt_str_strcasecmp(b->subtype, "signed") != 0))
422  {
423  return SEC_NO_FLAGS;
424  }
425 
426  char *p = mutt_param_get(&b->parameter, "protocol");
427  if (!p)
428  return SEC_NO_FLAGS;
429 
430  if (!(mutt_str_strcasecmp(p, "multipart/mixed") != 0))
431  return SEC_SIGN;
432 
433  if (((WithCrypto & APPLICATION_PGP) != 0) &&
434  !(mutt_str_strcasecmp(p, "application/pgp-signature") != 0))
435  {
436  return PGP_SIGN;
437  }
438 
439  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
440  !(mutt_str_strcasecmp(p, "application/x-pkcs7-signature") != 0))
441  {
442  return SMIME_SIGN;
443  }
444  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
445  !(mutt_str_strcasecmp(p, "application/pkcs7-signature") != 0))
446  {
447  return SMIME_SIGN;
448  }
449 
450  return SEC_NO_FLAGS;
451 }
#define SMIME_SIGN
Definition: lib.h:150
#define WithCrypto
Definition: lib.h:163
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
#define PGP_SIGN
Definition: lib.h:144
unsigned int type
content-type primary type
Definition: body.h:65
#define SEC_SIGN
Email is signed.
Definition: lib.h:126
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 483 of file crypt.c.

484 {
486  return 0;
487 
488  b = b->parts;
489  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
490  (mutt_str_strcasecmp(b->subtype, "pgp-encrypted") != 0))
491  {
492  return 0;
493  }
494 
495  b = b->next;
496  if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
497  (mutt_str_strcasecmp(b->subtype, "octet-stream") != 0))
498  {
499  return 0;
500  }
501 
502  return PGP_ENCRYPT;
503 }
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:124
#define PGP_ENCRYPT
Definition: lib.h:143
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:459
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
Definition: body.h:65
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
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 Email e,
char *  keylist,
bool  postpone 
)

Encrypt and/or sign a message.

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

Definition at line 171 of file crypt.c.

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

Process a protected header - Implements handler_t.

Definition at line 1102 of file crypt.c.

1103 {
1104  if (C_CryptProtectedHeadersRead && a->mime_headers)
1105  {
1106  if (a->mime_headers->subject)
1107  {
1108  const bool display = (s->flags & MUTT_DISPLAY);
1109 
1110  if (display && C_Weed && mutt_matches_ignore("subject"))
1111  return 0;
1112 
1114  int wraplen = display ? mutt_window_wrap_cols(s->wraplen, C_Wrap) : 0;
1115 
1116  mutt_write_one_header(s->fp_out, "Subject", a->mime_headers->subject,
1117  s->prefix, wraplen, display ? CH_DISPLAY : CH_NO_FLAGS);
1118  state_puts(s, "\n");
1119  }
1120  }
1121 
1122  return 0;
1123 }
bool mutt_matches_ignore(const char *s)
Does the string match the ignore list.
Definition: parse.c:308
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#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
WHERE short C_Wrap
Config: Width to wrap text in the pager.
Definition: globals.h:153
FILE * fp_out
File to write to.
Definition: state.h:47
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:50
#define CH_DISPLAY
Display result to user.
Definition: copy.h:69
int mutt_window_wrap_cols(int width, short wrap)
Calculate the wrap column for a given screen width.
Definition: mutt_window.c:385
void state_mark_protected_header(struct State *s)
Write a unique marker around protected headers.
Definition: state.c:56
WHERE bool C_CryptProtectedHeadersRead
Config: Display protected headers (Memory Hole) in the pager.
Definition: globals.h:270
int mutt_write_one_header(FILE *fp, const char *tag, const char *value, const char *pfx, int wraplen, CopyHeaderFlags chflags)
Write one header line to a file.
Definition: sendlib.c:2154
bool C_Weed
Config: Filter headers when displaying/forwarding/printing/replying.
Definition: email_globals.c:40
+ 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
boolTrue if the subject should be protected

Definition at line 1088 of file crypt.c.

1089 {
1092  {
1093  return true;
1094  }
1095 
1096  return false;
1097 }
WHERE char * C_CryptProtectedHeadersSubject
Config: Use this as the subject for encrypted emails.
Definition: globals.h:107
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:125
WHERE bool C_CryptProtectedHeadersWrite
Config: Generate protected header (Memory Hole) for signed and encrypted emails.
Definition: globals.h:272
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:134
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:132
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
+ Here is the caller graph for this function:

◆ mutt_signed_handler()

int mutt_signed_handler ( struct Body a,
struct State s 
)

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

Definition at line 1128 of file crypt.c.

1129 {
1130  if (!WithCrypto)
1131  return -1;
1132 
1133  bool inconsistent = false;
1134  struct Body *b = a;
1135  struct Body **signatures = NULL;
1136  int sigcnt = 0;
1137  int rc = 0;
1138  struct Buffer *tempfile = NULL;
1139 
1140  a = a->parts;
1141  SecurityFlags signed_type = mutt_is_multipart_signed(b);
1142  if (signed_type == SEC_NO_FLAGS)
1143  {
1144  /* A null protocol value is already checked for in mutt_body_handler() */
1145  state_printf(s,
1146  _("[-- Error: "
1147  "Unknown multipart/signed protocol %s --]\n\n"),
1148  mutt_param_get(&b->parameter, "protocol"));
1149  return mutt_body_handler(a, s);
1150  }
1151 
1152  if (!(a && a->next))
1153  inconsistent = true;
1154  else
1155  {
1156  switch (signed_type)
1157  {
1158  case SEC_SIGN:
1159  if ((a->next->type != TYPE_MULTIPART) ||
1160  (mutt_str_strcasecmp(a->next->subtype, "mixed") != 0))
1161  {
1162  inconsistent = true;
1163  }
1164  break;
1165  case PGP_SIGN:
1166  if ((a->next->type != TYPE_APPLICATION) ||
1167  (mutt_str_strcasecmp(a->next->subtype, "pgp-signature") != 0))
1168  {
1169  inconsistent = true;
1170  }
1171  break;
1172  case SMIME_SIGN:
1173  if ((a->next->type != TYPE_APPLICATION) ||
1174  ((mutt_str_strcasecmp(a->next->subtype, "x-pkcs7-signature") != 0) &&
1175  (mutt_str_strcasecmp(a->next->subtype, "pkcs7-signature") != 0)))
1176  {
1177  inconsistent = true;
1178  }
1179  break;
1180  default:
1181  inconsistent = true;
1182  }
1183  }
1184  if (inconsistent)
1185  {
1186  state_attach_puts(s, _("[-- Error: Missing or bad-format multipart/signed "
1187  "signature --]\n\n"));
1188  return mutt_body_handler(a, s);
1189  }
1190 
1191  if (s->flags & MUTT_DISPLAY)
1192  {
1193  crypt_fetch_signatures(&signatures, a->next, &sigcnt);
1194 
1195  if (sigcnt != 0)
1196  {
1197  tempfile = mutt_buffer_pool_get();
1198  mutt_buffer_mktemp(tempfile);
1199  bool goodsig = true;
1200  if (crypt_write_signed(a, s, mutt_b2s(tempfile)) == 0)
1201  {
1202  for (int i = 0; i < sigcnt; i++)
1203  {
1204  if (((WithCrypto & APPLICATION_PGP) != 0) &&
1205  (signatures[i]->type == TYPE_APPLICATION) &&
1206  (mutt_str_strcasecmp(signatures[i]->subtype, "pgp-signature") == 0))
1207  {
1208  if (crypt_pgp_verify_one(signatures[i], s, mutt_b2s(tempfile)) != 0)
1209  goodsig = false;
1210 
1211  continue;
1212  }
1213 
1214  if (((WithCrypto & APPLICATION_SMIME) != 0) &&
1215  (signatures[i]->type == TYPE_APPLICATION) &&
1216  ((mutt_str_strcasecmp(signatures[i]->subtype,
1217  "x-pkcs7-signature") == 0) ||
1218  (mutt_str_strcasecmp(signatures[i]->subtype,
1219  "pkcs7-signature") == 0)))
1220  {
1221  if (crypt_smime_verify_one(signatures[i], s, mutt_b2s(tempfile)) != 0)
1222  goodsig = false;
1223 
1224  continue;
1225  }
1226 
1227  state_printf(s,
1228  _("[-- Warning: "
1229  "We can't verify %s/%s signatures. --]\n\n"),
1230  TYPE(signatures[i]), signatures[i]->subtype);
1231  }
1232  }
1233 
1234  mutt_file_unlink(mutt_b2s(tempfile));
1235  mutt_buffer_pool_release(&tempfile);
1236 
1237  b->goodsig = goodsig;
1238  b->badsig = !goodsig;
1239 
1240  /* Now display the signed body */
1241  state_attach_puts(s, _("[-- The following data is signed --]\n\n"));
1242 
1244 
1245  FREE(&signatures);
1246  }
1247  else
1248  {
1250  _("[-- Warning: Can't find any signatures. --]\n\n"));
1251  }
1252  }
1253 
1254  rc = mutt_body_handler(a, s);
1255 
1256  if ((s->flags & MUTT_DISPLAY) && (sigcnt != 0))
1257  state_attach_puts(s, _("\n[-- End of signed data --]\n"));
1258 
1259  return rc;
1260 }
int mutt_protected_headers_handler(struct Body *a, struct State *s)
Process a protected header - Implements handler_t.
Definition: crypt.c:1102
int state_printf(struct State *s, const char *fmt,...)
Write a formatted string to the State.
Definition: state.c:153
#define mutt_buffer_mktemp(buf)
Definition: muttlib.h:81
#define MUTT_DISPLAY
Output is displayed to the user.
Definition: state.h:32
#define SMIME_SIGN
Definition: lib.h:150
#define WithCrypto
Definition: lib.h:163
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:124
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:123
int crypt_write_signed(struct Body *a, struct State *s, const char *tempfile)
Write the message body/part.
Definition: crypt.c:772
The body of an email.
Definition: body.h:34
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:77
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:418
char * subtype
content-type subtype
Definition: body.h:37
#define mutt_b2s(buf)
Definition: buffer.h:41
bool goodsig
Good cryptographic signature.
Definition: body.h:75
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
#define PGP_SIGN
Definition: lib.h:144
static void crypt_fetch_signatures(struct Body ***signatures, struct Body *a, int *n)
Create an array of an emails parts.
Definition: crypt.c:1064
unsigned int type
content-type primary type
Definition: body.h:65
#define SEC_SIGN
Email is signed.
Definition: lib.h:126
void state_attach_puts(struct State *s, const char *t)
Write a string to the state.
Definition: state.c:70
#define TYPE(body)
Definition: mime.h:83
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
int mutt_str_strcasecmp(const char *a, const char *b)
Compare two strings ignoring case, safely.
Definition: string.c:654
#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:522
int mutt_body_handler(struct Body *b, struct State *s)
Handler for the Body of an email.
Definition: handler.c:1550
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:376
+ 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:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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:163
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
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 98 of file cryptglue.c.

99 {
100 #ifdef CRYPT_BACKEND_CLASSIC_PGP
101  if (
102 #ifdef CRYPT_BACKEND_GPGME
103  (!C_CryptUseGpgme)
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_CryptUseGpgme)
115 #else
116  1
117 #endif
118  )
120 #endif
121 
122 #ifdef CRYPT_BACKEND_GPGME
123  if (C_CryptUseGpgme)
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 C_CryptUseGpgme
Config: Use GPGME crypto backend.
Definition: cryptglue.c:61
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
void crypto_module_register(struct CryptModuleSpecs *specs)
Register a new crypto module.
Definition: crypt_mod.c:51
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:84
struct CryptModuleSpecs CryptModSmimeGpgme
GPGME SMIME - Implements CryptModuleSpecs.
+ 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:163
#define mutt_message(...)
Definition: logging.h:83
#define _(a)
Definition: message.h:28
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:138
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
+ Here is the caller graph for this function:

◆ crypt_pgp_application_handler()

int crypt_pgp_application_handler ( struct Body m,
struct State s 
)

Wrapper for CryptModuleSpecs::application_handler()

Implements handler_t

Definition at line 239 of file cryptglue.c.

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

◆ crypt_pgp_check_traditional()

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

Wrapper for CryptModuleSpecs::pgp_check_traditional()

Definition at line 286 of file cryptglue.c.

287 {
288  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_check_traditional))
289  return CRYPT_MOD_CALL(PGP, pgp_check_traditional)(fp, b, just_one);
290 
291  return 0;
292 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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  if (C_Autocrypt)
216  {
217  OptAutocryptGpgme = true;
218  int result = pgp_gpgme_decrypt_mime(fp_in, fp_out, b, cur);
219  OptAutocryptGpgme = false;
220  if (result == 0)
221  {
222  b->is_autocrypt = true;
223  return result;
224  }
225  }
226 #endif
227 
228  if (CRYPT_MOD_CALL_CHECK(PGP, decrypt_mime))
229  return CRYPT_MOD_CALL(PGP, decrypt_mime)(fp_in, fp_out, b, cur);
230 
231  return -1;
232 }
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:200
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:79
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:90
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:2380
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 a,
struct State s 
)

Wrapper for CryptModuleSpecs::encrypted_handler()

Implements handler_t

Definition at line 252 of file cryptglue.c.

253 {
254 #ifdef USE_AUTOCRYPT
255  if (C_Autocrypt)
256  {
257  OptAutocryptGpgme = true;
258  int result = pgp_gpgme_encrypted_handler(a, s);
259  OptAutocryptGpgme = false;
260  if (result == 0)
261  {
262  a->is_autocrypt = true;
263  return result;
264  }
265  }
266 #endif
267 
268  if (CRYPT_MOD_CALL_CHECK(PGP, encrypted_handler))
269  return CRYPT_MOD_CALL(PGP, encrypted_handler)(a, s);
270 
271  return -1;
272 }
WHERE bool C_Autocrypt
Config: Enables the Autocrypt feature.
Definition: globals.h:200
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:79
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:90
int pgp_gpgme_encrypted_handler(struct Body *a, struct State *s)
Implements CryptModuleSpecs::encrypted_handler()
Definition: crypt_gpgme.c:3228
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 398 of file cryptglue.c.

399 {
400  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_extract_key_from_attachment))
401  CRYPT_MOD_CALL(PGP, pgp_extract_key_from_attachment)(fp, top);
402 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 277 of file cryptglue.c.

278 {
279  if (CRYPT_MOD_CALL_CHECK(PGP, pgp_invoke_getkeys))
280  CRYPT_MOD_CALL(PGP, pgp_invoke_getkeys)(addr);
281 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 308 of file cryptglue.c.

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

◆ crypt_pgp_send_menu()

int crypt_pgp_send_menu ( struct Email e)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 387 of file cryptglue.c.

388 {
389  if (CRYPT_MOD_CALL_CHECK(PGP, send_menu))
390  return CRYPT_MOD_CALL(PGP, send_menu)(e);
391 
392  return 0;
393 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ Here is the caller graph for this function:

◆ crypt_smime_application_handler()

int crypt_smime_application_handler ( struct Body m,
struct State s 
)

Wrapper for CryptModuleSpecs::application_handler()

Implements handler_t

Definition at line 449 of file cryptglue.c.

450 {
451  if (CRYPT_MOD_CALL_CHECK(SMIME, application_handler))
452  return CRYPT_MOD_CALL(SMIME, application_handler)(m, s);
453 
454  return -1;
455 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 436 of file cryptglue.c.

437 {
438  if (CRYPT_MOD_CALL_CHECK(SMIME, decrypt_mime))
439  return CRYPT_MOD_CALL(SMIME, decrypt_mime)(fp_in, fp_out, b, cur);
440 
441  return -1;
442 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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 460 of file cryptglue.c.

461 {
462  if (CRYPT_MOD_CALL_CHECK(SMIME, smime_getkeys))
463  CRYPT_MOD_CALL(SMIME, smime_getkeys)(env);
464 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ Here is the caller graph for this function:

◆ crypt_smime_send_menu()

int crypt_smime_send_menu ( struct Email e)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 533 of file cryptglue.c.

534 {
535  if (CRYPT_MOD_CALL_CHECK(SMIME, send_menu))
536  return CRYPT_MOD_CALL(SMIME, send_menu)(e);
537 
538  return 0;
539 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ Here is the caller graph for this function:

◆ crypt_smime_verify_sender()

int crypt_smime_verify_sender ( struct Mailbox m,
struct Email e 
)

Wrapper for CryptModuleSpecs::smime_verify_sender()

Definition at line 469 of file cryptglue.c.

470 {
471  if (CRYPT_MOD_CALL_CHECK(SMIME, smime_verify_sender))
472  return CRYPT_MOD_CALL(SMIME, smime_verify_sender)(m, e);
473 
474  return 1;
475 }
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:90
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:84
+ 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:399
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:359
#define FREE(x)
Definition: memory.h:40
+ Here is the caller graph for this function:

◆ pgp_gpgme_init()

void pgp_gpgme_init ( void  )

Implements CryptModuleSpecs::init()

Definition at line 5577 of file crypt_gpgme.c.

5578 {
5579  init_common();
5580  init_pgp();
5581 }
static void init_common(void)
Initialise code common to PGP and SMIME parts of GPGME.
Definition: crypt_gpgme.c:5536
static void init_pgp(void)
Initialise the PGP crypto backend.
Definition: crypt_gpgme.c:5555
+ Here is the call graph for this function:
+ 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 5389 of file crypt_gpgme.c.

5390 {
5391  int rc = -1, junk;
5392  gpgme_error_t err;
5393  gpgme_key_t key = NULL;
5394  gpgme_user_id_t uid = NULL;
5395  struct CryptKeyInfo *results = NULL, *k = NULL;
5396  struct CryptKeyInfo **kend = NULL;
5397  struct CryptKeyInfo *choice = NULL;
5398 
5399  gpgme_ctx_t ctx = create_gpgme_context(false);
5400 
5401  /* list all secret keys */
5402  if (gpgme_op_keylist_start(ctx, NULL, 1))
5403  goto cleanup;
5404 
5405  kend = &results;
5406 
5407  while (!(err = gpgme_op_keylist_next(ctx, &key)))
5408  {
5410 
5412  flags |= KEYFLAG_CANENCRYPT;
5413  if (key_check_cap(key, KEY_CAP_CAN_SIGN))
5414  flags |= KEYFLAG_CANSIGN;
5415 
5416  if (key->revoked)
5417  flags |= KEYFLAG_REVOKED;
5418  if (key->expired)
5419  flags |= KEYFLAG_EXPIRED;
5420  if (key->disabled)
5421  flags |= KEYFLAG_DISABLED;
5422 
5423  int idx;
5424  for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
5425  {
5426  k = mutt_mem_calloc(1, sizeof(*k));
5427  k->kobj = key;
5428  gpgme_key_ref(k->kobj);
5429  k->idx = idx;
5430  k->uid = uid->uid;
5431  k->flags = flags;
5432  if (uid->revoked)
5433  k->flags |= KEYFLAG_REVOKED;
5434  k->validity = uid->validity;
5435  *kend = k;
5436  kend = &k->next;
5437  }
5438  gpgme_key_unref(key);
5439  }
5440  if (gpg_err_code(err) != GPG_ERR_EOF)
5441  mutt_error(_("gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
5442  gpgme_op_keylist_end(ctx);
5443 
5444  if (!results)
5445  {
5446  /* L10N: mutt_gpgme_select_secret_key() tries to list all secret keys to choose
5447  from. This error is displayed if no results were found. */
5448  mutt_error(_("No secret keys found"));
5449  goto cleanup;
5450  }
5451 
5452  choice = crypt_select_key(results, NULL, "*", APPLICATION_PGP, &junk);
5453  if (!(choice && choice->kobj && choice->kobj->subkeys && choice->kobj->subkeys->fpr))
5454  goto cleanup;
5455  mutt_buffer_strcpy(keyid, choice->kobj->subkeys->fpr);
5456 
5457  rc = 0;
5458 
5459 cleanup:
5460  crypt_key_free(&choice);
5461  crypt_key_free(&results);
5462  gpgme_release(ctx);
5463  return rc;
5464 }
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:637
static struct CryptKeyInfo * crypt_select_key(struct CryptKeyInfo *keys, struct Address *p, const char *s, unsigned int app, int *forced_valid)
Get the user to select a key.
Definition: crypt_gpgme.c:4714
#define _(a)
Definition: message.h:28
struct CryptKeyInfo * next
Definition: crypt_gpgme.c:119
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:175
A stored PGP key.
Definition: crypt_gpgme.c:117
int idx
and the user ID at this index
Definition: crypt_gpgme.c:121
static gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
Definition: crypt_gpgme.c:758
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:178
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:137
#define KEYFLAG_NO_FLAGS
No flags are set.
Definition: lib.h:173
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:172
gpgme_key_t kobj
Definition: crypt_gpgme.c:120
Key can be used for signing.
Definition: crypt_gpgme.c:155
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:180
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:174
Key can be used for encryption.
Definition: crypt_gpgme.c:154
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.c:123
#define mutt_error(...)
Definition: logging.h:84
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:179
static unsigned int key_check_cap(gpgme_key_t key, enum KeyCap cap)
Check the capabilities of a key.
Definition: crypt_gpgme.c:4107
+ 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 5872 of file crypt_gpgme.c.

5873 {
5874  return GPGME_VERSION;
5875 }
+ Here is the caller graph for this function:

Variable Documentation

◆ C_CryptTimestamp

bool C_CryptTimestamp

Config: Add a timestamp to PGP or SMIME output to prevent spoofing.

Definition at line 64 of file crypt.c.

◆ C_PgpEncryptSelf

unsigned char C_PgpEncryptSelf

Deprecated, see C_PgpSelfEncrypt.

Definition at line 68 of file crypt.c.

◆ C_PgpMimeAuto

unsigned char C_PgpMimeAuto

Config: Prompt the user to use MIME if inline PGP fails.

Definition at line 69 of file crypt.c.

◆ C_PgpRetainableSigs

bool C_PgpRetainableSigs

Config: Create nested multipart/signed or encrypted messages.

Definition at line 70 of file crypt.c.

◆ C_PgpSelfEncrypt

bool C_PgpSelfEncrypt

Config: Encrypted messages will also be encrypted to C_PgpDefaultKey too.

Definition at line 71 of file crypt.c.

◆ C_PgpStrictEnc

bool C_PgpStrictEnc

Config: Encode PGP signed messages with quoted-printable (don't unset)

Definition at line 72 of file crypt.c.

◆ C_SmimeEncryptSelf

unsigned char C_SmimeEncryptSelf

Deprecated, see C_SmimeSelfEncrypt.

Definition at line 73 of file crypt.c.

◆ C_SmimeSelfEncrypt

bool C_SmimeSelfEncrypt

Config: Encrypted messages will also be encrypt to C_SmimeDefaultKey too.

Definition at line 74 of file crypt.c.

◆ C_CryptUseGpgme

bool C_CryptUseGpgme

Config: Use GPGME crypto backend.

Definition at line 61 of file cryptglue.c.

◆ C_PgpCheckExit

bool C_PgpCheckExit

Config: Check the exit code of PGP subprocess.

Definition at line 69 of file pgp.c.

◆ C_PgpCheckGpgDecryptStatusFd

bool C_PgpCheckGpgDecryptStatusFd

Config: File descriptor used for status info.

Definition at line 70 of file pgp.c.

◆ C_PgpDecryptionOkay

struct Regex* C_PgpDecryptionOkay

Config: Text indicating a successful decryption.

Definition at line 71 of file pgp.c.

◆ C_PgpGoodSign

struct Regex* C_PgpGoodSign

Config: Text indicating a good signature.

Definition at line 72 of file pgp.c.

◆ C_PgpTimeout

long C_PgpTimeout

Config: Time in seconds to cache a passphrase.

Definition at line 73 of file pgp.c.

◆ C_PgpUseGpgAgent

bool C_PgpUseGpgAgent

Config: Use a PGP agent for caching passwords.

Definition at line 74 of file pgp.c.

◆ C_PgpClearsignCommand

char* C_PgpClearsignCommand

Config: (pgp) External command to inline-sign a message.

Definition at line 53 of file pgpinvoke.c.

◆ C_PgpDecodeCommand

char* C_PgpDecodeCommand

Config: (pgp) External command to decode a PGP attachment.

Definition at line 54 of file pgpinvoke.c.

◆ C_PgpDecryptCommand

char* C_PgpDecryptCommand

Config: (pgp) External command to decrypt a PGP message.

Definition at line 55 of file pgpinvoke.c.

◆ C_PgpEncryptOnlyCommand

char* C_PgpEncryptOnlyCommand

Config: (pgp) External command to encrypt, but not sign a message.

Definition at line 56 of file pgpinvoke.c.

◆ C_PgpEncryptSignCommand

char* C_PgpEncryptSignCommand

Config: (pgp) External command to encrypt and sign a message.

Definition at line 57 of file pgpinvoke.c.

◆ C_PgpExportCommand

char* C_PgpExportCommand

Config: (pgp) External command to export a public key from the user's keyring.

Definition at line 58 of file pgpinvoke.c.

◆ C_PgpGetkeysCommand

char* C_PgpGetkeysCommand

Config: (pgp) External command to download a key for an email address.

Definition at line 59 of file pgpinvoke.c.

◆ C_PgpImportCommand

char* C_PgpImportCommand

Config: (pgp) External command to import a key into the user's keyring.

Definition at line 60 of file pgpinvoke.c.

◆ C_PgpListPubringCommand

char* C_PgpListPubringCommand

Config: (pgp) External command to list the public keys in a user's keyring.

Definition at line 61 of file pgpinvoke.c.

◆ C_PgpListSecringCommand

char* C_PgpListSecringCommand

Config: (pgp) External command to list the private keys in a user's keyring.

Definition at line 62 of file pgpinvoke.c.

◆ C_PgpSignCommand

char* C_PgpSignCommand

Config: (pgp) External command to create a detached PGP signature.

Definition at line 63 of file pgpinvoke.c.

◆ C_PgpVerifyCommand

char* C_PgpVerifyCommand

Config: (pgp) External command to verify PGP signatures.

Definition at line 64 of file pgpinvoke.c.

◆ C_PgpVerifyKeyCommand

char* C_PgpVerifyKeyCommand

Config: (pgp) External command to verify key information.

Definition at line 65 of file pgpinvoke.c.

◆ C_SmimeAskCertLabel

bool C_SmimeAskCertLabel

Config: Prompt the user for a label for SMIME certificates.

Definition at line 68 of file smime.c.

◆ C_SmimeCaLocation

char* C_SmimeCaLocation

Config: File containing trusted certificates.

Definition at line 69 of file smime.c.

◆ C_SmimeCertificates

char* C_SmimeCertificates

Config: File containing user's public certificates.

Definition at line 70 of file smime.c.

◆ C_SmimeDecryptCommand

char* C_SmimeDecryptCommand

Config: (smime) External command to decrypt an SMIME message.

Definition at line 71 of file smime.c.

◆ C_SmimeDecryptUseDefaultKey

bool C_SmimeDecryptUseDefaultKey

Config: Use the default key for decryption.

Definition at line 72 of file smime.c.

◆ C_SmimeEncryptCommand

char* C_SmimeEncryptCommand

Config: (smime) External command to encrypt a message.

Definition at line 73 of file smime.c.

◆ C_SmimeGetCertCommand

char* C_SmimeGetCertCommand

Config: (smime) External command to extract a certificate from a message.

Definition at line 74 of file smime.c.

◆ C_SmimeGetCertEmailCommand

char* C_SmimeGetCertEmailCommand

Config: (smime) External command to get a certificate for an email.

Definition at line 75 of file smime.c.

◆ C_SmimeGetSignerCertCommand

char* C_SmimeGetSignerCertCommand

Config: (smime) External command to extract a certificate from an email.

Definition at line 76 of file smime.c.

◆ C_SmimeImportCertCommand

char* C_SmimeImportCertCommand

Config: (smime) External command to import a certificate.

Definition at line 77 of file smime.c.

◆ C_SmimeKeys

char* C_SmimeKeys

Config: File containing user's private certificates.

Definition at line 78 of file smime.c.

◆ C_SmimePk7outCommand

char* C_SmimePk7outCommand

Config: (smime) External command to extract a public certificate.

Definition at line 79 of file smime.c.

◆ C_SmimeSignCommand

char* C_SmimeSignCommand

Config: (smime) External command to sign a message.

Definition at line 80 of file smime.c.

◆ C_SmimeSignDigestAlg

char* C_SmimeSignDigestAlg

Config: Digest algorithm.

Definition at line 81 of file smime.c.

◆ C_SmimeTimeout

long C_SmimeTimeout

Config: Time in seconds to cache a passphrase.

Definition at line 82 of file smime.c.

◆ C_SmimeVerifyCommand

char* C_SmimeVerifyCommand

Config: (smime) External command to verify a signed message.

Definition at line 83 of file smime.c.

◆ C_SmimeVerifyOpaqueCommand

char* C_SmimeVerifyOpaqueCommand

Config: (smime) External command to verify a signature.

Definition at line 84 of file smime.c.