2
0

opt.h 15 KB

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