Add SSL_OP_ALLOW_CLIENT_RENEGOTIATION
[openssl.git] / apps / include / opt.h
1 /*
2  * Copyright 2018-2021 The OpenSSL Project Authors. All Rights Reserved.
3  *
4  * Licensed under the Apache License 2.0 (the "License").  You may not use
5  * this file except in compliance with the License.  You can obtain a copy
6  * in the file LICENSE in the source distribution or at
7  * https://www.openssl.org/source/license.html
8  */
9 #ifndef OSSL_APPS_OPT_H
10 #define OSSL_APPS_OPT_H
11
12 #include <sys/types.h>
13 #include <openssl/e_os2.h>
14 #include <openssl/types.h>
15 #include <stdarg.h>
16
17 #define OPT_COMMON OPT_ERR = -1, OPT_EOF = 0, OPT_HELP
18
19 /*
20  * Common verification options.
21  */
22 # define OPT_V_ENUM \
23         OPT_V__FIRST=2000, \
24         OPT_V_POLICY, OPT_V_PURPOSE, OPT_V_VERIFY_NAME, OPT_V_VERIFY_DEPTH, \
25         OPT_V_ATTIME, OPT_V_VERIFY_HOSTNAME, OPT_V_VERIFY_EMAIL, \
26         OPT_V_VERIFY_IP, OPT_V_IGNORE_CRITICAL, OPT_V_ISSUER_CHECKS, \
27         OPT_V_CRL_CHECK, OPT_V_CRL_CHECK_ALL, OPT_V_POLICY_CHECK, \
28         OPT_V_EXPLICIT_POLICY, OPT_V_INHIBIT_ANY, OPT_V_INHIBIT_MAP, \
29         OPT_V_X509_STRICT, OPT_V_EXTENDED_CRL, OPT_V_USE_DELTAS, \
30         OPT_V_POLICY_PRINT, OPT_V_CHECK_SS_SIG, OPT_V_TRUSTED_FIRST, \
31         OPT_V_SUITEB_128_ONLY, OPT_V_SUITEB_128, OPT_V_SUITEB_192, \
32         OPT_V_PARTIAL_CHAIN, OPT_V_NO_ALT_CHAINS, OPT_V_NO_CHECK_TIME, \
33         OPT_V_VERIFY_AUTH_LEVEL, OPT_V_ALLOW_PROXY_CERTS, \
34         OPT_V__LAST
35
36 # define OPT_V_OPTIONS \
37         OPT_SECTION("Validation"), \
38         { "policy", OPT_V_POLICY, 's', "adds policy to the acceptable policy set"}, \
39         { "purpose", OPT_V_PURPOSE, 's', \
40             "certificate chain purpose"}, \
41         { "verify_name", OPT_V_VERIFY_NAME, 's', "verification policy name"}, \
42         { "verify_depth", OPT_V_VERIFY_DEPTH, 'n', \
43             "chain depth limit" }, \
44         { "auth_level", OPT_V_VERIFY_AUTH_LEVEL, 'n', \
45             "chain authentication security level" }, \
46         { "attime", OPT_V_ATTIME, 'M', "verification epoch time" }, \
47         { "verify_hostname", OPT_V_VERIFY_HOSTNAME, 's', \
48             "expected peer hostname" }, \
49         { "verify_email", OPT_V_VERIFY_EMAIL, 's', \
50             "expected peer email" }, \
51         { "verify_ip", OPT_V_VERIFY_IP, 's', \
52             "expected peer IP address" }, \
53         { "ignore_critical", OPT_V_IGNORE_CRITICAL, '-', \
54             "permit unhandled critical extensions"}, \
55         { "issuer_checks", OPT_V_ISSUER_CHECKS, '-', "(deprecated)"}, \
56         { "crl_check", OPT_V_CRL_CHECK, '-', "check leaf certificate revocation" }, \
57         { "crl_check_all", OPT_V_CRL_CHECK_ALL, '-', "check full chain revocation" }, \
58         { "policy_check", OPT_V_POLICY_CHECK, '-', "perform rfc5280 policy checks"}, \
59         { "explicit_policy", OPT_V_EXPLICIT_POLICY, '-', \
60             "set policy variable require-explicit-policy"}, \
61         { "inhibit_any", OPT_V_INHIBIT_ANY, '-', \
62             "set policy variable inhibit-any-policy"}, \
63         { "inhibit_map", OPT_V_INHIBIT_MAP, '-', \
64             "set policy variable inhibit-policy-mapping"}, \
65         { "x509_strict", OPT_V_X509_STRICT, '-', \
66             "disable certificate compatibility work-arounds"}, \
67         { "extended_crl", OPT_V_EXTENDED_CRL, '-', \
68             "enable extended CRL features"}, \
69         { "use_deltas", OPT_V_USE_DELTAS, '-', \
70             "use delta CRLs"}, \
71         { "policy_print", OPT_V_POLICY_PRINT, '-', \
72             "print policy processing diagnostics"}, \
73         { "check_ss_sig", OPT_V_CHECK_SS_SIG, '-', \
74             "check root CA self-signatures"}, \
75         { "trusted_first", OPT_V_TRUSTED_FIRST, '-', \
76             "search trust store first (default)" }, \
77         { "suiteB_128_only", OPT_V_SUITEB_128_ONLY, '-', "Suite B 128-bit-only mode"}, \
78         { "suiteB_128", OPT_V_SUITEB_128, '-', \
79             "Suite B 128-bit mode allowing 192-bit algorithms"}, \
80         { "suiteB_192", OPT_V_SUITEB_192, '-', "Suite B 192-bit-only mode" }, \
81         { "partial_chain", OPT_V_PARTIAL_CHAIN, '-', \
82             "accept chains anchored by intermediate trust-store CAs"}, \
83         { "no_alt_chains", OPT_V_NO_ALT_CHAINS, '-', "(deprecated)" }, \
84         { "no_check_time", OPT_V_NO_CHECK_TIME, '-', "ignore certificate validity time" }, \
85         { "allow_proxy_certs", OPT_V_ALLOW_PROXY_CERTS, '-', "allow the use of proxy certificates" }
86
87 # define OPT_V_CASES \
88         OPT_V__FIRST: case OPT_V__LAST: break; \
89         case OPT_V_POLICY: \
90         case OPT_V_PURPOSE: \
91         case OPT_V_VERIFY_NAME: \
92         case OPT_V_VERIFY_DEPTH: \
93         case OPT_V_VERIFY_AUTH_LEVEL: \
94         case OPT_V_ATTIME: \
95         case OPT_V_VERIFY_HOSTNAME: \
96         case OPT_V_VERIFY_EMAIL: \
97         case OPT_V_VERIFY_IP: \
98         case OPT_V_IGNORE_CRITICAL: \
99         case OPT_V_ISSUER_CHECKS: \
100         case OPT_V_CRL_CHECK: \
101         case OPT_V_CRL_CHECK_ALL: \
102         case OPT_V_POLICY_CHECK: \
103         case OPT_V_EXPLICIT_POLICY: \
104         case OPT_V_INHIBIT_ANY: \
105         case OPT_V_INHIBIT_MAP: \
106         case OPT_V_X509_STRICT: \
107         case OPT_V_EXTENDED_CRL: \
108         case OPT_V_USE_DELTAS: \
109         case OPT_V_POLICY_PRINT: \
110         case OPT_V_CHECK_SS_SIG: \
111         case OPT_V_TRUSTED_FIRST: \
112         case OPT_V_SUITEB_128_ONLY: \
113         case OPT_V_SUITEB_128: \
114         case OPT_V_SUITEB_192: \
115         case OPT_V_PARTIAL_CHAIN: \
116         case OPT_V_NO_ALT_CHAINS: \
117         case OPT_V_NO_CHECK_TIME: \
118         case OPT_V_ALLOW_PROXY_CERTS
119
120 /*
121  * Common "extended validation" options.
122  */
123 # define OPT_X_ENUM \
124         OPT_X__FIRST=1000, \
125         OPT_X_KEY, OPT_X_CERT, OPT_X_CHAIN, OPT_X_CHAIN_BUILD, \
126         OPT_X_CERTFORM, OPT_X_KEYFORM, \
127         OPT_X__LAST
128
129 # define OPT_X_OPTIONS \
130         OPT_SECTION("Extended certificate"), \
131         { "xkey", OPT_X_KEY, '<', "key for Extended certificates"}, \
132         { "xcert", OPT_X_CERT, '<', "cert for Extended certificates"}, \
133         { "xchain", OPT_X_CHAIN, '<', "chain for Extended certificates"}, \
134         { "xchain_build", OPT_X_CHAIN_BUILD, '-', \
135             "build certificate chain for the extended certificates"}, \
136         { "xcertform", OPT_X_CERTFORM, 'F', \
137             "format of Extended certificate (PEM/DER/P12); has no effect" }, \
138         { "xkeyform", OPT_X_KEYFORM, 'F', \
139             "format of Extended certificate's key (DER/PEM/P12); has no effect"}
140
141 # define OPT_X_CASES \
142         OPT_X__FIRST: case OPT_X__LAST: break; \
143         case OPT_X_KEY: \
144         case OPT_X_CERT: \
145         case OPT_X_CHAIN: \
146         case OPT_X_CHAIN_BUILD: \
147         case OPT_X_CERTFORM: \
148         case OPT_X_KEYFORM
149
150 /*
151  * Common SSL options.
152  * Any changes here must be coordinated with ../ssl/ssl_conf.c
153  */
154 # define OPT_S_ENUM \
155         OPT_S__FIRST=3000, \
156         OPT_S_NOSSL3, OPT_S_NOTLS1, OPT_S_NOTLS1_1, OPT_S_NOTLS1_2, \
157         OPT_S_NOTLS1_3, OPT_S_BUGS, OPT_S_NO_COMP, OPT_S_NOTICKET, \
158         OPT_S_SERVERPREF, OPT_S_LEGACYRENEG, OPT_S_CLIENTRENEG, \
159         OPT_S_LEGACYCONN, \
160         OPT_S_ONRESUMP, OPT_S_NOLEGACYCONN, OPT_S_ALLOW_NO_DHE_KEX, \
161         OPT_S_PRIORITIZE_CHACHA, \
162         OPT_S_STRICT, OPT_S_SIGALGS, OPT_S_CLIENTSIGALGS, OPT_S_GROUPS, \
163         OPT_S_CURVES, OPT_S_NAMEDCURVE, OPT_S_CIPHER, OPT_S_CIPHERSUITES, \
164         OPT_S_RECORD_PADDING, OPT_S_DEBUGBROKE, OPT_S_COMP, \
165         OPT_S_MINPROTO, OPT_S_MAXPROTO, OPT_S_IMMEDIATE_RENEG, \
166         OPT_S_NO_RENEGOTIATION, OPT_S_NO_MIDDLEBOX, OPT_S__LAST
167
168 # define OPT_S_OPTIONS \
169         OPT_SECTION("TLS/SSL"), \
170         {"no_ssl3", OPT_S_NOSSL3, '-',"Just disable SSLv3" }, \
171         {"no_tls1", OPT_S_NOTLS1, '-', "Just disable TLSv1"}, \
172         {"no_tls1_1", OPT_S_NOTLS1_1, '-', "Just disable TLSv1.1" }, \
173         {"no_tls1_2", OPT_S_NOTLS1_2, '-', "Just disable TLSv1.2"}, \
174         {"no_tls1_3", OPT_S_NOTLS1_3, '-', "Just disable TLSv1.3"}, \
175         {"bugs", OPT_S_BUGS, '-', "Turn on SSL bug compatibility"}, \
176         {"no_comp", OPT_S_NO_COMP, '-', "Disable SSL/TLS compression (default)" }, \
177         {"comp", OPT_S_COMP, '-', "Use SSL/TLS-level compression" }, \
178         {"no_ticket", OPT_S_NOTICKET, '-', \
179             "Disable use of TLS session tickets"}, \
180         {"serverpref", OPT_S_SERVERPREF, '-', "Use server's cipher preferences"}, \
181         {"legacy_renegotiation", OPT_S_LEGACYRENEG, '-', \
182             "Enable use of legacy renegotiation (dangerous)"}, \
183         {"client_renegotiation", OPT_S_CLIENTRENEG, '-', \
184             "Allow client-initiated renegotiation" }, \
185         {"no_renegotiation", OPT_S_NO_RENEGOTIATION, '-', \
186             "Disable all renegotiation."}, \
187         {"legacy_server_connect", OPT_S_LEGACYCONN, '-', \
188             "Allow initial connection to servers that don't support RI"}, \
189         {"no_resumption_on_reneg", OPT_S_ONRESUMP, '-', \
190             "Disallow session resumption on renegotiation"}, \
191         {"no_legacy_server_connect", OPT_S_NOLEGACYCONN, '-', \
192             "Disallow initial connection to servers that don't support RI"}, \
193         {"allow_no_dhe_kex", OPT_S_ALLOW_NO_DHE_KEX, '-', \
194             "In TLSv1.3 allow non-(ec)dhe based key exchange on resumption"}, \
195         {"prioritize_chacha", OPT_S_PRIORITIZE_CHACHA, '-', \
196             "Prioritize ChaCha ciphers when preferred by clients"}, \
197         {"strict", OPT_S_STRICT, '-', \
198             "Enforce strict certificate checks as per TLS standard"}, \
199         {"sigalgs", OPT_S_SIGALGS, 's', \
200             "Signature algorithms to support (colon-separated list)" }, \
201         {"client_sigalgs", OPT_S_CLIENTSIGALGS, 's', \
202             "Signature algorithms to support for client certificate" \
203             " authentication (colon-separated list)" }, \
204         {"groups", OPT_S_GROUPS, 's', \
205             "Groups to advertise (colon-separated list)" }, \
206         {"curves", OPT_S_CURVES, 's', \
207             "Groups to advertise (colon-separated list)" }, \
208         {"named_curve", OPT_S_NAMEDCURVE, 's', \
209             "Elliptic curve used for ECDHE (server-side only)" }, \
210         {"cipher", OPT_S_CIPHER, 's', "Specify TLSv1.2 and below cipher list to be used"}, \
211         {"ciphersuites", OPT_S_CIPHERSUITES, 's', "Specify TLSv1.3 ciphersuites to be used"}, \
212         {"min_protocol", OPT_S_MINPROTO, 's', "Specify the minimum protocol version to be used"}, \
213         {"max_protocol", OPT_S_MAXPROTO, 's', "Specify the maximum protocol version to be used"}, \
214         {"immediate_renegotiation", OPT_S_IMMEDIATE_RENEG, '-', \
215             "Immediately attempt renegotiation"}, \
216         {"record_padding", OPT_S_RECORD_PADDING, 's', \
217             "Block size to pad TLS 1.3 records to."}, \
218         {"debug_broken_protocol", OPT_S_DEBUGBROKE, '-', \
219             "Perform all sorts of protocol violations for testing purposes"}, \
220         {"no_middlebox", OPT_S_NO_MIDDLEBOX, '-', \
221             "Disable TLSv1.3 middlebox compat mode" }
222
223 # define OPT_S_CASES \
224         OPT_S__FIRST: case OPT_S__LAST: break; \
225         case OPT_S_NOSSL3: \
226         case OPT_S_NOTLS1: \
227         case OPT_S_NOTLS1_1: \
228         case OPT_S_NOTLS1_2: \
229         case OPT_S_NOTLS1_3: \
230         case OPT_S_BUGS: \
231         case OPT_S_NO_COMP: \
232         case OPT_S_COMP: \
233         case OPT_S_NOTICKET: \
234         case OPT_S_SERVERPREF: \
235         case OPT_S_LEGACYRENEG: \
236         case OPT_S_CLIENTRENEG: \
237         case OPT_S_LEGACYCONN: \
238         case OPT_S_ONRESUMP: \
239         case OPT_S_NOLEGACYCONN: \
240         case OPT_S_ALLOW_NO_DHE_KEX: \
241         case OPT_S_PRIORITIZE_CHACHA: \
242         case OPT_S_STRICT: \
243         case OPT_S_SIGALGS: \
244         case OPT_S_CLIENTSIGALGS: \
245         case OPT_S_GROUPS: \
246         case OPT_S_CURVES: \
247         case OPT_S_NAMEDCURVE: \
248         case OPT_S_CIPHER: \
249         case OPT_S_CIPHERSUITES: \
250         case OPT_S_RECORD_PADDING: \
251         case OPT_S_NO_RENEGOTIATION: \
252         case OPT_S_MINPROTO: \
253         case OPT_S_MAXPROTO: \
254         case OPT_S_DEBUGBROKE: \
255         case OPT_S_NO_MIDDLEBOX
256
257 #define IS_NO_PROT_FLAG(o) \
258  (o == OPT_S_NOSSL3 || o == OPT_S_NOTLS1 || o == OPT_S_NOTLS1_1 \
259   || o == OPT_S_NOTLS1_2 || o == OPT_S_NOTLS1_3)
260
261 /*
262  * Random state options.
263  */
264 # define OPT_R_ENUM \
265         OPT_R__FIRST=1500, OPT_R_RAND, OPT_R_WRITERAND, OPT_R__LAST
266
267 # define OPT_R_OPTIONS \
268     OPT_SECTION("Random state"), \
269     {"rand", OPT_R_RAND, 's', "Load the given file(s) into the random number generator"}, \
270     {"writerand", OPT_R_WRITERAND, '>', "Write random data to the specified file"}
271
272 # define OPT_R_CASES \
273         OPT_R__FIRST: case OPT_R__LAST: break; \
274         case OPT_R_RAND: case OPT_R_WRITERAND
275
276 /*
277  * Provider options.
278  */
279 # define OPT_PROV_ENUM \
280         OPT_PROV__FIRST=1600, \
281         OPT_PROV_PROVIDER, OPT_PROV_PROVIDER_PATH, OPT_PROV_PROPQUERY, \
282         OPT_PROV__LAST
283
284 # define OPT_CONFIG_OPTION \
285         { "config", OPT_CONFIG, '<', "Load a configuration file (this may load modules)" }
286
287 # define OPT_PROV_OPTIONS \
288         OPT_SECTION("Provider"), \
289         { "provider-path", OPT_PROV_PROVIDER_PATH, 's', "Provider load path (must be before 'provider' argument if required)" }, \
290         { "provider", OPT_PROV_PROVIDER, 's', "Provider to load (can be specified multiple times)" }, \
291         { "propquery", OPT_PROV_PROPQUERY, 's', "Property query used when fetching algorithms" }
292
293 # define OPT_PROV_CASES \
294         OPT_PROV__FIRST: case OPT_PROV__LAST: break; \
295         case OPT_PROV_PROVIDER: \
296         case OPT_PROV_PROVIDER_PATH: \
297         case OPT_PROV_PROPQUERY
298
299 /*
300  * Option parsing.
301  */
302 extern const char OPT_HELP_STR[];
303 extern const char OPT_MORE_STR[];
304 extern const char OPT_SECTION_STR[];
305 extern const char OPT_PARAM_STR[];
306
307 typedef struct options_st {
308     const char *name;
309     int retval;
310     /*
311      * value type: - no value (also the value zero), n number, p positive
312      * number, u unsigned, l long, s string, < input file, > output file,
313      * f any format, F der/pem format, E der/pem/engine format identifier.
314      * l, n and u include zero; p does not.
315      */
316     int valtype;
317     const char *helpstr;
318 } OPTIONS;
319
320 /*
321  * A string/int pairing; widely use for option value lookup, hence the
322  * name OPT_PAIR. But that name is misleading in s_cb.c, so we also use
323  * the "generic" name STRINT_PAIR.
324  */
325 typedef struct string_int_pair_st {
326     const char *name;
327     int retval;
328 } OPT_PAIR, STRINT_PAIR;
329
330 /* Flags to pass into opt_format; see FORMAT_xxx, below. */
331 # define OPT_FMT_PEMDER          (1L <<  1)
332 # define OPT_FMT_PKCS12          (1L <<  2)
333 # define OPT_FMT_SMIME           (1L <<  3)
334 # define OPT_FMT_ENGINE          (1L <<  4)
335 # define OPT_FMT_MSBLOB          (1L <<  5)
336 /* (1L <<  6) was OPT_FMT_NETSCAPE, but wasn't used */
337 # define OPT_FMT_NSS             (1L <<  7)
338 # define OPT_FMT_TEXT            (1L <<  8)
339 # define OPT_FMT_HTTP            (1L <<  9)
340 # define OPT_FMT_PVK             (1L << 10)
341 # define OPT_FMT_PDE     (OPT_FMT_PEMDER | OPT_FMT_ENGINE)
342 # define OPT_FMT_PDS     (OPT_FMT_PEMDER | OPT_FMT_SMIME)
343 # define OPT_FMT_ANY     ( \
344         OPT_FMT_PEMDER | OPT_FMT_PKCS12 | OPT_FMT_SMIME | \
345         OPT_FMT_ENGINE | OPT_FMT_MSBLOB | OPT_FMT_NSS   | \
346         OPT_FMT_TEXT   | OPT_FMT_HTTP   | OPT_FMT_PVK)
347
348 /* Divide options into sections when displaying usage */
349 #define OPT_SECTION(sec) { OPT_SECTION_STR, 1, '-', sec " options:\n" }
350 #define OPT_PARAMETERS() { OPT_PARAM_STR, 1, '-', "Parameters:\n" }
351
352 const char *opt_path_end(const char *filename);
353 char *opt_init(int ac, char **av, const OPTIONS * o);
354 char *opt_progname(const char *argv0);
355 char *opt_appname(const char *argv0);
356 char *opt_getprog(void);
357 void opt_help(const OPTIONS * list);
358
359 void opt_begin(void);
360 int opt_next(void);
361 char *opt_flag(void);
362 char *opt_arg(void);
363 char *opt_unknown(void);
364 int opt_cipher(const char *name, EVP_CIPHER **cipherp);
365 int opt_cipher_silent(const char *name, EVP_CIPHER **cipherp);
366 int opt_md(const char *name, EVP_MD **mdp);
367 int opt_md_silent(const char *name, EVP_MD **mdp);
368
369 int opt_int(const char *arg, int *result);
370 int opt_int_arg(void);
371 int opt_long(const char *arg, long *result);
372 int opt_ulong(const char *arg, unsigned long *result);
373 #if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L && \
374     defined(INTMAX_MAX) && defined(UINTMAX_MAX) && \
375     !defined(OPENSSL_NO_INTTYPES_H)
376 int opt_intmax(const char *arg, intmax_t *result);
377 int opt_uintmax(const char *arg, uintmax_t *result);
378 #else
379 # define opt_intmax opt_long
380 # define opt_uintmax opt_ulong
381 # define intmax_t long
382 # define uintmax_t unsigned long
383 #endif
384
385 int opt_isdir(const char *name);
386 int opt_format(const char *s, unsigned long flags, int *result);
387 void print_format_error(int format, unsigned long flags);
388 int opt_printf_stderr(const char *fmt, ...);
389 int opt_string(const char *name, const char **options);
390 int opt_pair(const char *arg, const OPT_PAIR * pairs, int *result);
391
392 int opt_verify(int i, X509_VERIFY_PARAM *vpm);
393 int opt_rand(int i);
394 int opt_provider(int i);
395
396 char **opt_rest(void);
397 int opt_num_rest(void);
398
399 #endif /* OSSL_APPS_OPT_H */