Thanks to visit codestin.com
Credit goes to code.neomutt.org

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