NeoMutt  2024-02-01-35-geee02f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h File Reference

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

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

Go to the source code of this file.

Macros

#define SEC_NO_FLAGS   0
 No flags are set.
 
#define SEC_ENCRYPT   (1 << 0)
 Email is encrypted.
 
#define SEC_SIGN   (1 << 1)
 Email is signed.
 
#define SEC_GOODSIGN   (1 << 2)
 Email has a valid signature.
 
#define SEC_BADSIGN   (1 << 3)
 Email has a bad signature.
 
#define SEC_PARTSIGN   (1 << 4)
 Not all parts of the email is signed.
 
#define SEC_SIGNOPAQUE   (1 << 5)
 Email has an opaque signature (encrypted)
 
#define SEC_KEYBLOCK   (1 << 6)
 Email has a key attached.
 
#define SEC_INLINE   (1 << 7)
 Email has an inline signature.
 
#define SEC_OPPENCRYPT   (1 << 8)
 Opportunistic encrypt mode.
 
#define SEC_AUTOCRYPT   (1 << 9)
 (Autocrypt) Message will be, or was Autocrypt encrypt+signed
 
#define SEC_AUTOCRYPT_OVERRIDE   (1 << 10)
 (Autocrypt) Indicates manual set/unset of encryption
 
#define APPLICATION_PGP   (1 << 11)
 Use PGP to encrypt/sign.
 
#define APPLICATION_SMIME   (1 << 12)
 Use SMIME to encrypt/sign.
 
#define PGP_TRADITIONAL_CHECKED   (1 << 13)
 Email has a traditional (inline) signature.
 
#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.
 
#define KEYFLAG_CANSIGN   (1 << 0)
 Key is suitable for signing.
 
#define KEYFLAG_CANENCRYPT   (1 << 1)
 Key is suitable for encryption.
 
#define KEYFLAG_ISX509   (1 << 2)
 Key is an X.509 key.
 
#define KEYFLAG_SECRET   (1 << 7)
 Key is a secret key.
 
#define KEYFLAG_EXPIRED   (1 << 8)
 Key is expired.
 
#define KEYFLAG_REVOKED   (1 << 9)
 Key is revoked.
 
#define KEYFLAG_DISABLED   (1 << 10)
 Key is marked disabled.
 
#define KEYFLAG_SUBKEY   (1 << 11)
 Key is a subkey.
 
#define KEYFLAG_CRITICAL   (1 << 12)
 Key is marked critical.
 
#define KEYFLAG_PREFER_ENCRYPTION   (1 << 13)
 Key's owner prefers encryption.
 
#define KEYFLAG_PREFER_SIGNING   (1 << 14)
 Key's owner prefers signing.
 
#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.
 
typedef uint16_t KeyFlags
 Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
 

Functions

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

Detailed Description

API for encryption/signing of emails.

Authors
  • Richard Russon
  • 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 77 of file lib.h.

◆ SEC_ENCRYPT

#define SEC_ENCRYPT   (1 << 0)

Email is encrypted.

Definition at line 78 of file lib.h.

◆ SEC_SIGN

#define SEC_SIGN   (1 << 1)

Email is signed.

Definition at line 79 of file lib.h.

◆ SEC_GOODSIGN

#define SEC_GOODSIGN   (1 << 2)

Email has a valid signature.

Definition at line 80 of file lib.h.

◆ SEC_BADSIGN

#define SEC_BADSIGN   (1 << 3)

Email has a bad signature.

Definition at line 81 of file lib.h.

◆ SEC_PARTSIGN

#define SEC_PARTSIGN   (1 << 4)

Not all parts of the email is signed.

Definition at line 82 of file lib.h.

◆ SEC_SIGNOPAQUE

#define SEC_SIGNOPAQUE   (1 << 5)

Email has an opaque signature (encrypted)

Definition at line 83 of file lib.h.

◆ SEC_KEYBLOCK

#define SEC_KEYBLOCK   (1 << 6)

Email has a key attached.

Definition at line 84 of file lib.h.

◆ SEC_INLINE

#define SEC_INLINE   (1 << 7)

Email has an inline signature.

Definition at line 85 of file lib.h.

◆ SEC_OPPENCRYPT

#define SEC_OPPENCRYPT   (1 << 8)

Opportunistic encrypt mode.

Definition at line 86 of file lib.h.

◆ SEC_AUTOCRYPT

#define SEC_AUTOCRYPT   (1 << 9)

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

Definition at line 87 of file lib.h.

◆ SEC_AUTOCRYPT_OVERRIDE

#define SEC_AUTOCRYPT_OVERRIDE   (1 << 10)

(Autocrypt) Indicates manual set/unset of encryption

Definition at line 88 of file lib.h.

◆ APPLICATION_PGP

#define APPLICATION_PGP   (1 << 11)

Use PGP to encrypt/sign.

Definition at line 90 of file lib.h.

◆ APPLICATION_SMIME

#define APPLICATION_SMIME   (1 << 12)

Use SMIME to encrypt/sign.

Definition at line 91 of file lib.h.

◆ PGP_TRADITIONAL_CHECKED

#define PGP_TRADITIONAL_CHECKED   (1 << 13)

Email has a traditional (inline) signature.

Definition at line 92 of file lib.h.

◆ SEC_ALL_FLAGS

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

Definition at line 94 of file lib.h.

◆ PGP_ENCRYPT

#define PGP_ENCRYPT   (APPLICATION_PGP | SEC_ENCRYPT)

Definition at line 96 of file lib.h.

◆ PGP_SIGN

#define PGP_SIGN   (APPLICATION_PGP | SEC_SIGN)

Definition at line 97 of file lib.h.

◆ PGP_GOODSIGN

#define PGP_GOODSIGN   (APPLICATION_PGP | SEC_GOODSIGN)

Definition at line 98 of file lib.h.

◆ PGP_KEY

#define PGP_KEY   (APPLICATION_PGP | SEC_KEYBLOCK)

Definition at line 99 of file lib.h.

◆ PGP_INLINE

#define PGP_INLINE   (APPLICATION_PGP | SEC_INLINE)

Definition at line 100 of file lib.h.

◆ SMIME_ENCRYPT

#define SMIME_ENCRYPT   (APPLICATION_SMIME | SEC_ENCRYPT)

Definition at line 102 of file lib.h.

◆ SMIME_SIGN

#define SMIME_SIGN   (APPLICATION_SMIME | SEC_SIGN)

Definition at line 103 of file lib.h.

◆ SMIME_GOODSIGN

#define SMIME_GOODSIGN   (APPLICATION_SMIME | SEC_GOODSIGN)

Definition at line 104 of file lib.h.

◆ SMIME_BADSIGN

#define SMIME_BADSIGN   (APPLICATION_SMIME | SEC_BADSIGN)

Definition at line 105 of file lib.h.

◆ SMIME_OPAQUE

#define SMIME_OPAQUE   (APPLICATION_SMIME | SEC_SIGNOPAQUE)

Definition at line 106 of file lib.h.

◆ WithCrypto

#define WithCrypto   (APPLICATION_PGP | APPLICATION_SMIME)

Definition at line 116 of file lib.h.

◆ KEYFLAG_NO_FLAGS

#define KEYFLAG_NO_FLAGS   0

No flags are set.

Definition at line 126 of file lib.h.

