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