NeoMutt  2020-11-20
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 ConfigSet;
67 struct Email;
68 struct EmailList;
69 struct Envelope;
70 struct Mailbox;
71 struct State;
72 
73 extern bool C_CryptOpportunisticEncrypt;
74 extern bool C_CryptProtectedHeadersRead;
75 extern bool C_CryptProtectedHeadersSave;
76 extern unsigned char C_CryptVerifySig;
77 extern bool C_PgpAutoDecode;
78 extern char * C_PgpSignAs;
79 extern char * C_SmimeEncryptWith;
80 extern bool C_SmimeIsDefault;
81 extern char * C_SmimeSignAs;
82 
83 typedef uint16_t SecurityFlags;
84 #define SEC_NO_FLAGS 0
85 #define SEC_ENCRYPT (1 << 0)
86 #define SEC_SIGN (1 << 1)
87 #define SEC_GOODSIGN (1 << 2)
88 #define SEC_BADSIGN (1 << 3)
89 #define SEC_PARTSIGN (1 << 4)
90 #define SEC_SIGNOPAQUE (1 << 5)
91 #define SEC_KEYBLOCK (1 << 6)
92 #define SEC_INLINE (1 << 7)
93 #define SEC_OPPENCRYPT (1 << 8)
94 #define SEC_AUTOCRYPT (1 << 9)
95 #define SEC_AUTOCRYPT_OVERRIDE (1 << 10)
96 
97 #define APPLICATION_PGP (1 << 11)
98 #define APPLICATION_SMIME (1 << 12)
99 #define PGP_TRADITIONAL_CHECKED (1 << 13)
100 
101 #define SEC_ALL_FLAGS ((1 << 14) - 1)
102 
103 #define PGP_ENCRYPT (APPLICATION_PGP | SEC_ENCRYPT)
104 #define PGP_SIGN (APPLICATION_PGP | SEC_SIGN)
105 #define PGP_GOODSIGN (APPLICATION_PGP | SEC_GOODSIGN)
106 #define PGP_KEY (APPLICATION_PGP | SEC_KEYBLOCK)
107 #define PGP_INLINE (APPLICATION_PGP | SEC_INLINE)
108 
109 #define SMIME_ENCRYPT (APPLICATION_SMIME | SEC_ENCRYPT)
110 #define SMIME_SIGN (APPLICATION_SMIME | SEC_SIGN)
111 #define SMIME_GOODSIGN (APPLICATION_SMIME | SEC_GOODSIGN)
112 #define SMIME_BADSIGN (APPLICATION_SMIME | SEC_BADSIGN)
113 #define SMIME_OPAQUE (APPLICATION_SMIME | SEC_SIGNOPAQUE)
114 
115 /* WITHCRYPTO actually replaces ifdefs to make the code more readable.
116  * Because it is defined as a constant and known at compile time, the
117  * compiler can do dead code elimination and thus it behaves
118  * effectively as a conditional compile directive. It is set to false
119  * if no crypto backend is configured or to a bit vector denoting the
120  * configured backends. */
121 #if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || \
122  defined(CRYPT_BACKEND_GPGME)
123 #define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
124 #elif defined(CRYPT_BACKEND_CLASSIC_PGP)
125 #define WithCrypto APPLICATION_PGP
126 #elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
127 #define WithCrypto APPLICATION_SMIME
128 #else
129 #define WithCrypto 0
130 #endif
131 
132 typedef uint16_t KeyFlags;
133 #define KEYFLAG_NO_FLAGS 0
134 #define KEYFLAG_CANSIGN (1 << 0)
135 #define KEYFLAG_CANENCRYPT (1 << 1)
136 #define KEYFLAG_ISX509 (1 << 2)
137 #define KEYFLAG_SECRET (1 << 7)
138 #define KEYFLAG_EXPIRED (1 << 8)
139 #define KEYFLAG_REVOKED (1 << 9)
140 #define KEYFLAG_DISABLED (1 << 10)
141 #define KEYFLAG_SUBKEY (1 << 11)
142 #define KEYFLAG_CRITICAL (1 << 12)
143 #define KEYFLAG_PREFER_ENCRYPTION (1 << 13)
144 #define KEYFLAG_PREFER_SIGNING (1 << 14)
145 
146 #define KEYFLAG_CANTUSE (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
147 #define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
148 
149 #define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
150 
151 /* crypt.c */
152 void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el);
153 void crypt_forget_passphrase(void);
154 int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode);
155 void crypt_opportunistic_encrypt(struct Email *e);
156 SecurityFlags crypt_query(struct Body *m);
164 int mutt_protect(struct Email *e, char *keylist, bool postpone);
165 int mutt_protected_headers_handler(struct Body *m, struct State *s);
167 int mutt_signed_handler(struct Body *a, struct State *s);
168 
169 /* cryptglue.c */
170 void crypt_cleanup(void);
172 void crypt_init(void);
174 int crypt_pgp_application_handler(struct Body *m, struct State *s);
175 int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one);
176 int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
177 int crypt_pgp_encrypted_handler(struct Body *a, struct State *s);
178 void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top);
179 void crypt_pgp_invoke_getkeys(struct Address *addr);
180 struct Body *crypt_pgp_make_key_attachment(void);
181 int crypt_pgp_send_menu(struct Email *e);
182 int crypt_smime_application_handler(struct Body *m, struct State *s);
183 int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
184 void crypt_smime_getkeys(struct Envelope *env);
185 int crypt_smime_send_menu(struct Email *e);
186 int crypt_smime_verify_sender(struct Mailbox *m, struct Email *e);
187 
188 /* crypt_mod.c */
189 void crypto_module_free(void);
190 
191 #ifdef CRYPT_BACKEND_GPGME
192 /* crypt_gpgme.c */
193 void pgp_gpgme_init(void);
194 #ifdef USE_AUTOCRYPT
195 int mutt_gpgme_select_secret_key (struct Buffer *keyid);
196 #endif
197 const char *mutt_gpgme_print_version(void);
198 #endif
199 
200 #endif /* MUTT_NCRYPT_LIB_H */
int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one)
Wrapper for CryptModuleSpecs::pgp_check_traditional()
Definition: cryptglue.c:281
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:508
SecurityFlags mutt_is_application_pgp(struct Body *m)
Does the message use PGP?
Definition: crypt.c:552
char * C_SmimeEncryptWith
Config: Algorithm for encryption.
Definition: config.c:71
Container for lots of config items.
Definition: set.h:228
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:303
void crypto_module_free(void)
Clean up the crypto modules.
Definition: crypt_mod.c:81
char * C_PgpSignAs
Config: Use this alternative key for signing messages.
Definition: config.c:67
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:134
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:685
unsigned char C_CryptVerifySig
Config: Verify PGP or SMIME signatures.
Definition: config.c:123
int mutt_protected_headers_handler(struct Body *m, struct State *s)
Process a protected header - Implements handler_t.
Definition: crypt.c:1087
int crypt_smime_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler()
Definition: cryptglue.c:444
String manipulation buffer.
Definition: buffer.h:33
An email address.
Definition: address.h:34
FILE * fp_out
File to write to.
Definition: state.h:47
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:83
const char * mutt_gpgme_print_version(void)
Get version of GPGME.
Definition: crypt_gpgme.c:4425
bool C_CryptOpportunisticEncrypt
Config: Enable encryption when the recipient&#39;s key is available.
Definition: config.c:56
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:447
char * C_SmimeSignAs
Config: Use this alternative key for signing messages.
Definition: config.c:70
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:455
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:272
StateFlags flags
Flags, e.g. MUTT_DISPLAY.
Definition: state.h:49
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1021
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition: crypt.c:1073
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:407
int crypt_smime_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:528
void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el)
Extract keys from a message.
Definition: crypt.c:844
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:943
int mutt_signed_handler(struct Body *a, struct State *s)
Verify a "multipart/signed" body - Implements handler_t.
Definition: crypt.c:1113
bool C_PgpAutoDecode
Config: Automatically decrypt PGP messages.
Definition: config.c:122
A mailbox.
Definition: mailbox.h:81
void crypt_cleanup(void)
Clean up backend.
Definition: cryptglue.c:138
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:132
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:207
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition: cryptglue.c:167
int crypt_pgp_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:382
bool C_CryptProtectedHeadersSave
Config: Save the cleartext Subject with the headers.
Definition: config.c:59
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:610
bool C_SmimeIsDefault
Config: Use SMIME rather than PGP by default.
Definition: config.c:61
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
Definition: crypt.c:92
Keep track when processing files.
Definition: state.h:44
int crypt_smime_verify_sender(struct Mailbox *m, struct Email *e)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition: cryptglue.c:464
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:431
void pgp_gpgme_init(void)
Implements CryptModuleSpecs::init()
Definition: crypt_gpgme.c:4130
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition: crypt.c:471
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition: crypt.c:159
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
Definition: crypt_gpgme.c:3942
int crypt_pgp_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler()
Definition: cryptglue.c:234
void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top)
Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()
Definition: cryptglue.c:393
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:247
void crypt_init(void)
Initialise the crypto backends.
Definition: cryptglue.c:93
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition: cryptglue.c:153
bool C_CryptProtectedHeadersRead
Config: Display protected headers (Memory Hole) in the pager.
Definition: config.c:58