◆ KEYFLAG_CANSIGN

#define KEYFLAG_CANSIGN   (1 << 0)

Key is suitable for signing.

Definition at line 127 of file lib.h.

◆ KEYFLAG_CANENCRYPT

#define KEYFLAG_CANENCRYPT   (1 << 1)

Key is suitable for encryption.

Definition at line 128 of file lib.h.

◆ KEYFLAG_ISX509

#define KEYFLAG_ISX509   (1 << 2)

Key is an X.509 key.

Definition at line 129 of file lib.h.

◆ KEYFLAG_SECRET

#define KEYFLAG_SECRET   (1 << 7)

Key is a secret key.

Definition at line 130 of file lib.h.

◆ KEYFLAG_EXPIRED

#define KEYFLAG_EXPIRED   (1 << 8)

Key is expired.

Definition at line 131 of file lib.h.

◆ KEYFLAG_REVOKED

#define KEYFLAG_REVOKED   (1 << 9)

Key is revoked.

Definition at line 132 of file lib.h.

◆ KEYFLAG_DISABLED

#define KEYFLAG_DISABLED   (1 << 10)

Key is marked disabled.

Definition at line 133 of file lib.h.

◆ KEYFLAG_SUBKEY

#define KEYFLAG_SUBKEY   (1 << 11)

Key is a subkey.

Definition at line 134 of file lib.h.

◆ KEYFLAG_CRITICAL

#define KEYFLAG_CRITICAL   (1 << 12)

Key is marked critical.

Definition at line 135 of file lib.h.

◆ KEYFLAG_PREFER_ENCRYPTION

#define KEYFLAG_PREFER_ENCRYPTION   (1 << 13)

Key's owner prefers encryption.

Definition at line 136 of file lib.h.

◆ KEYFLAG_PREFER_SIGNING

#define KEYFLAG_PREFER_SIGNING   (1 << 14)

Key's owner prefers signing.

Definition at line 137 of file lib.h.

◆ KEYFLAG_CANTUSE

#define KEYFLAG_CANTUSE   (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)

Definition at line 139 of file lib.h.

◆ KEYFLAG_RESTRICTIONS

#define KEYFLAG_RESTRICTIONS   (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)

Definition at line 140 of file lib.h.

◆ KEYFLAG_ABILITIES

Definition at line 142 of file lib.h.

Typedef Documentation

◆ SecurityFlags

typedef uint16_t SecurityFlags

Flags, e.g. SEC_ENCRYPT.

Definition at line 76 of file lib.h.

◆ KeyFlags

typedef uint16_t KeyFlags

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

Definition at line 125 of file lib.h.

Function Documentation

◆ crypt_extract_keys_from_messages()

void crypt_extract_keys_from_messages ( struct Mailbox m,
struct EmailArray *  ea 
)

Extract keys from a message.

Parameters
mMailbox
eaArray of Emails to process

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

Definition at line 844 of file crypt.c.

