You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

634 regels
18 KiB

  1. /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
  2. * All rights reserved.
  3. *
  4. * This package is an SSL implementation written
  5. * by Eric Young (eay@cryptsoft.com).
  6. * The implementation was written so as to conform with Netscapes SSL.
  7. *
  8. * This library is free for commercial and non-commercial use as long as
  9. * the following conditions are aheared to. The following conditions
  10. * apply to all code found in this distribution, be it the RC4, RSA,
  11. * lhash, DES, etc., code; not just the SSL code. The SSL documentation
  12. * included with this distribution is covered by the same copyright terms
  13. * except that the holder is Tim Hudson (tjh@cryptsoft.com).
  14. *
  15. * Copyright remains Eric Young's, and as such any Copyright notices in
  16. * the code are not to be removed.
  17. * If this package is used in a product, Eric Young should be given attribution
  18. * as the author of the parts of the library used.
  19. * This can be in the form of a textual message at program startup or
  20. * in documentation (online or textual) provided with the package.
  21. *
  22. * Redistribution and use in source and binary forms, with or without
  23. * modification, are permitted provided that the following conditions
  24. * are met:
  25. * 1. Redistributions of source code must retain the copyright
  26. * notice, this list of conditions and the following disclaimer.
  27. * 2. Redistributions in binary form must reproduce the above copyright
  28. * notice, this list of conditions and the following disclaimer in the
  29. * documentation and/or other materials provided with the distribution.
  30. * 3. All advertising materials mentioning features or use of this software
  31. * must display the following acknowledgement:
  32. * "This product includes cryptographic software written by
  33. * Eric Young (eay@cryptsoft.com)"
  34. * The word 'cryptographic' can be left out if the rouines from the library
  35. * being used are not cryptographic related :-).
  36. * 4. If you include any Windows specific code (or a derivative thereof) from
  37. * the apps directory (application code) you must include an acknowledgement:
  38. * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
  39. *
  40. * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
  41. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  42. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  43. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  44. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  45. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  46. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  47. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  48. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  49. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  50. * SUCH DAMAGE.
  51. *
  52. * The licence and distribution terms for any publically available version or
  53. * derivative of this code cannot be changed. i.e. this code cannot simply be
  54. * copied and put under another distribution licence
  55. * [including the GNU Public Licence.]
  56. */
  57. /* ====================================================================
  58. * Copyright (c) 1998-2007 The OpenSSL Project. All rights reserved.
  59. *
  60. * Redistribution and use in source and binary forms, with or without
  61. * modification, are permitted provided that the following conditions
  62. * are met:
  63. *
  64. * 1. Redistributions of source code must retain the above copyright
  65. * notice, this list of conditions and the following disclaimer.
  66. *
  67. * 2. Redistributions in binary form must reproduce the above copyright
  68. * notice, this list of conditions and the following disclaimer in
  69. * the documentation and/or other materials provided with the
  70. * distribution.
  71. *
  72. * 3. All advertising materials mentioning features or use of this
  73. * software must display the following acknowledgment:
  74. * "This product includes software developed by the OpenSSL Project
  75. * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
  76. *
  77. * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
  78. * endorse or promote products derived from this software without
  79. * prior written permission. For written permission, please contact
  80. * openssl-core@openssl.org.
  81. *
  82. * 5. Products derived from this software may not be called "OpenSSL"
  83. * nor may "OpenSSL" appear in their names without prior written
  84. * permission of the OpenSSL Project.
  85. *
  86. * 6. Redistributions of any form whatsoever must retain the following
  87. * acknowledgment:
  88. * "This product includes software developed by the OpenSSL Project
  89. * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
  90. *
  91. * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
  92. * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  93. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  94. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
  95. * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  96. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  97. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  98. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  99. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  100. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  101. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  102. * OF THE POSSIBILITY OF SUCH DAMAGE.
  103. * ====================================================================
  104. *
  105. * This product includes cryptographic software written by Eric Young
  106. * (eay@cryptsoft.com). This product includes software written by Tim
  107. * Hudson (tjh@cryptsoft.com).
  108. *
  109. */
  110. #include <openssl/ssl.h>
  111. #include <errno.h>
  112. #include <string.h>
  113. #include <openssl/asn1.h>
  114. #include <openssl/bio.h>
  115. #include <openssl/err.h>
  116. #include <openssl/mem.h>
  117. #include <openssl/pem.h>
  118. #include <openssl/stack.h>
  119. #include <openssl/x509.h>
  120. #include "../crypto/directory.h"
  121. #include "internal.h"
  122. static int xname_cmp(const X509_NAME **a, const X509_NAME **b) {
  123. return X509_NAME_cmp(*a, *b);
  124. }
  125. /* TODO(davidben): Is there any reason this doesn't call
  126. * |SSL_add_file_cert_subjects_to_stack|? */
  127. STACK_OF(X509_NAME) *SSL_load_client_CA_file(const char *file) {
  128. BIO *in;
  129. X509 *x = NULL;
  130. X509_NAME *xn = NULL;
  131. STACK_OF(X509_NAME) *ret = NULL, *sk;
  132. sk = sk_X509_NAME_new(xname_cmp);
  133. in = BIO_new(BIO_s_file());
  134. if (sk == NULL || in == NULL) {
  135. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  136. goto err;
  137. }
  138. if (!BIO_read_filename(in, file)) {
  139. goto err;
  140. }
  141. for (;;) {
  142. if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL) {
  143. break;
  144. }
  145. if (ret == NULL) {
  146. ret = sk_X509_NAME_new_null();
  147. if (ret == NULL) {
  148. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  149. goto err;
  150. }
  151. }
  152. xn = X509_get_subject_name(x);
  153. if (xn == NULL) {
  154. goto err;
  155. }
  156. /* check for duplicates */
  157. xn = X509_NAME_dup(xn);
  158. if (xn == NULL) {
  159. goto err;
  160. }
  161. if (sk_X509_NAME_find(sk, NULL, xn)) {
  162. X509_NAME_free(xn);
  163. } else {
  164. sk_X509_NAME_push(sk, xn);
  165. sk_X509_NAME_push(ret, xn);
  166. }
  167. }
  168. if (0) {
  169. err:
  170. sk_X509_NAME_pop_free(ret, X509_NAME_free);
  171. ret = NULL;
  172. }
  173. sk_X509_NAME_free(sk);
  174. BIO_free(in);
  175. X509_free(x);
  176. if (ret != NULL) {
  177. ERR_clear_error();
  178. }
  179. return ret;
  180. }
  181. int SSL_add_file_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
  182. const char *file) {
  183. BIO *in;
  184. X509 *x = NULL;
  185. X509_NAME *xn = NULL;
  186. int ret = 1;
  187. int (*oldcmp)(const X509_NAME **a, const X509_NAME **b);
  188. oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_cmp);
  189. in = BIO_new(BIO_s_file());
  190. if (in == NULL) {
  191. OPENSSL_PUT_ERROR(SSL, ERR_R_MALLOC_FAILURE);
  192. goto err;
  193. }
  194. if (!BIO_read_filename(in, file)) {
  195. goto err;
  196. }
  197. for (;;) {
  198. if (PEM_read_bio_X509(in, &x, NULL, NULL) == NULL) {
  199. break;
  200. }
  201. xn = X509_get_subject_name(x);
  202. if (xn == NULL) {
  203. goto err;
  204. }
  205. xn = X509_NAME_dup(xn);
  206. if (xn == NULL) {
  207. goto err;
  208. }
  209. if (sk_X509_NAME_find(stack, NULL, xn)) {
  210. X509_NAME_free(xn);
  211. } else {
  212. sk_X509_NAME_push(stack, xn);
  213. }
  214. }
  215. ERR_clear_error();
  216. if (0) {
  217. err:
  218. ret = 0;
  219. }
  220. BIO_free(in);
  221. X509_free(x);
  222. (void) sk_X509_NAME_set_cmp_func(stack, oldcmp);
  223. return ret;
  224. }
  225. /* Add a directory of certs to a stack.
  226. *
  227. * \param stack the stack to append to.
  228. * \param dir the directory to append from. All files in this directory will be
  229. * examined as potential certs. Any that are acceptable to
  230. * SSL_add_dir_cert_subjects_to_stack() that are not already in the stack will
  231. * be included.
  232. * \return 1 for success, 0 for failure. Note that in the case of failure some
  233. * certs may have been added to \c stack. */
  234. int SSL_add_dir_cert_subjects_to_stack(STACK_OF(X509_NAME) *stack,
  235. const char *dir) {
  236. OPENSSL_DIR_CTX *d = NULL;
  237. const char *filename;
  238. int ret = 0;
  239. /* Note that a side effect is that the CAs will be sorted by name */
  240. while ((filename = OPENSSL_DIR_read(&d, dir))) {
  241. char buf[1024];
  242. int r;
  243. if (strlen(dir) + strlen(filename) + 2 > sizeof(buf)) {
  244. OPENSSL_PUT_ERROR(SSL, SSL_R_PATH_TOO_LONG);
  245. goto err;
  246. }
  247. r = BIO_snprintf(buf, sizeof buf, "%s/%s", dir, filename);
  248. if (r <= 0 || r >= (int)sizeof(buf) ||
  249. !SSL_add_file_cert_subjects_to_stack(stack, buf)) {
  250. goto err;
  251. }
  252. }
  253. if (errno) {
  254. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  255. ERR_add_error_data(3, "OPENSSL_DIR_read(&ctx, '", dir, "')");
  256. goto err;
  257. }
  258. ret = 1;
  259. err:
  260. if (d) {
  261. OPENSSL_DIR_end(&d);
  262. }
  263. return ret;
  264. }
  265. int SSL_use_certificate_file(SSL *ssl, const char *file, int type) {
  266. int reason_code;
  267. BIO *in;
  268. int ret = 0;
  269. X509 *x = NULL;
  270. in = BIO_new(BIO_s_file());
  271. if (in == NULL) {
  272. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  273. goto end;
  274. }
  275. if (BIO_read_filename(in, file) <= 0) {
  276. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  277. goto end;
  278. }
  279. if (type == SSL_FILETYPE_ASN1) {
  280. reason_code = ERR_R_ASN1_LIB;
  281. x = d2i_X509_bio(in, NULL);
  282. } else if (type == SSL_FILETYPE_PEM) {
  283. reason_code = ERR_R_PEM_LIB;
  284. x = PEM_read_bio_X509(in, NULL, ssl->ctx->default_passwd_callback,
  285. ssl->ctx->default_passwd_callback_userdata);
  286. } else {
  287. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  288. goto end;
  289. }
  290. if (x == NULL) {
  291. OPENSSL_PUT_ERROR(SSL, reason_code);
  292. goto end;
  293. }
  294. ret = SSL_use_certificate(ssl, x);
  295. end:
  296. X509_free(x);
  297. BIO_free(in);
  298. return ret;
  299. }
  300. int SSL_use_RSAPrivateKey_file(SSL *ssl, const char *file, int type) {
  301. int reason_code, ret = 0;
  302. BIO *in;
  303. RSA *rsa = NULL;
  304. in = BIO_new(BIO_s_file());
  305. if (in == NULL) {
  306. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  307. goto end;
  308. }
  309. if (BIO_read_filename(in, file) <= 0) {
  310. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  311. goto end;
  312. }
  313. if (type == SSL_FILETYPE_ASN1) {
  314. reason_code = ERR_R_ASN1_LIB;
  315. rsa = d2i_RSAPrivateKey_bio(in, NULL);
  316. } else if (type == SSL_FILETYPE_PEM) {
  317. reason_code = ERR_R_PEM_LIB;
  318. rsa =
  319. PEM_read_bio_RSAPrivateKey(in, NULL, ssl->ctx->default_passwd_callback,
  320. ssl->ctx->default_passwd_callback_userdata);
  321. } else {
  322. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  323. goto end;
  324. }
  325. if (rsa == NULL) {
  326. OPENSSL_PUT_ERROR(SSL, reason_code);
  327. goto end;
  328. }
  329. ret = SSL_use_RSAPrivateKey(ssl, rsa);
  330. RSA_free(rsa);
  331. end:
  332. BIO_free(in);
  333. return ret;
  334. }
  335. int SSL_use_PrivateKey_file(SSL *ssl, const char *file, int type) {
  336. int reason_code, ret = 0;
  337. BIO *in;
  338. EVP_PKEY *pkey = NULL;
  339. in = BIO_new(BIO_s_file());
  340. if (in == NULL) {
  341. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  342. goto end;
  343. }
  344. if (BIO_read_filename(in, file) <= 0) {
  345. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  346. goto end;
  347. }
  348. if (type == SSL_FILETYPE_PEM) {
  349. reason_code = ERR_R_PEM_LIB;
  350. pkey = PEM_read_bio_PrivateKey(in, NULL, ssl->ctx->default_passwd_callback,
  351. ssl->ctx->default_passwd_callback_userdata);
  352. } else if (type == SSL_FILETYPE_ASN1) {
  353. reason_code = ERR_R_ASN1_LIB;
  354. pkey = d2i_PrivateKey_bio(in, NULL);
  355. } else {
  356. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  357. goto end;
  358. }
  359. if (pkey == NULL) {
  360. OPENSSL_PUT_ERROR(SSL, reason_code);
  361. goto end;
  362. }
  363. ret = SSL_use_PrivateKey(ssl, pkey);
  364. EVP_PKEY_free(pkey);
  365. end:
  366. BIO_free(in);
  367. return ret;
  368. }
  369. int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type) {
  370. int reason_code;
  371. BIO *in;
  372. int ret = 0;
  373. X509 *x = NULL;
  374. in = BIO_new(BIO_s_file());
  375. if (in == NULL) {
  376. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  377. goto end;
  378. }
  379. if (BIO_read_filename(in, file) <= 0) {
  380. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  381. goto end;
  382. }
  383. if (type == SSL_FILETYPE_ASN1) {
  384. reason_code = ERR_R_ASN1_LIB;
  385. x = d2i_X509_bio(in, NULL);
  386. } else if (type == SSL_FILETYPE_PEM) {
  387. reason_code = ERR_R_PEM_LIB;
  388. x = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
  389. ctx->default_passwd_callback_userdata);
  390. } else {
  391. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  392. goto end;
  393. }
  394. if (x == NULL) {
  395. OPENSSL_PUT_ERROR(SSL, reason_code);
  396. goto end;
  397. }
  398. ret = SSL_CTX_use_certificate(ctx, x);
  399. end:
  400. X509_free(x);
  401. BIO_free(in);
  402. return ret;
  403. }
  404. int SSL_CTX_use_RSAPrivateKey_file(SSL_CTX *ctx, const char *file, int type) {
  405. int reason_code, ret = 0;
  406. BIO *in;
  407. RSA *rsa = NULL;
  408. in = BIO_new(BIO_s_file());
  409. if (in == NULL) {
  410. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  411. goto end;
  412. }
  413. if (BIO_read_filename(in, file) <= 0) {
  414. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  415. goto end;
  416. }
  417. if (type == SSL_FILETYPE_ASN1) {
  418. reason_code = ERR_R_ASN1_LIB;
  419. rsa = d2i_RSAPrivateKey_bio(in, NULL);
  420. } else if (type == SSL_FILETYPE_PEM) {
  421. reason_code = ERR_R_PEM_LIB;
  422. rsa = PEM_read_bio_RSAPrivateKey(in, NULL, ctx->default_passwd_callback,
  423. ctx->default_passwd_callback_userdata);
  424. } else {
  425. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  426. goto end;
  427. }
  428. if (rsa == NULL) {
  429. OPENSSL_PUT_ERROR(SSL, reason_code);
  430. goto end;
  431. }
  432. ret = SSL_CTX_use_RSAPrivateKey(ctx, rsa);
  433. RSA_free(rsa);
  434. end:
  435. BIO_free(in);
  436. return ret;
  437. }
  438. int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type) {
  439. int reason_code, ret = 0;
  440. BIO *in;
  441. EVP_PKEY *pkey = NULL;
  442. in = BIO_new(BIO_s_file());
  443. if (in == NULL) {
  444. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  445. goto end;
  446. }
  447. if (BIO_read_filename(in, file) <= 0) {
  448. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  449. goto end;
  450. }
  451. if (type == SSL_FILETYPE_PEM) {
  452. reason_code = ERR_R_PEM_LIB;
  453. pkey = PEM_read_bio_PrivateKey(in, NULL, ctx->default_passwd_callback,
  454. ctx->default_passwd_callback_userdata);
  455. } else if (type == SSL_FILETYPE_ASN1) {
  456. reason_code = ERR_R_ASN1_LIB;
  457. pkey = d2i_PrivateKey_bio(in, NULL);
  458. } else {
  459. OPENSSL_PUT_ERROR(SSL, SSL_R_BAD_SSL_FILETYPE);
  460. goto end;
  461. }
  462. if (pkey == NULL) {
  463. OPENSSL_PUT_ERROR(SSL, reason_code);
  464. goto end;
  465. }
  466. ret = SSL_CTX_use_PrivateKey(ctx, pkey);
  467. EVP_PKEY_free(pkey);
  468. end:
  469. BIO_free(in);
  470. return ret;
  471. }
  472. /* Read a file that contains our certificate in "PEM" format, possibly followed
  473. * by a sequence of CA certificates that should be sent to the peer in the
  474. * Certificate message. */
  475. int SSL_CTX_use_certificate_chain_file(SSL_CTX *ctx, const char *file) {
  476. BIO *in;
  477. int ret = 0;
  478. X509 *x = NULL;
  479. ERR_clear_error(); /* clear error stack for SSL_CTX_use_certificate() */
  480. in = BIO_new(BIO_s_file());
  481. if (in == NULL) {
  482. OPENSSL_PUT_ERROR(SSL, ERR_R_BUF_LIB);
  483. goto end;
  484. }
  485. if (BIO_read_filename(in, file) <= 0) {
  486. OPENSSL_PUT_ERROR(SSL, ERR_R_SYS_LIB);
  487. goto end;
  488. }
  489. x = PEM_read_bio_X509_AUX(in, NULL, ctx->default_passwd_callback,
  490. ctx->default_passwd_callback_userdata);
  491. if (x == NULL) {
  492. OPENSSL_PUT_ERROR(SSL, ERR_R_PEM_LIB);
  493. goto end;
  494. }
  495. ret = SSL_CTX_use_certificate(ctx, x);
  496. if (ERR_peek_error() != 0) {
  497. ret = 0; /* Key/certificate mismatch doesn't imply ret==0 ... */
  498. }
  499. if (ret) {
  500. /* If we could set up our certificate, now proceed to the CA
  501. * certificates. */
  502. X509 *ca;
  503. int r;
  504. uint32_t err;
  505. SSL_CTX_clear_chain_certs(ctx);
  506. while ((ca = PEM_read_bio_X509(in, NULL, ctx->default_passwd_callback,
  507. ctx->default_passwd_callback_userdata)) !=
  508. NULL) {
  509. r = SSL_CTX_add0_chain_cert(ctx, ca);
  510. if (!r) {
  511. X509_free(ca);
  512. ret = 0;
  513. goto end;
  514. }
  515. /* Note that we must not free r if it was successfully added to the chain
  516. * (while we must free the main certificate, since its reference count is
  517. * increased by SSL_CTX_use_certificate). */
  518. }
  519. /* When the while loop ends, it's usually just EOF. */
  520. err = ERR_peek_last_error();
  521. if (ERR_GET_LIB(err) == ERR_LIB_PEM &&
  522. ERR_GET_REASON(err) == PEM_R_NO_START_LINE) {
  523. ERR_clear_error();
  524. } else {
  525. ret = 0; /* some real error */
  526. }
  527. }
  528. end:
  529. X509_free(x);
  530. BIO_free(in);
  531. return ret;
  532. }
  533. void SSL_CTX_set_default_passwd_cb(SSL_CTX *ctx, pem_password_cb *cb) {
  534. ctx->default_passwd_callback = cb;
  535. }
  536. void SSL_CTX_set_default_passwd_cb_userdata(SSL_CTX *ctx, void *data) {
  537. ctx->default_passwd_callback_userdata = data;
  538. }
  539. SSL_SESSION *d2i_SSL_SESSION_bio(BIO *bio, SSL_SESSION **out) {
  540. return ASN1_d2i_bio_of(SSL_SESSION, SSL_SESSION_new, d2i_SSL_SESSION, bio,
  541. out);
  542. }
  543. int i2d_SSL_SESSION_bio(BIO *bio, const SSL_SESSION *session) {
  544. return ASN1_i2d_bio_of(SSL_SESSION, i2d_SSL_SESSION, bio, session);
  545. }
  546. IMPLEMENT_PEM_rw(SSL_SESSION, SSL_SESSION, PEM_STRING_SSL_SESSION, SSL_SESSION)