gtls.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2007, Daniel Stenberg, <daniel@haxx.se>, 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. * $Id$
  22. ***************************************************************************/
  23. /*
  24. * Source file for all GnuTLS-specific code for the TLS/SSL layer. No code
  25. * but sslgen.c should ever call or use these functions.
  26. *
  27. * Note: don't use the GnuTLS' *_t variable type names in this source code,
  28. * since they were not present in 1.0.X.
  29. */
  30. #include "setup.h"
  31. #ifdef USE_GNUTLS
  32. #include <gnutls/gnutls.h>
  33. #include <gnutls/x509.h>
  34. #include <string.h>
  35. #include <stdlib.h>
  36. #include <ctype.h>
  37. #ifdef HAVE_SYS_TYPES_H
  38. #include <sys/types.h>
  39. #endif
  40. #ifdef HAVE_SYS_SOCKET_H
  41. #include <sys/socket.h>
  42. #endif
  43. #include "urldata.h"
  44. #include "sendf.h"
  45. #include "gtls.h"
  46. #include "sslgen.h"
  47. #include "parsedate.h"
  48. #include "connect.h" /* for the connect timeout */
  49. #include "select.h"
  50. #define _MPRINTF_REPLACE /* use our functions only */
  51. #include <curl/mprintf.h>
  52. #include "memory.h"
  53. /* The last #include file should be: */
  54. #include "memdebug.h"
  55. /* Enable GnuTLS debugging by defining GTLSDEBUG */
  56. /*#define GTLSDEBUG */
  57. #ifdef GTLSDEBUG
  58. static void tls_log_func(int level, const char *str)
  59. {
  60. fprintf(stderr, "|<%d>| %s", level, str);
  61. }
  62. #endif
  63. /*
  64. * Custom push and pull callback functions used by GNU TLS to read and write
  65. * to the socket. These functions are simple wrappers to send() and recv()
  66. * (although here using the sread/swrite macros as defined by setup_once.h).
  67. * We use custom functions rather than the GNU TLS defaults because it allows
  68. * us to get specific about the fourth "flags" argument, and to use arbitrary
  69. * private data with gnutls_transport_set_ptr if we wish.
  70. */
  71. static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
  72. {
  73. return swrite(s, buf, len);
  74. }
  75. static ssize_t Curl_gtls_pull(void *s, void *buf, size_t len)
  76. {
  77. return sread(s, buf, len);
  78. }
  79. /* Global GnuTLS init, called from Curl_ssl_init() */
  80. int Curl_gtls_init(void)
  81. {
  82. gnutls_global_init();
  83. #ifdef GTLSDEBUG
  84. gnutls_global_set_log_function(tls_log_func);
  85. gnutls_global_set_log_level(2);
  86. #endif
  87. return 1;
  88. }
  89. int Curl_gtls_cleanup(void)
  90. {
  91. gnutls_global_deinit();
  92. return 1;
  93. }
  94. static void showtime(struct SessionHandle *data,
  95. const char *text,
  96. time_t stamp)
  97. {
  98. struct tm *tm;
  99. #ifdef HAVE_GMTIME_R
  100. struct tm buffer;
  101. tm = (struct tm *)gmtime_r(&stamp, &buffer);
  102. #else
  103. tm = gmtime(&stamp);
  104. #endif
  105. snprintf(data->state.buffer,
  106. BUFSIZE,
  107. "\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT\n",
  108. text,
  109. Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
  110. tm->tm_mday,
  111. Curl_month[tm->tm_mon],
  112. tm->tm_year + 1900,
  113. tm->tm_hour,
  114. tm->tm_min,
  115. tm->tm_sec);
  116. infof(data, "%s", data->state.buffer);
  117. }
  118. /* this function does a BLOCKING SSL/TLS (re-)handshake */
  119. static CURLcode handshake(struct connectdata *conn,
  120. gnutls_session session,
  121. int sockindex,
  122. bool duringconnect)
  123. {
  124. struct SessionHandle *data = conn->data;
  125. int rc;
  126. do {
  127. rc = gnutls_handshake(session);
  128. if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {
  129. long timeout_ms = DEFAULT_CONNECT_TIMEOUT;
  130. long has_passed;
  131. if(duringconnect && data->set.connecttimeout)
  132. timeout_ms = data->set.connecttimeout*1000;
  133. if(data->set.timeout) {
  134. /* get the strictest timeout of the ones converted to milliseconds */
  135. if((data->set.timeout*1000) < timeout_ms)
  136. timeout_ms = data->set.timeout*1000;
  137. }
  138. /* Evaluate in milliseconds how much time that has passed */
  139. has_passed = Curl_tvdiff(Curl_tvnow(), data->progress.t_startsingle);
  140. /* subtract the passed time */
  141. timeout_ms -= has_passed;
  142. if(timeout_ms < 0) {
  143. /* a precaution, no need to continue if time already is up */
  144. failf(data, "SSL connection timeout");
  145. return CURLE_OPERATION_TIMEOUTED;
  146. }
  147. rc = Curl_select(conn->sock[sockindex],
  148. conn->sock[sockindex], (int)timeout_ms);
  149. if(rc > 0)
  150. /* reabable or writable, go loop*/
  151. continue;
  152. else if(0 == rc) {
  153. /* timeout */
  154. failf(data, "SSL connection timeout");
  155. return CURLE_OPERATION_TIMEDOUT;
  156. }
  157. else {
  158. /* anything that gets here is fatally bad */
  159. failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
  160. return CURLE_SSL_CONNECT_ERROR;
  161. }
  162. }
  163. else
  164. break;
  165. } while(1);
  166. if (rc < 0) {
  167. failf(data, "gnutls_handshake() failed: %s", gnutls_strerror(rc));
  168. return CURLE_SSL_CONNECT_ERROR;
  169. }
  170. return CURLE_OK;
  171. }
  172. static gnutls_x509_crt_fmt do_file_type(const char *type)
  173. {
  174. if(!type || !type[0])
  175. return GNUTLS_X509_FMT_PEM;
  176. if(curl_strequal(type, "PEM"))
  177. return GNUTLS_X509_FMT_PEM;
  178. if(curl_strequal(type, "DER"))
  179. return GNUTLS_X509_FMT_DER;
  180. return -1;
  181. }
  182. /*
  183. * This function is called after the TCP connect has completed. Setup the TLS
  184. * layer and do all necessary magic.
  185. */
  186. CURLcode
  187. Curl_gtls_connect(struct connectdata *conn,
  188. int sockindex)
  189. {
  190. const int cert_type_priority[] = { GNUTLS_CRT_X509, 0 };
  191. struct SessionHandle *data = conn->data;
  192. gnutls_session session;
  193. int rc;
  194. unsigned int cert_list_size;
  195. const gnutls_datum *chainp;
  196. unsigned int verify_status;
  197. gnutls_x509_crt x509_cert;
  198. char certbuf[256]; /* big enough? */
  199. size_t size;
  200. unsigned int algo;
  201. unsigned int bits;
  202. time_t clock;
  203. const char *ptr;
  204. void *ssl_sessionid;
  205. size_t ssl_idsize;
  206. /* GnuTLS only supports TLSv1 (and SSLv3?) */
  207. if(data->set.ssl.version == CURL_SSLVERSION_SSLv2) {
  208. failf(data, "GnuTLS does not support SSLv2");
  209. return CURLE_SSL_CONNECT_ERROR;
  210. }
  211. /* allocate a cred struct */
  212. rc = gnutls_certificate_allocate_credentials(&conn->ssl[sockindex].cred);
  213. if(rc < 0) {
  214. failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc));
  215. return CURLE_SSL_CONNECT_ERROR;
  216. }
  217. if(data->set.ssl.CAfile) {
  218. /* set the trusted CA cert bundle file */
  219. gnutls_certificate_set_verify_flags(conn->ssl[sockindex].cred,
  220. GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
  221. rc = gnutls_certificate_set_x509_trust_file(conn->ssl[sockindex].cred,
  222. data->set.ssl.CAfile,
  223. GNUTLS_X509_FMT_PEM);
  224. if(rc < 0) {
  225. infof(data, "error reading ca cert file %s (%s)\n",
  226. data->set.ssl.CAfile, gnutls_strerror(rc));
  227. if (data->set.ssl.verifypeer)
  228. return CURLE_SSL_CACERT_BADFILE;
  229. }
  230. else
  231. infof(data, "found %d certificates in %s\n",
  232. rc, data->set.ssl.CAfile);
  233. }
  234. /* Initialize TLS session as a client */
  235. rc = gnutls_init(&conn->ssl[sockindex].session, GNUTLS_CLIENT);
  236. if(rc) {
  237. failf(data, "gnutls_init() failed: %d", rc);
  238. return CURLE_SSL_CONNECT_ERROR;
  239. }
  240. /* convenient assign */
  241. session = conn->ssl[sockindex].session;
  242. /* Use default priorities */
  243. rc = gnutls_set_default_priority(session);
  244. if(rc < 0)
  245. return CURLE_SSL_CONNECT_ERROR;
  246. /* Sets the priority on the certificate types supported by gnutls. Priority
  247. is higher for types specified before others. After specifying the types
  248. you want, you must append a 0. */
  249. rc = gnutls_certificate_type_set_priority(session, cert_type_priority);
  250. if(rc < 0)
  251. return CURLE_SSL_CONNECT_ERROR;
  252. if(data->set.cert) {
  253. if( gnutls_certificate_set_x509_key_file(
  254. conn->ssl[sockindex].cred, data->set.cert,
  255. data->set.key != 0 ? data->set.key : data->set.cert,
  256. do_file_type(data->set.cert_type) ) ) {
  257. failf(data, "error reading X.509 key or certificate file");
  258. return CURLE_SSL_CONNECT_ERROR;
  259. }
  260. }
  261. /* put the credentials to the current session */
  262. rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE,
  263. conn->ssl[sockindex].cred);
  264. /* set the connection handle (file descriptor for the socket) */
  265. gnutls_transport_set_ptr(session,
  266. (gnutls_transport_ptr)conn->sock[sockindex]);
  267. /* register callback functions to send and receive data. */
  268. gnutls_transport_set_push_function(session, Curl_gtls_push);
  269. gnutls_transport_set_pull_function(session, Curl_gtls_pull);
  270. /* lowat must be set to zero when using custom push and pull functions. */
  271. gnutls_transport_set_lowat(session, 0);
  272. /* This might be a reconnect, so we check for a session ID in the cache
  273. to speed up things */
  274. if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize)) {
  275. /* we got a session id, use it! */
  276. gnutls_session_set_data(session, ssl_sessionid, ssl_idsize);
  277. /* Informational message */
  278. infof (data, "SSL re-using session ID\n");
  279. }
  280. rc = handshake(conn, session, sockindex, TRUE);
  281. if(rc)
  282. /* handshake() sets its own error message with failf() */
  283. return rc;
  284. /* This function will return the peer's raw certificate (chain) as sent by
  285. the peer. These certificates are in raw format (DER encoded for
  286. X.509). In case of a X.509 then a certificate list may be present. The
  287. first certificate in the list is the peer's certificate, following the
  288. issuer's certificate, then the issuer's issuer etc. */
  289. chainp = gnutls_certificate_get_peers(session, &cert_list_size);
  290. if(!chainp) {
  291. if(data->set.ssl.verifyhost) {
  292. failf(data, "failed to get server cert");
  293. return CURLE_SSL_PEER_CERTIFICATE;
  294. }
  295. infof(data, "\t common name: WARNING couldn't obtain\n");
  296. }
  297. /* This function will try to verify the peer's certificate and return its
  298. status (trusted, invalid etc.). The value of status should be one or more
  299. of the gnutls_certificate_status_t enumerated elements bitwise or'd. To
  300. avoid denial of service attacks some default upper limits regarding the
  301. certificate key size and chain size are set. To override them use
  302. gnutls_certificate_set_verify_limits(). */
  303. rc = gnutls_certificate_verify_peers2(session, &verify_status);
  304. if (rc < 0) {
  305. failf(data, "server cert verify failed: %d", rc);
  306. return CURLE_SSL_CONNECT_ERROR;
  307. }
  308. /* verify_status is a bitmask of gnutls_certificate_status bits */
  309. if(verify_status & GNUTLS_CERT_INVALID) {
  310. if (data->set.ssl.verifypeer) {
  311. failf(data, "server certificate verification failed. CAfile: %s",
  312. data->set.ssl.CAfile?data->set.ssl.CAfile:"none");
  313. return CURLE_SSL_CACERT;
  314. }
  315. else
  316. infof(data, "\t server certificate verification FAILED\n");
  317. }
  318. else
  319. infof(data, "\t server certificate verification OK\n");
  320. /* initialize an X.509 certificate structure. */
  321. gnutls_x509_crt_init(&x509_cert);
  322. /* convert the given DER or PEM encoded Certificate to the native
  323. gnutls_x509_crt_t format */
  324. gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER);
  325. size=sizeof(certbuf);
  326. rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, GNUTLS_OID_X520_COMMON_NAME,
  327. 0, /* the first and only one */
  328. FALSE,
  329. certbuf,
  330. &size);
  331. if(rc) {
  332. infof(data, "error fetching CN from cert:%s\n",
  333. gnutls_strerror(rc));
  334. }
  335. /* This function will check if the given certificate's subject matches the
  336. given hostname. This is a basic implementation of the matching described
  337. in RFC2818 (HTTPS), which takes into account wildcards, and the subject
  338. alternative name PKIX extension. Returns non zero on success, and zero on
  339. failure. */
  340. rc = gnutls_x509_crt_check_hostname(x509_cert, conn->host.name);
  341. if(!rc) {
  342. if (data->set.ssl.verifyhost > 1) {
  343. failf(data, "SSL: certificate subject name (%s) does not match "
  344. "target host name '%s'", certbuf, conn->host.dispname);
  345. gnutls_x509_crt_deinit(x509_cert);
  346. return CURLE_SSL_PEER_CERTIFICATE;
  347. }
  348. else
  349. infof(data, "\t common name: %s (does not match '%s')\n",
  350. certbuf, conn->host.dispname);
  351. }
  352. else
  353. infof(data, "\t common name: %s (matched)\n", certbuf);
  354. /* Show:
  355. - ciphers used
  356. - subject
  357. - start date
  358. - expire date
  359. - common name
  360. - issuer
  361. */
  362. /* public key algorithm's parameters */
  363. algo = gnutls_x509_crt_get_pk_algorithm(x509_cert, &bits);
  364. infof(data, "\t certificate public key: %s\n",
  365. gnutls_pk_algorithm_get_name(algo));
  366. /* version of the X.509 certificate. */
  367. infof(data, "\t certificate version: #%d\n",
  368. gnutls_x509_crt_get_version(x509_cert));
  369. size = sizeof(certbuf);
  370. gnutls_x509_crt_get_dn(x509_cert, certbuf, &size);
  371. infof(data, "\t subject: %s\n", certbuf);
  372. clock = gnutls_x509_crt_get_activation_time(x509_cert);
  373. showtime(data, "start date", clock);
  374. clock = gnutls_x509_crt_get_expiration_time(x509_cert);
  375. showtime(data, "expire date", clock);
  376. size = sizeof(certbuf);
  377. gnutls_x509_crt_get_issuer_dn(x509_cert, certbuf, &size);
  378. infof(data, "\t issuer: %s\n", certbuf);
  379. gnutls_x509_crt_deinit(x509_cert);
  380. /* compression algorithm (if any) */
  381. ptr = gnutls_compression_get_name(gnutls_compression_get(session));
  382. /* the *_get_name() says "NULL" if GNUTLS_COMP_NULL is returned */
  383. infof(data, "\t compression: %s\n", ptr);
  384. /* the name of the cipher used. ie 3DES. */
  385. ptr = gnutls_cipher_get_name(gnutls_cipher_get(session));
  386. infof(data, "\t cipher: %s\n", ptr);
  387. /* the MAC algorithms name. ie SHA1 */
  388. ptr = gnutls_mac_get_name(gnutls_mac_get(session));
  389. infof(data, "\t MAC: %s\n", ptr);
  390. if(!ssl_sessionid) {
  391. /* this session was not previously in the cache, add it now */
  392. /* get the session ID data size */
  393. gnutls_session_get_data(session, NULL, &ssl_idsize);
  394. ssl_sessionid = malloc(ssl_idsize); /* get a buffer for it */
  395. if(ssl_sessionid) {
  396. /* extract session ID to the allocated buffer */
  397. gnutls_session_get_data(session, ssl_sessionid, &ssl_idsize);
  398. /* store this session id */
  399. return Curl_ssl_addsessionid(conn, ssl_sessionid, ssl_idsize);
  400. }
  401. }
  402. return CURLE_OK;
  403. }
  404. /* return number of sent (non-SSL) bytes */
  405. ssize_t Curl_gtls_send(struct connectdata *conn,
  406. int sockindex,
  407. void *mem,
  408. size_t len)
  409. {
  410. ssize_t rc = gnutls_record_send(conn->ssl[sockindex].session, mem, len);
  411. if(rc < 0 ) {
  412. if(rc == GNUTLS_E_AGAIN)
  413. return 0; /* EWOULDBLOCK equivalent */
  414. rc = -1; /* generic error code for send failure */
  415. }
  416. return rc;
  417. }
  418. void Curl_gtls_close_all(struct SessionHandle *data)
  419. {
  420. /* FIX: make the OpenSSL code more generic and use parts of it here */
  421. (void)data;
  422. }
  423. static void close_one(struct connectdata *conn,
  424. int index)
  425. {
  426. if(conn->ssl[index].session) {
  427. gnutls_bye(conn->ssl[index].session, GNUTLS_SHUT_RDWR);
  428. gnutls_deinit(conn->ssl[index].session);
  429. }
  430. gnutls_certificate_free_credentials(conn->ssl[index].cred);
  431. }
  432. void Curl_gtls_close(struct connectdata *conn)
  433. {
  434. if(conn->ssl[0].use)
  435. close_one(conn, 0);
  436. if(conn->ssl[1].use)
  437. close_one(conn, 1);
  438. }
  439. /*
  440. * This function is called to shut down the SSL layer but keep the
  441. * socket open (CCC - Clear Command Channel)
  442. */
  443. int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
  444. {
  445. int result;
  446. int retval = 0;
  447. struct SessionHandle *data = conn->data;
  448. int done = 0;
  449. ssize_t nread;
  450. char buf[120];
  451. /* This has only been tested on the proftpd server, and the mod_tls code
  452. sends a close notify alert without waiting for a close notify alert in
  453. response. Thus we wait for a close notify alert from the server, but
  454. we do not send one. Let's hope other servers do the same... */
  455. if(conn->ssl[sockindex].session) {
  456. while(!done) {
  457. int what = Curl_select(conn->sock[sockindex],
  458. CURL_SOCKET_BAD, SSL_SHUTDOWN_TIMEOUT);
  459. if(what > 0) {
  460. /* Something to read, let's do it and hope that it is the close
  461. notify alert from the server */
  462. result = gnutls_record_recv(conn->ssl[sockindex].session,
  463. buf, sizeof(buf));
  464. switch(result) {
  465. case 0:
  466. /* This is the expected response. There was no data but only
  467. the close notify alert */
  468. done = 1;
  469. break;
  470. case GNUTLS_E_AGAIN:
  471. case GNUTLS_E_INTERRUPTED:
  472. infof(data, "GNUTLS_E_AGAIN || GNUTLS_E_INTERRUPTED\n");
  473. break;
  474. default:
  475. retval = -1;
  476. done = 1;
  477. break;
  478. }
  479. }
  480. else if(0 == what) {
  481. /* timeout */
  482. failf(data, "SSL shutdown timeout");
  483. done = 1;
  484. break;
  485. }
  486. else {
  487. /* anything that gets here is fatally bad */
  488. failf(data, "select on SSL socket, errno: %d", Curl_sockerrno());
  489. retval = -1;
  490. done = 1;
  491. }
  492. }
  493. gnutls_deinit(conn->ssl[sockindex].session);
  494. }
  495. gnutls_certificate_free_credentials(conn->ssl[sockindex].cred);
  496. conn->ssl[sockindex].session = NULL;
  497. conn->ssl[sockindex].use = FALSE;
  498. return retval;
  499. }
  500. /*
  501. * If the read would block we return -1 and set 'wouldblock' to TRUE.
  502. * Otherwise we return the amount of data read. Other errors should return -1
  503. * and set 'wouldblock' to FALSE.
  504. */
  505. ssize_t Curl_gtls_recv(struct connectdata *conn, /* connection data */
  506. int num, /* socketindex */
  507. char *buf, /* store read data here */
  508. size_t buffersize, /* max amount to read */
  509. bool *wouldblock)
  510. {
  511. ssize_t ret;
  512. ret = gnutls_record_recv(conn->ssl[num].session, buf, buffersize);
  513. if((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)) {
  514. *wouldblock = TRUE;
  515. return -1;
  516. }
  517. if(ret == GNUTLS_E_REHANDSHAKE) {
  518. /* BLOCKING call, this is bad but a work-around for now. Fixing this "the
  519. proper way" takes a whole lot of work. */
  520. CURLcode rc = handshake(conn, conn->ssl[num].session, num, FALSE);
  521. if(rc)
  522. /* handshake() writes error message on its own */
  523. return rc;
  524. *wouldblock = TRUE; /* then return as if this was a wouldblock */
  525. return -1;
  526. }
  527. *wouldblock = FALSE;
  528. if (!ret) {
  529. failf(conn->data, "Peer closed the TLS connection");
  530. return -1;
  531. }
  532. if (ret < 0) {
  533. failf(conn->data, "GnuTLS recv error (%d): %s",
  534. (int)ret, gnutls_strerror(ret));
  535. return -1;
  536. }
  537. return ret;
  538. }
  539. void Curl_gtls_session_free(void *ptr)
  540. {
  541. free(ptr);
  542. }
  543. size_t Curl_gtls_version(char *buffer, size_t size)
  544. {
  545. return snprintf(buffer, size, " GnuTLS/%s", gnutls_check_version(NULL));
  546. }
  547. #endif /* USE_GNUTLS */