845{
846 if (!WithCrypto)
847 return;
848
849 struct Buffer *tempfname = buf_pool_get();
850 buf_mktemp(tempfname);
851 FILE *fp_out = mutt_file_fopen(buf_string(tempfname), "w");
852 if (!fp_out)
853 {
854 mutt_perror("%s", buf_string(tempfname));
855 goto cleanup;
856 }
857
860
861 struct Email **ep = NULL;
862 ARRAY_FOREACH(ep, ea)
863 {
864 struct Email *e = *ep;
865 struct Message *msg = mx_msg_open(m, e);
866 if (!msg)
867 {
868 continue;
869 }
872 {
873 mx_msg_close(m, &msg);
874 mutt_file_fclose(&fp_out);
875 break;
876 }
877
878 if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
879 {
881 fflush(fp_out);
882
883 mutt_endwin();
884 puts(_("Trying to extract PGP keys...\n"));
886 }
887
889 {
890 const bool encrypt = e->security & SEC_ENCRYPT;
891 mutt_copy_message(fp_out, e, msg,
894 CH_NO_FLAGS, 0);
895 fflush(fp_out);
896
897 const char *mbox = NULL;
898 if (!TAILQ_EMPTY(&e->env->from))
899 {
901 mbox = buf_string(TAILQ_FIRST(&e->env->from)->mailbox);
902 }
903 else if (!TAILQ_EMPTY(&e->env->sender))
904 {
906 mbox = buf_string(TAILQ_FIRST(&e->env->sender)->mailbox);
907 }
908 if (mbox)
909 {
910 mutt_endwin();
911 puts(_("Trying to extract S/MIME certificates..."));
912 crypt_smime_invoke_import(buf_string(tempfname), mbox);
913 }
914 }
915 mx_msg_close(m, &msg);
916
917 rewind(fp_out);
918 }
919
920 mutt_file_fclose(&fp_out);
921 if (isendwin())
923
924 mutt_file_unlink(buf_string(tempfname));
925
927 OptDontHandlePgpKeys = false;
928
929cleanup:
930 buf_pool_release(&tempfname);
931}
void mutt_expand_aliases(struct AddressList *al)
Expand aliases in a List of Addresses.
Definition: alias.c:300
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition: array.h:212
void mutt_parse_mime_message(struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:597
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:97
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Definition: copy.c:908
#define MUTT_CM_DECODE
Decode the message body into text/plain.
Definition: copy.h:40
#define MUTT_CM_CHARCONV
Perform character set conversions.
Definition: copy.h:44
#define MUTT_CM_DECODE_SMIME
Used for decoding S/MIME messages.
Definition: copy.h:48
#define MUTT_CM_NO_FLAGS
No flags are set.
Definition: copy.h:37
#define MUTT_CM_DECODE_CRYPT
Definition: copy.h:50
#define MUTT_CM_NOHEADER
Don't copy the message header.
Definition: copy.h:38
#define CH_NO_FLAGS
No flags are set.
Definition: copy.h:53
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:132
void crypt_pgp_invoke_import(const char *fname)
Wrapper for CryptModuleSpecs::pgp_invoke_import()
Definition: cryptglue.c:363
void crypt_smime_invoke_import(const char *infile, const char *mailbox)
Wrapper for CryptModuleSpecs::smime_invoke_import()
Definition: cryptglue.c:507
int mutt_any_key_to_continue(const char *s)
Prompt the user to 'press any key' and wait.
Definition: curs_lib.c:175
void mutt_endwin(void)
Shutdown curses.
Definition: curs_lib.c:153
void mutt_file_unlink(const char *s)
Delete a file, carefully.
Definition: file.c:216
#define mutt_file_fclose(FP)
Definition: file.h:148
#define mutt_file_fopen(PATH, MODE)
Definition: file.h:147
bool OptDontHandlePgpKeys
(pseudo) used to extract PGP keys
Definition: globals.c:64
#define mutt_perror(...)
Definition: logging2.h:93
#define _(a)
Definition: message.h:28
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
Definition: mx.c:1178
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
Definition: mx.c:1132
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:78
#define WithCrypto
Definition: lib.h:116
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
#define TAILQ_FIRST(head)
Definition: queue.h:723
#define TAILQ_EMPTY(head)
Definition: queue.h:721
String manipulation buffer.
Definition: buffer.h:36
The envelope/body of an email.
Definition: email.h:39
struct Envelope * env
Envelope information.
Definition: email.h:68
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:43
struct AddressList sender
Email's sender.
Definition: envelope.h:63
struct AddressList from
Email's 'From' list.
Definition: envelope.h:59
A local copy of an email.
Definition: message.h:34
FILE * fp
pointer to the message data
Definition: message.h:35
#define buf_mktemp(buf)
Definition: tmp.h:33
+ 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 90 of file crypt.c.

91{
94
97
98 if (WithCrypto)
99 {
100 /* L10N: Due to the implementation details (e.g. some passwords are managed
101 by gpg-agent) we can't know whether we forgot zero, 1, 12, ...
102 passwords. So in English we use "Passphrases". Your language might
103 have other means to express this. */
104 mutt_message(_("Passphrases forgotten"));
105 }
106}
void crypt_smime_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
Definition: cryptglue.c:412
void crypt_pgp_void_passphrase(void)
Wrapper for CryptModuleSpecs::void_passphrase()
Definition: cryptglue.c:190
#define mutt_message(...)
Definition: logging2.h:91
+ 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 947 of file crypt.c.

948{
949 if (!WithCrypto)
950 return 0;
951
952 struct AddressList addrlist = TAILQ_HEAD_INITIALIZER(addrlist);
953 const char *fqdn = mutt_fqdn(true, NeoMutt->sub);
954 const char *self_encrypt = NULL;
955
956 /* Do a quick check to make sure that we can find all of the encryption
957 * keys if the user has requested this service. */
958
959 *keylist = NULL;
960
961#ifdef USE_AUTOCRYPT
962 if (!oppenc_mode && (e->security & SEC_AUTOCRYPT))
963 {
965 return -1;
966 return 0;
967 }
968#endif
969
971 OptPgpCheckTrust = true;
972
973 mutt_addrlist_copy(&addrlist, &e->env->to, false);
974 mutt_addrlist_copy(&addrlist, &e->env->cc, false);
975 mutt_addrlist_copy(&addrlist, &e->env->bcc, false);
976 mutt_addrlist_qualify(&addrlist, fqdn);
977 mutt_addrlist_dedupe(&addrlist);
978
979 if (oppenc_mode || (e->security & SEC_ENCRYPT))
980 {
981 if (((WithCrypto & APPLICATION_PGP) != 0) && (e->security & APPLICATION_PGP))
982 {
983 *keylist = crypt_pgp_find_keys(&addrlist, oppenc_mode);
984 if (!*keylist)
985 {
986 mutt_addrlist_clear(&addrlist);
987 return -1;
988 }
989 OptPgpCheckTrust = false;
990 const bool c_pgp_self_encrypt = cs_subset_bool(NeoMutt->sub, "pgp_self_encrypt");
991 const char *const c_pgp_default_key = cs_subset_string(NeoMutt->sub, "pgp_default_key");
992 const enum QuadOption c_pgp_encrypt_self = cs_subset_quad(NeoMutt->sub, "pgp_encrypt_self");
993 if (c_pgp_self_encrypt || (c_pgp_encrypt_self == MUTT_YES))
994 self_encrypt = c_pgp_default_key;
995 }
997 {
998 *keylist = crypt_smime_find_keys(&addrlist, oppenc_mode);
999 if (!*keylist)
1000 {
1001 mutt_addrlist_clear(&addrlist);
1002 return -1;
1003 }
1004 const bool c_smime_self_encrypt = cs_subset_bool(NeoMutt->sub, "smime_self_encrypt");
1005 const char *const c_smime_default_key = cs_subset_string(NeoMutt->sub, "smime_default_key");
1006 const enum QuadOption c_smime_encrypt_self = cs_subset_quad(NeoMutt->sub, "smime_encrypt_self");
1007 if (c_smime_self_encrypt || (c_smime_encrypt_self == MUTT_YES))
1008 self_encrypt = c_smime_default_key;
1009 }
1010 }
1011
1012 if (!oppenc_mode && self_encrypt)
1013 {
1014 const size_t keylist_size = mutt_str_len(*keylist);
1015 mutt_mem_realloc(keylist, keylist_size + mutt_str_len(self_encrypt) + 2);
1016 sprintf(*keylist + keylist_size, " %s", self_encrypt);
1017 }
1018
1019 mutt_addrlist_clear(&addrlist);
1020
1021 return 0;
1022}
void mutt_addrlist_copy(struct AddressList *dst, const struct AddressList *src, bool prune)
Copy a list of addresses into another list.
Definition: address.c:765
void mutt_addrlist_qualify(struct AddressList *al, const char *host)
Expand local names in an Address list using a hostname.
Definition: address.c:680
void mutt_addrlist_clear(struct AddressList *al)
Unlink and free all Address in an AddressList.
Definition: address.c:1464
void mutt_addrlist_dedupe(struct AddressList *al)
Remove duplicate addresses.
Definition: address.c:1401
@ AUTOCRYPT_REC_NO
Do no use Autocrypt.
Definition: lib.h:160
enum AutocryptRec mutt_autocrypt_ui_recommendation(const struct Email *e, char **keylist)
Get the recommended action for an Email.
Definition: autocrypt.c:560
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:292
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:193
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
char * crypt_smime_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:474
char * crypt_pgp_find_keys(struct AddressList *addrlist, bool oppenc_mode)
Wrapper for CryptModuleSpecs::find_keys()
Definition: cryptglue.c:315
bool OptPgpCheckTrust
(pseudo) used by dlg_pgp()
Definition: globals.c:73
void mutt_mem_realloc(void *ptr, size_t size)
Resize a block of memory on the heap.
Definition: memory.c:114
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:545
#define SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition: lib.h:87
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
#define TAILQ_HEAD_INITIALIZER(head)
Definition: queue.h:637
const char * mutt_fqdn(bool may_hide_host, const struct ConfigSubset *sub)
Get the Fully-Qualified Domain Name.
Definition: sendlib.c:706
struct AddressList to
Email's 'To' list.
Definition: envelope.h:60
struct AddressList cc
Email's 'Cc' list.
Definition: envelope.h:61
struct AddressList bcc
Email's 'Bcc' list.
Definition: envelope.h:62
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ 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 1031 of file crypt.c.

1032{
1033 if (!WithCrypto)
1034 return;
1035
1036 const bool c_crypt_opportunistic_encrypt = cs_subset_bool(NeoMutt->sub, "crypt_opportunistic_encrypt");
1037 if (!(c_crypt_opportunistic_encrypt && (e->security & SEC_OPPENCRYPT)))
1038 return;
1039
1040 char *pgpkeylist = NULL;
1041
1042 crypt_get_keys(e, &pgpkeylist, true);
1043 if (pgpkeylist)
1044 {
1045 e->security |= SEC_ENCRYPT;
1046 FREE(&pgpkeylist);
1047 }
1048 else
1049 {
1050 e->security &= ~SEC_ENCRYPT;
1051 }
1052}
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:947
#define FREE(x)
Definition: memory.h:45
#define SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition: lib.h:86
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ crypt_query()

SecurityFlags crypt_query ( struct Body b)

Check out the type of encryption used.

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

Set the cached status values if there are any.

Definition at line 673 of file crypt.c.

674{
675 if (!WithCrypto || !b)
676 return SEC_NO_FLAGS;
677
679
680 if (b->type == TYPE_APPLICATION)
681 {
684
686 {
688 if (rc && b->goodsig)
689 rc |= SEC_GOODSIGN;
690 if (rc && b->badsig)
691 rc |= SEC_BADSIGN;
692 }
693 }
694 else if (((WithCrypto & APPLICATION_PGP) != 0) && (b->type == TYPE_TEXT))
695 {
697 if (rc && b->goodsig)
698 rc |= SEC_GOODSIGN;
699 }
700
701 if (b->type == TYPE_MULTIPART)
702 {
706
707 if (rc && b->goodsig)
708 rc |= SEC_GOODSIGN;
709#ifdef USE_AUTOCRYPT
710 if (rc && b->is_autocrypt)
711 rc |= SEC_AUTOCRYPT;
712#endif
713 }
714
715 if ((b->type == TYPE_MULTIPART) || (b->type == TYPE_MESSAGE))
716 {
717 SecurityFlags u = b->parts ? SEC_ALL_FLAGS : SEC_NO_FLAGS; /* Bits set in all parts */
718 SecurityFlags w = SEC_NO_FLAGS; /* Bits set in any part */
719
720 for (b = b->parts; b; b = b->next)
721 {
722 const SecurityFlags v = crypt_query(b);
723 u &= v;
724 w |= v;
725 }
726 rc |= u | (w & ~SEC_GOODSIGN);
727
728 if ((w & SEC_GOODSIGN) && !(u & SEC_GOODSIGN))
729 rc |= SEC_PARTSIGN;
730 }
731
732 return rc;
733}
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
Definition: crypt.c:534
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:394
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:595
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:429
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:490
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:673
@ TYPE_MESSAGE
Type: 'message/*'.
Definition: mime.h:35
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
@ TYPE_APPLICATION
Type: 'application/*'.
Definition: mime.h:33
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:76
#define SEC_ALL_FLAGS
Definition: lib.h:94
#define SEC_GOODSIGN
Email has a valid signature.
Definition: lib.h:80
#define SEC_BADSIGN
Email has a bad signature.
Definition: lib.h:81
#define SEC_NO_FLAGS
No flags are set.
Definition: lib.h:77
#define SEC_PARTSIGN
Not all parts of the email is signed.
Definition: lib.h:82
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
bool badsig
Bad cryptographic signature (needed to check encrypted s/mime-signatures)
Definition: body.h:43
bool is_autocrypt
Flag autocrypt-decrypted messages for replying.
Definition: body.h:50
struct Body * next
next attachment in the list
Definition: body.h:71
bool goodsig
Good cryptographic signature.
Definition: body.h:45
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
+ 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 132 of file crypt.c.

133{
134 bool rc = false;
135
136#ifndef DEBUG
137 disable_coredumps();
138#endif
139
140 if (((WithCrypto & APPLICATION_PGP) != 0) && (flags & APPLICATION_PGP))
142
143 if (((WithCrypto & APPLICATION_SMIME) != 0) && (flags & APPLICATION_SMIME))
145
146 return rc;
147}
bool crypt_smime_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
Definition: cryptglue.c:421
bool crypt_pgp_valid_passphrase(void)
Wrapper for CryptModuleSpecs::valid_passphrase()
Definition: cryptglue.c:199
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_application_pgp()

SecurityFlags mutt_is_application_pgp ( struct Body b)

Does the message use PGP?

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

Definition at line 534 of file crypt.c.

535{
537 char *p = NULL;
538
539 if (b->type == TYPE_APPLICATION)
540 {
541 if (mutt_istr_equal(b->subtype, "pgp") || mutt_istr_equal(b->subtype, "x-pgp-message"))
542 {
543 p = mutt_param_get(&b->parameter, "x-action");
544 if (p && (mutt_istr_equal(p, "sign") || mutt_istr_equal(p, "signclear")))
545 {
546 t |= PGP_SIGN;
547 }
548
549 p = mutt_param_get(&b->parameter, "format");
550 if (p && mutt_istr_equal(p, "keys-only"))
551 {
552 t |= PGP_KEY;
553 }
554
555 if (t == SEC_NO_FLAGS)
556 t |= PGP_ENCRYPT; /* not necessarily correct, but... */
557 }
558
559 if (mutt_istr_equal(b->subtype, "pgp-signed"))
560 t |= PGP_SIGN;
561
562 if (mutt_istr_equal(b->subtype, "pgp-keys"))
563 t |= PGP_KEY;
564 }
565 else if ((b->type == TYPE_TEXT) && mutt_istr_equal("plain", b->subtype))
566 {
567 if (((p = mutt_param_get(&b->parameter, "x-mutt-action")) ||
568 (p = mutt_param_get(&b->parameter, "x-action")) ||
569 (p = mutt_param_get(&b->parameter, "action"))) &&
570 mutt_istr_startswith(p, "pgp-sign"))
571 {
572 t |= PGP_SIGN;
573 }
574 else if (p && mutt_istr_startswith(p, "pgp-encrypt"))
575 {
576 t |= PGP_ENCRYPT;
577 }
578 else if (p && mutt_istr_startswith(p, "pgp-keys"))
579 {
580 t |= PGP_KEY;
581 }
582 }
583 if (t)
584 t |= PGP_INLINE;
585
586 return t;
587}
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:721
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:242
#define PGP_SIGN
Definition: lib.h:97
#define PGP_ENCRYPT
Definition: lib.h:96
#define PGP_INLINE
Definition: lib.h:100
#define PGP_KEY
Definition: lib.h:99
char * mutt_param_get(const struct ParameterList *pl, const char *s)
Find a matching Parameter.
Definition: parameter.c:85
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
char * subtype
content-type subtype
Definition: body.h:60
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_is_application_smime()

SecurityFlags mutt_is_application_smime ( struct Body b)

Does the message use S/MIME?

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

Definition at line 595 of file crypt.c.

596{
597 if (!b)
598 return SEC_NO_FLAGS;
599
600 if (((b->type & TYPE_APPLICATION) == 0) || !b->subtype)
601 return SEC_NO_FLAGS;
602
603 char *t = NULL;
604 bool complain = false;
605 /* S/MIME MIME types don't need x- anymore, see RFC2311 */
606 if (mutt_istr_equal(b->subtype, "x-pkcs7-mime") || mutt_istr_equal(b->subtype, "pkcs7-mime"))
607 {
608 t = mutt_param_get(&b->parameter, "smime-type");
609 if (t)
610 {
611 if (mutt_istr_equal(t, "enveloped-data"))
612 return SMIME_ENCRYPT;
613 if (mutt_istr_equal(t, "signed-data"))
614 return SMIME_SIGN | SMIME_OPAQUE;
615 return SEC_NO_FLAGS;
616 }
617 /* Netscape 4.7 uses
618 * Content-Description: S/MIME Encrypted Message
619 * instead of Content-Type parameter */
620 if (mutt_istr_equal(b->description, "S/MIME Encrypted Message"))
621 return SMIME_ENCRYPT;
622 complain = true;
623 }
624 else if (!mutt_istr_equal(b->subtype, "octet-stream"))
625 {
626 return SEC_NO_FLAGS;
627 }
628
629 t = mutt_param_get(&b->parameter, "name");
630
631 if (!t)
632 t = b->d_filename;
633 if (!t)
634 t = b->filename;
635 if (!t)
636 {
637 if (complain)
638 {
639 mutt_message(_("S/MIME messages with no hints on content are unsupported"));
640 }
641 return SEC_NO_FLAGS;
642 }
643
644 /* no .p7c, .p10 support yet. */
645
646 int len = mutt_str_len(t) - 4;
647 if ((len > 0) && (*(t + len) == '.'))
648 {
649 len++;
650 if (mutt_istr_equal((t + len), "p7m"))
651 {
652 /* Not sure if this is the correct thing to do, but
653 * it's required for compatibility with Outlook */
654 return SMIME_SIGN | SMIME_OPAQUE;
655 }
656 else if (mutt_istr_equal((t + len), "p7s"))
657 {
658 return SMIME_SIGN | SMIME_OPAQUE;
659 }
660 }
661
662 return SEC_NO_FLAGS;
663}
#define SMIME_SIGN
Definition: lib.h:103
#define SMIME_OPAQUE
Definition: lib.h:106
#define SMIME_ENCRYPT
Definition: lib.h:102
char * d_filename
filename to be used for the content-disposition header If NULL, filename is used instead.
Definition: body.h:56
char * description
content-description
Definition: body.h:55
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:58
+ 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 490 of file crypt.c.

491{
493 return SEC_NO_FLAGS;
494
495 if (!b || (b->type != TYPE_MULTIPART) || !b->subtype || !mutt_istr_equal(b->subtype, "mixed"))
496 {
497 return SEC_NO_FLAGS;
498 }
499
500 b = b->parts;
501 if (!b || (b->type != TYPE_TEXT) || !b->subtype ||
502 !mutt_istr_equal(b->subtype, "plain") || (b->length != 0))
503 {
504 return SEC_NO_FLAGS;
505 }
506
507 b = b->next;
508 if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
509 !mutt_istr_equal(b->subtype, "pgp-encrypted"))
510 {
511 return SEC_NO_FLAGS;
512 }
513
514 b = b->next;
515 if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
516 !mutt_istr_equal(b->subtype, "octet-stream"))
517 {
518 return SEC_NO_FLAGS;
519 }
520
521 b = b->next;
522 if (b)
523 return SEC_NO_FLAGS;
524
525 return PGP_ENCRYPT;
526}
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
+ 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 429 of file crypt.c.

