NeoMutt  2025-12-11-949-g4870ee
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
lib.h
Go to the documentation of this file.
1
23
63
64#ifndef MUTT_NCRYPT_LIB_H
65#define MUTT_NCRYPT_LIB_H
66
67#include <stdbool.h>
68#include <stdint.h>
69#include <stdio.h>
70
71struct Address;
72struct Body;
73#ifdef USE_AUTOCRYPT
74struct Buffer;
75#endif
76struct Email;
77struct EmailArray;
78struct Envelope;
79struct Mailbox;
80struct Message;
81struct NcryptModuleData;
82struct NeoMutt;
83struct State;
84struct SubMenu;
85
90{
92 SEC_ENCRYPT = 1U << 0,
93 SEC_SIGN = 1U << 1,
94 SEC_GOODSIGN = 1U << 2,
95 SEC_BADSIGN = 1U << 3,
96 SEC_PARTSIGN = 1U << 4,
97 SEC_SIGNOPAQUE = 1U << 5,
98 SEC_KEYBLOCK = 1U << 6,
99 SEC_INLINE = 1U << 7,
100 SEC_OPPENCRYPT = 1U << 8,
101 SEC_AUTOCRYPT = 1U << 9,
103};
104typedef uint16_t SecurityFlags;
105
106#define APPLICATION_PGP (1 << 11)
107#define APPLICATION_SMIME (1 << 12)
108#define PGP_TRADITIONAL_CHECKED (1 << 13)
109
110#define SEC_ALL_FLAGS ((1 << 14) - 1)
111
112#define PGP_ENCRYPT (APPLICATION_PGP | SEC_ENCRYPT)
113#define PGP_SIGN (APPLICATION_PGP | SEC_SIGN)
114#define PGP_GOODSIGN (APPLICATION_PGP | SEC_GOODSIGN)
115#define PGP_KEY (APPLICATION_PGP | SEC_KEYBLOCK)
116#define PGP_INLINE (APPLICATION_PGP | SEC_INLINE)
117
118#define SMIME_ENCRYPT (APPLICATION_SMIME | SEC_ENCRYPT)
119#define SMIME_SIGN (APPLICATION_SMIME | SEC_SIGN)
120#define SMIME_GOODSIGN (APPLICATION_SMIME | SEC_GOODSIGN)
121#define SMIME_BADSIGN (APPLICATION_SMIME | SEC_BADSIGN)
122#define SMIME_OPAQUE (APPLICATION_SMIME | SEC_SIGNOPAQUE)
123
124/* WITHCRYPTO actually replaces ifdefs to make the code more readable.
125 * Because it is defined as a constant and known at compile time, the
126 * compiler can do dead code elimination and thus it behaves
127 * effectively as a conditional compile directive. It is set to false
128 * if no crypto backend is configured or to a bit vector denoting the
129 * configured backends. */
130#if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || \
131 defined(CRYPT_BACKEND_GPGME)
132#define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
133#elif defined(CRYPT_BACKEND_CLASSIC_PGP)
134#define WithCrypto APPLICATION_PGP
135#elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
136#define WithCrypto APPLICATION_SMIME
137#else
138#define WithCrypto 0
139#endif
140
159typedef uint16_t KeyFlags;
160
161#define KEYFLAG_CANTUSE (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
162#define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
163
164#define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
165
166void pgp_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic);
167
168/* crypt.c */
169void crypt_extract_keys_from_messages (struct Mailbox *m, struct EmailArray *ea);
170void crypt_forget_passphrase (void);
171int crypt_get_keys (struct Email *e, char **keylist, bool oppenc_mode);
172void crypt_opportunistic_encrypt (struct Email *e);
173SecurityFlags crypt_query (struct Body *b);
181int mutt_protected_headers_handler (struct Body *b, struct State *state);
182int mutt_protect (struct Email *e, char *keylist, bool postpone);
184int mutt_signed_handler (struct Body *b, struct State *state);
185
186/* cryptglue.c */
187void crypt_cleanup (struct NcryptModuleData *mod_data);
189void crypt_init (void);
191int crypt_pgp_application_handler (struct Body *b_email, struct State *state);
192bool crypt_pgp_check_traditional (FILE *fp, struct Body *b, bool just_one);
193int crypt_pgp_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec);
194int crypt_pgp_encrypted_handler (struct Body *b_email, struct State *state);
195void crypt_pgp_extract_key_from_attachment (FILE *fp, struct Body *b);
196void crypt_pgp_invoke_getkeys (struct Address *addr);
197struct Body * crypt_pgp_make_key_attachment (void);
199int crypt_smime_application_handler (struct Body *b_email, struct State *state);
200int crypt_smime_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec);
201void crypt_smime_getkeys (struct Envelope *env);
203int crypt_smime_verify_sender (struct Email *e, struct Message *msg);
204
205/* crypt_mod.c */
206void crypto_module_cleanup (struct NcryptModuleData *mod_data);
207
208#ifdef CRYPT_BACKEND_GPGME
209/* crypt_gpgme.c */
210void pgp_gpgme_init (void);
211#ifdef USE_AUTOCRYPT
212int mutt_gpgme_select_secret_key (struct Buffer *keyid);
213#endif
214const char * mutt_gpgme_print_version (void);
215#endif
216
217#endif /* MUTT_NCRYPT_LIB_H */
void pgp_gpgme_init(void)
Initialise the crypto module - Implements CryptModuleSpecs::init() -.
int crypt_pgp_application_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition cryptglue.c:266
int crypt_smime_application_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition cryptglue.c:524
int crypt_pgp_encrypted_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::encrypted_handler() - Implements handler_t -.
Definition cryptglue.c:280
int mutt_protected_headers_handler(struct Body *b, struct State *state)
Handler for protected headers - Implements handler_t -.
Definition crypt.c:1122
int mutt_signed_handler(struct Body *b, struct State *state)
Handler for "multipart/signed" - Implements handler_t -.
Definition crypt.c:1249
void pgp_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic)
Initialise the PGP Keybindings - Implements ::init_keys_api.
Definition functions.c:84
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition cryptglue.c:188
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition cryptglue.c:174
uint16_t SecurityFlags
Definition lib.h:104
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition cryptglue.c:237
SecurityFlag
Flags describing an email's cryptographic state.
Definition lib.h:90
@ SEC_NONE
No flags are set.
Definition lib.h:91
@ SEC_OPPENCRYPT
Opportunistic encrypt mode.
Definition lib.h:100
@ SEC_BADSIGN
Email has a bad signature.
Definition lib.h:95
@ SEC_PARTSIGN
Not all parts of the email is signed.
Definition lib.h:96
@ SEC_SIGNOPAQUE
Email has an opaque signature (encrypted)
Definition lib.h:97
@ SEC_SIGN
Email is signed.
Definition lib.h:93
@ SEC_INLINE
Email has an inline signature.
Definition lib.h:99
@ SEC_KEYBLOCK
Email has a key attached.
Definition lib.h:98
@ SEC_ENCRYPT
Email is encrypted.
Definition lib.h:92
@ SEC_AUTOCRYPT
(Autocrypt) Message will be, or was Autocrypt encrypt+signed
Definition lib.h:101
@ SEC_GOODSIGN
Email has a valid signature.
Definition lib.h:94
@ SEC_AUTOCRYPT_OVERRIDE
(Autocrypt) Indicates manual set/unset of encryption
Definition lib.h:102
void crypto_module_cleanup(struct NcryptModuleData *mod_data)
Clean up the crypto modules.
Definition crypt_mod.c:74
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition crypt.c:1050
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.
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition crypt.c:408
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition cryptglue.c:538
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition crypt.c:609
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition crypt.c:131
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition crypt.c:467
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition crypt.c:1105
uint16_t KeyFlags
Definition lib.h:159
bool crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one)
Wrapper for CryptModuleSpecs::pgp_check_traditional()
Definition cryptglue.c:321
struct Body * crypt_pgp_make_key_attachment(void)
Wrapper for CryptModuleSpecs::pgp_make_key_attachment()
Definition cryptglue.c:349
SecurityFlags crypt_smime_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition cryptglue.c:632
void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailArray *ea)
Extract keys from a message.
Definition crypt.c:863
SecurityFlags crypt_pgp_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition cryptglue.c:446
KeyFlag
Flags describing PGP/SMIME keys.
Definition lib.h:145
@ KEYFLAG_REVOKED
Key is revoked.
Definition lib.h:152
@ KEYFLAG_PREFER_SIGNING
Key's owner prefers signing.
Definition lib.h:157
@ KEYFLAG_NONE
No flags are set.
Definition lib.h:146
@ KEYFLAG_SECRET
Key is a secret key.
Definition lib.h:150
@ KEYFLAG_PREFER_ENCRYPTION
Key's owner prefers encryption.
Definition lib.h:156
@ KEYFLAG_CANSIGN
Key is suitable for signing.
Definition lib.h:147
@ KEYFLAG_ISX509
Key is an X.509 key.
Definition lib.h:149
@ KEYFLAG_EXPIRED
Key is expired.
Definition lib.h:151
@ KEYFLAG_CANENCRYPT
Key is suitable for encryption.
Definition lib.h:148
@ KEYFLAG_SUBKEY
Key is a subkey.
Definition lib.h:154
@ KEYFLAG_DISABLED
Key is marked disabled.
Definition lib.h:153
@ KEYFLAG_CRITICAL
Key is marked critical.
Definition lib.h:155
void crypt_pgp_invoke_getkeys(struct Address *addr)
Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()
Definition cryptglue.c:309
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition crypt.c:443
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition crypt.c:156
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
Definition crypt.c:89
void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *b)
Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()
Definition cryptglue.c:460
int crypt_smime_verify_sender(struct Email *e, struct Message *msg)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition cryptglue.c:550
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition crypt.c:504
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition cryptglue.c:510
void crypt_init(void)
Initialise the crypto backends.
Definition cryptglue.c:99
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition crypt.c:966
void crypt_cleanup(struct NcryptModuleData *mod_data)
Clean up backend.
Definition cryptglue.c:151
SecurityFlags mutt_is_application_pgp(const struct Body *b)
Does the message use PGP?
Definition crypt.c:548
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition crypt.c:692
An email address.
Definition address.h:35
The body of an email.
Definition body.h:36
String manipulation buffer.
Definition buffer.h:36
The envelope/body of an email.
Definition email.h:39
The header of an Email.
Definition envelope.h:57
A mailbox.
Definition mailbox.h:81
A local copy of an email.
Definition message.h:34
Ncrypt private Module data.
Definition module_data.h:39
Container for Accounts, Notifications.
Definition neomutt.h:41
Keep track when processing files.
Definition state.h:54
Collection of related functions.
Definition menudef.h:33