x509_vpm.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662
  1. /* x509_vpm.c */
  2. /*
  3. * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL project
  4. * 2004.
  5. */
  6. /* ====================================================================
  7. * Copyright (c) 2004 The OpenSSL Project. All rights reserved.
  8. *
  9. * Redistribution and use in source and binary forms, with or without
  10. * modification, are permitted provided that the following conditions
  11. * are met:
  12. *
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions and the following disclaimer.
  15. *
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in
  18. * the documentation and/or other materials provided with the
  19. * distribution.
  20. *
  21. * 3. All advertising materials mentioning features or use of this
  22. * software must display the following acknowledgment:
  23. * "This product includes software developed by the OpenSSL Project
  24. * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)"
  25. *
  26. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  27. * endorse or promote products derived from this software without
  28. * prior written permission. For written permission, please contact
  29. * licensing@OpenSSL.org.
  30. *
  31. * 5. Products derived from this software may not be called "OpenSSL"
  32. * nor may "OpenSSL" appear in their names without prior written
  33. * permission of the OpenSSL Project.
  34. *
  35. * 6. Redistributions of any form whatsoever must retain the following
  36. * acknowledgment:
  37. * "This product includes software developed by the OpenSSL Project
  38. * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  41. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  43. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  44. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  45. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  46. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  47. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  48. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  49. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  50. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  51. * OF THE POSSIBILITY OF SUCH DAMAGE.
  52. * ====================================================================
  53. *
  54. * This product includes cryptographic software written by Eric Young
  55. * (eay@cryptsoft.com). This product includes software written by Tim
  56. * Hudson (tjh@cryptsoft.com).
  57. *
  58. */
  59. #include <stdio.h>
  60. #include "cryptlib.h"
  61. #include <openssl/crypto.h>
  62. #include <openssl/lhash.h>
  63. #include <openssl/buffer.h>
  64. #include <openssl/x509.h>
  65. #include <openssl/x509v3.h>
  66. #include "vpm_int.h"
  67. /* X509_VERIFY_PARAM functions */
  68. #define SET_HOST 0
  69. #define ADD_HOST 1
  70. static char *str_copy(const char *s)
  71. {
  72. return OPENSSL_strdup(s);
  73. }
  74. static void str_free(char *s)
  75. {
  76. OPENSSL_free(s);
  77. }
  78. #define string_stack_free(sk) sk_OPENSSL_STRING_pop_free(sk, str_free)
  79. static int int_x509_param_set_hosts(X509_VERIFY_PARAM_ID *id, int mode,
  80. const char *name, size_t namelen)
  81. {
  82. char *copy;
  83. /*
  84. * Refuse names with embedded NUL bytes, except perhaps as final byte.
  85. * XXX: Do we need to push an error onto the error stack?
  86. */
  87. if (namelen == 0 || name == NULL)
  88. namelen = name ? strlen(name) : 0;
  89. else if (name && memchr(name, '\0', namelen > 1 ? namelen - 1 : namelen))
  90. return 0;
  91. if (namelen > 0 && name[namelen - 1] == '\0')
  92. --namelen;
  93. if (mode == SET_HOST && id->hosts) {
  94. string_stack_free(id->hosts);
  95. id->hosts = NULL;
  96. }
  97. if (name == NULL || namelen == 0)
  98. return 1;
  99. copy = BUF_strndup(name, namelen);
  100. if (copy == NULL)
  101. return 0;
  102. if (id->hosts == NULL &&
  103. (id->hosts = sk_OPENSSL_STRING_new_null()) == NULL) {
  104. OPENSSL_free(copy);
  105. return 0;
  106. }
  107. if (!sk_OPENSSL_STRING_push(id->hosts, copy)) {
  108. OPENSSL_free(copy);
  109. if (sk_OPENSSL_STRING_num(id->hosts) == 0) {
  110. sk_OPENSSL_STRING_free(id->hosts);
  111. id->hosts = NULL;
  112. }
  113. return 0;
  114. }
  115. return 1;
  116. }
  117. static void x509_verify_param_zero(X509_VERIFY_PARAM *param)
  118. {
  119. X509_VERIFY_PARAM_ID *paramid;
  120. if (!param)
  121. return;
  122. param->name = NULL;
  123. param->purpose = 0;
  124. param->trust = 0;
  125. /*
  126. * param->inh_flags = X509_VP_FLAG_DEFAULT;
  127. */
  128. param->inh_flags = 0;
  129. param->flags = 0;
  130. param->depth = -1;
  131. if (param->policies) {
  132. sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free);
  133. param->policies = NULL;
  134. }
  135. paramid = param->id;
  136. if (paramid->hosts) {
  137. string_stack_free(paramid->hosts);
  138. paramid->hosts = NULL;
  139. }
  140. if (paramid->peername)
  141. OPENSSL_free(paramid->peername);
  142. paramid->peername = NULL;
  143. if (paramid->email) {
  144. OPENSSL_free(paramid->email);
  145. paramid->email = NULL;
  146. paramid->emaillen = 0;
  147. }
  148. if (paramid->ip) {
  149. OPENSSL_free(paramid->ip);
  150. paramid->ip = NULL;
  151. paramid->iplen = 0;
  152. }
  153. }
  154. X509_VERIFY_PARAM *X509_VERIFY_PARAM_new(void)
  155. {
  156. X509_VERIFY_PARAM *param;
  157. X509_VERIFY_PARAM_ID *paramid;
  158. param = OPENSSL_malloc(sizeof *param);
  159. if (!param)
  160. return NULL;
  161. memset(param, 0, sizeof(*param));
  162. paramid = OPENSSL_malloc(sizeof(*paramid));
  163. if (!paramid) {
  164. OPENSSL_free(param);
  165. return NULL;
  166. }
  167. memset(paramid, 0, sizeof(*paramid));
  168. /* Exotic platforms may have non-zero bit representation of NULL */
  169. paramid->hosts = NULL;
  170. paramid->peername = NULL;
  171. paramid->email = NULL;
  172. paramid->ip = NULL;
  173. param->id = paramid;
  174. x509_verify_param_zero(param);
  175. return param;
  176. }
  177. void X509_VERIFY_PARAM_free(X509_VERIFY_PARAM *param)
  178. {
  179. if (param == NULL)
  180. return;
  181. x509_verify_param_zero(param);
  182. OPENSSL_free(param->id);
  183. OPENSSL_free(param);
  184. }
  185. /*-
  186. * This function determines how parameters are "inherited" from one structure
  187. * to another. There are several different ways this can happen.
  188. *
  189. * 1. If a child structure needs to have its values initialized from a parent
  190. * they are simply copied across. For example SSL_CTX copied to SSL.
  191. * 2. If the structure should take on values only if they are currently unset.
  192. * For example the values in an SSL structure will take appropriate value
  193. * for SSL servers or clients but only if the application has not set new
  194. * ones.
  195. *
  196. * The "inh_flags" field determines how this function behaves.
  197. *
  198. * Normally any values which are set in the default are not copied from the
  199. * destination and verify flags are ORed together.
  200. *
  201. * If X509_VP_FLAG_DEFAULT is set then anything set in the source is copied
  202. * to the destination. Effectively the values in "to" become default values
  203. * which will be used only if nothing new is set in "from".
  204. *
  205. * If X509_VP_FLAG_OVERWRITE is set then all value are copied across whether
  206. * they are set or not. Flags is still Ored though.
  207. *
  208. * If X509_VP_FLAG_RESET_FLAGS is set then the flags value is copied instead
  209. * of ORed.
  210. *
  211. * If X509_VP_FLAG_LOCKED is set then no values are copied.
  212. *
  213. * If X509_VP_FLAG_ONCE is set then the current inh_flags setting is zeroed
  214. * after the next call.
  215. */
  216. /* Macro to test if a field should be copied from src to dest */
  217. #define test_x509_verify_param_copy(field, def) \
  218. (to_overwrite || \
  219. ((src->field != def) && (to_default || (dest->field == def))))
  220. /* As above but for ID fields */
  221. #define test_x509_verify_param_copy_id(idf, def) \
  222. test_x509_verify_param_copy(id->idf, def)
  223. /* Macro to test and copy a field if necessary */
  224. #define x509_verify_param_copy(field, def) \
  225. if (test_x509_verify_param_copy(field, def)) \
  226. dest->field = src->field
  227. int X509_VERIFY_PARAM_inherit(X509_VERIFY_PARAM *dest,
  228. const X509_VERIFY_PARAM *src)
  229. {
  230. unsigned long inh_flags;
  231. int to_default, to_overwrite;
  232. X509_VERIFY_PARAM_ID *id;
  233. if (!src)
  234. return 1;
  235. id = src->id;
  236. inh_flags = dest->inh_flags | src->inh_flags;
  237. if (inh_flags & X509_VP_FLAG_ONCE)
  238. dest->inh_flags = 0;
  239. if (inh_flags & X509_VP_FLAG_LOCKED)
  240. return 1;
  241. if (inh_flags & X509_VP_FLAG_DEFAULT)
  242. to_default = 1;
  243. else
  244. to_default = 0;
  245. if (inh_flags & X509_VP_FLAG_OVERWRITE)
  246. to_overwrite = 1;
  247. else
  248. to_overwrite = 0;
  249. x509_verify_param_copy(purpose, 0);
  250. x509_verify_param_copy(trust, 0);
  251. x509_verify_param_copy(depth, -1);
  252. /* If overwrite or check time not set, copy across */
  253. if (to_overwrite || !(dest->flags & X509_V_FLAG_USE_CHECK_TIME)) {
  254. dest->check_time = src->check_time;
  255. dest->flags &= ~X509_V_FLAG_USE_CHECK_TIME;
  256. /* Don't need to copy flag: that is done below */
  257. }
  258. if (inh_flags & X509_VP_FLAG_RESET_FLAGS)
  259. dest->flags = 0;
  260. dest->flags |= src->flags;
  261. if (test_x509_verify_param_copy(policies, NULL)) {
  262. if (!X509_VERIFY_PARAM_set1_policies(dest, src->policies))
  263. return 0;
  264. }
  265. /* Copy the host flags if and only if we're copying the host list */
  266. if (test_x509_verify_param_copy_id(hosts, NULL)) {
  267. if (dest->id->hosts) {
  268. string_stack_free(dest->id->hosts);
  269. dest->id->hosts = NULL;
  270. }
  271. if (id->hosts) {
  272. dest->id->hosts =
  273. sk_OPENSSL_STRING_deep_copy(id->hosts, str_copy, str_free);
  274. if (dest->id->hosts == NULL)
  275. return 0;
  276. dest->id->hostflags = id->hostflags;
  277. }
  278. }
  279. if (test_x509_verify_param_copy_id(email, NULL)) {
  280. if (!X509_VERIFY_PARAM_set1_email(dest, id->email, id->emaillen))
  281. return 0;
  282. }
  283. if (test_x509_verify_param_copy_id(ip, NULL)) {
  284. if (!X509_VERIFY_PARAM_set1_ip(dest, id->ip, id->iplen))
  285. return 0;
  286. }
  287. return 1;
  288. }
  289. int X509_VERIFY_PARAM_set1(X509_VERIFY_PARAM *to,
  290. const X509_VERIFY_PARAM *from)
  291. {
  292. unsigned long save_flags = to->inh_flags;
  293. int ret;
  294. to->inh_flags |= X509_VP_FLAG_DEFAULT;
  295. ret = X509_VERIFY_PARAM_inherit(to, from);
  296. to->inh_flags = save_flags;
  297. return ret;
  298. }
  299. static int int_x509_param_set1(char **pdest, size_t *pdestlen,
  300. const char *src, size_t srclen)
  301. {
  302. void *tmp;
  303. if (src) {
  304. if (srclen == 0) {
  305. tmp = BUF_strdup(src);
  306. srclen = strlen(src);
  307. } else
  308. tmp = BUF_memdup(src, srclen);
  309. if (!tmp)
  310. return 0;
  311. } else {
  312. tmp = NULL;
  313. srclen = 0;
  314. }
  315. if (*pdest)
  316. OPENSSL_free(*pdest);
  317. *pdest = tmp;
  318. if (pdestlen)
  319. *pdestlen = srclen;
  320. return 1;
  321. }
  322. int X509_VERIFY_PARAM_set1_name(X509_VERIFY_PARAM *param, const char *name)
  323. {
  324. if (param->name)
  325. OPENSSL_free(param->name);
  326. param->name = BUF_strdup(name);
  327. if (param->name)
  328. return 1;
  329. return 0;
  330. }
  331. int X509_VERIFY_PARAM_set_flags(X509_VERIFY_PARAM *param, unsigned long flags)
  332. {
  333. param->flags |= flags;
  334. if (flags & X509_V_FLAG_POLICY_MASK)
  335. param->flags |= X509_V_FLAG_POLICY_CHECK;
  336. return 1;
  337. }
  338. int X509_VERIFY_PARAM_clear_flags(X509_VERIFY_PARAM *param,
  339. unsigned long flags)
  340. {
  341. param->flags &= ~flags;
  342. return 1;
  343. }
  344. unsigned long X509_VERIFY_PARAM_get_flags(X509_VERIFY_PARAM *param)
  345. {
  346. return param->flags;
  347. }
  348. int X509_VERIFY_PARAM_set_purpose(X509_VERIFY_PARAM *param, int purpose)
  349. {
  350. return X509_PURPOSE_set(&param->purpose, purpose);
  351. }
  352. int X509_VERIFY_PARAM_set_trust(X509_VERIFY_PARAM *param, int trust)
  353. {
  354. return X509_TRUST_set(&param->trust, trust);
  355. }
  356. void X509_VERIFY_PARAM_set_depth(X509_VERIFY_PARAM *param, int depth)
  357. {
  358. param->depth = depth;
  359. }
  360. void X509_VERIFY_PARAM_set_time(X509_VERIFY_PARAM *param, time_t t)
  361. {
  362. param->check_time = t;
  363. param->flags |= X509_V_FLAG_USE_CHECK_TIME;
  364. }
  365. int X509_VERIFY_PARAM_add0_policy(X509_VERIFY_PARAM *param,
  366. ASN1_OBJECT *policy)
  367. {
  368. if (!param->policies) {
  369. param->policies = sk_ASN1_OBJECT_new_null();
  370. if (!param->policies)
  371. return 0;
  372. }
  373. if (!sk_ASN1_OBJECT_push(param->policies, policy))
  374. return 0;
  375. return 1;
  376. }
  377. int X509_VERIFY_PARAM_set1_policies(X509_VERIFY_PARAM *param,
  378. STACK_OF(ASN1_OBJECT) *policies)
  379. {
  380. int i;
  381. ASN1_OBJECT *oid, *doid;
  382. if (!param)
  383. return 0;
  384. if (param->policies)
  385. sk_ASN1_OBJECT_pop_free(param->policies, ASN1_OBJECT_free);
  386. if (!policies) {
  387. param->policies = NULL;
  388. return 1;
  389. }
  390. param->policies = sk_ASN1_OBJECT_new_null();
  391. if (!param->policies)
  392. return 0;
  393. for (i = 0; i < sk_ASN1_OBJECT_num(policies); i++) {
  394. oid = sk_ASN1_OBJECT_value(policies, i);
  395. doid = OBJ_dup(oid);
  396. if (!doid)
  397. return 0;
  398. if (!sk_ASN1_OBJECT_push(param->policies, doid)) {
  399. ASN1_OBJECT_free(doid);
  400. return 0;
  401. }
  402. }
  403. param->flags |= X509_V_FLAG_POLICY_CHECK;
  404. return 1;
  405. }
  406. int X509_VERIFY_PARAM_set1_host(X509_VERIFY_PARAM *param,
  407. const char *name, size_t namelen)
  408. {
  409. return int_x509_param_set_hosts(param->id, SET_HOST, name, namelen);
  410. }
  411. int X509_VERIFY_PARAM_add1_host(X509_VERIFY_PARAM *param,
  412. const char *name, size_t namelen)
  413. {
  414. return int_x509_param_set_hosts(param->id, ADD_HOST, name, namelen);
  415. }
  416. void X509_VERIFY_PARAM_set_hostflags(X509_VERIFY_PARAM *param,
  417. unsigned int flags)
  418. {
  419. param->id->hostflags = flags;
  420. }
  421. char *X509_VERIFY_PARAM_get0_peername(X509_VERIFY_PARAM *param)
  422. {
  423. return param->id->peername;
  424. }
  425. int X509_VERIFY_PARAM_set1_email(X509_VERIFY_PARAM *param,
  426. const char *email, size_t emaillen)
  427. {
  428. return int_x509_param_set1(&param->id->email, &param->id->emaillen,
  429. email, emaillen);
  430. }
  431. int X509_VERIFY_PARAM_set1_ip(X509_VERIFY_PARAM *param,
  432. const unsigned char *ip, size_t iplen)
  433. {
  434. if (iplen != 0 && iplen != 4 && iplen != 16)
  435. return 0;
  436. return int_x509_param_set1((char **)&param->id->ip, &param->id->iplen,
  437. (char *)ip, iplen);
  438. }
  439. int X509_VERIFY_PARAM_set1_ip_asc(X509_VERIFY_PARAM *param, const char *ipasc)
  440. {
  441. unsigned char ipout[16];
  442. size_t iplen;
  443. iplen = (size_t)a2i_ipadd(ipout, ipasc);
  444. if (iplen == 0)
  445. return 0;
  446. return X509_VERIFY_PARAM_set1_ip(param, ipout, iplen);
  447. }
  448. int X509_VERIFY_PARAM_get_depth(const X509_VERIFY_PARAM *param)
  449. {
  450. return param->depth;
  451. }
  452. const char *X509_VERIFY_PARAM_get0_name(const X509_VERIFY_PARAM *param)
  453. {
  454. return param->name;
  455. }
  456. static X509_VERIFY_PARAM_ID _empty_id = { NULL, 0U, NULL, NULL, 0, NULL, 0 };
  457. #define vpm_empty_id (X509_VERIFY_PARAM_ID *)&_empty_id
  458. /*
  459. * Default verify parameters: these are used for various applications and can
  460. * be overridden by the user specified table. NB: the 'name' field *must* be
  461. * in alphabetical order because it will be searched using OBJ_search.
  462. */
  463. static const X509_VERIFY_PARAM default_table[] = {
  464. {
  465. "default", /* X509 default parameters */
  466. 0, /* Check time */
  467. 0, /* internal flags */
  468. 0, /* flags */
  469. 0, /* purpose */
  470. 0, /* trust */
  471. 100, /* depth */
  472. NULL, /* policies */
  473. vpm_empty_id},
  474. {
  475. "pkcs7", /* S/MIME sign parameters */
  476. 0, /* Check time */
  477. 0, /* internal flags */
  478. 0, /* flags */
  479. X509_PURPOSE_SMIME_SIGN, /* purpose */
  480. X509_TRUST_EMAIL, /* trust */
  481. -1, /* depth */
  482. NULL, /* policies */
  483. vpm_empty_id},
  484. {
  485. "smime_sign", /* S/MIME sign parameters */
  486. 0, /* Check time */
  487. 0, /* internal flags */
  488. 0, /* flags */
  489. X509_PURPOSE_SMIME_SIGN, /* purpose */
  490. X509_TRUST_EMAIL, /* trust */
  491. -1, /* depth */
  492. NULL, /* policies */
  493. vpm_empty_id},
  494. {
  495. "ssl_client", /* SSL/TLS client parameters */
  496. 0, /* Check time */
  497. 0, /* internal flags */
  498. 0, /* flags */
  499. X509_PURPOSE_SSL_CLIENT, /* purpose */
  500. X509_TRUST_SSL_CLIENT, /* trust */
  501. -1, /* depth */
  502. NULL, /* policies */
  503. vpm_empty_id},
  504. {
  505. "ssl_server", /* SSL/TLS server parameters */
  506. 0, /* Check time */
  507. 0, /* internal flags */
  508. 0, /* flags */
  509. X509_PURPOSE_SSL_SERVER, /* purpose */
  510. X509_TRUST_SSL_SERVER, /* trust */
  511. -1, /* depth */
  512. NULL, /* policies */
  513. vpm_empty_id}
  514. };
  515. static STACK_OF(X509_VERIFY_PARAM) *param_table = NULL;
  516. static int table_cmp(const X509_VERIFY_PARAM *a, const X509_VERIFY_PARAM *b)
  517. {
  518. return strcmp(a->name, b->name);
  519. }
  520. DECLARE_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table);
  521. IMPLEMENT_OBJ_BSEARCH_CMP_FN(X509_VERIFY_PARAM, X509_VERIFY_PARAM, table);
  522. static int param_cmp(const X509_VERIFY_PARAM *const *a,
  523. const X509_VERIFY_PARAM *const *b)
  524. {
  525. return strcmp((*a)->name, (*b)->name);
  526. }
  527. int X509_VERIFY_PARAM_add0_table(X509_VERIFY_PARAM *param)
  528. {
  529. int idx;
  530. X509_VERIFY_PARAM *ptmp;
  531. if (!param_table) {
  532. param_table = sk_X509_VERIFY_PARAM_new(param_cmp);
  533. if (!param_table)
  534. return 0;
  535. } else {
  536. idx = sk_X509_VERIFY_PARAM_find(param_table, param);
  537. if (idx != -1) {
  538. ptmp = sk_X509_VERIFY_PARAM_value(param_table, idx);
  539. X509_VERIFY_PARAM_free(ptmp);
  540. (void)sk_X509_VERIFY_PARAM_delete(param_table, idx);
  541. }
  542. }
  543. if (!sk_X509_VERIFY_PARAM_push(param_table, param))
  544. return 0;
  545. return 1;
  546. }
  547. int X509_VERIFY_PARAM_get_count(void)
  548. {
  549. int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM);
  550. if (param_table)
  551. num += sk_X509_VERIFY_PARAM_num(param_table);
  552. return num;
  553. }
  554. const X509_VERIFY_PARAM *X509_VERIFY_PARAM_get0(int id)
  555. {
  556. int num = sizeof(default_table) / sizeof(X509_VERIFY_PARAM);
  557. if (id < num)
  558. return default_table + id;
  559. return sk_X509_VERIFY_PARAM_value(param_table, id - num);
  560. }
  561. const X509_VERIFY_PARAM *X509_VERIFY_PARAM_lookup(const char *name)
  562. {
  563. int idx;
  564. X509_VERIFY_PARAM pm;
  565. pm.name = (char *)name;
  566. if (param_table) {
  567. idx = sk_X509_VERIFY_PARAM_find(param_table, &pm);
  568. if (idx != -1)
  569. return sk_X509_VERIFY_PARAM_value(param_table, idx);
  570. }
  571. return OBJ_bsearch_table(&pm, default_table,
  572. sizeof(default_table) /
  573. sizeof(X509_VERIFY_PARAM));
  574. }
  575. void X509_VERIFY_PARAM_table_cleanup(void)
  576. {
  577. if (param_table)
  578. sk_X509_VERIFY_PARAM_pop_free(param_table, X509_VERIFY_PARAM_free);
  579. param_table = NULL;
  580. }