430{
431 if ((WithCrypto & APPLICATION_PGP) == 0)
432 return SEC_NO_FLAGS;
433
434 char *p = NULL;
435
436 if (!b || (b->type != TYPE_MULTIPART) || !b->subtype ||
437 !mutt_istr_equal(b->subtype, "encrypted") ||
438 !(p = mutt_param_get(&b->parameter, "protocol")) ||
439 !mutt_istr_equal(p, "application/pgp-encrypted"))
440 {
441 return SEC_NO_FLAGS;
442 }
443
444 return PGP_ENCRYPT;
445}
+ 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 394 of file crypt.c.

395{
396 if (!b || (b->type != TYPE_MULTIPART) || !b->subtype || !mutt_istr_equal(b->subtype, "signed"))
397 {
398 return SEC_NO_FLAGS;
399 }
400
401 char *p = mutt_param_get(&b->parameter, "protocol");
402 if (!p)
403 return SEC_NO_FLAGS;
404
405 if (mutt_istr_equal(p, "multipart/mixed"))
406 return SEC_SIGN;
407
408 if (((WithCrypto & APPLICATION_PGP) != 0) && mutt_istr_equal(p, "application/pgp-signature"))
409 {
410 return PGP_SIGN;
411 }
412
413 if (((WithCrypto & APPLICATION_SMIME) != 0) &&
414 (mutt_istr_equal(p, "application/x-pkcs7-signature") ||
415 mutt_istr_equal(p, "application/pkcs7-signature")))
416 {
417 return SMIME_SIGN;
418 }
419
420 return SEC_NO_FLAGS;
421}
#define SEC_SIGN
Email is signed.
Definition: lib.h:79
+ 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 453 of file crypt.c.

