NeoMutt  2025-12-11-769-g906513
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 NeoMutt;
82struct State;
83struct SubMenu;
84
85typedef uint16_t SecurityFlags;
86#define SEC_NO_FLAGS 0
87#define SEC_ENCRYPT (1 << 0)
88#define SEC_SIGN (1 << 1)
89#define SEC_GOODSIGN (1 << 2)
90#define SEC_BADSIGN (1 << 3)
91#define SEC_PARTSIGN (1 << 4)
92#define SEC_SIGNOPAQUE (1 << 5)
93#define SEC_KEYBLOCK (1 << 6)
94#define SEC_INLINE (1 << 7)
95#define SEC_OPPENCRYPT (1 << 8)
96#define SEC_AUTOCRYPT (1 << 9)
97#define SEC_AUTOCRYPT_OVERRIDE (1 << 10)
98
99#define APPLICATION_PGP (1 << 11)
100#define APPLICATION_SMIME (1 << 12)
101#define PGP_TRADITIONAL_CHECKED (1 << 13)
102
103#define SEC_ALL_FLAGS ((1 << 14) - 1)
104
105#define PGP_ENCRYPT (APPLICATION_PGP | SEC_ENCRYPT)
106#define PGP_SIGN (APPLICATION_PGP | SEC_SIGN)
107#define PGP_GOODSIGN (APPLICATION_PGP | SEC_GOODSIGN)
108#define PGP_KEY (APPLICATION_PGP | SEC_KEYBLOCK)
109#define PGP_INLINE (APPLICATION_PGP | SEC_INLINE)
110
111#define SMIME_ENCRYPT (APPLICATION_SMIME | SEC_ENCRYPT)
112#define SMIME_SIGN (APPLICATION_SMIME | SEC_SIGN)
113#define SMIME_GOODSIGN (APPLICATION_SMIME | SEC_GOODSIGN)
114#define SMIME_BADSIGN (APPLICATION_SMIME | SEC_BADSIGN)
115#define SMIME_OPAQUE (APPLICATION_SMIME | SEC_SIGNOPAQUE)
116
117/* WITHCRYPTO actually replaces ifdefs to make the code more readable.
118 * Because it is defined as a constant and known at compile time, the
119 * compiler can do dead code elimination and thus it behaves
120 * effectively as a conditional compile directive. It is set to false
121 * if no crypto backend is configured or to a bit vector denoting the
122 * configured backends. */
123#if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || \
124 defined(CRYPT_BACKEND_GPGME)
125#define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
126#elif defined(CRYPT_BACKEND_CLASSIC_PGP)
127#define WithCrypto APPLICATION_PGP
128#elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
129#define WithCrypto APPLICATION_SMIME
130#else
131#define WithCrypto 0
132#endif
133
134typedef uint16_t KeyFlags;
135#define KEYFLAG_NO_FLAGS 0
136#define KEYFLAG_CANSIGN (1 << 0)
137#define KEYFLAG_CANENCRYPT (1 << 1)
138#define KEYFLAG_ISX509 (1 << 2)
139#define KEYFLAG_SECRET (1 << 7)
140#define KEYFLAG_EXPIRED (1 << 8)
141#define KEYFLAG_REVOKED (1 << 9)
142#define KEYFLAG_DISABLED (1 << 10)
143#define KEYFLAG_SUBKEY (1 << 11)
144#define KEYFLAG_CRITICAL (1 << 12)
145#define KEYFLAG_PREFER_ENCRYPTION (1 << 13)
146#define KEYFLAG_PREFER_SIGNING (1 << 14)
147
148#define KEYFLAG_CANTUSE (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
149#define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
150
151#define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
152
153void pgp_init_keys(struct NeoMutt *n, struct SubMenu *sm_generic);
154
155/* crypt.c */
156void crypt_extract_keys_from_messages (struct Mailbox *m, struct EmailArray *ea);
157void crypt_forget_passphrase (void);
158int crypt_get_keys (struct Email *e, char **keylist, bool oppenc_mode);
159void crypt_opportunistic_encrypt (struct Email *e);
160SecurityFlags crypt_query (struct Body *b);
168int mutt_protected_headers_handler (struct Body *b, struct State *state);
169int mutt_protect (struct Email *e, char *keylist, bool postpone);
171int mutt_signed_handler (struct Body *b, struct State *state);
172
173/* cryptglue.c */
174void crypt_cleanup (void);
176void crypt_init (void);
178int crypt_pgp_application_handler (struct Body *b_email, struct State *state);
179bool crypt_pgp_check_traditional (FILE *fp, struct Body *b, bool just_one);
180int crypt_pgp_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec);
181int crypt_pgp_encrypted_handler (struct Body *b_email, struct State *state);
182void crypt_pgp_extract_key_from_attachment (FILE *fp, struct Body *b);
183void crypt_pgp_invoke_getkeys (struct Address *addr);
184struct Body * crypt_pgp_make_key_attachment (void);
186int crypt_smime_application_handler (struct Body *b_email, struct State *state);
187int crypt_smime_decrypt_mime (FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec);
188void crypt_smime_getkeys (struct Envelope *env);
190int crypt_smime_verify_sender (struct Email *e, struct Message *msg);
191
192/* crypt_mod.c */
193void crypto_module_cleanup (void);
194
195#ifdef CRYPT_BACKEND_GPGME
196/* crypt_gpgme.c */
197void pgp_gpgme_init (void);
198#ifdef USE_AUTOCRYPT
199int mutt_gpgme_select_secret_key (struct Buffer *keyid);
200#endif
201const char * mutt_gpgme_print_version (void);
202#endif
203
204#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:249
int crypt_smime_application_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition cryptglue.c:456
int crypt_pgp_encrypted_handler(struct Body *b_email, struct State *state)
Wrapper for CryptModuleSpecs::encrypted_handler() - Implements handler_t -.
Definition cryptglue.c:260
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:88
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition cryptglue.c:183
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition cryptglue.c:169
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition lib.h:85
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:223
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_cleanup(void)
Clean up backend.
Definition cryptglue.c:146
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition cryptglue.c:467
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
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition lib.h:134
bool crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one)
Wrapper for CryptModuleSpecs::pgp_check_traditional()
Definition cryptglue.c:295
void crypto_module_cleanup(void)
Clean up the crypto modules.
Definition crypt_mod.c:73
struct Body * crypt_pgp_make_key_attachment(void)
Wrapper for CryptModuleSpecs::pgp_make_key_attachment()
Definition cryptglue.c:317
SecurityFlags crypt_smime_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition cryptglue.c:540
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:396
void crypt_pgp_invoke_getkeys(struct Address *addr)
Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()
Definition cryptglue.c:286
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:407
int crypt_smime_verify_sender(struct Email *e, struct Message *msg)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition cryptglue.c:476
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:445
void crypt_init(void)
Initialise the crypto backends.
Definition cryptglue.c:98
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition crypt.c:966
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:78
A local copy of an email.
Definition message.h:34
Container for Accounts, Notifications.
Definition neomutt.h:41
Keep track when processing files.
Definition state.h:48
Collection of related functions.
Definition menu.h:68