NeoMutt  2022-04-29-81-g9c5a59
Teaching an old dog new tricks
DOXYGEN
config.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stddef.h>
31 #include <config/lib.h>
32 #include <stdbool.h>
33 #include "mutt/lib.h"
34 
38 const struct Mapping SortKeyMethods[] = {
39  // clang-format off
40  { "address", SORT_ADDRESS },
41  { "date", SORT_DATE },
42  { "keyid", SORT_KEYID },
43  { "trust", SORT_TRUST },
44  { NULL, 0 },
45  // clang-format on
46 };
47 
48 static struct ConfigDef NcryptVars[] = {
49  // clang-format off
50  { "crypt_confirm_hook", DT_BOOL, true, 0, NULL,
51  "Prompt the user to confirm keys before use"
52  },
53  { "crypt_opportunistic_encrypt", DT_BOOL, false, 0, NULL,
54  "Enable encryption when the recipient's key is available"
55  },
56  { "crypt_opportunistic_encrypt_strong_keys", DT_BOOL, false, 0, NULL,
57  "Enable encryption only when strong a key is available"
58  },
59  { "crypt_protected_headers_read", DT_BOOL, true, 0, NULL,
60  "Display protected headers (Memory Hole) in the pager"
61  },
62  { "crypt_protected_headers_subject", DT_STRING, IP "...", 0, NULL,
63  "Use this as the subject for encrypted emails"
64  },
65  { "crypt_protected_headers_write", DT_BOOL, false, 0, NULL,
66  "Generate protected header (Memory Hole) for signed and encrypted emails"
67  },
68  { "crypt_timestamp", DT_BOOL, true, 0, NULL,
69  "Add a timestamp to PGP or SMIME output to prevent spoofing"
70  },
71  { "envelope_from_address", DT_ADDRESS, 0, 0, NULL,
72  "Manually set the sender for outgoing messages"
73  },
74  { "pgp_auto_inline", DT_BOOL, false, 0, NULL,
75  "Use old-style inline PGP messages (not recommended)"
76  },
77  { "pgp_default_key", DT_STRING, 0, 0, NULL,
78  "Default key to use for PGP operations"
79  },
80  { "pgp_entry_format", DT_STRING|DT_NOT_EMPTY, IP "%4n %t%f %4l/0x%k %-4a %2c %u", 0, NULL,
81  "printf-like format string for the PGP key selection menu"
82  },
83  { "pgp_ignore_subkeys", DT_BOOL, true, 0, NULL,
84  "Only use the principal PGP key"
85  },
86  { "pgp_long_ids", DT_BOOL, true, 0, NULL,
87  "Display long PGP key IDs to the user"
88  },
89  { "pgp_mime_auto", DT_QUAD, MUTT_ASKYES, 0, NULL,
90  "Prompt the user to use MIME if inline PGP fails"
91  },
92  { "pgp_retainable_sigs", DT_BOOL, false, 0, NULL,
93  "Create nested multipart/signed or encrypted messages"
94  },
95  { "pgp_self_encrypt", DT_BOOL, true, 0, NULL,
96  "Encrypted messages will also be encrypted to $pgp_default_key too"
97  },
98  { "pgp_show_unusable", DT_BOOL, true, 0, NULL,
99  "Show non-usable keys in the key selection"
100  },
101  { "pgp_sign_as", DT_STRING, 0, 0, NULL,
102  "Use this alternative key for signing messages"
103  },
104  { "pgp_sort_keys", DT_SORT|DT_SORT_REVERSE, SORT_ADDRESS, IP SortKeyMethods, NULL,
105  "Sort order for PGP keys"
106  },
107  { "pgp_strict_enc", DT_BOOL, true, 0, NULL,
108  "Encode PGP signed messages with quoted-printable (don't unset)"
109  },
110  { "smime_default_key", DT_STRING, 0, 0, NULL,
111  "Default key for SMIME operations"
112  },
113  { "smime_encrypt_with", DT_STRING, IP "aes256", 0, NULL,
114  "Algorithm for encryption"
115  },
116  { "smime_self_encrypt", DT_BOOL, true, 0, NULL,
117  "Encrypted messages will also be encrypt to $smime_default_key too"
118  },
119  { "smime_sign_as", DT_STRING, 0, 0, NULL,
120  "Use this alternative key for signing messages"
121  },
122  { "smime_is_default", DT_BOOL, false, 0, NULL,
123  "Use SMIME rather than PGP by default"
124  },
125  { "pgp_auto_decode", DT_BOOL, false, 0, NULL,
126  "Automatically decrypt PGP messages"
127  },
128  { "crypt_verify_sig", DT_QUAD, MUTT_YES, 0, NULL,
129  "Verify PGP or SMIME signatures"
130  },
131  { "crypt_protected_headers_save", DT_BOOL, false, 0, NULL,
132  "Save the cleartext Subject with the headers"
133  },
134 
135  { "crypt_confirmhook", DT_SYNONYM, IP "crypt_confirm_hook", IP "2021-02-11" },
136  { "pgp_autoinline", DT_SYNONYM, IP "pgp_auto_inline", IP "2021-02-11" },
137  { "pgp_create_traditional", DT_SYNONYM, IP "pgp_auto_inline", IP "2004-04-12" },
138  { "pgp_self_encrypt_as", DT_SYNONYM, IP "pgp_default_key", IP "2018-01-11" },
139  { "pgp_verify_sig", DT_SYNONYM, IP "crypt_verify_sig", IP "2002-01-24" },
140  { "smime_self_encrypt_as", DT_SYNONYM, IP "smime_default_key", IP "2018-01-11" },
141 
142  { "pgp_encrypt_self", DT_DEPRECATED|DT_QUAD, MUTT_NO, IP "2019-09-09" },
143  { "smime_encrypt_self", DT_DEPRECATED|DT_QUAD, MUTT_NO, IP "2019-09-09" },
144 
145  { NULL },
146  // clang-format on
147 };
148 
149 #if defined(CRYPT_BACKEND_GPGME)
150 static struct ConfigDef NcryptVarsGpgme[] = {
151  // clang-format off
152  { "crypt_use_gpgme", DT_BOOL, true, 0, NULL,
153  "Use GPGME crypto backend"
154  },
155  { "crypt_use_pka", DT_BOOL, false, 0, NULL,
156  "Use GPGME to use PKA (lookup PGP keys using DNS)"
157  },
158  { NULL },
159  // clang-format on
160 };
161 #endif
162 
163 #if defined(CRYPT_BACKEND_CLASSIC_PGP)
164 static struct ConfigDef NcryptVarsPgp[] = {
165  // clang-format off
166  { "pgp_check_exit", DT_BOOL, true, 0, NULL,
167  "Check the exit code of PGP subprocess"
168  },
169  { "pgp_check_gpg_decrypt_status_fd", DT_BOOL, true, 0, NULL,
170  "File descriptor used for status info"
171  },
172  { "pgp_clear_sign_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
173  "(pgp) External command to inline-sign a message"
174  },
175  { "pgp_decode_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
176  "(pgp) External command to decode a PGP attachment"
177  },
178  { "pgp_decrypt_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
179  "(pgp) External command to decrypt a PGP message"
180  },
181  { "pgp_decryption_okay", DT_REGEX, 0, 0, NULL,
182  "Text indicating a successful decryption"
183  },
184  { "pgp_encrypt_only_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
185  "(pgp) External command to encrypt, but not sign a message"
186  },
187  { "pgp_encrypt_sign_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
188  "(pgp) External command to encrypt and sign a message"
189  },
190  { "pgp_export_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
191  "(pgp) External command to export a public key from the user's keyring"
192  },
193  { "pgp_get_keys_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
194  "(pgp) External command to download a key for an email address"
195  },
196  { "pgp_good_sign", DT_REGEX, 0, 0, NULL,
197  "Text indicating a good signature"
198  },
199  { "pgp_import_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
200  "(pgp) External command to import a key into the user's keyring"
201  },
202  { "pgp_list_pubring_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
203  "(pgp) External command to list the public keys in a user's keyring"
204  },
205  { "pgp_list_secring_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
206  "(pgp) External command to list the private keys in a user's keyring"
207  },
208  { "pgp_sign_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
209  "(pgp) External command to create a detached PGP signature"
210  },
211  { "pgp_timeout", DT_LONG|DT_NOT_NEGATIVE, 300, 0, NULL,
212  "Time in seconds to cache a passphrase"
213  },
214  { "pgp_use_gpg_agent", DT_BOOL, true, 0, NULL,
215  "Use a PGP agent for caching passwords"
216  },
217  { "pgp_verify_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
218  "(pgp) External command to verify PGP signatures"
219  },
220  { "pgp_verify_key_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
221  "(pgp) External command to verify key information"
222  },
223  { "pgp_clearsign_command", DT_SYNONYM, IP "pgp_clear_sign_command", IP "2021-02-11" },
224  { "pgp_getkeys_command", DT_SYNONYM, IP "pgp_get_keys_command", IP "2021-02-11" },
225  { NULL },
226  // clang-format on
227 };
228 #endif
229 
230 #if defined(CRYPT_BACKEND_CLASSIC_SMIME)
231 static struct ConfigDef NcryptVarsSmime[] = {
232  // clang-format off
233  { "smime_ask_cert_label", DT_BOOL, true, 0, NULL,
234  "Prompt the user for a label for SMIME certificates"
235  },
236  { "smime_ca_location", DT_PATH|DT_PATH_FILE, 0, 0, NULL,
237  "File containing trusted certificates"
238  },
239  { "smime_certificates", DT_PATH|DT_PATH_DIR, 0, 0, NULL,
240  "File containing user's public certificates"
241  },
242  { "smime_decrypt_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
243  "(smime) External command to decrypt an SMIME message"
244  },
245  { "smime_decrypt_use_default_key", DT_BOOL, true, 0, NULL,
246  "Use the default key for decryption"
247  },
248  { "smime_encrypt_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
249  "(smime) External command to encrypt a message"
250  },
251  { "smime_get_cert_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
252  "(smime) External command to extract a certificate from a message"
253  },
254  { "smime_get_cert_email_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
255  "(smime) External command to get a certificate for an email"
256  },
257  { "smime_get_signer_cert_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
258  "(smime) External command to extract a certificate from an email"
259  },
260  { "smime_import_cert_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
261  "(smime) External command to import a certificate"
262  },
263  { "smime_keys", DT_PATH|DT_PATH_DIR, 0, 0, NULL,
264  "File containing user's private certificates"
265  },
266  { "smime_pk7out_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
267  "(smime) External command to extract a public certificate"
268  },
269  { "smime_sign_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
270  "(smime) External command to sign a message"
271  },
272  { "smime_sign_digest_alg", DT_STRING, IP "sha256", 0, NULL,
273  "Digest algorithm"
274  },
275  { "smime_timeout", DT_NUMBER|DT_NOT_NEGATIVE, 300, 0, NULL,
276  "Time in seconds to cache a passphrase"
277  },
278  { "smime_verify_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
279  "(smime) External command to verify a signed message"
280  },
281  { "smime_verify_opaque_command", DT_STRING|DT_COMMAND, 0, 0, NULL,
282  "(smime) External command to verify a signature"
283  },
284  { NULL },
285  // clang-format on
286 };
287 #endif
288 
293 {
294  bool rc = cs_register_variables(cs, NcryptVars, 0);
295 
296 #if defined(CRYPT_BACKEND_GPGME)
298 #endif
299 
300 #if defined(CRYPT_BACKEND_CLASSIC_PGP)
301  rc |= cs_register_variables(cs, NcryptVarsPgp, 0);
302 #endif
303 
304 #if defined(CRYPT_BACKEND_CLASSIC_SMIME)
306 #endif
307 
308  return rc;
309 }
Convenience wrapper for the config headers.
bool config_init_ncrypt(struct ConfigSet *cs)
Register ncrypt config variables - Implements module_init_config_t -.
Definition: config.c:292
Convenience wrapper for the library headers.
static struct ConfigDef NcryptVarsPgp[]
Definition: config.c:164
static struct ConfigDef NcryptVarsSmime[]
Definition: config.c:231
const struct Mapping SortKeyMethods[]
Sort methods for encryption keys.
Definition: config.c:38
static struct ConfigDef NcryptVars[]
Definition: config.c:48
static struct ConfigDef NcryptVarsGpgme[]
Definition: config.c:150
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:38
@ MUTT_ASKYES
Ask the user, defaulting to 'Yes'.
Definition: quad.h:41
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
bool cs_register_variables(const struct ConfigSet *cs, struct ConfigDef vars[], uint32_t flags)
Register a set of config items.
Definition: set.c:276
#define IP
Definition: set.h:54
#define DT_SORT_REVERSE
Sort flag for -reverse prefix.
Definition: sort2.h:36
@ SORT_TRUST
Sort by encryption key's trust level.
Definition: sort2.h:56
@ SORT_KEYID
Sort by the encryption key's ID.
Definition: sort2.h:55
@ SORT_DATE
Sort by the date the email was sent.
Definition: sort2.h:43
@ SORT_ADDRESS
Sort by email address.
Definition: sort2.h:54
Definition: set.h:64
Container for lots of config items.
Definition: set.h:260
Mapping between user-readable string and a constant.
Definition: mapping.h:32
#define DT_SORT
sorting methods
Definition: types.h:40
#define DT_QUAD
quad-option (no/yes/ask-no/ask-yes)
Definition: types.h:37
#define DT_LONG
a number (long)
Definition: types.h:33
#define DT_BOOL
boolean option
Definition: types.h:30
#define DT_PATH_DIR
Path is a directory.
Definition: types.h:53
#define DT_DEPRECATED
Config item shouldn't be used any more.
Definition: types.h:77
#define DT_PATH_FILE
Path is a file.
Definition: types.h:54
#define DT_PATH
a path to a file/directory
Definition: types.h:36
#define DT_NOT_EMPTY
Empty strings are not allowed.
Definition: types.h:46
#define DT_STRING
a string
Definition: types.h:41
#define DT_COMMAND
A command.
Definition: types.h:50
#define DT_SYNONYM
synonym for another variable
Definition: types.h:42
#define DT_NOT_NEGATIVE
Negative numbers are not allowed.
Definition: types.h:47
#define DT_ADDRESS
e-mail address
Definition: types.h:29
#define DT_REGEX
regular expressions
Definition: types.h:38
#define DT_NUMBER
a number
Definition: types.h:35