454{
456 return 0;
457
458 b = b->parts;
459 if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
460 !mutt_istr_equal(b->subtype, "pgp-encrypted"))
461 {
462 return 0;
463 }
464
465 b = b->next;
466 if (!b || (b->type != TYPE_APPLICATION) || !b->subtype ||
467 !mutt_istr_equal(b->subtype, "octet-stream"))
468 {
469 return 0;
470 }
471
472 return PGP_ENCRYPT;
473}
+ 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 157 of file crypt.c.

158{
159 struct Body *pbody = NULL, *tmp_pbody = NULL;
160 struct Body *tmp_smime_pbody = NULL;
161 struct Body *tmp_pgp_pbody = NULL;
162 bool has_retainable_sig = false;
163
164 if (!WithCrypto)
165 return -1;
166
167 SecurityFlags security = e->security;
168 int sign = security & (SEC_AUTOCRYPT | SEC_SIGN);
169 if (postpone)
170 {
171 sign = SEC_NO_FLAGS;
172 security &= ~SEC_SIGN;
173 }
174
175 if (!(security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) && !sign)
176 return 0;
177
178 if (sign && !(security & SEC_AUTOCRYPT) && !crypt_valid_passphrase(security))
179 return -1;
180
181 if (((WithCrypto & APPLICATION_PGP) != 0) && !(security & SEC_AUTOCRYPT) &&
182 ((security & PGP_INLINE) == PGP_INLINE))
183 {
184 if ((e->body->type != TYPE_TEXT) || !mutt_istr_equal(e->body->subtype, "plain"))
185 {
186 if (query_quadoption(_("Inline PGP can't be used with attachments. Revert to PGP/MIME?"),
187 NeoMutt->sub, "pgp_mime_auto") != MUTT_YES)
188 {
189 mutt_error(_("Mail not sent: inline PGP can't be used with attachments"));
190 return -1;
191 }
192 }
193 else if (mutt_istr_equal("flowed", mutt_param_get(&e->body->parameter, "format")))
194 {
195 if ((query_quadoption(_("Inline PGP can't be used with format=flowed. Revert to PGP/MIME?"),
196 NeoMutt->sub, "pgp_mime_auto")) != MUTT_YES)
197 {
198 mutt_error(_("Mail not sent: inline PGP can't be used with format=flowed"));
199 return -1;
200 }
201 }
202 else
203 {
204 /* they really want to send it inline... go for it */
205 if (!isendwin())
206 {
207 mutt_endwin();
208 puts(_("Invoking PGP..."));
209 }
210 pbody = crypt_pgp_traditional_encryptsign(e->body, security, keylist);
211 if (pbody)
212 {
213 e->body = pbody;
214 return 0;
215 }
216
217 /* otherwise inline won't work...ask for revert */
218 if (query_quadoption(_("Message can't be sent inline. Revert to using PGP/MIME?"),
219 NeoMutt->sub, "pgp_mime_auto") != MUTT_YES)
220 {
221 mutt_error(_("Mail not sent"));
222 return -1;
223 }
224 }
225
226 /* go ahead with PGP/MIME */
227 }
228
229 if (!isendwin())
230 mutt_endwin();
231
233 tmp_smime_pbody = e->body;
235 tmp_pgp_pbody = e->body;
236
237#ifdef CRYPT_BACKEND_GPGME
238 const bool c_crypt_use_pka = cs_subset_bool(NeoMutt->sub, "crypt_use_pka");
239 if (sign && c_crypt_use_pka)
240#else
241 if (sign)
242#endif
243 {
244 /* Set sender (necessary for e.g. PKA). */
245 const char *mailbox = NULL;
246 struct Address *from = TAILQ_FIRST(&e->env->from);
247 bool free_from = false;
248
249 if (!from)
250 {
251 free_from = true;
253 }
254
255 mailbox = buf_string(from->mailbox);
256 const struct Address *c_envelope_from_address = cs_subset_address(NeoMutt->sub, "envelope_from_address");
257 if (!mailbox && c_envelope_from_address)
258 mailbox = buf_string(c_envelope_from_address->mailbox);
259
260 if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
262 else if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP))
264
265 if (free_from)
266 mutt_addr_free(&from);
267 }
268
269 const bool c_crypt_protected_headers_write = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_write");
270 if (c_crypt_protected_headers_write)
271 {
272 struct Envelope *protected_headers = mutt_env_new();
273 mutt_env_set_subject(protected_headers, e->env->subject);
274 /* Note: if other headers get added, such as to, cc, then a call to
275 * mutt_env_to_intl() will need to be added here too. */
276 mutt_prepare_envelope(protected_headers, 0, NeoMutt->sub);
277
279 e->body->mime_headers = protected_headers;
280 mutt_param_set(&e->body->parameter, "protected-headers", "v1");
281 }
282
283#ifdef USE_AUTOCRYPT
284 /* A note about e->body->mime_headers. If postpone or send
285 * fails, the mime_headers is cleared out before returning to the
286 * compose menu. So despite the "robustness" code above and in the
287 * gen_gossip_list function below, mime_headers will not be set when
288 * entering mutt_protect().
289 *
290 * This is important to note because the user could toggle
291 * $crypt_protected_headers_write or $autocrypt off back in the
292 * compose menu. We don't want mutt_write_rfc822_header() to write
293 * stale data from one option if the other is set.
294 */
295 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
296 if (c_autocrypt && !postpone && (security & SEC_AUTOCRYPT))
297 {
299 }
300#endif
301
302 if (sign)
303 {
304 if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
305 {
306 tmp_pbody = crypt_smime_sign_message(e->body, &e->env->from);
307 if (!tmp_pbody)
308 goto bail;
309 pbody = tmp_pbody;
310 tmp_smime_pbody = tmp_pbody;
311 }
312
313 const bool c_pgp_retainable_sigs = cs_subset_bool(NeoMutt->sub, "pgp_retainable_sigs");
314 if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP) &&
315 (!(security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) || c_pgp_retainable_sigs))
316 {
317 tmp_pbody = crypt_pgp_sign_message(e->body, &e->env->from);
318 if (!tmp_pbody)
319 goto bail;
320
321 has_retainable_sig = true;
322 sign = SEC_NO_FLAGS;
323 pbody = tmp_pbody;
324 tmp_pgp_pbody = tmp_pbody;
325 }
326 }
327
328 if (security & (SEC_ENCRYPT | SEC_AUTOCRYPT))
329 {
330 if (((WithCrypto & APPLICATION_SMIME) != 0) && (security & APPLICATION_SMIME))
331 {
332 tmp_pbody = crypt_smime_build_smime_entity(tmp_smime_pbody, keylist);
333 if (!tmp_pbody)
334 {
335 /* signed ? free it! */
336 goto bail;
337 }
338 /* free tmp_body if messages was signed AND encrypted ... */
339 if ((tmp_smime_pbody != e->body) && (tmp_smime_pbody != tmp_pbody))
340 {
341 /* detach and don't delete e->body,
342 * which tmp_smime_pbody->parts after signing. */
343 tmp_smime_pbody->parts = tmp_smime_pbody->parts->next;
344 e->body->next = NULL;
345 mutt_body_free(&tmp_smime_pbody);
346 }
347 pbody = tmp_pbody;
348 }
349
350 if (((WithCrypto & APPLICATION_PGP) != 0) && (security & APPLICATION_PGP))
351 {
352 pbody = crypt_pgp_encrypt_message(e, tmp_pgp_pbody, keylist, sign, &e->env->from);
353 if (!pbody)
354 {
355 /* did we perform a retainable signature? */
356 if (has_retainable_sig)
357 {
358 /* remove the outer multipart layer */
359 tmp_pgp_pbody = mutt_remove_multipart(tmp_pgp_pbody);
360 /* get rid of the signature */
361 mutt_body_free(&tmp_pgp_pbody->next);
362 }
363
364 goto bail;
365 }
366
367 // destroy temporary signature envelope when doing retainable signatures.
368 if (has_retainable_sig)
369 {
370 tmp_pgp_pbody = mutt_remove_multipart(tmp_pgp_pbody);
371 mutt_body_free(&tmp_pgp_pbody->next);
372 }
373 }
374 }
375
376 if (pbody)
377 {
378 e->body = pbody;
379 return 0;
380 }
381
382bail:
384 mutt_param_delete(&e->body->parameter, "protected-headers");
385 return -1;
386}
void mutt_addr_free(struct Address **ptr)
Free a single Address.
Definition: address.c:462
int mutt_autocrypt_generate_gossip_list(struct Email *e)
Create the gossip list headers.
Definition: autocrypt.c:825
const struct Address * cs_subset_address(const struct ConfigSubset *sub, const char *name)
Get an Address config item by name.
Definition: config_type.c:273
struct Body * crypt_smime_build_smime_entity(struct Body *b, char *certlist)
Wrapper for CryptModuleSpecs::smime_build_smime_entity()
Definition: cryptglue.c:496
struct Body * crypt_smime_sign_message(struct Body *b, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
Definition: cryptglue.c:485
struct Body * crypt_pgp_traditional_encryptsign(struct Body *b, SecurityFlags flags, char *keylist)
Wrapper for CryptModuleSpecs::pgp_traditional_encryptsign()
Definition: cryptglue.c:293
struct Body * crypt_pgp_sign_message(struct Body *b, const struct AddressList *from)
Wrapper for CryptModuleSpecs::sign_message()
Definition: cryptglue.c:326
void crypt_pgp_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
Definition: cryptglue.c:403
void crypt_smime_set_sender(const char *sender)
Wrapper for CryptModuleSpecs::set_sender()
Definition: cryptglue.c:538
struct Body * crypt_pgp_encrypt_message(struct Email *e, struct Body *b, char *keylist, int sign, const struct AddressList *from)
Wrapper for CryptModuleSpecs::pgp_encrypt_message()
Definition: cryptglue.c:337
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
struct Envelope * mutt_env_new(void)
Create a new Envelope.
Definition: envelope.c:46
void mutt_env_set_subject(struct Envelope *env, const char *subj)
Set both subject and real_subj to subj.
Definition: envelope.c:69
#define mutt_error(...)
Definition: logging2.h:92
struct Body * mutt_remove_multipart(struct Body *b)
Extract the multipart body if it exists.
Definition: multipart.c:126
void mutt_param_delete(struct ParameterList *pl, const char *attribute)
Delete a matching Parameter.
Definition: parameter.c:143
void mutt_param_set(struct ParameterList *pl, const char *attribute, const char *value)
Set a Parameter.
Definition: parameter.c:111
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
Definition: question.c:373
struct Address * mutt_default_from(struct ConfigSubset *sub)
Get a default 'from' Address.
Definition: send.c:1460
void mutt_prepare_envelope(struct Envelope *env, bool final, struct ConfigSubset *sub)
Prepare an email header.
Definition: sendlib.c:779
An email address.
Definition: address.h:36
struct Buffer * mailbox
Mailbox and host address.
Definition: address.h:38
The body of an email.
Definition: body.h:36
struct Envelope * mime_headers
Memory hole protected headers.
Definition: body.h:75
struct Body * body
List of MIME parts.
Definition: email.h:69
The header of an Email.
Definition: envelope.h:57
char *const subject
Email's subject.
Definition: envelope.h:70
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_should_hide_protected_subject()

bool mutt_should_hide_protected_subject ( struct Email e)

Should NeoMutt hide the protected subject?

Parameters
eEmail to test
Return values
trueThe subject should be protected

Definition at line 1086 of file crypt.c.

1087{
1088 const bool c_crypt_protected_headers_write = cs_subset_bool(NeoMutt->sub, "crypt_protected_headers_write");
1089 const char *const c_crypt_protected_headers_subject =
1090 cs_subset_string(NeoMutt->sub, "crypt_protected_headers_subject");
1091 if (c_crypt_protected_headers_write && (e->security & (SEC_ENCRYPT | SEC_AUTOCRYPT)) &&
1092 !(e->security & SEC_INLINE) && c_crypt_protected_headers_subject)
1093 {
1094 return true;
1095 }
1096
1097 return false;
1098}
#define SEC_INLINE
Email has an inline signature.
Definition: lib.h:85
+ 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 141 of file cryptglue.c.

142{
143 if (CRYPT_MOD_CALL_CHECK(PGP, cleanup))
144 (CRYPT_MOD_CALL(PGP, cleanup))();
145
146 if (CRYPT_MOD_CALL_CHECK(SMIME, cleanup))
147 (CRYPT_MOD_CALL(SMIME, cleanup))();
148}
#define CRYPT_MOD_CALL_CHECK(identifier, func)
Definition: cryptglue.c:79
#define CRYPT_MOD_CALL(identifier, func)
Definition: cryptglue.c:85
+ 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 170 of file cryptglue.c.

171{
172 if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP) &&
174 {
175 return true;
176 }
177
178 if (((WithCrypto & APPLICATION_SMIME) != 0) && (type & APPLICATION_SMIME) &&
180 {
181 return true;
182 }
183
184 return false;
185}
const struct CryptModuleSpecs * crypto_module_lookup(int identifier)
Lookup a crypto module by name.
Definition: crypt_mod.c:68
+ 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 93 of file cryptglue.c.

94{
95#ifdef CRYPT_BACKEND_GPGME
96 const bool c_crypt_use_gpgme = cs_subset_bool(NeoMutt->sub, "crypt_use_gpgme");
97#endif
98#ifdef CRYPT_BACKEND_CLASSIC_PGP
99 if (
100#ifdef CRYPT_BACKEND_GPGME
101 (!c_crypt_use_gpgme)
102#else
103 1
104#endif
105 )
107#endif
108
109#ifdef CRYPT_BACKEND_CLASSIC_SMIME
110 if (
111#ifdef CRYPT_BACKEND_GPGME
112 (!c_crypt_use_gpgme)
113#else
114 1
115#endif
116 )
118#endif
119
120#ifdef CRYPT_BACKEND_GPGME
121 if (c_crypt_use_gpgme)
122 {
125 }
126#endif
127
128#if defined(CRYPT_BACKEND_CLASSIC_PGP) || \
129 defined(CRYPT_BACKEND_CLASSIC_SMIME) || defined(CRYPT_BACKEND_GPGME)
130 if (CRYPT_MOD_CALL_CHECK(PGP, init))
131 CRYPT_MOD_CALL(PGP, init)();
132
133 if (CRYPT_MOD_CALL_CHECK(SMIME, init))
134 CRYPT_MOD_CALL(SMIME, init)();
135#endif
136}
void crypto_module_register(const struct CryptModuleSpecs *specs)
Register a new crypto module.
Definition: crypt_mod.c:54
const struct CryptModuleSpecs CryptModSmimeGpgme
GPGME SMIME - Implements CryptModuleSpecs -.
const struct CryptModuleSpecs CryptModSmimeClassic
CLI SMIME - Implements CryptModuleSpecs -.
const struct CryptModuleSpecs CryptModPgpGpgme
GPGME PGP - Implements CryptModuleSpecs -.
const struct CryptModuleSpecs CryptModPgpClassic
CLI PGP - 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 156 of file cryptglue.c.

157{
158 if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP))
159 mutt_message(_("Invoking PGP..."));
160 else if (((WithCrypto & APPLICATION_SMIME) != 0) && (type & APPLICATION_SMIME))
161 mutt_message(_("Invoking S/MIME..."));
162}
+ Here is the caller graph for this function:

