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