NeoMutt  2022-04-29-145-g9b6a0e
Teaching an old dog new tricks
DOXYGEN
lib.h
Go to the documentation of this file.
1 
57 #ifndef MUTT_NCRYPT_LIB_H
58 #define MUTT_NCRYPT_LIB_H
59 
60 #include <stdbool.h>
61 #include <stdint.h>
62 #include <stdio.h>
63 
64 struct Address;
65 struct Body;
66 #ifdef USE_AUTOCRYPT
67 struct Buffer;
68 #endif
69 struct Email;
70 struct EmailList;
71 struct Envelope;
72 struct Mailbox;
73 struct Message;
74 struct State;
75 
76 typedef uint16_t SecurityFlags;
77 #define SEC_NO_FLAGS 0
78 #define SEC_ENCRYPT (1 << 0)
79 #define SEC_SIGN (1 << 1)
80 #define SEC_GOODSIGN (1 << 2)
81 #define SEC_BADSIGN (1 << 3)
82 #define SEC_PARTSIGN (1 << 4)
83 #define SEC_SIGNOPAQUE (1 << 5)
84 #define SEC_KEYBLOCK (1 << 6)
85 #define SEC_INLINE (1 << 7)
86 #define SEC_OPPENCRYPT (1 << 8)
87 #define SEC_AUTOCRYPT (1 << 9)
88 #define SEC_AUTOCRYPT_OVERRIDE (1 << 10)
89 
90 #define APPLICATION_PGP (1 << 11)
91 #define APPLICATION_SMIME (1 << 12)
92 #define PGP_TRADITIONAL_CHECKED (1 << 13)
93 
94 #define SEC_ALL_FLAGS ((1 << 14) - 1)
95 
96 #define PGP_ENCRYPT (APPLICATION_PGP | SEC_ENCRYPT)
97 #define PGP_SIGN (APPLICATION_PGP | SEC_SIGN)
98 #define PGP_GOODSIGN (APPLICATION_PGP | SEC_GOODSIGN)
99 #define PGP_KEY (APPLICATION_PGP | SEC_KEYBLOCK)
100 #define PGP_INLINE (APPLICATION_PGP | SEC_INLINE)
101 
102 #define SMIME_ENCRYPT (APPLICATION_SMIME | SEC_ENCRYPT)
103 #define SMIME_SIGN (APPLICATION_SMIME | SEC_SIGN)
104 #define SMIME_GOODSIGN (APPLICATION_SMIME | SEC_GOODSIGN)
105 #define SMIME_BADSIGN (APPLICATION_SMIME | SEC_BADSIGN)
106 #define SMIME_OPAQUE (APPLICATION_SMIME | SEC_SIGNOPAQUE)
107 
108 /* WITHCRYPTO actually replaces ifdefs to make the code more readable.
109  * Because it is defined as a constant and known at compile time, the
110  * compiler can do dead code elimination and thus it behaves
111  * effectively as a conditional compile directive. It is set to false
112  * if no crypto backend is configured or to a bit vector denoting the
113  * configured backends. */
114 #if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || \
115  defined(CRYPT_BACKEND_GPGME)
116 #define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
117 #elif defined(CRYPT_BACKEND_CLASSIC_PGP)
118 #define WithCrypto APPLICATION_PGP
119 #elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
120 #define WithCrypto APPLICATION_SMIME
121 #else
122 #define WithCrypto 0
123 #endif
124 
125 typedef uint16_t KeyFlags;
126 #define KEYFLAG_NO_FLAGS 0
127 #define KEYFLAG_CANSIGN (1 << 0)
128 #define KEYFLAG_CANENCRYPT (1 << 1)
129 #define KEYFLAG_ISX509 (1 << 2)
130 #define KEYFLAG_SECRET (1 << 7)
131 #define KEYFLAG_EXPIRED (1 << 8)
132 #define KEYFLAG_REVOKED (1 << 9)
133 #define KEYFLAG_DISABLED (1 << 10)
134 #define KEYFLAG_SUBKEY (1 << 11)
135 #define KEYFLAG_CRITICAL (1 << 12)
136 #define KEYFLAG_PREFER_ENCRYPTION (1 << 13)
137 #define KEYFLAG_PREFER_SIGNING (1 << 14)
138 
139 #define KEYFLAG_CANTUSE (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
140 #define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
141 
142 #define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
143 
144 /* crypt.c */
145 void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el);
146 void crypt_forget_passphrase(void);
147 int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode);
148 void crypt_opportunistic_encrypt(struct Email *e);
149 SecurityFlags crypt_query(struct Body *b);
157 int mutt_protect(struct Email *e, char *keylist, bool postpone);
158 int mutt_protected_headers_handler(struct Body *b, struct State *s);
160 int mutt_signed_handler(struct Body *b, struct State *s);
161 
162 /* cryptglue.c */
163 void crypt_cleanup(void);
165 void crypt_init(void);
167 int crypt_pgp_application_handler(struct Body *m, struct State *s);
168 bool crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one);
169 int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
170 int crypt_pgp_encrypted_handler(struct Body *a, struct State *s);
171 void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top);
172 void crypt_pgp_invoke_getkeys(struct Address *addr);
173 struct Body *crypt_pgp_make_key_attachment(void);
175 int crypt_smime_application_handler(struct Body *m, struct State *s);
176 int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
177 void crypt_smime_getkeys(struct Envelope *env);
179 int crypt_smime_verify_sender(struct Email *e, struct Message *msg);
180 
181 /* crypt_mod.c */
182 void crypto_module_free(void);
183 
184 #ifdef CRYPT_BACKEND_GPGME
185 /* crypt_gpgme.c */
186 void pgp_gpgme_init(void);
187 #ifdef USE_AUTOCRYPT
188 int mutt_gpgme_select_secret_key (struct Buffer *keyid);
189 #endif
190 const char *mutt_gpgme_print_version(void);
191 #endif
192 
193 #endif /* MUTT_NCRYPT_LIB_H */
void pgp_gpgme_init(void)
Implements CryptModuleSpecs::init() -.
Definition: crypt_gpgme.c:4148
int mutt_signed_handler(struct Body *b, struct State *s)
Verify a "multipart/signed" body - Implements handler_t -.
Definition: crypt.c:1124
int mutt_protected_headers_handler(struct Body *b, struct State *s)
Process a protected header - Implements handler_t -.
Definition: crypt.c:1095
int crypt_pgp_encrypted_handler(struct Body *a, struct State *s)
Wrapper for CryptModuleSpecs::encrypted_handler() - Implements handler_t -.
Definition: cryptglue.c:248
int crypt_smime_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition: cryptglue.c:444
int crypt_pgp_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler() - Implements handler_t -.
Definition: cryptglue.c:237
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition: cryptglue.c:171
SecurityFlags mutt_is_application_pgp(struct Body *b)
Does the message use PGP?
Definition: crypt.c:544
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition: cryptglue.c:157
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:74
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1025
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
Definition: crypt_gpgme.c:3967
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:402
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:433
void crypt_cleanup(void)
Clean up backend.
Definition: cryptglue.c:142
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:455
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:601
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:134
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition: crypt.c:463
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition: crypt.c:1078
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:125
bool crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one)
Wrapper for CryptModuleSpecs::pgp_check_traditional()
Definition: cryptglue.c:283
const char * mutt_gpgme_print_version(void)
Get version of GPGME.
Definition: crypt_gpgme.c:4442
void crypto_module_free(void)
Clean up the crypto modules.
Definition: crypt_mod.c:81
SecurityFlags crypt_smime_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:528
SecurityFlags crypt_pgp_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:384
void crypt_pgp_invoke_getkeys(struct Address *addr)
Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()
Definition: cryptglue.c:274
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:439
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition: crypt.c:159
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
Definition: crypt.c:92
int crypt_smime_verify_sender(struct Email *e, struct Message *msg)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition: cryptglue.c:464
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:500
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:211
void crypt_init(void)
Initialise the crypto backends.
Definition: cryptglue.c:94
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:941
struct Body * crypt_pgp_make_key_attachment(void)
Wrapper for CryptModuleSpecs::pgp_make_key_attachment()
Definition: cryptglue.c:305
void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el)
Extract keys from a message.
Definition: crypt.c:838
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:675
void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top)
Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()
Definition: cryptglue.c:395
An email address.
Definition: address.h:36
The body of an email.
Definition: body.h:36
String manipulation buffer.
Definition: buffer.h:34
The envelope/body of an email.
Definition: email.h:37
The header of an Email.
Definition: envelope.h:57
A mailbox.
Definition: mailbox.h:79
A local copy of an email.
Definition: mxapi.h:43
Keep track when processing files.
Definition: state.h:46
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:50
FILE * fp_out
File to write to.
Definition: state.h:48
FILE * fp_in
File to read from.
Definition: state.h:47