ssl_pm.c 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626
  1. // Copyright 2015-2016 Espressif Systems (Shanghai) PTE LTD
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. // http://www.apache.org/licenses/LICENSE-2.0
  7. //
  8. // Unless required by applicable law or agreed to in writing, software
  9. // distributed under the License is distributed on an "AS IS" BASIS,
  10. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  11. // See the License for the specific language governing permissions and
  12. // limitations under the License.
  13. #include "ssl_pm.h"
  14. #include "ssl_port.h"
  15. #include "ssl_dbg.h"
  16. /* mbedtls include */
  17. #include "mbedtls/platform.h"
  18. #include "mbedtls/net.h"
  19. #include "mbedtls/debug.h"
  20. #include "mbedtls/entropy.h"
  21. #include "mbedtls/ctr_drbg.h"
  22. #include "mbedtls/error.h"
  23. #include "mbedtls/certs.h"
  24. #if 0
  25. #define DEBUG_LOAD_BUF_STRING(str) SSL_DEBUG(1, "%s\n", str)
  26. #else
  27. #define DEBUG_LOAD_BUF_STRING(str)
  28. #endif
  29. #define X509_INFO_STRING_LENGTH 1024
  30. struct ssl_pm
  31. {
  32. /* local socket file description */
  33. mbedtls_net_context fd;
  34. /* remote client socket file description */
  35. mbedtls_net_context cl_fd;
  36. mbedtls_ssl_config conf;
  37. mbedtls_ctr_drbg_context ctr_drbg;
  38. mbedtls_ssl_context ssl;
  39. mbedtls_entropy_context entropy;
  40. };
  41. struct x509_pm
  42. {
  43. mbedtls_x509_crt *x509_crt;
  44. mbedtls_x509_crt *ex_crt;
  45. };
  46. struct pkey_pm
  47. {
  48. mbedtls_pk_context *pkey;
  49. mbedtls_pk_context *ex_pkey;
  50. };
  51. unsigned int max_content_len;
  52. /*********************************************************************************************/
  53. /************************************ SSL arch interface *************************************/
  54. /**
  55. * @brief create SSL low-level object
  56. */
  57. int ssl_pm_new(SSL *ssl)
  58. {
  59. struct ssl_pm *ssl_pm;
  60. int ret;
  61. const unsigned char pers[] = "OpenSSL PM";
  62. size_t pers_len = sizeof(pers);
  63. int endpoint;
  64. int version;
  65. const SSL_METHOD *method = ssl->method;
  66. ssl_pm = ssl_mem_zalloc(sizeof(struct ssl_pm));
  67. if (!ssl_pm)
  68. SSL_ERR(ret, failed1, "ssl_mem_zalloc\n");
  69. max_content_len = ssl->ctx->read_buffer_len;
  70. mbedtls_net_init(&ssl_pm->fd);
  71. mbedtls_net_init(&ssl_pm->cl_fd);
  72. mbedtls_ssl_config_init(&ssl_pm->conf);
  73. mbedtls_ctr_drbg_init(&ssl_pm->ctr_drbg);
  74. mbedtls_entropy_init(&ssl_pm->entropy);
  75. mbedtls_ssl_init(&ssl_pm->ssl);
  76. ret = mbedtls_ctr_drbg_seed(&ssl_pm->ctr_drbg, mbedtls_entropy_func, &ssl_pm->entropy, pers, pers_len);
  77. if (ret)
  78. SSL_ERR(ret, failed2, "mbedtls_ctr_drbg_seed:[-0x%x]\n", -ret);
  79. if (method->endpoint) {
  80. endpoint = MBEDTLS_SSL_IS_SERVER;
  81. } else {
  82. endpoint = MBEDTLS_SSL_IS_CLIENT;
  83. }
  84. ret = mbedtls_ssl_config_defaults(&ssl_pm->conf, endpoint, MBEDTLS_SSL_TRANSPORT_STREAM, MBEDTLS_SSL_PRESET_DEFAULT);
  85. if (ret)
  86. SSL_ERR(ret, failed2, "mbedtls_ssl_config_defaults:[-0x%x]\n", -ret);
  87. if (TLS_ANY_VERSION != ssl->version) {
  88. if (TLS1_2_VERSION == ssl->version)
  89. version = MBEDTLS_SSL_MINOR_VERSION_3;
  90. else if (TLS1_1_VERSION == ssl->version)
  91. version = MBEDTLS_SSL_MINOR_VERSION_2;
  92. else if (TLS1_VERSION == ssl->version)
  93. version = MBEDTLS_SSL_MINOR_VERSION_1;
  94. else
  95. version = MBEDTLS_SSL_MINOR_VERSION_0;
  96. mbedtls_ssl_conf_max_version(&ssl_pm->conf, MBEDTLS_SSL_MAJOR_VERSION_3, version);
  97. mbedtls_ssl_conf_min_version(&ssl_pm->conf, MBEDTLS_SSL_MAJOR_VERSION_3, version);
  98. }
  99. mbedtls_ssl_conf_rng(&ssl_pm->conf, mbedtls_ctr_drbg_random, &ssl_pm->ctr_drbg);
  100. mbedtls_ssl_conf_dbg(&ssl_pm->conf, NULL, NULL);
  101. ret = mbedtls_ssl_setup(&ssl_pm->ssl, &ssl_pm->conf);
  102. if (ret)
  103. SSL_ERR(ret, failed3, "mbedtls_ssl_setup:[-0x%x]\n", -ret);
  104. mbedtls_ssl_set_bio(&ssl_pm->ssl, &ssl_pm->fd, mbedtls_net_send, mbedtls_net_recv, NULL);
  105. ssl->ssl_pm = ssl_pm;
  106. return 0;
  107. failed3:
  108. mbedtls_ssl_config_free(&ssl_pm->conf);
  109. mbedtls_ctr_drbg_free(&ssl_pm->ctr_drbg);
  110. failed2:
  111. mbedtls_entropy_free(&ssl_pm->entropy);
  112. ssl_mem_free(ssl_pm);
  113. failed1:
  114. return -1;
  115. }
  116. /**
  117. * @brief free SSL low-level object
  118. */
  119. void ssl_pm_free(SSL *ssl)
  120. {
  121. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  122. mbedtls_ctr_drbg_free(&ssl_pm->ctr_drbg);
  123. mbedtls_entropy_free(&ssl_pm->entropy);
  124. mbedtls_ssl_config_free(&ssl_pm->conf);
  125. mbedtls_ssl_free(&ssl_pm->ssl);
  126. ssl_mem_free(ssl_pm);
  127. ssl->ssl_pm = NULL;
  128. }
  129. /**
  130. * @brief reload SSL low-level certification object
  131. */
  132. static int ssl_pm_reload_crt(SSL *ssl)
  133. {
  134. int ret;
  135. int mode;
  136. struct ssl_pm *ssl_pm = ssl->ssl_pm;
  137. struct x509_pm *ca_pm = (struct x509_pm *)ssl->client_CA->x509_pm;
  138. struct pkey_pm *pkey_pm = (struct pkey_pm *)ssl->cert->pkey->pkey_pm;
  139. struct x509_pm *crt_pm = (struct x509_pm *)ssl->cert->x509->x509_pm;
  140. if (ssl->verify_mode == SSL_VERIFY_PEER)
  141. mode = MBEDTLS_SSL_VERIFY_REQUIRED;
  142. else if (ssl->verify_mode == SSL_VERIFY_FAIL_IF_NO_PEER_CERT)
  143. mode = MBEDTLS_SSL_VERIFY_OPTIONAL;
  144. else if (ssl->verify_mode == SSL_VERIFY_CLIENT_ONCE)
  145. mode = MBEDTLS_SSL_VERIFY_UNSET;
  146. else
  147. mode = MBEDTLS_SSL_VERIFY_NONE;
  148. mbedtls_ssl_conf_authmode(&ssl_pm->conf, mode);
  149. if (ca_pm->x509_crt) {
  150. mbedtls_ssl_conf_ca_chain(&ssl_pm->conf, ca_pm->x509_crt, NULL);
  151. } else if (ca_pm->ex_crt) {
  152. mbedtls_ssl_conf_ca_chain(&ssl_pm->conf, ca_pm->ex_crt, NULL);
  153. }
  154. if (crt_pm->x509_crt && pkey_pm->pkey) {
  155. ret = mbedtls_ssl_conf_own_cert(&ssl_pm->conf, crt_pm->x509_crt, pkey_pm->pkey);
  156. } else if (crt_pm->ex_crt && pkey_pm->ex_pkey) {
  157. ret = mbedtls_ssl_conf_own_cert(&ssl_pm->conf, crt_pm->ex_crt, pkey_pm->ex_pkey);
  158. } else {
  159. ret = 0;
  160. }
  161. if (ret)
  162. return -1;
  163. return 0;
  164. }
  165. /*
  166. * Perform the mbedtls SSL handshake instead of mbedtls_ssl_handshake.
  167. * We can add debug here.
  168. */
  169. static int mbedtls_handshake( mbedtls_ssl_context *ssl )
  170. {
  171. int ret = 0;
  172. if (ssl == NULL || ssl->conf == NULL)
  173. return MBEDTLS_ERR_SSL_BAD_INPUT_DATA;
  174. while (ssl->state != MBEDTLS_SSL_HANDSHAKE_OVER)
  175. {
  176. ret = mbedtls_ssl_handshake_step(ssl);
  177. SSL_DEBUG(1, "ssl ret %d state %d heap %d\n",
  178. ret, ssl->state, system_get_free_heap_size());
  179. if (ret != 0)
  180. break;
  181. }
  182. return ret;
  183. }
  184. int ssl_pm_handshake(SSL *ssl)
  185. {
  186. int ret, mbed_ret;
  187. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  188. mbed_ret = ssl_pm_reload_crt(ssl);
  189. if (mbed_ret)
  190. return 0;
  191. SSL_DEBUG(1, "ssl_speed_up_enter ");
  192. ssl_speed_up_enter();
  193. SSL_DEBUG(1, "OK\n");
  194. while((mbed_ret = mbedtls_handshake(&ssl_pm->ssl)) != 0) {
  195. if (mbed_ret != MBEDTLS_ERR_SSL_WANT_READ && mbed_ret != MBEDTLS_ERR_SSL_WANT_WRITE) {
  196. break;
  197. }
  198. }
  199. SSL_DEBUG(1, "ssl_speed_up_exit ");
  200. ssl_speed_up_exit();
  201. SSL_DEBUG(1, "OK\n");
  202. if (!mbed_ret) {
  203. struct x509_pm *x509_pm = (struct x509_pm *)ssl->session->peer->x509_pm;
  204. ret = 1;
  205. x509_pm->ex_crt = (mbedtls_x509_crt *)mbedtls_ssl_get_peer_cert(&ssl_pm->ssl);
  206. } else {
  207. ret = 0;
  208. SSL_DEBUG(1, "mbedtls_ssl_handshake [-0x%x]\n", -mbed_ret);
  209. }
  210. return ret;
  211. }
  212. int ssl_pm_shutdown(SSL *ssl)
  213. {
  214. int ret, mbed_ret;
  215. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  216. mbed_ret = mbedtls_ssl_close_notify(&ssl_pm->ssl);
  217. if (!mbed_ret) {
  218. struct x509_pm *x509_pm = (struct x509_pm *)ssl->session->peer->x509_pm;
  219. ret = 0;
  220. x509_pm->ex_crt = NULL;
  221. }
  222. else
  223. ret = -1;
  224. return ret;
  225. }
  226. int ssl_pm_clear(SSL *ssl)
  227. {
  228. return ssl_pm_shutdown(ssl);
  229. }
  230. int ssl_pm_read(SSL *ssl, void *buffer, int len)
  231. {
  232. int ret, mbed_ret;
  233. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  234. mbed_ret = mbedtls_ssl_read(&ssl_pm->ssl, buffer, len);
  235. if (mbed_ret < 0)
  236. ret = -1;
  237. else if (mbed_ret == 0)
  238. ret = 0;
  239. else
  240. ret = mbed_ret;
  241. return ret;
  242. }
  243. int ssl_pm_send(SSL *ssl, const void *buffer, int len)
  244. {
  245. int ret, mbed_ret;
  246. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  247. mbed_ret = mbedtls_ssl_write(&ssl_pm->ssl, buffer, len);
  248. if (mbed_ret < 0)
  249. ret = -1;
  250. else if (mbed_ret == 0)
  251. ret = 0;
  252. else
  253. ret = mbed_ret;
  254. return ret;
  255. }
  256. int ssl_pm_pending(const SSL *ssl)
  257. {
  258. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  259. return mbedtls_ssl_get_bytes_avail(&ssl_pm->ssl);
  260. }
  261. void ssl_pm_set_fd(SSL *ssl, int fd, int mode)
  262. {
  263. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  264. ssl_pm->fd.fd = fd;
  265. }
  266. int ssl_pm_get_fd(const SSL *ssl, int mode)
  267. {
  268. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  269. return ssl_pm->fd.fd;
  270. }
  271. OSSL_HANDSHAKE_STATE ssl_pm_get_state(const SSL *ssl)
  272. {
  273. OSSL_HANDSHAKE_STATE state;
  274. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  275. switch (ssl_pm->ssl.state)
  276. {
  277. case MBEDTLS_SSL_CLIENT_HELLO:
  278. state = TLS_ST_CW_CLNT_HELLO;
  279. break;
  280. case MBEDTLS_SSL_SERVER_HELLO:
  281. state = TLS_ST_SW_SRVR_HELLO;
  282. break;
  283. case MBEDTLS_SSL_SERVER_CERTIFICATE:
  284. state = TLS_ST_SW_CERT;
  285. break;
  286. case MBEDTLS_SSL_SERVER_HELLO_DONE:
  287. state = TLS_ST_SW_SRVR_DONE;
  288. break;
  289. case MBEDTLS_SSL_CLIENT_KEY_EXCHANGE:
  290. state = TLS_ST_CW_KEY_EXCH;
  291. break;
  292. case MBEDTLS_SSL_CLIENT_CHANGE_CIPHER_SPEC:
  293. state = TLS_ST_CW_CHANGE;
  294. break;
  295. case MBEDTLS_SSL_CLIENT_FINISHED:
  296. state = TLS_ST_CW_FINISHED;
  297. break;
  298. case MBEDTLS_SSL_SERVER_CHANGE_CIPHER_SPEC:
  299. state = TLS_ST_SW_CHANGE;
  300. break;
  301. case MBEDTLS_SSL_SERVER_FINISHED:
  302. state = TLS_ST_SW_FINISHED;
  303. break;
  304. case MBEDTLS_SSL_CLIENT_CERTIFICATE:
  305. state = TLS_ST_CW_CERT;
  306. break;
  307. case MBEDTLS_SSL_SERVER_KEY_EXCHANGE:
  308. state = TLS_ST_SR_KEY_EXCH;
  309. break;
  310. case MBEDTLS_SSL_SERVER_NEW_SESSION_TICKET:
  311. state = TLS_ST_SW_SESSION_TICKET;
  312. break;
  313. case MBEDTLS_SSL_SERVER_HELLO_VERIFY_REQUEST_SENT:
  314. state = TLS_ST_SW_CERT_REQ;
  315. break;
  316. case MBEDTLS_SSL_HANDSHAKE_OVER:
  317. state = TLS_ST_OK;
  318. break;
  319. default :
  320. state = TLS_ST_BEFORE;
  321. break;
  322. }
  323. return state;
  324. }
  325. int x509_pm_show_info(X509 *x)
  326. {
  327. int ret;
  328. char *buf;
  329. mbedtls_x509_crt *x509_crt;
  330. struct x509_pm *x509_pm = x->x509_pm;
  331. if (x509_pm->x509_crt)
  332. x509_crt = x509_pm->x509_crt;
  333. else if (x509_pm->ex_crt)
  334. x509_crt = x509_pm->ex_crt;
  335. else
  336. x509_crt = NULL;
  337. if (!x509_crt)
  338. return -1;
  339. buf = ssl_mem_malloc(X509_INFO_STRING_LENGTH);
  340. if (!buf)
  341. SSL_RET(failed1, "");
  342. ret = mbedtls_x509_crt_info(buf, X509_INFO_STRING_LENGTH - 1, "", x509_crt);
  343. if (ret <= 0)
  344. SSL_RET(failed2, "");
  345. buf[ret] = 0;
  346. ssl_mem_free(buf);
  347. SSL_DEBUG(1, "%s", buf);
  348. return 0;
  349. failed2:
  350. ssl_mem_free(buf);
  351. failed1:
  352. return -1;
  353. }
  354. int x509_pm_new(X509 *x, X509 *m_x)
  355. {
  356. struct x509_pm *x509_pm;
  357. x509_pm = ssl_mem_zalloc(sizeof(struct x509_pm));
  358. if (!x509_pm)
  359. SSL_RET(failed1, "ssl_mem_zalloc\n");
  360. x->x509_pm = x509_pm;
  361. if (m_x) {
  362. struct x509_pm *m_x509_pm = (struct x509_pm *)m_x->x509_pm;
  363. x509_pm->ex_crt = m_x509_pm->x509_crt;
  364. }
  365. return 0;
  366. failed1:
  367. return -1;
  368. }
  369. void x509_pm_free(X509 *x)
  370. {
  371. struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm;
  372. if (x509_pm->x509_crt) {
  373. mbedtls_x509_crt_free(x509_pm->x509_crt);
  374. ssl_mem_free(x509_pm->x509_crt);
  375. x509_pm->x509_crt = NULL;
  376. }
  377. ssl_mem_free(x->x509_pm);
  378. x->x509_pm = NULL;
  379. }
  380. int x509_pm_load(X509 *x, const unsigned char *buffer, int len)
  381. {
  382. int ret;
  383. unsigned char *load_buf;
  384. struct x509_pm *x509_pm = (struct x509_pm *)x->x509_pm;
  385. if (x509_pm->x509_crt)
  386. mbedtls_x509_crt_free(x509_pm->x509_crt);
  387. if (!x509_pm->x509_crt) {
  388. x509_pm->x509_crt = ssl_mem_malloc(sizeof(mbedtls_x509_crt));
  389. if (!x509_pm->x509_crt)
  390. SSL_RET(failed1, "ssl_mem_malloc\n");
  391. }
  392. load_buf = ssl_mem_malloc(len + 1);
  393. if (!load_buf)
  394. SSL_RET(failed2, "ssl_mem_malloc\n");
  395. ssl_memcpy(load_buf, buffer, len);
  396. load_buf[len] = '\0';
  397. DEBUG_LOAD_BUF_STRING(load_buf);
  398. mbedtls_x509_crt_init(x509_pm->x509_crt);
  399. ret = mbedtls_x509_crt_parse(x509_pm->x509_crt, load_buf, len + 1);
  400. ssl_mem_free(load_buf);
  401. if (ret)
  402. SSL_RET(failed2, "mbedtls_x509_crt_parse, return [-0x%x]\n", -ret);
  403. return 0;
  404. failed2:
  405. mbedtls_x509_crt_free(x509_pm->x509_crt);
  406. ssl_mem_free(x509_pm->x509_crt);
  407. x509_pm->x509_crt = NULL;
  408. failed1:
  409. return -1;
  410. }
  411. int pkey_pm_new(EVP_PKEY *pk, EVP_PKEY *m_pkey)
  412. {
  413. struct pkey_pm *pkey_pm;
  414. pkey_pm = ssl_mem_zalloc(sizeof(struct pkey_pm));
  415. if (!pkey_pm)
  416. return -1;
  417. pk->pkey_pm = pkey_pm;
  418. if (m_pkey) {
  419. struct pkey_pm *m_pkey_pm = (struct pkey_pm *)m_pkey->pkey_pm;
  420. pkey_pm->ex_pkey = m_pkey_pm->pkey;
  421. }
  422. return 0;
  423. }
  424. void pkey_pm_free(EVP_PKEY *pk)
  425. {
  426. struct pkey_pm *pkey_pm = (struct pkey_pm *)pk->pkey_pm;
  427. if (pkey_pm->pkey) {
  428. mbedtls_pk_free(pkey_pm->pkey);
  429. ssl_mem_free(pkey_pm->pkey);
  430. pkey_pm->pkey = NULL;
  431. }
  432. ssl_mem_free(pk->pkey_pm);
  433. pk->pkey_pm = NULL;
  434. }
  435. int pkey_pm_load(EVP_PKEY *pk, const unsigned char *buffer, int len)
  436. {
  437. int ret;
  438. unsigned char *load_buf;
  439. struct pkey_pm *pkey_pm = (struct pkey_pm *)pk->pkey_pm;
  440. if (pkey_pm->pkey)
  441. mbedtls_pk_free(pkey_pm->pkey);
  442. if (!pkey_pm->pkey) {
  443. pkey_pm->pkey = ssl_mem_malloc(sizeof(mbedtls_pk_context));
  444. if (!pkey_pm->pkey)
  445. SSL_RET(failed1, "ssl_mem_malloc\n");
  446. }
  447. load_buf = ssl_mem_malloc(len + 1);
  448. if (!load_buf)
  449. SSL_RET(failed2, "ssl_mem_malloc\n");
  450. ssl_memcpy(load_buf, buffer, len);
  451. load_buf[len] = '\0';
  452. DEBUG_LOAD_BUF_STRING(load_buf);
  453. mbedtls_pk_init(pkey_pm->pkey);
  454. ret = mbedtls_pk_parse_key(pkey_pm->pkey, load_buf, len + 1, NULL, 0);
  455. ssl_mem_free(load_buf);
  456. if (ret)
  457. SSL_RET(failed2, "mbedtls_pk_parse_key, return [-0x%x]\n", -ret);
  458. return 0;
  459. failed2:
  460. mbedtls_pk_free(pkey_pm->pkey);
  461. ssl_mem_free(pkey_pm->pkey);
  462. pkey_pm->pkey = NULL;
  463. failed1:
  464. return -1;
  465. }
  466. void ssl_pm_set_bufflen(SSL *ssl, int len)
  467. {
  468. max_content_len = len;
  469. }
  470. long ssl_pm_get_verify_result(const SSL *ssl)
  471. {
  472. long ret;
  473. long verify_result;
  474. struct ssl_pm *ssl_pm = (struct ssl_pm *)ssl->ssl_pm;
  475. ret = mbedtls_ssl_get_verify_result(&ssl_pm->ssl);
  476. if (!ret)
  477. verify_result = X509_V_OK;
  478. else
  479. verify_result = X509_V_ERR_UNSPECIFIED;
  480. return verify_result;
  481. }