ssl_conf.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. /*
  2. * Copyright 2012-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. #include <stdio.h>
  10. #include "ssl_local.h"
  11. #include <openssl/conf.h>
  12. #include <openssl/objects.h>
  13. #include <openssl/dh.h>
  14. #include "internal/nelem.h"
  15. DEFINE_STACK_OF(X509_NAME)
  16. /*
  17. * structure holding name tables. This is used for permitted elements in lists
  18. * such as TLSv1.
  19. */
  20. typedef struct {
  21. const char *name;
  22. int namelen;
  23. unsigned int name_flags;
  24. unsigned long option_value;
  25. } ssl_flag_tbl;
  26. /* Switch table: use for single command line switches like no_tls2 */
  27. typedef struct {
  28. unsigned long option_value;
  29. unsigned int name_flags;
  30. } ssl_switch_tbl;
  31. /* Sense of name is inverted e.g. "TLSv1" will clear SSL_OP_NO_TLSv1 */
  32. #define SSL_TFLAG_INV 0x1
  33. /* Mask for type of flag referred to */
  34. #define SSL_TFLAG_TYPE_MASK 0xf00
  35. /* Flag is for options */
  36. #define SSL_TFLAG_OPTION 0x000
  37. /* Flag is for cert_flags */
  38. #define SSL_TFLAG_CERT 0x100
  39. /* Flag is for verify mode */
  40. #define SSL_TFLAG_VFY 0x200
  41. /* Option can only be used for clients */
  42. #define SSL_TFLAG_CLIENT SSL_CONF_FLAG_CLIENT
  43. /* Option can only be used for servers */
  44. #define SSL_TFLAG_SERVER SSL_CONF_FLAG_SERVER
  45. #define SSL_TFLAG_BOTH (SSL_TFLAG_CLIENT|SSL_TFLAG_SERVER)
  46. #define SSL_FLAG_TBL(str, flag) \
  47. {str, (int)(sizeof(str) - 1), SSL_TFLAG_BOTH, flag}
  48. #define SSL_FLAG_TBL_SRV(str, flag) \
  49. {str, (int)(sizeof(str) - 1), SSL_TFLAG_SERVER, flag}
  50. #define SSL_FLAG_TBL_CLI(str, flag) \
  51. {str, (int)(sizeof(str) - 1), SSL_TFLAG_CLIENT, flag}
  52. #define SSL_FLAG_TBL_INV(str, flag) \
  53. {str, (int)(sizeof(str) - 1), SSL_TFLAG_INV|SSL_TFLAG_BOTH, flag}
  54. #define SSL_FLAG_TBL_SRV_INV(str, flag) \
  55. {str, (int)(sizeof(str) - 1), SSL_TFLAG_INV|SSL_TFLAG_SERVER, flag}
  56. #define SSL_FLAG_TBL_CERT(str, flag) \
  57. {str, (int)(sizeof(str) - 1), SSL_TFLAG_CERT|SSL_TFLAG_BOTH, flag}
  58. #define SSL_FLAG_VFY_CLI(str, flag) \
  59. {str, (int)(sizeof(str) - 1), SSL_TFLAG_VFY | SSL_TFLAG_CLIENT, flag}
  60. #define SSL_FLAG_VFY_SRV(str, flag) \
  61. {str, (int)(sizeof(str) - 1), SSL_TFLAG_VFY | SSL_TFLAG_SERVER, flag}
  62. /*
  63. * Opaque structure containing SSL configuration context.
  64. */
  65. struct ssl_conf_ctx_st {
  66. /*
  67. * Various flags indicating (among other things) which options we will
  68. * recognise.
  69. */
  70. unsigned int flags;
  71. /* Prefix and length of commands */
  72. char *prefix;
  73. size_t prefixlen;
  74. /* SSL_CTX or SSL structure to perform operations on */
  75. SSL_CTX *ctx;
  76. SSL *ssl;
  77. /* Pointer to SSL or SSL_CTX options field or NULL if none */
  78. uint32_t *poptions;
  79. /* Certificate filenames for each type */
  80. char *cert_filename[SSL_PKEY_NUM];
  81. /* Pointer to SSL or SSL_CTX cert_flags or NULL if none */
  82. uint32_t *pcert_flags;
  83. /* Pointer to SSL or SSL_CTX verify_mode or NULL if none */
  84. uint32_t *pvfy_flags;
  85. /* Pointer to SSL or SSL_CTX min_version field or NULL if none */
  86. int *min_version;
  87. /* Pointer to SSL or SSL_CTX max_version field or NULL if none */
  88. int *max_version;
  89. /* Current flag table being worked on */
  90. const ssl_flag_tbl *tbl;
  91. /* Size of table */
  92. size_t ntbl;
  93. /* Client CA names */
  94. STACK_OF(X509_NAME) *canames;
  95. };
  96. static void ssl_set_option(SSL_CONF_CTX *cctx, unsigned int name_flags,
  97. unsigned long option_value, int onoff)
  98. {
  99. uint32_t *pflags;
  100. if (cctx->poptions == NULL)
  101. return;
  102. if (name_flags & SSL_TFLAG_INV)
  103. onoff ^= 1;
  104. switch (name_flags & SSL_TFLAG_TYPE_MASK) {
  105. case SSL_TFLAG_CERT:
  106. pflags = cctx->pcert_flags;
  107. break;
  108. case SSL_TFLAG_VFY:
  109. pflags = cctx->pvfy_flags;
  110. break;
  111. case SSL_TFLAG_OPTION:
  112. pflags = cctx->poptions;
  113. break;
  114. default:
  115. return;
  116. }
  117. if (onoff)
  118. *pflags |= option_value;
  119. else
  120. *pflags &= ~option_value;
  121. }
  122. static int ssl_match_option(SSL_CONF_CTX *cctx, const ssl_flag_tbl *tbl,
  123. const char *name, int namelen, int onoff)
  124. {
  125. /* If name not relevant for context skip */
  126. if (!(cctx->flags & tbl->name_flags & SSL_TFLAG_BOTH))
  127. return 0;
  128. if (namelen == -1) {
  129. if (strcmp(tbl->name, name))
  130. return 0;
  131. } else if (tbl->namelen != namelen || strncasecmp(tbl->name, name, namelen))
  132. return 0;
  133. ssl_set_option(cctx, tbl->name_flags, tbl->option_value, onoff);
  134. return 1;
  135. }
  136. static int ssl_set_option_list(const char *elem, int len, void *usr)
  137. {
  138. SSL_CONF_CTX *cctx = usr;
  139. size_t i;
  140. const ssl_flag_tbl *tbl;
  141. int onoff = 1;
  142. /*
  143. * len == -1 indicates not being called in list context, just for single
  144. * command line switches, so don't allow +, -.
  145. */
  146. if (elem == NULL)
  147. return 0;
  148. if (len != -1) {
  149. if (*elem == '+') {
  150. elem++;
  151. len--;
  152. onoff = 1;
  153. } else if (*elem == '-') {
  154. elem++;
  155. len--;
  156. onoff = 0;
  157. }
  158. }
  159. for (i = 0, tbl = cctx->tbl; i < cctx->ntbl; i++, tbl++) {
  160. if (ssl_match_option(cctx, tbl, elem, len, onoff))
  161. return 1;
  162. }
  163. return 0;
  164. }
  165. /* Set supported signature algorithms */
  166. static int cmd_SignatureAlgorithms(SSL_CONF_CTX *cctx, const char *value)
  167. {
  168. int rv;
  169. if (cctx->ssl)
  170. rv = SSL_set1_sigalgs_list(cctx->ssl, value);
  171. /* NB: ctx == NULL performs syntax checking only */
  172. else
  173. rv = SSL_CTX_set1_sigalgs_list(cctx->ctx, value);
  174. return rv > 0;
  175. }
  176. /* Set supported client signature algorithms */
  177. static int cmd_ClientSignatureAlgorithms(SSL_CONF_CTX *cctx, const char *value)
  178. {
  179. int rv;
  180. if (cctx->ssl)
  181. rv = SSL_set1_client_sigalgs_list(cctx->ssl, value);
  182. /* NB: ctx == NULL performs syntax checking only */
  183. else
  184. rv = SSL_CTX_set1_client_sigalgs_list(cctx->ctx, value);
  185. return rv > 0;
  186. }
  187. static int cmd_Groups(SSL_CONF_CTX *cctx, const char *value)
  188. {
  189. int rv;
  190. if (cctx->ssl)
  191. rv = SSL_set1_groups_list(cctx->ssl, value);
  192. /* NB: ctx == NULL performs syntax checking only */
  193. else
  194. rv = SSL_CTX_set1_groups_list(cctx->ctx, value);
  195. return rv > 0;
  196. }
  197. /* This is the old name for cmd_Groups - retained for backwards compatibility */
  198. static int cmd_Curves(SSL_CONF_CTX *cctx, const char *value)
  199. {
  200. return cmd_Groups(cctx, value);
  201. }
  202. #ifndef OPENSSL_NO_EC
  203. /* ECDH temporary parameters */
  204. static int cmd_ECDHParameters(SSL_CONF_CTX *cctx, const char *value)
  205. {
  206. int rv = 1;
  207. int nid;
  208. /* Ignore values supported by 1.0.2 for the automatic selection */
  209. if ((cctx->flags & SSL_CONF_FLAG_FILE)
  210. && (strcasecmp(value, "+automatic") == 0
  211. || strcasecmp(value, "automatic") == 0))
  212. return 1;
  213. if ((cctx->flags & SSL_CONF_FLAG_CMDLINE) &&
  214. strcmp(value, "auto") == 0)
  215. return 1;
  216. nid = EC_curve_nist2nid(value);
  217. if (nid == NID_undef)
  218. nid = OBJ_sn2nid(value);
  219. if (nid == 0)
  220. return 0;
  221. if (cctx->ctx)
  222. rv = SSL_CTX_set1_groups(cctx->ctx, &nid, 1);
  223. else if (cctx->ssl)
  224. rv = SSL_set1_groups(cctx->ssl, &nid, 1);
  225. return rv > 0;
  226. }
  227. #endif
  228. static int cmd_CipherString(SSL_CONF_CTX *cctx, const char *value)
  229. {
  230. int rv = 1;
  231. if (cctx->ctx)
  232. rv = SSL_CTX_set_cipher_list(cctx->ctx, value);
  233. if (cctx->ssl)
  234. rv = SSL_set_cipher_list(cctx->ssl, value);
  235. return rv > 0;
  236. }
  237. static int cmd_Ciphersuites(SSL_CONF_CTX *cctx, const char *value)
  238. {
  239. int rv = 1;
  240. if (cctx->ctx)
  241. rv = SSL_CTX_set_ciphersuites(cctx->ctx, value);
  242. if (cctx->ssl)
  243. rv = SSL_set_ciphersuites(cctx->ssl, value);
  244. return rv > 0;
  245. }
  246. static int cmd_Protocol(SSL_CONF_CTX *cctx, const char *value)
  247. {
  248. static const ssl_flag_tbl ssl_protocol_list[] = {
  249. SSL_FLAG_TBL_INV("ALL", SSL_OP_NO_SSL_MASK),
  250. SSL_FLAG_TBL_INV("SSLv2", SSL_OP_NO_SSLv2),
  251. SSL_FLAG_TBL_INV("SSLv3", SSL_OP_NO_SSLv3),
  252. SSL_FLAG_TBL_INV("TLSv1", SSL_OP_NO_TLSv1),
  253. SSL_FLAG_TBL_INV("TLSv1.1", SSL_OP_NO_TLSv1_1),
  254. SSL_FLAG_TBL_INV("TLSv1.2", SSL_OP_NO_TLSv1_2),
  255. SSL_FLAG_TBL_INV("TLSv1.3", SSL_OP_NO_TLSv1_3),
  256. SSL_FLAG_TBL_INV("DTLSv1", SSL_OP_NO_DTLSv1),
  257. SSL_FLAG_TBL_INV("DTLSv1.2", SSL_OP_NO_DTLSv1_2)
  258. };
  259. cctx->tbl = ssl_protocol_list;
  260. cctx->ntbl = OSSL_NELEM(ssl_protocol_list);
  261. return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx);
  262. }
  263. /*
  264. * protocol_from_string - converts a protocol version string to a number
  265. *
  266. * Returns -1 on failure or the version on success
  267. */
  268. static int protocol_from_string(const char *value)
  269. {
  270. struct protocol_versions {
  271. const char *name;
  272. int version;
  273. };
  274. static const struct protocol_versions versions[] = {
  275. {"None", 0},
  276. {"SSLv3", SSL3_VERSION},
  277. {"TLSv1", TLS1_VERSION},
  278. {"TLSv1.1", TLS1_1_VERSION},
  279. {"TLSv1.2", TLS1_2_VERSION},
  280. {"TLSv1.3", TLS1_3_VERSION},
  281. {"DTLSv1", DTLS1_VERSION},
  282. {"DTLSv1.2", DTLS1_2_VERSION}
  283. };
  284. size_t i;
  285. size_t n = OSSL_NELEM(versions);
  286. for (i = 0; i < n; i++)
  287. if (strcmp(versions[i].name, value) == 0)
  288. return versions[i].version;
  289. return -1;
  290. }
  291. static int min_max_proto(SSL_CONF_CTX *cctx, const char *value, int *bound)
  292. {
  293. int method_version;
  294. int new_version;
  295. if (cctx->ctx != NULL)
  296. method_version = cctx->ctx->method->version;
  297. else if (cctx->ssl != NULL)
  298. method_version = cctx->ssl->ctx->method->version;
  299. else
  300. return 0;
  301. if ((new_version = protocol_from_string(value)) < 0)
  302. return 0;
  303. return ssl_set_version_bound(method_version, new_version, bound);
  304. }
  305. /*
  306. * cmd_MinProtocol - Set min protocol version
  307. * @cctx: config structure to save settings in
  308. * @value: The min protocol version in string form
  309. *
  310. * Returns 1 on success and 0 on failure.
  311. */
  312. static int cmd_MinProtocol(SSL_CONF_CTX *cctx, const char *value)
  313. {
  314. return min_max_proto(cctx, value, cctx->min_version);
  315. }
  316. /*
  317. * cmd_MaxProtocol - Set max protocol version
  318. * @cctx: config structure to save settings in
  319. * @value: The max protocol version in string form
  320. *
  321. * Returns 1 on success and 0 on failure.
  322. */
  323. static int cmd_MaxProtocol(SSL_CONF_CTX *cctx, const char *value)
  324. {
  325. return min_max_proto(cctx, value, cctx->max_version);
  326. }
  327. static int cmd_Options(SSL_CONF_CTX *cctx, const char *value)
  328. {
  329. static const ssl_flag_tbl ssl_option_list[] = {
  330. SSL_FLAG_TBL_INV("SessionTicket", SSL_OP_NO_TICKET),
  331. SSL_FLAG_TBL_INV("EmptyFragments",
  332. SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS),
  333. SSL_FLAG_TBL("Bugs", SSL_OP_ALL),
  334. SSL_FLAG_TBL_INV("Compression", SSL_OP_NO_COMPRESSION),
  335. SSL_FLAG_TBL_SRV("ServerPreference", SSL_OP_CIPHER_SERVER_PREFERENCE),
  336. SSL_FLAG_TBL_SRV("NoResumptionOnRenegotiation",
  337. SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION),
  338. SSL_FLAG_TBL_SRV("DHSingle", SSL_OP_SINGLE_DH_USE),
  339. SSL_FLAG_TBL_SRV("ECDHSingle", SSL_OP_SINGLE_ECDH_USE),
  340. SSL_FLAG_TBL("UnsafeLegacyRenegotiation",
  341. SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION),
  342. SSL_FLAG_TBL_INV("EncryptThenMac", SSL_OP_NO_ENCRYPT_THEN_MAC),
  343. SSL_FLAG_TBL("NoRenegotiation", SSL_OP_NO_RENEGOTIATION),
  344. SSL_FLAG_TBL("AllowNoDHEKEX", SSL_OP_ALLOW_NO_DHE_KEX),
  345. SSL_FLAG_TBL("PrioritizeChaCha", SSL_OP_PRIORITIZE_CHACHA),
  346. SSL_FLAG_TBL("MiddleboxCompat", SSL_OP_ENABLE_MIDDLEBOX_COMPAT),
  347. SSL_FLAG_TBL_INV("AntiReplay", SSL_OP_NO_ANTI_REPLAY),
  348. SSL_FLAG_TBL_INV("ExtendedMasterSecret", SSL_OP_NO_EXTENDED_MASTER_SECRET),
  349. SSL_FLAG_TBL_INV("CANames", SSL_OP_DISABLE_TLSEXT_CA_NAMES)
  350. };
  351. if (value == NULL)
  352. return -3;
  353. cctx->tbl = ssl_option_list;
  354. cctx->ntbl = OSSL_NELEM(ssl_option_list);
  355. return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx);
  356. }
  357. static int cmd_VerifyMode(SSL_CONF_CTX *cctx, const char *value)
  358. {
  359. static const ssl_flag_tbl ssl_vfy_list[] = {
  360. SSL_FLAG_VFY_CLI("Peer", SSL_VERIFY_PEER),
  361. SSL_FLAG_VFY_SRV("Request", SSL_VERIFY_PEER),
  362. SSL_FLAG_VFY_SRV("Require",
  363. SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT),
  364. SSL_FLAG_VFY_SRV("Once", SSL_VERIFY_PEER | SSL_VERIFY_CLIENT_ONCE),
  365. SSL_FLAG_VFY_SRV("RequestPostHandshake",
  366. SSL_VERIFY_PEER | SSL_VERIFY_POST_HANDSHAKE),
  367. SSL_FLAG_VFY_SRV("RequirePostHandshake",
  368. SSL_VERIFY_PEER | SSL_VERIFY_POST_HANDSHAKE |
  369. SSL_VERIFY_FAIL_IF_NO_PEER_CERT),
  370. };
  371. if (value == NULL)
  372. return -3;
  373. cctx->tbl = ssl_vfy_list;
  374. cctx->ntbl = OSSL_NELEM(ssl_vfy_list);
  375. return CONF_parse_list(value, ',', 1, ssl_set_option_list, cctx);
  376. }
  377. static int cmd_Certificate(SSL_CONF_CTX *cctx, const char *value)
  378. {
  379. int rv = 1;
  380. CERT *c = NULL;
  381. if (cctx->ctx) {
  382. rv = SSL_CTX_use_certificate_chain_file(cctx->ctx, value);
  383. c = cctx->ctx->cert;
  384. }
  385. if (cctx->ssl) {
  386. rv = SSL_use_certificate_chain_file(cctx->ssl, value);
  387. c = cctx->ssl->cert;
  388. }
  389. if (rv > 0 && c && cctx->flags & SSL_CONF_FLAG_REQUIRE_PRIVATE) {
  390. char **pfilename = &cctx->cert_filename[c->key - c->pkeys];
  391. OPENSSL_free(*pfilename);
  392. *pfilename = OPENSSL_strdup(value);
  393. if (*pfilename == NULL)
  394. rv = 0;
  395. }
  396. return rv > 0;
  397. }
  398. static int cmd_PrivateKey(SSL_CONF_CTX *cctx, const char *value)
  399. {
  400. int rv = 1;
  401. if (!(cctx->flags & SSL_CONF_FLAG_CERTIFICATE))
  402. return -2;
  403. if (cctx->ctx)
  404. rv = SSL_CTX_use_PrivateKey_file(cctx->ctx, value, SSL_FILETYPE_PEM);
  405. if (cctx->ssl)
  406. rv = SSL_use_PrivateKey_file(cctx->ssl, value, SSL_FILETYPE_PEM);
  407. return rv > 0;
  408. }
  409. static int cmd_ServerInfoFile(SSL_CONF_CTX *cctx, const char *value)
  410. {
  411. int rv = 1;
  412. if (cctx->ctx)
  413. rv = SSL_CTX_use_serverinfo_file(cctx->ctx, value);
  414. return rv > 0;
  415. }
  416. static int do_store(SSL_CONF_CTX *cctx,
  417. const char *CAfile, const char *CApath, const char *CAstore,
  418. int verify_store)
  419. {
  420. CERT *cert;
  421. X509_STORE **st;
  422. if (cctx->ctx)
  423. cert = cctx->ctx->cert;
  424. else if (cctx->ssl)
  425. cert = cctx->ssl->cert;
  426. else
  427. return 1;
  428. st = verify_store ? &cert->verify_store : &cert->chain_store;
  429. if (*st == NULL) {
  430. *st = X509_STORE_new();
  431. if (*st == NULL)
  432. return 0;
  433. }
  434. if (CAfile != NULL && !X509_STORE_load_file(*st, CAfile))
  435. return 0;
  436. if (CApath != NULL && !X509_STORE_load_path(*st, CApath))
  437. return 0;
  438. if (CAstore != NULL && !X509_STORE_load_store(*st, CAstore))
  439. return 0;
  440. return 1;
  441. }
  442. static int cmd_ChainCAPath(SSL_CONF_CTX *cctx, const char *value)
  443. {
  444. return do_store(cctx, NULL, value, NULL, 0);
  445. }
  446. static int cmd_ChainCAFile(SSL_CONF_CTX *cctx, const char *value)
  447. {
  448. return do_store(cctx, value, NULL, NULL, 0);
  449. }
  450. static int cmd_ChainCAStore(SSL_CONF_CTX *cctx, const char *value)
  451. {
  452. return do_store(cctx, NULL, NULL, value, 0);
  453. }
  454. static int cmd_VerifyCAPath(SSL_CONF_CTX *cctx, const char *value)
  455. {
  456. return do_store(cctx, NULL, value, NULL, 1);
  457. }
  458. static int cmd_VerifyCAFile(SSL_CONF_CTX *cctx, const char *value)
  459. {
  460. return do_store(cctx, value, NULL, NULL, 1);
  461. }
  462. static int cmd_VerifyCAStore(SSL_CONF_CTX *cctx, const char *value)
  463. {
  464. return do_store(cctx, NULL, NULL, value, 1);
  465. }
  466. static int cmd_RequestCAFile(SSL_CONF_CTX *cctx, const char *value)
  467. {
  468. if (cctx->canames == NULL)
  469. cctx->canames = sk_X509_NAME_new_null();
  470. if (cctx->canames == NULL)
  471. return 0;
  472. return SSL_add_file_cert_subjects_to_stack(cctx->canames, value);
  473. }
  474. static int cmd_ClientCAFile(SSL_CONF_CTX *cctx, const char *value)
  475. {
  476. return cmd_RequestCAFile(cctx, value);
  477. }
  478. static int cmd_RequestCAPath(SSL_CONF_CTX *cctx, const char *value)
  479. {
  480. if (cctx->canames == NULL)
  481. cctx->canames = sk_X509_NAME_new_null();
  482. if (cctx->canames == NULL)
  483. return 0;
  484. return SSL_add_dir_cert_subjects_to_stack(cctx->canames, value);
  485. }
  486. static int cmd_ClientCAPath(SSL_CONF_CTX *cctx, const char *value)
  487. {
  488. return cmd_RequestCAPath(cctx, value);
  489. }
  490. static int cmd_RequestCAStore(SSL_CONF_CTX *cctx, const char *value)
  491. {
  492. if (cctx->canames == NULL)
  493. cctx->canames = sk_X509_NAME_new_null();
  494. if (cctx->canames == NULL)
  495. return 0;
  496. return SSL_add_store_cert_subjects_to_stack(cctx->canames, value);
  497. }
  498. static int cmd_ClientCAStore(SSL_CONF_CTX *cctx, const char *value)
  499. {
  500. return cmd_RequestCAStore(cctx, value);
  501. }
  502. #ifndef OPENSSL_NO_DH
  503. static int cmd_DHParameters(SSL_CONF_CTX *cctx, const char *value)
  504. {
  505. int rv = 0;
  506. DH *dh = NULL;
  507. BIO *in = NULL;
  508. if (cctx->ctx || cctx->ssl) {
  509. in = BIO_new(BIO_s_file());
  510. if (in == NULL)
  511. goto end;
  512. if (BIO_read_filename(in, value) <= 0)
  513. goto end;
  514. dh = PEM_read_bio_DHparams(in, NULL, NULL, NULL);
  515. if (dh == NULL)
  516. goto end;
  517. } else
  518. return 1;
  519. if (cctx->ctx)
  520. rv = SSL_CTX_set_tmp_dh(cctx->ctx, dh);
  521. if (cctx->ssl)
  522. rv = SSL_set_tmp_dh(cctx->ssl, dh);
  523. end:
  524. DH_free(dh);
  525. BIO_free(in);
  526. return rv > 0;
  527. }
  528. #endif
  529. static int cmd_RecordPadding(SSL_CONF_CTX *cctx, const char *value)
  530. {
  531. int rv = 0;
  532. int block_size = atoi(value);
  533. /*
  534. * All we care about is a non-negative value,
  535. * the setters check the range
  536. */
  537. if (block_size >= 0) {
  538. if (cctx->ctx)
  539. rv = SSL_CTX_set_block_padding(cctx->ctx, block_size);
  540. if (cctx->ssl)
  541. rv = SSL_set_block_padding(cctx->ssl, block_size);
  542. }
  543. return rv;
  544. }
  545. static int cmd_NumTickets(SSL_CONF_CTX *cctx, const char *value)
  546. {
  547. int rv = 0;
  548. int num_tickets = atoi(value);
  549. if (num_tickets >= 0) {
  550. if (cctx->ctx)
  551. rv = SSL_CTX_set_num_tickets(cctx->ctx, num_tickets);
  552. if (cctx->ssl)
  553. rv = SSL_set_num_tickets(cctx->ssl, num_tickets);
  554. }
  555. return rv;
  556. }
  557. typedef struct {
  558. int (*cmd) (SSL_CONF_CTX *cctx, const char *value);
  559. const char *str_file;
  560. const char *str_cmdline;
  561. unsigned short flags;
  562. unsigned short value_type;
  563. } ssl_conf_cmd_tbl;
  564. /* Table of supported parameters */
  565. #define SSL_CONF_CMD(name, cmdopt, flags, type) \
  566. {cmd_##name, #name, cmdopt, flags, type}
  567. #define SSL_CONF_CMD_STRING(name, cmdopt, flags) \
  568. SSL_CONF_CMD(name, cmdopt, flags, SSL_CONF_TYPE_STRING)
  569. #define SSL_CONF_CMD_SWITCH(name, flags) \
  570. {0, NULL, name, flags, SSL_CONF_TYPE_NONE}
  571. /* See apps/apps.h if you change this table. */
  572. static const ssl_conf_cmd_tbl ssl_conf_cmds[] = {
  573. SSL_CONF_CMD_SWITCH("no_ssl3", 0),
  574. SSL_CONF_CMD_SWITCH("no_tls1", 0),
  575. SSL_CONF_CMD_SWITCH("no_tls1_1", 0),
  576. SSL_CONF_CMD_SWITCH("no_tls1_2", 0),
  577. SSL_CONF_CMD_SWITCH("no_tls1_3", 0),
  578. SSL_CONF_CMD_SWITCH("bugs", 0),
  579. SSL_CONF_CMD_SWITCH("no_comp", 0),
  580. SSL_CONF_CMD_SWITCH("comp", 0),
  581. SSL_CONF_CMD_SWITCH("ecdh_single", SSL_CONF_FLAG_SERVER),
  582. SSL_CONF_CMD_SWITCH("no_ticket", 0),
  583. SSL_CONF_CMD_SWITCH("serverpref", SSL_CONF_FLAG_SERVER),
  584. SSL_CONF_CMD_SWITCH("legacy_renegotiation", 0),
  585. SSL_CONF_CMD_SWITCH("legacy_server_connect", SSL_CONF_FLAG_SERVER),
  586. SSL_CONF_CMD_SWITCH("no_renegotiation", 0),
  587. SSL_CONF_CMD_SWITCH("no_resumption_on_reneg", SSL_CONF_FLAG_SERVER),
  588. SSL_CONF_CMD_SWITCH("no_legacy_server_connect", SSL_CONF_FLAG_SERVER),
  589. SSL_CONF_CMD_SWITCH("allow_no_dhe_kex", 0),
  590. SSL_CONF_CMD_SWITCH("prioritize_chacha", SSL_CONF_FLAG_SERVER),
  591. SSL_CONF_CMD_SWITCH("strict", 0),
  592. SSL_CONF_CMD_SWITCH("no_middlebox", 0),
  593. SSL_CONF_CMD_SWITCH("anti_replay", SSL_CONF_FLAG_SERVER),
  594. SSL_CONF_CMD_SWITCH("no_anti_replay", SSL_CONF_FLAG_SERVER),
  595. SSL_CONF_CMD_STRING(SignatureAlgorithms, "sigalgs", 0),
  596. SSL_CONF_CMD_STRING(ClientSignatureAlgorithms, "client_sigalgs", 0),
  597. SSL_CONF_CMD_STRING(Curves, "curves", 0),
  598. SSL_CONF_CMD_STRING(Groups, "groups", 0),
  599. #ifndef OPENSSL_NO_EC
  600. SSL_CONF_CMD_STRING(ECDHParameters, "named_curve", SSL_CONF_FLAG_SERVER),
  601. #endif
  602. SSL_CONF_CMD_STRING(CipherString, "cipher", 0),
  603. SSL_CONF_CMD_STRING(Ciphersuites, "ciphersuites", 0),
  604. SSL_CONF_CMD_STRING(Protocol, NULL, 0),
  605. SSL_CONF_CMD_STRING(MinProtocol, "min_protocol", 0),
  606. SSL_CONF_CMD_STRING(MaxProtocol, "max_protocol", 0),
  607. SSL_CONF_CMD_STRING(Options, NULL, 0),
  608. SSL_CONF_CMD_STRING(VerifyMode, NULL, 0),
  609. SSL_CONF_CMD(Certificate, "cert", SSL_CONF_FLAG_CERTIFICATE,
  610. SSL_CONF_TYPE_FILE),
  611. SSL_CONF_CMD(PrivateKey, "key", SSL_CONF_FLAG_CERTIFICATE,
  612. SSL_CONF_TYPE_FILE),
  613. SSL_CONF_CMD(ServerInfoFile, NULL,
  614. SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CERTIFICATE,
  615. SSL_CONF_TYPE_FILE),
  616. SSL_CONF_CMD(ChainCAPath, "chainCApath", SSL_CONF_FLAG_CERTIFICATE,
  617. SSL_CONF_TYPE_DIR),
  618. SSL_CONF_CMD(ChainCAFile, "chainCAfile", SSL_CONF_FLAG_CERTIFICATE,
  619. SSL_CONF_TYPE_FILE),
  620. SSL_CONF_CMD(ChainCAStore, "chainCAstore", SSL_CONF_FLAG_CERTIFICATE,
  621. SSL_CONF_TYPE_STORE),
  622. SSL_CONF_CMD(VerifyCAPath, "verifyCApath", SSL_CONF_FLAG_CERTIFICATE,
  623. SSL_CONF_TYPE_DIR),
  624. SSL_CONF_CMD(VerifyCAFile, "verifyCAfile", SSL_CONF_FLAG_CERTIFICATE,
  625. SSL_CONF_TYPE_FILE),
  626. SSL_CONF_CMD(VerifyCAStore, "verifyCAstore", SSL_CONF_FLAG_CERTIFICATE,
  627. SSL_CONF_TYPE_STORE),
  628. SSL_CONF_CMD(RequestCAFile, "requestCAFile", SSL_CONF_FLAG_CERTIFICATE,
  629. SSL_CONF_TYPE_FILE),
  630. SSL_CONF_CMD(ClientCAFile, NULL,
  631. SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CERTIFICATE,
  632. SSL_CONF_TYPE_FILE),
  633. SSL_CONF_CMD(RequestCAPath, NULL, SSL_CONF_FLAG_CERTIFICATE,
  634. SSL_CONF_TYPE_DIR),
  635. SSL_CONF_CMD(ClientCAPath, NULL,
  636. SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CERTIFICATE,
  637. SSL_CONF_TYPE_DIR),
  638. SSL_CONF_CMD(RequestCAStore, "requestCAStore", SSL_CONF_FLAG_CERTIFICATE,
  639. SSL_CONF_TYPE_STORE),
  640. SSL_CONF_CMD(ClientCAStore, NULL,
  641. SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CERTIFICATE,
  642. SSL_CONF_TYPE_STORE),
  643. #ifndef OPENSSL_NO_DH
  644. SSL_CONF_CMD(DHParameters, "dhparam",
  645. SSL_CONF_FLAG_SERVER | SSL_CONF_FLAG_CERTIFICATE,
  646. SSL_CONF_TYPE_FILE),
  647. #endif
  648. SSL_CONF_CMD_STRING(RecordPadding, "record_padding", 0),
  649. SSL_CONF_CMD_STRING(NumTickets, "num_tickets", SSL_CONF_FLAG_SERVER),
  650. };
  651. /* Supported switches: must match order of switches in ssl_conf_cmds */
  652. static const ssl_switch_tbl ssl_cmd_switches[] = {
  653. {SSL_OP_NO_SSLv3, 0}, /* no_ssl3 */
  654. {SSL_OP_NO_TLSv1, 0}, /* no_tls1 */
  655. {SSL_OP_NO_TLSv1_1, 0}, /* no_tls1_1 */
  656. {SSL_OP_NO_TLSv1_2, 0}, /* no_tls1_2 */
  657. {SSL_OP_NO_TLSv1_3, 0}, /* no_tls1_3 */
  658. {SSL_OP_ALL, 0}, /* bugs */
  659. {SSL_OP_NO_COMPRESSION, 0}, /* no_comp */
  660. {SSL_OP_NO_COMPRESSION, SSL_TFLAG_INV}, /* comp */
  661. {SSL_OP_SINGLE_ECDH_USE, 0}, /* ecdh_single */
  662. {SSL_OP_NO_TICKET, 0}, /* no_ticket */
  663. {SSL_OP_CIPHER_SERVER_PREFERENCE, 0}, /* serverpref */
  664. /* legacy_renegotiation */
  665. {SSL_OP_ALLOW_UNSAFE_LEGACY_RENEGOTIATION, 0},
  666. /* legacy_server_connect */
  667. {SSL_OP_LEGACY_SERVER_CONNECT, 0},
  668. /* no_renegotiation */
  669. {SSL_OP_NO_RENEGOTIATION, 0},
  670. /* no_resumption_on_reneg */
  671. {SSL_OP_NO_SESSION_RESUMPTION_ON_RENEGOTIATION, 0},
  672. /* no_legacy_server_connect */
  673. {SSL_OP_LEGACY_SERVER_CONNECT, SSL_TFLAG_INV},
  674. /* allow_no_dhe_kex */
  675. {SSL_OP_ALLOW_NO_DHE_KEX, 0},
  676. /* chacha reprioritization */
  677. {SSL_OP_PRIORITIZE_CHACHA, 0},
  678. {SSL_CERT_FLAG_TLS_STRICT, SSL_TFLAG_CERT}, /* strict */
  679. /* no_middlebox */
  680. {SSL_OP_ENABLE_MIDDLEBOX_COMPAT, SSL_TFLAG_INV},
  681. /* anti_replay */
  682. {SSL_OP_NO_ANTI_REPLAY, SSL_TFLAG_INV},
  683. /* no_anti_replay */
  684. {SSL_OP_NO_ANTI_REPLAY, 0},
  685. };
  686. static int ssl_conf_cmd_skip_prefix(SSL_CONF_CTX *cctx, const char **pcmd)
  687. {
  688. if (pcmd == NULL || *pcmd == NULL)
  689. return 0;
  690. /* If a prefix is set, check and skip */
  691. if (cctx->prefix) {
  692. if (strlen(*pcmd) <= cctx->prefixlen)
  693. return 0;
  694. if (cctx->flags & SSL_CONF_FLAG_CMDLINE &&
  695. strncmp(*pcmd, cctx->prefix, cctx->prefixlen))
  696. return 0;
  697. if (cctx->flags & SSL_CONF_FLAG_FILE &&
  698. strncasecmp(*pcmd, cctx->prefix, cctx->prefixlen))
  699. return 0;
  700. *pcmd += cctx->prefixlen;
  701. } else if (cctx->flags & SSL_CONF_FLAG_CMDLINE) {
  702. if (**pcmd != '-' || !(*pcmd)[1])
  703. return 0;
  704. *pcmd += 1;
  705. }
  706. return 1;
  707. }
  708. /* Determine if a command is allowed according to cctx flags */
  709. static int ssl_conf_cmd_allowed(SSL_CONF_CTX *cctx, const ssl_conf_cmd_tbl * t)
  710. {
  711. unsigned int tfl = t->flags;
  712. unsigned int cfl = cctx->flags;
  713. if ((tfl & SSL_CONF_FLAG_SERVER) && !(cfl & SSL_CONF_FLAG_SERVER))
  714. return 0;
  715. if ((tfl & SSL_CONF_FLAG_CLIENT) && !(cfl & SSL_CONF_FLAG_CLIENT))
  716. return 0;
  717. if ((tfl & SSL_CONF_FLAG_CERTIFICATE)
  718. && !(cfl & SSL_CONF_FLAG_CERTIFICATE))
  719. return 0;
  720. return 1;
  721. }
  722. static const ssl_conf_cmd_tbl *ssl_conf_cmd_lookup(SSL_CONF_CTX *cctx,
  723. const char *cmd)
  724. {
  725. const ssl_conf_cmd_tbl *t;
  726. size_t i;
  727. if (cmd == NULL)
  728. return NULL;
  729. /* Look for matching parameter name in table */
  730. for (i = 0, t = ssl_conf_cmds; i < OSSL_NELEM(ssl_conf_cmds); i++, t++) {
  731. if (ssl_conf_cmd_allowed(cctx, t)) {
  732. if (cctx->flags & SSL_CONF_FLAG_CMDLINE) {
  733. if (t->str_cmdline && strcmp(t->str_cmdline, cmd) == 0)
  734. return t;
  735. }
  736. if (cctx->flags & SSL_CONF_FLAG_FILE) {
  737. if (t->str_file && strcasecmp(t->str_file, cmd) == 0)
  738. return t;
  739. }
  740. }
  741. }
  742. return NULL;
  743. }
  744. static int ctrl_switch_option(SSL_CONF_CTX *cctx, const ssl_conf_cmd_tbl * cmd)
  745. {
  746. /* Find index of command in table */
  747. size_t idx = cmd - ssl_conf_cmds;
  748. const ssl_switch_tbl *scmd;
  749. /* Sanity check index */
  750. if (idx >= OSSL_NELEM(ssl_cmd_switches))
  751. return 0;
  752. /* Obtain switches entry with same index */
  753. scmd = ssl_cmd_switches + idx;
  754. ssl_set_option(cctx, scmd->name_flags, scmd->option_value, 1);
  755. return 1;
  756. }
  757. int SSL_CONF_cmd(SSL_CONF_CTX *cctx, const char *cmd, const char *value)
  758. {
  759. const ssl_conf_cmd_tbl *runcmd;
  760. if (cmd == NULL) {
  761. SSLerr(SSL_F_SSL_CONF_CMD, SSL_R_INVALID_NULL_CMD_NAME);
  762. return 0;
  763. }
  764. if (!ssl_conf_cmd_skip_prefix(cctx, &cmd))
  765. return -2;
  766. runcmd = ssl_conf_cmd_lookup(cctx, cmd);
  767. if (runcmd) {
  768. int rv;
  769. if (runcmd->value_type == SSL_CONF_TYPE_NONE) {
  770. return ctrl_switch_option(cctx, runcmd);
  771. }
  772. if (value == NULL)
  773. return -3;
  774. rv = runcmd->cmd(cctx, value);
  775. if (rv > 0)
  776. return 2;
  777. if (rv == -2)
  778. return -2;
  779. if (cctx->flags & SSL_CONF_FLAG_SHOW_ERRORS) {
  780. SSLerr(SSL_F_SSL_CONF_CMD, SSL_R_BAD_VALUE);
  781. ERR_add_error_data(4, "cmd=", cmd, ", value=", value);
  782. }
  783. return 0;
  784. }
  785. if (cctx->flags & SSL_CONF_FLAG_SHOW_ERRORS) {
  786. SSLerr(SSL_F_SSL_CONF_CMD, SSL_R_UNKNOWN_CMD_NAME);
  787. ERR_add_error_data(2, "cmd=", cmd);
  788. }
  789. return -2;
  790. }
  791. int SSL_CONF_cmd_argv(SSL_CONF_CTX *cctx, int *pargc, char ***pargv)
  792. {
  793. int rv;
  794. const char *arg = NULL, *argn;
  795. if (pargc != NULL && *pargc == 0)
  796. return 0;
  797. if (pargc == NULL || *pargc > 0)
  798. arg = **pargv;
  799. if (arg == NULL)
  800. return 0;
  801. if (pargc == NULL || *pargc > 1)
  802. argn = (*pargv)[1];
  803. else
  804. argn = NULL;
  805. cctx->flags &= ~SSL_CONF_FLAG_FILE;
  806. cctx->flags |= SSL_CONF_FLAG_CMDLINE;
  807. rv = SSL_CONF_cmd(cctx, arg, argn);
  808. if (rv > 0) {
  809. /* Success: update pargc, pargv */
  810. (*pargv) += rv;
  811. if (pargc)
  812. (*pargc) -= rv;
  813. return rv;
  814. }
  815. /* Unknown switch: indicate no arguments processed */
  816. if (rv == -2)
  817. return 0;
  818. /* Some error occurred processing command, return fatal error */
  819. if (rv == 0)
  820. return -1;
  821. return rv;
  822. }
  823. int SSL_CONF_cmd_value_type(SSL_CONF_CTX *cctx, const char *cmd)
  824. {
  825. if (ssl_conf_cmd_skip_prefix(cctx, &cmd)) {
  826. const ssl_conf_cmd_tbl *runcmd;
  827. runcmd = ssl_conf_cmd_lookup(cctx, cmd);
  828. if (runcmd)
  829. return runcmd->value_type;
  830. }
  831. return SSL_CONF_TYPE_UNKNOWN;
  832. }
  833. SSL_CONF_CTX *SSL_CONF_CTX_new(void)
  834. {
  835. SSL_CONF_CTX *ret = OPENSSL_zalloc(sizeof(*ret));
  836. return ret;
  837. }
  838. int SSL_CONF_CTX_finish(SSL_CONF_CTX *cctx)
  839. {
  840. /* See if any certificates are missing private keys */
  841. size_t i;
  842. CERT *c = NULL;
  843. if (cctx->ctx)
  844. c = cctx->ctx->cert;
  845. else if (cctx->ssl)
  846. c = cctx->ssl->cert;
  847. if (c && cctx->flags & SSL_CONF_FLAG_REQUIRE_PRIVATE) {
  848. for (i = 0; i < SSL_PKEY_NUM; i++) {
  849. const char *p = cctx->cert_filename[i];
  850. /*
  851. * If missing private key try to load one from certificate file
  852. */
  853. if (p && !c->pkeys[i].privatekey) {
  854. if (!cmd_PrivateKey(cctx, p))
  855. return 0;
  856. }
  857. }
  858. }
  859. if (cctx->canames) {
  860. if (cctx->ssl)
  861. SSL_set0_CA_list(cctx->ssl, cctx->canames);
  862. else if (cctx->ctx)
  863. SSL_CTX_set0_CA_list(cctx->ctx, cctx->canames);
  864. else
  865. sk_X509_NAME_pop_free(cctx->canames, X509_NAME_free);
  866. cctx->canames = NULL;
  867. }
  868. return 1;
  869. }
  870. void SSL_CONF_CTX_free(SSL_CONF_CTX *cctx)
  871. {
  872. if (cctx) {
  873. size_t i;
  874. for (i = 0; i < SSL_PKEY_NUM; i++)
  875. OPENSSL_free(cctx->cert_filename[i]);
  876. OPENSSL_free(cctx->prefix);
  877. sk_X509_NAME_pop_free(cctx->canames, X509_NAME_free);
  878. OPENSSL_free(cctx);
  879. }
  880. }
  881. unsigned int SSL_CONF_CTX_set_flags(SSL_CONF_CTX *cctx, unsigned int flags)
  882. {
  883. cctx->flags |= flags;
  884. return cctx->flags;
  885. }
  886. unsigned int SSL_CONF_CTX_clear_flags(SSL_CONF_CTX *cctx, unsigned int flags)
  887. {
  888. cctx->flags &= ~flags;
  889. return cctx->flags;
  890. }
  891. int SSL_CONF_CTX_set1_prefix(SSL_CONF_CTX *cctx, const char *pre)
  892. {
  893. char *tmp = NULL;
  894. if (pre) {
  895. tmp = OPENSSL_strdup(pre);
  896. if (tmp == NULL)
  897. return 0;
  898. }
  899. OPENSSL_free(cctx->prefix);
  900. cctx->prefix = tmp;
  901. if (tmp)
  902. cctx->prefixlen = strlen(tmp);
  903. else
  904. cctx->prefixlen = 0;
  905. return 1;
  906. }
  907. void SSL_CONF_CTX_set_ssl(SSL_CONF_CTX *cctx, SSL *ssl)
  908. {
  909. cctx->ssl = ssl;
  910. cctx->ctx = NULL;
  911. if (ssl) {
  912. cctx->poptions = &ssl->options;
  913. cctx->min_version = &ssl->min_proto_version;
  914. cctx->max_version = &ssl->max_proto_version;
  915. cctx->pcert_flags = &ssl->cert->cert_flags;
  916. cctx->pvfy_flags = &ssl->verify_mode;
  917. } else {
  918. cctx->poptions = NULL;
  919. cctx->min_version = NULL;
  920. cctx->max_version = NULL;
  921. cctx->pcert_flags = NULL;
  922. cctx->pvfy_flags = NULL;
  923. }
  924. }
  925. void SSL_CONF_CTX_set_ssl_ctx(SSL_CONF_CTX *cctx, SSL_CTX *ctx)
  926. {
  927. cctx->ctx = ctx;
  928. cctx->ssl = NULL;
  929. if (ctx) {
  930. cctx->poptions = &ctx->options;
  931. cctx->min_version = &ctx->min_proto_version;
  932. cctx->max_version = &ctx->max_proto_version;
  933. cctx->pcert_flags = &ctx->cert->cert_flags;
  934. cctx->pvfy_flags = &ctx->verify_mode;
  935. } else {
  936. cctx->poptions = NULL;
  937. cctx->min_version = NULL;
  938. cctx->max_version = NULL;
  939. cctx->pcert_flags = NULL;
  940. cctx->pvfy_flags = NULL;
  941. }
  942. }