NeoMutt  2020-04-24
Teaching an old dog new tricks
DOXYGEN
lib.h
Go to the documentation of this file.
1 
50 #ifndef MUTT_NCRYPT_LIB_H
51 #define MUTT_NCRYPT_LIB_H
52 
53 #include <stdbool.h>
54 #include <stdint.h>
55 #include <stdio.h>
56 
57 struct Address;
58 struct Body;
59 struct Buffer;
60 struct Envelope;
61 struct Email;
62 struct EmailList;
63 struct Mailbox;
64 struct State;
65 
66 /* These Config Variables are only used in ncrypt/crypt.c */
67 extern bool C_CryptTimestamp;
68 extern unsigned char C_PgpEncryptSelf;
69 extern unsigned char C_PgpMimeAuto;
70 extern bool C_PgpRetainableSigs;
71 extern bool C_PgpSelfEncrypt;
72 extern bool C_PgpStrictEnc;
73 extern unsigned char C_SmimeEncryptSelf;
74 extern bool C_SmimeSelfEncrypt;
75 
76 #ifdef CRYPT_BACKEND_GPGME
77 /* These Config Variables are only used in ncrypt/cryptglue.c */
78 extern bool C_CryptUseGpgme;
79 #endif
80 
81 /* These Config Variables are only used in ncrypt/pgp.c */
82 extern bool C_PgpCheckExit;
84 extern struct Regex *C_PgpDecryptionOkay;
85 extern struct Regex *C_PgpGoodSign;
86 extern long C_PgpTimeout;
87 extern bool C_PgpUseGpgAgent;
88 
89 /* These Config Variables are only used in ncrypt/pgpinvoke.c */
90 extern char *C_PgpClearsignCommand;
91 extern char *C_PgpDecodeCommand;
92 extern char *C_PgpDecryptCommand;
93 extern char *C_PgpEncryptOnlyCommand;
94 extern char *C_PgpEncryptSignCommand;
95 extern char *C_PgpExportCommand;
96 extern char *C_PgpGetkeysCommand;
97 extern char *C_PgpImportCommand;
98 extern char *C_PgpListPubringCommand;
99 extern char *C_PgpListSecringCommand;
100 extern char *C_PgpSignCommand;
101 extern char *C_PgpVerifyCommand;
102 extern char *C_PgpVerifyKeyCommand;
103 
104 /* These Config Variables are only used in ncrypt/smime.c */
105 extern bool C_SmimeAskCertLabel;
106 extern char *C_SmimeCaLocation;
107 extern char *C_SmimeCertificates;
108 extern char *C_SmimeDecryptCommand;
109 extern bool C_SmimeDecryptUseDefaultKey;
110 extern char *C_SmimeEncryptCommand;
111 extern char *C_SmimeGetCertCommand;
112 extern char *C_SmimeGetCertEmailCommand;
113 extern char *C_SmimeGetSignerCertCommand;
114 extern char *C_SmimeImportCertCommand;
115 extern char *C_SmimeKeys;
116 extern char *C_SmimePk7outCommand;
117 extern char *C_SmimeSignCommand;
118 extern char *C_SmimeSignDigestAlg;
119 extern long C_SmimeTimeout;
120 extern char *C_SmimeVerifyCommand;
121 extern char *C_SmimeVerifyOpaqueCommand;
122 
123 typedef uint16_t SecurityFlags;
124 #define SEC_NO_FLAGS 0
125 #define SEC_ENCRYPT (1 << 0)
126 #define SEC_SIGN (1 << 1)
127 #define SEC_GOODSIGN (1 << 2)
128 #define SEC_BADSIGN (1 << 3)
129 #define SEC_PARTSIGN (1 << 4)
130 #define SEC_SIGNOPAQUE (1 << 5)
131 #define SEC_KEYBLOCK (1 << 6)
132 #define SEC_INLINE (1 << 7)
133 #define SEC_OPPENCRYPT (1 << 8)
134 #define SEC_AUTOCRYPT (1 << 9)
135 #define SEC_AUTOCRYPT_OVERRIDE (1 << 10)
136 
137 #define APPLICATION_PGP (1 << 11)
138 #define APPLICATION_SMIME (1 << 12)
139 #define PGP_TRADITIONAL_CHECKED (1 << 13)
140 
141 #define SEC_ALL_FLAGS ((1 << 14) - 1)
142 
143 #define PGP_ENCRYPT (APPLICATION_PGP | SEC_ENCRYPT)
144 #define PGP_SIGN (APPLICATION_PGP | SEC_SIGN)
145 #define PGP_GOODSIGN (APPLICATION_PGP | SEC_GOODSIGN)
146 #define PGP_KEY (APPLICATION_PGP | SEC_KEYBLOCK)
147 #define PGP_INLINE (APPLICATION_PGP | SEC_INLINE)
148 
149 #define SMIME_ENCRYPT (APPLICATION_SMIME | SEC_ENCRYPT)
150 #define SMIME_SIGN (APPLICATION_SMIME | SEC_SIGN)
151 #define SMIME_GOODSIGN (APPLICATION_SMIME | SEC_GOODSIGN)
152 #define SMIME_BADSIGN (APPLICATION_SMIME | SEC_BADSIGN)
153 #define SMIME_OPAQUE (APPLICATION_SMIME | SEC_SIGNOPAQUE)
154 
155 /* WITHCRYPTO actually replaces ifdefs to make the code more readable.
156  * Because it is defined as a constant and known at compile time, the
157  * compiler can do dead code elimination and thus it behaves
158  * effectively as a conditional compile directive. It is set to false
159  * if no crypto backend is configured or to a bit vector denoting the
160  * configured backends. */
161 #if (defined(CRYPT_BACKEND_CLASSIC_PGP) && defined(CRYPT_BACKEND_CLASSIC_SMIME)) || \
162  defined(CRYPT_BACKEND_GPGME)
163 #define WithCrypto (APPLICATION_PGP | APPLICATION_SMIME)
164 #elif defined(CRYPT_BACKEND_CLASSIC_PGP)
165 #define WithCrypto APPLICATION_PGP
166 #elif defined(CRYPT_BACKEND_CLASSIC_SMIME)
167 #define WithCrypto APPLICATION_SMIME
168 #else
169 #define WithCrypto 0
170 #endif
171 
172 typedef uint16_t KeyFlags;
173 #define KEYFLAG_NO_FLAGS 0
174 #define KEYFLAG_CANSIGN (1 << 0)
175 #define KEYFLAG_CANENCRYPT (1 << 1)
176 #define KEYFLAG_ISX509 (1 << 2)
177 #define KEYFLAG_SECRET (1 << 7)
178 #define KEYFLAG_EXPIRED (1 << 8)
179 #define KEYFLAG_REVOKED (1 << 9)
180 #define KEYFLAG_DISABLED (1 << 10)
181 #define KEYFLAG_SUBKEY (1 << 11)
182 #define KEYFLAG_CRITICAL (1 << 12)
183 #define KEYFLAG_PREFER_ENCRYPTION (1 << 13)
184 #define KEYFLAG_PREFER_SIGNING (1 << 14)
185 
186 #define KEYFLAG_CANTUSE (KEYFLAG_DISABLED | KEYFLAG_REVOKED | KEYFLAG_EXPIRED)
187 #define KEYFLAG_RESTRICTIONS (KEYFLAG_CANTUSE | KEYFLAG_CRITICAL)
188 
189 #define KEYFLAG_ABILITIES (KEYFLAG_CANSIGN | KEYFLAG_CANENCRYPT | KEYFLAG_PREFER_ENCRYPTION | KEYFLAG_PREFER_SIGNING)
190 
191 /* crypt.c */
192 void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el);
193 void crypt_forget_passphrase(void);
194 int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode);
195 void crypt_opportunistic_encrypt(struct Email *e);
196 SecurityFlags crypt_query(struct Body *m);
204 int mutt_protect(struct Email *e, char *keylist, bool postpone);
205 int mutt_protected_headers_handler(struct Body *m, struct State *s);
207 int mutt_signed_handler(struct Body *a, struct State *s);
208 
209 /* cryptglue.c */
210 void crypt_cleanup(void);
212 void crypt_init(void);
214 int crypt_pgp_application_handler(struct Body *m, struct State *s);
215 int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one);
216 int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
217 int crypt_pgp_encrypted_handler(struct Body *a, struct State *s);
218 void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top);
219 void crypt_pgp_invoke_getkeys(struct Address *addr);
220 struct Body *crypt_pgp_make_key_attachment(void);
221 int crypt_pgp_send_menu(struct Email *e);
222 int crypt_smime_application_handler(struct Body *m, struct State *s);
223 int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur);
224 void crypt_smime_getkeys(struct Envelope *env);
225 int crypt_smime_send_menu(struct Email *e);
226 int crypt_smime_verify_sender(struct Mailbox *m, struct Email *e);
227 
228 /* crypt_mod.c */
229 void crypto_module_free(void);
230 
231 #ifdef CRYPT_BACKEND_GPGME
232 /* crypt_gpgme.c */
233 void pgp_gpgme_init(void);
234 #ifdef USE_AUTOCRYPT
235 int mutt_gpgme_select_secret_key (struct Buffer *keyid);
236 #endif
237 const char *mutt_gpgme_print_version(void);
238 #endif
239 
240 #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:286
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:520
SecurityFlags mutt_is_application_pgp(struct Body *m)
Does the message use PGP?
Definition: crypt.c:565
char * C_PgpSignCommand
Config: (pgp) External command to create a detached PGP signature.
Definition: pgpinvoke.c:63
bool C_CryptUseGpgme
Config: Use GPGME crypto backend.
Definition: cryptglue.c:61
char * C_SmimeGetCertEmailCommand
Config: (smime) External command to get a certificate for an email.
Definition: smime.c:75
The envelope/body of an email.
Definition: email.h:37
char * C_PgpListSecringCommand
Config: (pgp) External command to list the private keys in a user&#39;s keyring.
Definition: pgpinvoke.c:62
struct Body * crypt_pgp_make_key_attachment(void)
Wrapper for CryptModuleSpecs::pgp_make_key_attachment()
Definition: cryptglue.c:308
void crypto_module_free(void)
Clean up the crypto modules.
Definition: crypt_mod.c:81
char * C_PgpGetkeysCommand
Config: (pgp) External command to download a key for an email address.
Definition: pgpinvoke.c:59
char * C_PgpEncryptOnlyCommand
Config: (pgp) External command to encrypt, but not sign a message.
Definition: pgpinvoke.c:56
char * C_PgpClearsignCommand
Config: (pgp) External command to inline-sign a message.
Definition: pgpinvoke.c:53
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:146
SecurityFlags crypt_query(struct Body *m)
Check out the type of encryption used.
Definition: crypt.c:700
bool C_CryptTimestamp
Config: Add a timestamp to PGP or SMIME output to prevent spoofing.
Definition: crypt.c:64
char * C_SmimeEncryptCommand
Config: (smime) External command to encrypt a message.
Definition: smime.c:73
int mutt_protected_headers_handler(struct Body *m, struct State *s)
Process a protected header - Implements handler_t.
Definition: crypt.c:1102
char * C_PgpVerifyKeyCommand
Config: (pgp) External command to verify key information.
Definition: pgpinvoke.c:65
char * C_SmimeGetSignerCertCommand
Config: (smime) External command to extract a certificate from an email.
Definition: smime.c:76
int crypt_smime_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler()
Definition: cryptglue.c:449
String manipulation buffer.
Definition: buffer.h:33
char * C_SmimeDecryptCommand
Config: (smime) External command to decrypt an SMIME message.
Definition: smime.c:71
struct Regex * C_PgpGoodSign
Config: Text indicating a good signature.
Definition: pgp.c:72
An email address.
Definition: address.h:34
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:123
const char * mutt_gpgme_print_version(void)
Get version of GPGME.
Definition: crypt_gpgme.c:5872
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:459
char * C_PgpListPubringCommand
Config: (pgp) External command to list the public keys in a user&#39;s keyring.
Definition: pgpinvoke.c:61
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:460
unsigned char C_SmimeEncryptSelf
Deprecated, see C_SmimeSelfEncrypt.
Definition: crypt.c:73
char * C_SmimeCertificates
Config: File containing user&#39;s public certificates.
Definition: smime.c:70
The body of an email.
Definition: body.h:34
char * C_PgpDecodeCommand
Config: (pgp) External command to decode a PGP attachment.
Definition: pgpinvoke.c:54
void crypt_pgp_invoke_getkeys(struct Address *addr)
Wrapper for CryptModuleSpecs::pgp_invoke_getkeys()
Definition: cryptglue.c:277
void crypt_opportunistic_encrypt(struct Email *e)
Can all recipients be determined.
Definition: crypt.c:1036
bool mutt_should_hide_protected_subject(struct Email *e)
Should NeoMutt hide the protected subject?
Definition: crypt.c:1088
char * C_PgpEncryptSignCommand
Config: (pgp) External command to encrypt and sign a message.
Definition: pgpinvoke.c:57
char * C_SmimeVerifyOpaqueCommand
Config: (smime) External command to verify a signature.
Definition: smime.c:84
char * C_SmimeSignCommand
Config: (smime) External command to sign a message.
Definition: smime.c:80
char * C_SmimePk7outCommand
Config: (smime) External command to extract a public certificate.
Definition: smime.c:79
char * C_PgpExportCommand
Config: (pgp) External command to export a public key from the user&#39;s keyring.
Definition: pgpinvoke.c:58
char * C_SmimeGetCertCommand
Config: (smime) External command to extract a certificate from a message.
Definition: smime.c:74
SecurityFlags mutt_is_multipart_signed(struct Body *b)
Is a message signed?
Definition: crypt.c:418
int crypt_smime_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:533
void crypt_extract_keys_from_messages(struct Mailbox *m, struct EmailList *el)
Extract keys from a message.
Definition: crypt.c:859
unsigned char C_PgpEncryptSelf
Deprecated, see C_PgpSelfEncrypt.
Definition: crypt.c:68
int crypt_get_keys(struct Email *e, char **keylist, bool oppenc_mode)
Check we have all the keys we need.
Definition: crypt.c:958
int mutt_signed_handler(struct Body *a, struct State *s)
Verify a "multipart/signed" body - Implements handler_t.
Definition: crypt.c:1128
A mailbox.
Definition: mailbox.h:81
bool C_SmimeAskCertLabel
Config: Prompt the user for a label for SMIME certificates.
Definition: smime.c:68
char * C_PgpVerifyCommand
Config: (pgp) External command to verify PGP signatures.
Definition: pgpinvoke.c:64
void crypt_cleanup(void)
Clean up backend.
Definition: cryptglue.c:143
struct Regex * C_PgpDecryptionOkay
Config: Text indicating a successful decryption.
Definition: pgp.c:71
uint16_t KeyFlags
Flags describing PGP/SMIME keys, e.g. KEYFLAG_CANSIGN.
Definition: lib.h:172
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
char * C_SmimeVerifyCommand
Config: (smime) External command to verify a signed message.
Definition: smime.c:83
char * C_SmimeCaLocation
Config: File containing trusted certificates.
Definition: smime.c:69
char * C_SmimeKeys
Config: File containing user&#39;s private certificates.
Definition: smime.c:78
bool C_PgpStrictEnc
Config: Encode PGP signed messages with quoted-printable (don&#39;t unset)
Definition: crypt.c:72
bool crypt_has_module_backend(SecurityFlags type)
Is there a crypto backend for a given type?
Definition: cryptglue.c:172
bool C_PgpRetainableSigs
Config: Create nested multipart/signed or encrypted messages.
Definition: crypt.c:70
char * C_PgpImportCommand
Config: (pgp) External command to import a key into the user&#39;s keyring.
Definition: pgpinvoke.c:60
int crypt_pgp_send_menu(struct Email *e)
Wrapper for CryptModuleSpecs::send_menu()
Definition: cryptglue.c:387
bool C_PgpCheckExit
Config: Check the exit code of PGP subprocess.
Definition: pgp.c:69
SecurityFlags mutt_is_application_smime(struct Body *m)
Does the message use S/MIME?
Definition: crypt.c:624
long C_PgpTimeout
Config: Time in seconds to cache a passphrase.
Definition: pgp.c:73
bool C_PgpUseGpgAgent
Config: Use a PGP agent for caching passwords.
Definition: pgp.c:74
Cached regular expression.
Definition: regex3.h:88
bool C_PgpSelfEncrypt
Config: Encrypted messages will also be encrypted to C_PgpDefaultKey too.
Definition: crypt.c:71
bool C_SmimeSelfEncrypt
Config: Encrypted messages will also be encrypt to C_SmimeDefaultKey too.
Definition: crypt.c:74
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
Definition: crypt.c:104
char * C_SmimeImportCertCommand
Config: (smime) External command to import a certificate.
Definition: smime.c:77
Keep track when processing files.
Definition: state.h:44
unsigned char C_PgpMimeAuto
Config: Prompt the user to use MIME if inline PGP fails.
Definition: crypt.c:69
char * C_PgpDecryptCommand
Config: (pgp) External command to decrypt a PGP message.
Definition: pgpinvoke.c:55
int crypt_smime_verify_sender(struct Mailbox *m, struct Email *e)
Wrapper for CryptModuleSpecs::smime_verify_sender()
Definition: cryptglue.c:469
bool C_SmimeDecryptUseDefaultKey
Config: Use the default key for decryption.
Definition: smime.c:72
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:436
void pgp_gpgme_init(void)
Implements CryptModuleSpecs::init()
Definition: crypt_gpgme.c:5577
int mutt_is_valid_multipart_pgp_encrypted(struct Body *b)
Is this a valid multi-part encrypted message?
Definition: crypt.c:483
int mutt_protect(struct Email *e, char *keylist, bool postpone)
Encrypt and/or sign a message.
Definition: crypt.c:171
long C_SmimeTimeout
Config: Time in seconds to cache a passphrase.
Definition: smime.c:82
char * C_SmimeSignDigestAlg
Config: Digest algorithm.
Definition: smime.c:81
int mutt_gpgme_select_secret_key(struct Buffer *keyid)
Select a private Autocrypt key for a new account.
Definition: crypt_gpgme.c:5389
int crypt_pgp_application_handler(struct Body *m, struct State *s)
Wrapper for CryptModuleSpecs::application_handler()
Definition: cryptglue.c:239
void crypt_pgp_extract_key_from_attachment(FILE *fp, struct Body *top)
Wrapper for CryptModuleSpecs::pgp_extract_key_from_attachment()
Definition: cryptglue.c:398
The header of an Email.
Definition: envelope.h:54
bool C_PgpCheckGpgDecryptStatusFd
Config: File descriptor used for status info.
Definition: pgp.c:70
int crypt_pgp_encrypted_handler(struct Body *a, struct State *s)
Wrapper for CryptModuleSpecs::encrypted_handler()
Definition: cryptglue.c:252
void crypt_init(void)
Initialise the crypto backends.
Definition: cryptglue.c:98
void crypt_invoke_message(SecurityFlags type)
Display an informative message.
Definition: cryptglue.c:158