vtls.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2014, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. ***************************************************************************/
  22. /* This file is for implementing all "generic" SSL functions that all libcurl
  23. internals should use. It is then responsible for calling the proper
  24. "backend" function.
  25. SSL-functions in libcurl should call functions in this source file, and not
  26. to any specific SSL-layer.
  27. Curl_ssl_ - prefix for generic ones
  28. Curl_ossl_ - prefix for OpenSSL ones
  29. Curl_gtls_ - prefix for GnuTLS ones
  30. Curl_nss_ - prefix for NSS ones
  31. Curl_qssl_ - prefix for QsoSSL ones
  32. Curl_gskit_ - prefix for GSKit ones
  33. Curl_polarssl_ - prefix for PolarSSL ones
  34. Curl_cyassl_ - prefix for CyaSSL ones
  35. Curl_schannel_ - prefix for Schannel SSPI ones
  36. Curl_darwinssl_ - prefix for SecureTransport (Darwin) ones
  37. Note that this source code uses curlssl_* functions, and they are all
  38. defines/macros #defined by the lib-specific header files.
  39. "SSL/TLS Strong Encryption: An Introduction"
  40. http://httpd.apache.org/docs-2.0/ssl/ssl_intro.html
  41. */
  42. #include "curl_setup.h"
  43. #ifdef HAVE_SYS_TYPES_H
  44. #include <sys/types.h>
  45. #endif
  46. #ifdef HAVE_SYS_STAT_H
  47. #include <sys/stat.h>
  48. #endif
  49. #ifdef HAVE_FCNTL_H
  50. #include <fcntl.h>
  51. #endif
  52. #include "urldata.h"
  53. #include "vtls.h" /* generic SSL protos etc */
  54. #include "openssl.h" /* OpenSSL versions */
  55. #include "gtls.h" /* GnuTLS versions */
  56. #include "nssg.h" /* NSS versions */
  57. #include "qssl.h" /* QSOSSL versions */
  58. #include "gskit.h" /* Global Secure ToolKit versions */
  59. #include "polarssl.h" /* PolarSSL versions */
  60. #include "axtls.h" /* axTLS versions */
  61. #include "cyassl.h" /* CyaSSL versions */
  62. #include "curl_schannel.h" /* Schannel SSPI version */
  63. #include "curl_darwinssl.h" /* SecureTransport (Darwin) version */
  64. #include "slist.h"
  65. #include "sendf.h"
  66. #include "rawstr.h"
  67. #include "url.h"
  68. #include "curl_memory.h"
  69. #include "progress.h"
  70. #include "share.h"
  71. #include "timeval.h"
  72. #define _MPRINTF_REPLACE /* use our functions only */
  73. #include <curl/mprintf.h>
  74. /* The last #include file should be: */
  75. #include "memdebug.h"
  76. /* convenience macro to check if this handle is using a shared SSL session */
  77. #define SSLSESSION_SHARED(data) (data->share && \
  78. (data->share->specifier & \
  79. (1<<CURL_LOCK_DATA_SSL_SESSION)))
  80. static bool safe_strequal(char* str1, char* str2)
  81. {
  82. if(str1 && str2)
  83. /* both pointers point to something then compare them */
  84. return (0 != Curl_raw_equal(str1, str2)) ? TRUE : FALSE;
  85. else
  86. /* if both pointers are NULL then treat them as equal */
  87. return (!str1 && !str2) ? TRUE : FALSE;
  88. }
  89. bool
  90. Curl_ssl_config_matches(struct ssl_config_data* data,
  91. struct ssl_config_data* needle)
  92. {
  93. if((data->version == needle->version) &&
  94. (data->verifypeer == needle->verifypeer) &&
  95. (data->verifyhost == needle->verifyhost) &&
  96. safe_strequal(data->CApath, needle->CApath) &&
  97. safe_strequal(data->CAfile, needle->CAfile) &&
  98. safe_strequal(data->random_file, needle->random_file) &&
  99. safe_strequal(data->egdsocket, needle->egdsocket) &&
  100. safe_strequal(data->cipher_list, needle->cipher_list))
  101. return TRUE;
  102. return FALSE;
  103. }
  104. bool
  105. Curl_clone_ssl_config(struct ssl_config_data *source,
  106. struct ssl_config_data *dest)
  107. {
  108. dest->sessionid = source->sessionid;
  109. dest->verifyhost = source->verifyhost;
  110. dest->verifypeer = source->verifypeer;
  111. dest->version = source->version;
  112. if(source->CAfile) {
  113. dest->CAfile = strdup(source->CAfile);
  114. if(!dest->CAfile)
  115. return FALSE;
  116. }
  117. else
  118. dest->CAfile = NULL;
  119. if(source->CApath) {
  120. dest->CApath = strdup(source->CApath);
  121. if(!dest->CApath)
  122. return FALSE;
  123. }
  124. else
  125. dest->CApath = NULL;
  126. if(source->cipher_list) {
  127. dest->cipher_list = strdup(source->cipher_list);
  128. if(!dest->cipher_list)
  129. return FALSE;
  130. }
  131. else
  132. dest->cipher_list = NULL;
  133. if(source->egdsocket) {
  134. dest->egdsocket = strdup(source->egdsocket);
  135. if(!dest->egdsocket)
  136. return FALSE;
  137. }
  138. else
  139. dest->egdsocket = NULL;
  140. if(source->random_file) {
  141. dest->random_file = strdup(source->random_file);
  142. if(!dest->random_file)
  143. return FALSE;
  144. }
  145. else
  146. dest->random_file = NULL;
  147. return TRUE;
  148. }
  149. void Curl_free_ssl_config(struct ssl_config_data* sslc)
  150. {
  151. Curl_safefree(sslc->CAfile);
  152. Curl_safefree(sslc->CApath);
  153. Curl_safefree(sslc->cipher_list);
  154. Curl_safefree(sslc->egdsocket);
  155. Curl_safefree(sslc->random_file);
  156. }
  157. /*
  158. * Curl_rand() returns a random unsigned integer, 32bit.
  159. *
  160. * This non-SSL function is put here only because this file is the only one
  161. * with knowledge of what the underlying SSL libraries provide in terms of
  162. * randomizers.
  163. *
  164. * NOTE: 'data' may be passed in as NULL when coming from external API without
  165. * easy handle!
  166. *
  167. */
  168. unsigned int Curl_rand(struct SessionHandle *data)
  169. {
  170. unsigned int r;
  171. static unsigned int randseed;
  172. static bool seeded = FALSE;
  173. #ifdef CURLDEBUG
  174. char *force_entropy = getenv("CURL_ENTROPY");
  175. if(force_entropy) {
  176. if(!seeded) {
  177. size_t elen = strlen(force_entropy);
  178. size_t clen = sizeof(randseed);
  179. size_t min = elen < clen ? elen : clen;
  180. memcpy((char *)&randseed, force_entropy, min);
  181. seeded = TRUE;
  182. }
  183. else
  184. randseed++;
  185. return randseed;
  186. }
  187. #endif
  188. /* data may be NULL! */
  189. if(!Curl_ssl_random(data, (unsigned char *)&r, sizeof(r)))
  190. return r;
  191. /* If Curl_ssl_random() returns non-zero it couldn't offer randomness and we
  192. instead perform a "best effort" */
  193. #ifdef RANDOM_FILE
  194. if(!seeded) {
  195. /* if there's a random file to read a seed from, use it */
  196. int fd = open(RANDOM_FILE, O_RDONLY);
  197. if(fd > -1) {
  198. /* read random data into the randseed variable */
  199. ssize_t nread = read(fd, &randseed, sizeof(randseed));
  200. if(nread == sizeof(randseed))
  201. seeded = TRUE;
  202. close(fd);
  203. }
  204. }
  205. #endif
  206. if(!seeded) {
  207. struct timeval now = curlx_tvnow();
  208. infof(data, "WARNING: Using weak random seed\n");
  209. randseed += (unsigned int)now.tv_usec + (unsigned int)now.tv_sec;
  210. randseed = randseed * 1103515245 + 12345;
  211. randseed = randseed * 1103515245 + 12345;
  212. randseed = randseed * 1103515245 + 12345;
  213. seeded = TRUE;
  214. }
  215. /* Return an unsigned 32-bit pseudo-random number. */
  216. r = randseed = randseed * 1103515245 + 12345;
  217. return (r << 16) | ((r >> 16) & 0xFFFF);
  218. }
  219. int Curl_ssl_backend(void)
  220. {
  221. return (int)CURL_SSL_BACKEND;
  222. }
  223. #ifdef USE_SSL
  224. /* "global" init done? */
  225. static bool init_ssl=FALSE;
  226. /**
  227. * Global SSL init
  228. *
  229. * @retval 0 error initializing SSL
  230. * @retval 1 SSL initialized successfully
  231. */
  232. int Curl_ssl_init(void)
  233. {
  234. /* make sure this is only done once */
  235. if(init_ssl)
  236. return 1;
  237. init_ssl = TRUE; /* never again */
  238. return curlssl_init();
  239. }
  240. /* Global cleanup */
  241. void Curl_ssl_cleanup(void)
  242. {
  243. if(init_ssl) {
  244. /* only cleanup if we did a previous init */
  245. curlssl_cleanup();
  246. init_ssl = FALSE;
  247. }
  248. }
  249. CURLcode
  250. Curl_ssl_connect(struct connectdata *conn, int sockindex)
  251. {
  252. CURLcode res;
  253. /* mark this is being ssl-enabled from here on. */
  254. conn->ssl[sockindex].use = TRUE;
  255. conn->ssl[sockindex].state = ssl_connection_negotiating;
  256. res = curlssl_connect(conn, sockindex);
  257. if(!res)
  258. Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
  259. return res;
  260. }
  261. CURLcode
  262. Curl_ssl_connect_nonblocking(struct connectdata *conn, int sockindex,
  263. bool *done)
  264. {
  265. CURLcode res;
  266. /* mark this is being ssl requested from here on. */
  267. conn->ssl[sockindex].use = TRUE;
  268. #ifdef curlssl_connect_nonblocking
  269. res = curlssl_connect_nonblocking(conn, sockindex, done);
  270. #else
  271. *done = TRUE; /* fallback to BLOCKING */
  272. res = curlssl_connect(conn, sockindex);
  273. #endif /* non-blocking connect support */
  274. if(!res && *done)
  275. Curl_pgrsTime(conn->data, TIMER_APPCONNECT); /* SSL is connected */
  276. return res;
  277. }
  278. /*
  279. * Check if there's a session ID for the given connection in the cache, and if
  280. * there's one suitable, it is provided. Returns TRUE when no entry matched.
  281. */
  282. int Curl_ssl_getsessionid(struct connectdata *conn,
  283. void **ssl_sessionid,
  284. size_t *idsize) /* set 0 if unknown */
  285. {
  286. struct curl_ssl_session *check;
  287. struct SessionHandle *data = conn->data;
  288. size_t i;
  289. long *general_age;
  290. bool no_match = TRUE;
  291. *ssl_sessionid = NULL;
  292. if(!conn->ssl_config.sessionid)
  293. /* session ID re-use is disabled */
  294. return TRUE;
  295. /* Lock if shared */
  296. if(SSLSESSION_SHARED(data)) {
  297. Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
  298. general_age = &data->share->sessionage;
  299. }
  300. else
  301. general_age = &data->state.sessionage;
  302. for(i = 0; i < data->set.ssl.max_ssl_sessions; i++) {
  303. check = &data->state.session[i];
  304. if(!check->sessionid)
  305. /* not session ID means blank entry */
  306. continue;
  307. if(Curl_raw_equal(conn->host.name, check->name) &&
  308. (conn->remote_port == check->remote_port) &&
  309. Curl_ssl_config_matches(&conn->ssl_config, &check->ssl_config)) {
  310. /* yes, we have a session ID! */
  311. (*general_age)++; /* increase general age */
  312. check->age = *general_age; /* set this as used in this age */
  313. *ssl_sessionid = check->sessionid;
  314. if(idsize)
  315. *idsize = check->idsize;
  316. no_match = FALSE;
  317. break;
  318. }
  319. }
  320. /* Unlock */
  321. if(SSLSESSION_SHARED(data))
  322. Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
  323. return no_match;
  324. }
  325. /*
  326. * Kill a single session ID entry in the cache.
  327. */
  328. void Curl_ssl_kill_session(struct curl_ssl_session *session)
  329. {
  330. if(session->sessionid) {
  331. /* defensive check */
  332. /* free the ID the SSL-layer specific way */
  333. curlssl_session_free(session->sessionid);
  334. session->sessionid = NULL;
  335. session->age = 0; /* fresh */
  336. Curl_free_ssl_config(&session->ssl_config);
  337. Curl_safefree(session->name);
  338. }
  339. }
  340. /*
  341. * Delete the given session ID from the cache.
  342. */
  343. void Curl_ssl_delsessionid(struct connectdata *conn, void *ssl_sessionid)
  344. {
  345. size_t i;
  346. struct SessionHandle *data=conn->data;
  347. if(SSLSESSION_SHARED(data))
  348. Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
  349. for(i = 0; i < data->set.ssl.max_ssl_sessions; i++) {
  350. struct curl_ssl_session *check = &data->state.session[i];
  351. if(check->sessionid == ssl_sessionid) {
  352. Curl_ssl_kill_session(check);
  353. break;
  354. }
  355. }
  356. if(SSLSESSION_SHARED(data))
  357. Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
  358. }
  359. /*
  360. * Store session id in the session cache. The ID passed on to this function
  361. * must already have been extracted and allocated the proper way for the SSL
  362. * layer. Curl_XXXX_session_free() will be called to free/kill the session ID
  363. * later on.
  364. */
  365. CURLcode Curl_ssl_addsessionid(struct connectdata *conn,
  366. void *ssl_sessionid,
  367. size_t idsize)
  368. {
  369. size_t i;
  370. struct SessionHandle *data=conn->data; /* the mother of all structs */
  371. struct curl_ssl_session *store = &data->state.session[0];
  372. long oldest_age=data->state.session[0].age; /* zero if unused */
  373. char *clone_host;
  374. long *general_age;
  375. /* Even though session ID re-use might be disabled, that only disables USING
  376. IT. We still store it here in case the re-using is again enabled for an
  377. upcoming transfer */
  378. clone_host = strdup(conn->host.name);
  379. if(!clone_host)
  380. return CURLE_OUT_OF_MEMORY; /* bail out */
  381. /* Now we should add the session ID and the host name to the cache, (remove
  382. the oldest if necessary) */
  383. /* If using shared SSL session, lock! */
  384. if(SSLSESSION_SHARED(data)) {
  385. Curl_share_lock(data, CURL_LOCK_DATA_SSL_SESSION, CURL_LOCK_ACCESS_SINGLE);
  386. general_age = &data->share->sessionage;
  387. }
  388. else {
  389. general_age = &data->state.sessionage;
  390. }
  391. /* find an empty slot for us, or find the oldest */
  392. for(i = 1; (i < data->set.ssl.max_ssl_sessions) &&
  393. data->state.session[i].sessionid; i++) {
  394. if(data->state.session[i].age < oldest_age) {
  395. oldest_age = data->state.session[i].age;
  396. store = &data->state.session[i];
  397. }
  398. }
  399. if(i == data->set.ssl.max_ssl_sessions)
  400. /* cache is full, we must "kill" the oldest entry! */
  401. Curl_ssl_kill_session(store);
  402. else
  403. store = &data->state.session[i]; /* use this slot */
  404. /* now init the session struct wisely */
  405. store->sessionid = ssl_sessionid;
  406. store->idsize = idsize;
  407. store->age = *general_age; /* set current age */
  408. if(store->name)
  409. /* free it if there's one already present */
  410. free(store->name);
  411. store->name = clone_host; /* clone host name */
  412. store->remote_port = conn->remote_port; /* port number */
  413. /* Unlock */
  414. if(SSLSESSION_SHARED(data))
  415. Curl_share_unlock(data, CURL_LOCK_DATA_SSL_SESSION);
  416. if(!Curl_clone_ssl_config(&conn->ssl_config, &store->ssl_config)) {
  417. store->sessionid = NULL; /* let caller free sessionid */
  418. free(clone_host);
  419. return CURLE_OUT_OF_MEMORY;
  420. }
  421. return CURLE_OK;
  422. }
  423. void Curl_ssl_close_all(struct SessionHandle *data)
  424. {
  425. size_t i;
  426. /* kill the session ID cache if not shared */
  427. if(data->state.session && !SSLSESSION_SHARED(data)) {
  428. for(i = 0; i < data->set.ssl.max_ssl_sessions; i++)
  429. /* the single-killer function handles empty table slots */
  430. Curl_ssl_kill_session(&data->state.session[i]);
  431. /* free the cache data */
  432. Curl_safefree(data->state.session);
  433. }
  434. curlssl_close_all(data);
  435. }
  436. void Curl_ssl_close(struct connectdata *conn, int sockindex)
  437. {
  438. DEBUGASSERT((sockindex <= 1) && (sockindex >= -1));
  439. curlssl_close(conn, sockindex);
  440. }
  441. CURLcode Curl_ssl_shutdown(struct connectdata *conn, int sockindex)
  442. {
  443. if(curlssl_shutdown(conn, sockindex))
  444. return CURLE_SSL_SHUTDOWN_FAILED;
  445. conn->ssl[sockindex].use = FALSE; /* get back to ordinary socket usage */
  446. conn->ssl[sockindex].state = ssl_connection_none;
  447. conn->recv[sockindex] = Curl_recv_plain;
  448. conn->send[sockindex] = Curl_send_plain;
  449. return CURLE_OK;
  450. }
  451. /* Selects an SSL crypto engine
  452. */
  453. CURLcode Curl_ssl_set_engine(struct SessionHandle *data, const char *engine)
  454. {
  455. return curlssl_set_engine(data, engine);
  456. }
  457. /* Selects the default SSL crypto engine
  458. */
  459. CURLcode Curl_ssl_set_engine_default(struct SessionHandle *data)
  460. {
  461. return curlssl_set_engine_default(data);
  462. }
  463. /* Return list of OpenSSL crypto engine names. */
  464. struct curl_slist *Curl_ssl_engines_list(struct SessionHandle *data)
  465. {
  466. return curlssl_engines_list(data);
  467. }
  468. /*
  469. * This sets up a session ID cache to the specified size. Make sure this code
  470. * is agnostic to what underlying SSL technology we use.
  471. */
  472. CURLcode Curl_ssl_initsessions(struct SessionHandle *data, size_t amount)
  473. {
  474. struct curl_ssl_session *session;
  475. if(data->state.session)
  476. /* this is just a precaution to prevent multiple inits */
  477. return CURLE_OK;
  478. session = calloc(amount, sizeof(struct curl_ssl_session));
  479. if(!session)
  480. return CURLE_OUT_OF_MEMORY;
  481. /* store the info in the SSL section */
  482. data->set.ssl.max_ssl_sessions = amount;
  483. data->state.session = session;
  484. data->state.sessionage = 1; /* this is brand new */
  485. return CURLE_OK;
  486. }
  487. size_t Curl_ssl_version(char *buffer, size_t size)
  488. {
  489. return curlssl_version(buffer, size);
  490. }
  491. /*
  492. * This function tries to determine connection status.
  493. *
  494. * Return codes:
  495. * 1 means the connection is still in place
  496. * 0 means the connection has been closed
  497. * -1 means the connection status is unknown
  498. */
  499. int Curl_ssl_check_cxn(struct connectdata *conn)
  500. {
  501. return curlssl_check_cxn(conn);
  502. }
  503. bool Curl_ssl_data_pending(const struct connectdata *conn,
  504. int connindex)
  505. {
  506. return curlssl_data_pending(conn, connindex);
  507. }
  508. void Curl_ssl_free_certinfo(struct SessionHandle *data)
  509. {
  510. int i;
  511. struct curl_certinfo *ci = &data->info.certs;
  512. if(ci->num_of_certs) {
  513. /* free all individual lists used */
  514. for(i=0; i<ci->num_of_certs; i++) {
  515. curl_slist_free_all(ci->certinfo[i]);
  516. ci->certinfo[i] = NULL;
  517. }
  518. free(ci->certinfo); /* free the actual array too */
  519. ci->certinfo = NULL;
  520. ci->num_of_certs = 0;
  521. }
  522. }
  523. int Curl_ssl_init_certinfo(struct SessionHandle * data,
  524. int num)
  525. {
  526. struct curl_certinfo * ci = &data->info.certs;
  527. struct curl_slist * * table;
  528. /* Initialize the certificate information structures. Return 0 if OK, else 1.
  529. */
  530. Curl_ssl_free_certinfo(data);
  531. ci->num_of_certs = num;
  532. table = calloc((size_t) num, sizeof(struct curl_slist *));
  533. if(!table)
  534. return 1;
  535. ci->certinfo = table;
  536. return 0;
  537. }
  538. /*
  539. * 'value' is NOT a zero terminated string
  540. */
  541. CURLcode Curl_ssl_push_certinfo_len(struct SessionHandle *data,
  542. int certnum,
  543. const char *label,
  544. const char *value,
  545. size_t valuelen)
  546. {
  547. struct curl_certinfo * ci = &data->info.certs;
  548. char * output;
  549. struct curl_slist * nl;
  550. CURLcode res = CURLE_OK;
  551. size_t labellen = strlen(label);
  552. size_t outlen = labellen + 1 + valuelen + 1; /* label:value\0 */
  553. output = malloc(outlen);
  554. if(!output)
  555. return CURLE_OUT_OF_MEMORY;
  556. /* sprintf the label and colon */
  557. snprintf(output, outlen, "%s:", label);
  558. /* memcpy the value (it might not be zero terminated) */
  559. memcpy(&output[labellen+1], value, valuelen);
  560. /* zero terminate the output */
  561. output[labellen + 1 + valuelen] = 0;
  562. nl = Curl_slist_append_nodup(ci->certinfo[certnum], output);
  563. if(!nl) {
  564. free(output);
  565. curl_slist_free_all(ci->certinfo[certnum]);
  566. res = CURLE_OUT_OF_MEMORY;
  567. }
  568. ci->certinfo[certnum] = nl;
  569. return res;
  570. }
  571. /*
  572. * This is a convenience function for push_certinfo_len that takes a zero
  573. * terminated value.
  574. */
  575. CURLcode Curl_ssl_push_certinfo(struct SessionHandle *data,
  576. int certnum,
  577. const char *label,
  578. const char *value)
  579. {
  580. size_t valuelen = strlen(value);
  581. return Curl_ssl_push_certinfo_len(data, certnum, label, value, valuelen);
  582. }
  583. int Curl_ssl_random(struct SessionHandle *data,
  584. unsigned char *entropy,
  585. size_t length)
  586. {
  587. return curlssl_random(data, entropy, length);
  588. }
  589. #ifdef have_curlssl_md5sum
  590. void Curl_ssl_md5sum(unsigned char *tmp, /* input */
  591. size_t tmplen,
  592. unsigned char *md5sum, /* output */
  593. size_t md5len)
  594. {
  595. curlssl_md5sum(tmp, tmplen, md5sum, md5len);
  596. }
  597. #endif
  598. #endif /* USE_SSL */