◆ crypt_pgp_check_traditional()

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

Wrapper for CryptModuleSpecs::pgp_check_traditional()

Definition at line 282 of file cryptglue.c.

283{
284 if (CRYPT_MOD_CALL_CHECK(PGP, pgp_check_traditional))
285 return CRYPT_MOD_CALL(PGP, pgp_check_traditional)(fp, b, just_one);
286
287 return false;
288}
+ 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 **  b_dec 
)

Wrapper for CryptModuleSpecs::decrypt_mime()

Definition at line 210 of file cryptglue.c.

211{
212#ifdef USE_AUTOCRYPT
213 const bool c_autocrypt = cs_subset_bool(NeoMutt->sub, "autocrypt");
214 if (c_autocrypt)
215 {
216 OptAutocryptGpgme = true;
217 int result = pgp_gpgme_decrypt_mime(fp_in, fp_out, b, b_dec);
218 OptAutocryptGpgme = false;
219 if (result == 0)
220 {
221 b->is_autocrypt = true;
222 return result;
223 }
224 }
225#endif
226
227 if (CRYPT_MOD_CALL_CHECK(PGP, decrypt_mime))
228 return CRYPT_MOD_CALL(PGP, decrypt_mime)(fp_in, fp_out, b, b_dec);
229
230 return -1;
231}
bool OptAutocryptGpgme
(pseudo) use Autocrypt context inside ncrypt/crypt_gpgme.c
Definition: globals.c:62
int pgp_gpgme_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Decrypt an encrypted MIME part - Implements CryptModuleSpecs::decrypt_mime() -.
Definition: crypt_gpgme.c:1852
+ 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 b 
)

Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()

