2
0

opt.h 16 KB

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