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