Definition at line 394 of file cryptglue.c.

395{
396 if (CRYPT_MOD_CALL_CHECK(PGP, pgp_extract_key_from_attachment))
397 CRYPT_MOD_CALL(PGP, pgp_extract_key_from_attachment)(fp, b);
398}
+ 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 273 of file cryptglue.c.

274{
275 if (CRYPT_MOD_CALL_CHECK(PGP, pgp_invoke_getkeys))
276 CRYPT_MOD_CALL(PGP, pgp_invoke_getkeys)(addr);
277}
+ 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 304 of file cryptglue.c.

305{
306 if (CRYPT_MOD_CALL_CHECK(PGP, pgp_make_key_attachment))
307 return CRYPT_MOD_CALL(PGP, pgp_make_key_attachment)();
308
309 return NULL;
310}
+ Here is the caller graph for this function:

◆ crypt_pgp_send_menu()

SecurityFlags crypt_pgp_send_menu ( struct Email e)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 383 of file cryptglue.c.

384{
385 if (CRYPT_MOD_CALL_CHECK(PGP, send_menu))
386 return CRYPT_MOD_CALL(PGP, send_menu)(e);
387
388 return 0;
389}
+ 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 **  b_dec 
)

Wrapper for CryptModuleSpecs::decrypt_mime()

Definition at line 432 of file cryptglue.c.

433{
434 if (CRYPT_MOD_CALL_CHECK(SMIME, decrypt_mime))
435 return CRYPT_MOD_CALL(SMIME, decrypt_mime)(fp_in, fp_out, b, b_dec);
436
437 return -1;
438}
+ 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 454 of file cryptglue.c.

455{
456 if (CRYPT_MOD_CALL_CHECK(SMIME, smime_getkeys))
457 CRYPT_MOD_CALL(SMIME, smime_getkeys)(env);
458}
+ Here is the caller graph for this function:

◆ crypt_smime_send_menu()

SecurityFlags crypt_smime_send_menu ( struct Email e)

Wrapper for CryptModuleSpecs::send_menu()

Definition at line 527 of file cryptglue.c.

528{
529 if (CRYPT_MOD_CALL_CHECK(SMIME, send_menu))
530 return CRYPT_MOD_CALL(SMIME, send_menu)(e);
531
532 return 0;
533}
+ Here is the caller graph for this function:

◆ crypt_smime_verify_sender()

int crypt_smime_verify_sender ( struct Email e,
struct Message msg 
)

Wrapper for CryptModuleSpecs::smime_verify_sender()

Definition at line 463 of file cryptglue.c.

464{
465 if (CRYPT_MOD_CALL_CHECK(SMIME, smime_verify_sender))
466 return CRYPT_MOD_CALL(SMIME, smime_verify_sender)(e, msg);
467
468 return 1;
469}
+ Here is the caller graph for this function:

◆ crypto_module_cleanup()

void crypto_module_cleanup ( void  )

Clean up the crypto modules.

Definition at line 84 of file crypt_mod.c.

85{
86 struct CryptModule *np = NULL, *tmp = NULL;
87 STAILQ_FOREACH_SAFE(np, &CryptModules, entries, tmp)
88 {
90 FREE(&np);
91 }
92}
static struct CryptModuleList CryptModules
Linked list of crypto modules, e.g. CryptModSmimeClassic, CryptModPgpGpgme.
Definition: crypt_mod.c:48
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:362
A crypto plugin module.
Definition: crypt_mod.c:41
+ 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 3581 of file crypt_gpgme.c.

3582{
3583 int rc = -1;
3584 gpgme_error_t err;
3585 gpgme_key_t key = NULL;
3586 gpgme_user_id_t uid = NULL;
3587 struct CryptKeyInfo *results = NULL, *k = NULL;
3588 struct CryptKeyInfo **kend = NULL;
3589 struct CryptKeyInfo *choice = NULL;
3590
3591 gpgme_ctx_t ctx = create_gpgme_context(false);
3592
3593 /* list all secret keys */
3594 if (gpgme_op_keylist_start(ctx, NULL, 1))
3595 goto cleanup;
3596
3597 kend = &results;
3598
3599 while (!(err = gpgme_op_keylist_next(ctx, &key)))
3600 {
3602
3607
3608 if (key->revoked)
3610 if (key->expired)
3612 if (key->disabled)
3614
3615 int idx;
3616 for (idx = 0, uid = key->uids; uid; idx++, uid = uid->next)
3617 {
3618 k = mutt_mem_calloc(1, sizeof(*k));
3619 k->kobj = key;
3620 gpgme_key_ref(k->kobj);
3621 k->idx = idx;
3622 k->uid = uid->uid;
3623 k->flags = flags;
3624 if (uid->revoked)
3625 k->flags |= KEYFLAG_REVOKED;
3626 k->validity = uid->validity;
3627 *kend = k;
3628 kend = &k->next;
3629 }
3630 gpgme_key_unref(key);
3631 }
3632 if (gpg_err_code(err) != GPG_ERR_EOF)
3633 mutt_error(_("gpgme_op_keylist_next failed: %s"), gpgme_strerror(err));
3634 gpgme_op_keylist_end(ctx);
3635
3636 if (!results)
3637 {
3638 /* L10N: mutt_gpgme_select_secret_key() tries to list all secret keys to choose
3639 from. This error is displayed if no results were found. */
3640 mutt_error(_("No secret keys found"));
3641 goto cleanup;
3642 }
3643
3644 choice = dlg_gpgme(results, NULL, "*", APPLICATION_PGP, NULL);
3645 if (!(choice && choice->kobj && choice->kobj->subkeys && choice->kobj->subkeys->fpr))
3646 goto cleanup;
3647 buf_strcpy(keyid, choice->kobj->subkeys->fpr);
3648
3649 rc = 0;
3650
3651cleanup:
3652 crypt_key_free(&choice);
3653 crypt_key_free(&results);
3654 gpgme_release(ctx);
3655 return rc;
3656}
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:412
gpgme_ctx_t create_gpgme_context(bool for_smime)
Create a new GPGME context.
Definition: crypt_gpgme.c:361
unsigned int key_check_cap(gpgme_key_t key, enum KeyCap cap)
Check the capabilities of a key.
Definition: crypt_gpgme.c:2844
static void crypt_key_free(struct CryptKeyInfo **keylist)
Release all the keys in a list.
Definition: crypt_gpgme.c:253
@ KEY_CAP_CAN_ENCRYPT
Key can be used for encryption.
Definition: crypt_gpgme.h:76
@ KEY_CAP_CAN_SIGN
Key can be used for signing.
Definition: crypt_gpgme.h:77
struct CryptKeyInfo * dlg_gpgme(struct CryptKeyInfo *keys, struct Address *p, const char *s, unsigned int app, bool *forced_valid)
Get the user to select a key -.
Definition: dlg_gpgme.c:625
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define KEYFLAG_EXPIRED
Key is expired.
Definition: lib.h:131
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:125
#define KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition: lib.h:128
#define KEYFLAG_NO_FLAGS
No flags are set.
Definition: lib.h:126
#define KEYFLAG_DISABLED
Key is marked disabled.
Definition: lib.h:133
#define KEYFLAG_REVOKED
Key is revoked.
Definition: lib.h:132
#define KEYFLAG_CANSIGN
Key is suitable for signing.
Definition: lib.h:127
A stored PGP key.
Definition: crypt_gpgme.h:44
KeyFlags flags
global and per uid flags (for convenience)
Definition: crypt_gpgme.h:49
int idx
and the user ID at this index
Definition: crypt_gpgme.h:47
struct CryptKeyInfo * next
Linked list.
Definition: crypt_gpgme.h:45
const char * uid
and for convenience point to this user ID
Definition: crypt_gpgme.h:48
gpgme_key_t kobj
Definition: crypt_gpgme.h:46
+ 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 4060 of file crypt_gpgme.c.

4061{
4062 return GPGME_VERSION;
4063}
+ Here is the caller graph for this function: