gtls.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 1998 - 2020, 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 https://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. /*
  23. * Source file for all GnuTLS-specific code for the TLS/SSL layer. No code
  24. * but vtls.c should ever call or use these functions.
  25. *
  26. * Note: don't use the GnuTLS' *_t variable type names in this source code,
  27. * since they were not present in 1.0.X.
  28. */
  29. #include "curl_setup.h"
  30. #ifdef USE_GNUTLS
  31. #include <gnutls/abstract.h>
  32. #include <gnutls/gnutls.h>
  33. #include <gnutls/x509.h>
  34. #ifdef USE_GNUTLS_NETTLE
  35. #include <gnutls/crypto.h>
  36. #include <nettle/md5.h>
  37. #include <nettle/sha2.h>
  38. #else
  39. #include <gcrypt.h>
  40. #endif
  41. #include "urldata.h"
  42. #include "sendf.h"
  43. #include "inet_pton.h"
  44. #include "gtls.h"
  45. #include "vtls.h"
  46. #include "parsedate.h"
  47. #include "connect.h" /* for the connect timeout */
  48. #include "select.h"
  49. #include "strcase.h"
  50. #include "warnless.h"
  51. #include "x509asn1.h"
  52. #include "multiif.h"
  53. #include "curl_printf.h"
  54. #include "curl_memory.h"
  55. /* The last #include file should be: */
  56. #include "memdebug.h"
  57. /* Enable GnuTLS debugging by defining GTLSDEBUG */
  58. /*#define GTLSDEBUG */
  59. #ifdef GTLSDEBUG
  60. static void tls_log_func(int level, const char *str)
  61. {
  62. fprintf(stderr, "|<%d>| %s", level, str);
  63. }
  64. #endif
  65. static bool gtls_inited = FALSE;
  66. #if !defined(GNUTLS_VERSION_NUMBER) || (GNUTLS_VERSION_NUMBER < 0x03010a)
  67. #error "too old GnuTLS version"
  68. #endif
  69. # include <gnutls/ocsp.h>
  70. struct ssl_backend_data {
  71. gnutls_session_t session;
  72. gnutls_certificate_credentials_t cred;
  73. #ifdef USE_TLS_SRP
  74. gnutls_srp_client_credentials_t srp_client_cred;
  75. #endif
  76. };
  77. static ssize_t Curl_gtls_push(void *s, const void *buf, size_t len)
  78. {
  79. curl_socket_t sock = *(curl_socket_t *)s;
  80. ssize_t ret = swrite(sock, buf, len);
  81. return ret;
  82. }
  83. static ssize_t Curl_gtls_pull(void *s, void *buf, size_t len)
  84. {
  85. curl_socket_t sock = *(curl_socket_t *)s;
  86. ssize_t ret = sread(sock, buf, len);
  87. return ret;
  88. }
  89. static ssize_t Curl_gtls_push_ssl(void *s, const void *buf, size_t len)
  90. {
  91. return gnutls_record_send((gnutls_session_t) s, buf, len);
  92. }
  93. static ssize_t Curl_gtls_pull_ssl(void *s, void *buf, size_t len)
  94. {
  95. return gnutls_record_recv((gnutls_session_t) s, buf, len);
  96. }
  97. /* Curl_gtls_init()
  98. *
  99. * Global GnuTLS init, called from Curl_ssl_init(). This calls functions that
  100. * are not thread-safe and thus this function itself is not thread-safe and
  101. * must only be called from within curl_global_init() to keep the thread
  102. * situation under control!
  103. */
  104. static int Curl_gtls_init(void)
  105. {
  106. int ret = 1;
  107. if(!gtls_inited) {
  108. ret = gnutls_global_init()?0:1;
  109. #ifdef GTLSDEBUG
  110. gnutls_global_set_log_function(tls_log_func);
  111. gnutls_global_set_log_level(2);
  112. #endif
  113. gtls_inited = TRUE;
  114. }
  115. return ret;
  116. }
  117. static void Curl_gtls_cleanup(void)
  118. {
  119. if(gtls_inited) {
  120. gnutls_global_deinit();
  121. gtls_inited = FALSE;
  122. }
  123. }
  124. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  125. static void showtime(struct Curl_easy *data,
  126. const char *text,
  127. time_t stamp)
  128. {
  129. struct tm buffer;
  130. const struct tm *tm = &buffer;
  131. char str[96];
  132. CURLcode result = Curl_gmtime(stamp, &buffer);
  133. if(result)
  134. return;
  135. msnprintf(str,
  136. sizeof(str),
  137. "\t %s: %s, %02d %s %4d %02d:%02d:%02d GMT",
  138. text,
  139. Curl_wkday[tm->tm_wday?tm->tm_wday-1:6],
  140. tm->tm_mday,
  141. Curl_month[tm->tm_mon],
  142. tm->tm_year + 1900,
  143. tm->tm_hour,
  144. tm->tm_min,
  145. tm->tm_sec);
  146. infof(data, "%s\n", str);
  147. }
  148. #endif
  149. static gnutls_datum_t load_file(const char *file)
  150. {
  151. FILE *f;
  152. gnutls_datum_t loaded_file = { NULL, 0 };
  153. long filelen;
  154. void *ptr;
  155. f = fopen(file, "rb");
  156. if(!f)
  157. return loaded_file;
  158. if(fseek(f, 0, SEEK_END) != 0
  159. || (filelen = ftell(f)) < 0
  160. || fseek(f, 0, SEEK_SET) != 0
  161. || !(ptr = malloc((size_t)filelen)))
  162. goto out;
  163. if(fread(ptr, 1, (size_t)filelen, f) < (size_t)filelen) {
  164. free(ptr);
  165. goto out;
  166. }
  167. loaded_file.data = ptr;
  168. loaded_file.size = (unsigned int)filelen;
  169. out:
  170. fclose(f);
  171. return loaded_file;
  172. }
  173. static void unload_file(gnutls_datum_t data)
  174. {
  175. free(data.data);
  176. }
  177. /* this function does a SSL/TLS (re-)handshake */
  178. static CURLcode handshake(struct connectdata *conn,
  179. int sockindex,
  180. bool duringconnect,
  181. bool nonblocking)
  182. {
  183. struct Curl_easy *data = conn->data;
  184. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  185. struct ssl_backend_data *backend = connssl->backend;
  186. gnutls_session_t session = backend->session;
  187. curl_socket_t sockfd = conn->sock[sockindex];
  188. for(;;) {
  189. timediff_t timeout_ms;
  190. int rc;
  191. /* check allowed time left */
  192. timeout_ms = Curl_timeleft(data, NULL, duringconnect);
  193. if(timeout_ms < 0) {
  194. /* no need to continue if time already is up */
  195. failf(data, "SSL connection timeout");
  196. return CURLE_OPERATION_TIMEDOUT;
  197. }
  198. /* if ssl is expecting something, check if it's available. */
  199. if(connssl->connecting_state == ssl_connect_2_reading
  200. || connssl->connecting_state == ssl_connect_2_writing) {
  201. int what;
  202. curl_socket_t writefd = ssl_connect_2_writing ==
  203. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  204. curl_socket_t readfd = ssl_connect_2_reading ==
  205. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  206. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
  207. nonblocking?0:
  208. timeout_ms?timeout_ms:1000);
  209. if(what < 0) {
  210. /* fatal error */
  211. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  212. return CURLE_SSL_CONNECT_ERROR;
  213. }
  214. else if(0 == what) {
  215. if(nonblocking)
  216. return CURLE_OK;
  217. else if(timeout_ms) {
  218. /* timeout */
  219. failf(data, "SSL connection timeout at %ld", (long)timeout_ms);
  220. return CURLE_OPERATION_TIMEDOUT;
  221. }
  222. }
  223. /* socket is readable or writable */
  224. }
  225. rc = gnutls_handshake(session);
  226. if((rc == GNUTLS_E_AGAIN) || (rc == GNUTLS_E_INTERRUPTED)) {
  227. connssl->connecting_state =
  228. gnutls_record_get_direction(session)?
  229. ssl_connect_2_writing:ssl_connect_2_reading;
  230. continue;
  231. }
  232. else if((rc < 0) && !gnutls_error_is_fatal(rc)) {
  233. const char *strerr = NULL;
  234. if(rc == GNUTLS_E_WARNING_ALERT_RECEIVED) {
  235. int alert = gnutls_alert_get(session);
  236. strerr = gnutls_alert_get_name(alert);
  237. }
  238. if(strerr == NULL)
  239. strerr = gnutls_strerror(rc);
  240. infof(data, "gnutls_handshake() warning: %s\n", strerr);
  241. continue;
  242. }
  243. else if(rc < 0) {
  244. const char *strerr = NULL;
  245. if(rc == GNUTLS_E_FATAL_ALERT_RECEIVED) {
  246. int alert = gnutls_alert_get(session);
  247. strerr = gnutls_alert_get_name(alert);
  248. }
  249. if(strerr == NULL)
  250. strerr = gnutls_strerror(rc);
  251. failf(data, "gnutls_handshake() failed: %s", strerr);
  252. return CURLE_SSL_CONNECT_ERROR;
  253. }
  254. /* Reset our connect state machine */
  255. connssl->connecting_state = ssl_connect_1;
  256. return CURLE_OK;
  257. }
  258. }
  259. static gnutls_x509_crt_fmt_t do_file_type(const char *type)
  260. {
  261. if(!type || !type[0])
  262. return GNUTLS_X509_FMT_PEM;
  263. if(strcasecompare(type, "PEM"))
  264. return GNUTLS_X509_FMT_PEM;
  265. if(strcasecompare(type, "DER"))
  266. return GNUTLS_X509_FMT_DER;
  267. return -1;
  268. }
  269. #define GNUTLS_CIPHERS "NORMAL:-ARCFOUR-128:-CTYPE-ALL:+CTYPE-X509"
  270. /* If GnuTLS was compiled without support for SRP it will error out if SRP is
  271. requested in the priority string, so treat it specially
  272. */
  273. #define GNUTLS_SRP "+SRP"
  274. static CURLcode
  275. set_ssl_version_min_max(const char **prioritylist, struct connectdata *conn)
  276. {
  277. struct Curl_easy *data = conn->data;
  278. long ssl_version = SSL_CONN_CONFIG(version);
  279. long ssl_version_max = SSL_CONN_CONFIG(version_max);
  280. if(ssl_version_max == CURL_SSLVERSION_MAX_NONE) {
  281. ssl_version_max = CURL_SSLVERSION_MAX_DEFAULT;
  282. }
  283. switch(ssl_version | ssl_version_max) {
  284. case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_0:
  285. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  286. "+VERS-TLS1.0";
  287. return CURLE_OK;
  288. case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_1:
  289. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  290. "+VERS-TLS1.0:+VERS-TLS1.1";
  291. return CURLE_OK;
  292. case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_TLSv1_2:
  293. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  294. "+VERS-TLS1.0:+VERS-TLS1.1:+VERS-TLS1.2";
  295. return CURLE_OK;
  296. case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_1:
  297. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  298. "+VERS-TLS1.1";
  299. return CURLE_OK;
  300. case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_TLSv1_2:
  301. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  302. "+VERS-TLS1.1:+VERS-TLS1.2";
  303. return CURLE_OK;
  304. case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_TLSv1_2:
  305. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  306. "+VERS-TLS1.2";
  307. return CURLE_OK;
  308. case CURL_SSLVERSION_TLSv1_3 | CURL_SSLVERSION_MAX_TLSv1_3:
  309. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  310. "+VERS-TLS1.3";
  311. return CURLE_OK;
  312. case CURL_SSLVERSION_TLSv1_0 | CURL_SSLVERSION_MAX_DEFAULT:
  313. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  314. "+VERS-TLS1.0:+VERS-TLS1.1:+VERS-TLS1.2"
  315. ":+VERS-TLS1.3";
  316. return CURLE_OK;
  317. case CURL_SSLVERSION_TLSv1_1 | CURL_SSLVERSION_MAX_DEFAULT:
  318. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  319. "+VERS-TLS1.1:+VERS-TLS1.2"
  320. ":+VERS-TLS1.3";
  321. return CURLE_OK;
  322. case CURL_SSLVERSION_TLSv1_2 | CURL_SSLVERSION_MAX_DEFAULT:
  323. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  324. "+VERS-TLS1.2"
  325. ":+VERS-TLS1.3";
  326. return CURLE_OK;
  327. case CURL_SSLVERSION_TLSv1_3 | CURL_SSLVERSION_MAX_DEFAULT:
  328. *prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0:-VERS-TLS-ALL:"
  329. "+VERS-TLS1.2"
  330. ":+VERS-TLS1.3";
  331. return CURLE_OK;
  332. }
  333. failf(data, "GnuTLS: cannot set ssl protocol");
  334. return CURLE_SSL_CONNECT_ERROR;
  335. }
  336. static CURLcode
  337. gtls_connect_step1(struct connectdata *conn,
  338. int sockindex)
  339. {
  340. struct Curl_easy *data = conn->data;
  341. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  342. struct ssl_backend_data *backend = connssl->backend;
  343. unsigned int init_flags;
  344. gnutls_session_t session;
  345. int rc;
  346. bool sni = TRUE; /* default is SNI enabled */
  347. void *transport_ptr = NULL;
  348. gnutls_push_func gnutls_transport_push = NULL;
  349. gnutls_pull_func gnutls_transport_pull = NULL;
  350. #ifdef ENABLE_IPV6
  351. struct in6_addr addr;
  352. #else
  353. struct in_addr addr;
  354. #endif
  355. const char *prioritylist;
  356. const char *err = NULL;
  357. #ifndef CURL_DISABLE_PROXY
  358. const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  359. conn->host.name;
  360. long * const certverifyresult = SSL_IS_PROXY() ?
  361. &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult;
  362. #else
  363. const char * const hostname = conn->host.name;
  364. long * const certverifyresult = &data->set.ssl.certverifyresult;
  365. #endif
  366. if(connssl->state == ssl_connection_complete)
  367. /* to make us tolerant against being called more than once for the
  368. same connection */
  369. return CURLE_OK;
  370. if(!gtls_inited)
  371. Curl_gtls_init();
  372. /* Initialize certverifyresult to OK */
  373. *certverifyresult = 0;
  374. if(SSL_CONN_CONFIG(version) == CURL_SSLVERSION_SSLv2) {
  375. failf(data, "GnuTLS does not support SSLv2");
  376. return CURLE_SSL_CONNECT_ERROR;
  377. }
  378. else if(SSL_CONN_CONFIG(version) == CURL_SSLVERSION_SSLv3)
  379. sni = FALSE; /* SSLv3 has no SNI */
  380. /* allocate a cred struct */
  381. rc = gnutls_certificate_allocate_credentials(&backend->cred);
  382. if(rc != GNUTLS_E_SUCCESS) {
  383. failf(data, "gnutls_cert_all_cred() failed: %s", gnutls_strerror(rc));
  384. return CURLE_SSL_CONNECT_ERROR;
  385. }
  386. #ifdef USE_TLS_SRP
  387. if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) {
  388. infof(data, "Using TLS-SRP username: %s\n", SSL_SET_OPTION(username));
  389. rc = gnutls_srp_allocate_client_credentials(
  390. &backend->srp_client_cred);
  391. if(rc != GNUTLS_E_SUCCESS) {
  392. failf(data, "gnutls_srp_allocate_client_cred() failed: %s",
  393. gnutls_strerror(rc));
  394. return CURLE_OUT_OF_MEMORY;
  395. }
  396. rc = gnutls_srp_set_client_credentials(backend->srp_client_cred,
  397. SSL_SET_OPTION(username),
  398. SSL_SET_OPTION(password));
  399. if(rc != GNUTLS_E_SUCCESS) {
  400. failf(data, "gnutls_srp_set_client_cred() failed: %s",
  401. gnutls_strerror(rc));
  402. return CURLE_BAD_FUNCTION_ARGUMENT;
  403. }
  404. }
  405. #endif
  406. if(SSL_CONN_CONFIG(CAfile)) {
  407. /* set the trusted CA cert bundle file */
  408. gnutls_certificate_set_verify_flags(backend->cred,
  409. GNUTLS_VERIFY_ALLOW_X509_V1_CA_CRT);
  410. rc = gnutls_certificate_set_x509_trust_file(backend->cred,
  411. SSL_CONN_CONFIG(CAfile),
  412. GNUTLS_X509_FMT_PEM);
  413. if(rc < 0) {
  414. infof(data, "error reading ca cert file %s (%s)\n",
  415. SSL_CONN_CONFIG(CAfile), gnutls_strerror(rc));
  416. if(SSL_CONN_CONFIG(verifypeer)) {
  417. *certverifyresult = rc;
  418. return CURLE_SSL_CACERT_BADFILE;
  419. }
  420. }
  421. else
  422. infof(data, "found %d certificates in %s\n", rc,
  423. SSL_CONN_CONFIG(CAfile));
  424. }
  425. if(SSL_CONN_CONFIG(CApath)) {
  426. /* set the trusted CA cert directory */
  427. rc = gnutls_certificate_set_x509_trust_dir(backend->cred,
  428. SSL_CONN_CONFIG(CApath),
  429. GNUTLS_X509_FMT_PEM);
  430. if(rc < 0) {
  431. infof(data, "error reading ca cert file %s (%s)\n",
  432. SSL_CONN_CONFIG(CApath), gnutls_strerror(rc));
  433. if(SSL_CONN_CONFIG(verifypeer)) {
  434. *certverifyresult = rc;
  435. return CURLE_SSL_CACERT_BADFILE;
  436. }
  437. }
  438. else
  439. infof(data, "found %d certificates in %s\n",
  440. rc, SSL_CONN_CONFIG(CApath));
  441. }
  442. #ifdef CURL_CA_FALLBACK
  443. /* use system ca certificate store as fallback */
  444. if(SSL_CONN_CONFIG(verifypeer) &&
  445. !(SSL_CONN_CONFIG(CAfile) || SSL_CONN_CONFIG(CApath))) {
  446. gnutls_certificate_set_x509_system_trust(backend->cred);
  447. }
  448. #endif
  449. if(SSL_SET_OPTION(CRLfile)) {
  450. /* set the CRL list file */
  451. rc = gnutls_certificate_set_x509_crl_file(backend->cred,
  452. SSL_SET_OPTION(CRLfile),
  453. GNUTLS_X509_FMT_PEM);
  454. if(rc < 0) {
  455. failf(data, "error reading crl file %s (%s)",
  456. SSL_SET_OPTION(CRLfile), gnutls_strerror(rc));
  457. return CURLE_SSL_CRL_BADFILE;
  458. }
  459. else
  460. infof(data, "found %d CRL in %s\n",
  461. rc, SSL_SET_OPTION(CRLfile));
  462. }
  463. /* Initialize TLS session as a client */
  464. init_flags = GNUTLS_CLIENT;
  465. #if defined(GNUTLS_FORCE_CLIENT_CERT)
  466. init_flags |= GNUTLS_FORCE_CLIENT_CERT;
  467. #endif
  468. #if defined(GNUTLS_NO_TICKETS)
  469. /* Disable TLS session tickets */
  470. init_flags |= GNUTLS_NO_TICKETS;
  471. #endif
  472. rc = gnutls_init(&backend->session, init_flags);
  473. if(rc != GNUTLS_E_SUCCESS) {
  474. failf(data, "gnutls_init() failed: %d", rc);
  475. return CURLE_SSL_CONNECT_ERROR;
  476. }
  477. /* convenient assign */
  478. session = backend->session;
  479. if((0 == Curl_inet_pton(AF_INET, hostname, &addr)) &&
  480. #ifdef ENABLE_IPV6
  481. (0 == Curl_inet_pton(AF_INET6, hostname, &addr)) &&
  482. #endif
  483. sni &&
  484. (gnutls_server_name_set(session, GNUTLS_NAME_DNS, hostname,
  485. strlen(hostname)) < 0))
  486. infof(data, "WARNING: failed to configure server name indication (SNI) "
  487. "TLS extension\n");
  488. /* Use default priorities */
  489. rc = gnutls_set_default_priority(session);
  490. if(rc != GNUTLS_E_SUCCESS)
  491. return CURLE_SSL_CONNECT_ERROR;
  492. /* Ensure +SRP comes at the *end* of all relevant strings so that it can be
  493. * removed if a run-time error indicates that SRP is not supported by this
  494. * GnuTLS version */
  495. switch(SSL_CONN_CONFIG(version)) {
  496. case CURL_SSLVERSION_SSLv3:
  497. prioritylist = GNUTLS_CIPHERS ":-VERS-TLS-ALL:+VERS-SSL3.0";
  498. break;
  499. case CURL_SSLVERSION_DEFAULT:
  500. case CURL_SSLVERSION_TLSv1:
  501. prioritylist = GNUTLS_CIPHERS ":-VERS-SSL3.0"
  502. #ifdef HAS_TLS13
  503. ":+VERS-TLS1.3"
  504. #endif
  505. ;
  506. break;
  507. case CURL_SSLVERSION_TLSv1_0:
  508. case CURL_SSLVERSION_TLSv1_1:
  509. case CURL_SSLVERSION_TLSv1_2:
  510. case CURL_SSLVERSION_TLSv1_3:
  511. {
  512. CURLcode result = set_ssl_version_min_max(&prioritylist, conn);
  513. if(result != CURLE_OK)
  514. return result;
  515. break;
  516. }
  517. case CURL_SSLVERSION_SSLv2:
  518. failf(data, "GnuTLS does not support SSLv2");
  519. return CURLE_SSL_CONNECT_ERROR;
  520. default:
  521. failf(data, "Unrecognized parameter passed via CURLOPT_SSLVERSION");
  522. return CURLE_SSL_CONNECT_ERROR;
  523. }
  524. #ifdef USE_TLS_SRP
  525. /* Only add SRP to the cipher list if SRP is requested. Otherwise
  526. * GnuTLS will disable TLS 1.3 support. */
  527. if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) {
  528. size_t len = strlen(prioritylist);
  529. char *prioritysrp = malloc(len + sizeof(GNUTLS_SRP) + 1);
  530. if(!prioritysrp)
  531. return CURLE_OUT_OF_MEMORY;
  532. strcpy(prioritysrp, prioritylist);
  533. strcpy(prioritysrp + len, ":" GNUTLS_SRP);
  534. rc = gnutls_priority_set_direct(session, prioritysrp, &err);
  535. free(prioritysrp);
  536. if((rc == GNUTLS_E_INVALID_REQUEST) && err) {
  537. infof(data, "This GnuTLS does not support SRP\n");
  538. }
  539. }
  540. else {
  541. #endif
  542. rc = gnutls_priority_set_direct(session, prioritylist, &err);
  543. #ifdef USE_TLS_SRP
  544. }
  545. #endif
  546. if(rc != GNUTLS_E_SUCCESS) {
  547. failf(data, "Error %d setting GnuTLS cipher list starting with %s",
  548. rc, err);
  549. return CURLE_SSL_CONNECT_ERROR;
  550. }
  551. if(conn->bits.tls_enable_alpn) {
  552. int cur = 0;
  553. gnutls_datum_t protocols[2];
  554. #ifdef USE_NGHTTP2
  555. if(data->set.httpversion >= CURL_HTTP_VERSION_2
  556. #ifndef CURL_DISABLE_PROXY
  557. && (!SSL_IS_PROXY() || !conn->bits.tunnel_proxy)
  558. #endif
  559. ) {
  560. protocols[cur].data = (unsigned char *)NGHTTP2_PROTO_VERSION_ID;
  561. protocols[cur].size = NGHTTP2_PROTO_VERSION_ID_LEN;
  562. cur++;
  563. infof(data, "ALPN, offering %s\n", NGHTTP2_PROTO_VERSION_ID);
  564. }
  565. #endif
  566. protocols[cur].data = (unsigned char *)ALPN_HTTP_1_1;
  567. protocols[cur].size = ALPN_HTTP_1_1_LENGTH;
  568. cur++;
  569. infof(data, "ALPN, offering %s\n", ALPN_HTTP_1_1);
  570. gnutls_alpn_set_protocols(session, protocols, cur, 0);
  571. }
  572. if(SSL_SET_OPTION(cert)) {
  573. if(SSL_SET_OPTION(key_passwd)) {
  574. const unsigned int supported_key_encryption_algorithms =
  575. GNUTLS_PKCS_USE_PKCS12_3DES | GNUTLS_PKCS_USE_PKCS12_ARCFOUR |
  576. GNUTLS_PKCS_USE_PKCS12_RC2_40 | GNUTLS_PKCS_USE_PBES2_3DES |
  577. GNUTLS_PKCS_USE_PBES2_AES_128 | GNUTLS_PKCS_USE_PBES2_AES_192 |
  578. GNUTLS_PKCS_USE_PBES2_AES_256;
  579. rc = gnutls_certificate_set_x509_key_file2(
  580. backend->cred,
  581. SSL_SET_OPTION(cert),
  582. SSL_SET_OPTION(key) ?
  583. SSL_SET_OPTION(key) : SSL_SET_OPTION(cert),
  584. do_file_type(SSL_SET_OPTION(cert_type)),
  585. SSL_SET_OPTION(key_passwd),
  586. supported_key_encryption_algorithms);
  587. if(rc != GNUTLS_E_SUCCESS) {
  588. failf(data,
  589. "error reading X.509 potentially-encrypted key file: %s",
  590. gnutls_strerror(rc));
  591. return CURLE_SSL_CONNECT_ERROR;
  592. }
  593. }
  594. else {
  595. if(gnutls_certificate_set_x509_key_file(
  596. backend->cred,
  597. SSL_SET_OPTION(cert),
  598. SSL_SET_OPTION(key) ?
  599. SSL_SET_OPTION(key) : SSL_SET_OPTION(cert),
  600. do_file_type(SSL_SET_OPTION(cert_type)) ) !=
  601. GNUTLS_E_SUCCESS) {
  602. failf(data, "error reading X.509 key or certificate file");
  603. return CURLE_SSL_CONNECT_ERROR;
  604. }
  605. }
  606. }
  607. #ifdef USE_TLS_SRP
  608. /* put the credentials to the current session */
  609. if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP) {
  610. rc = gnutls_credentials_set(session, GNUTLS_CRD_SRP,
  611. backend->srp_client_cred);
  612. if(rc != GNUTLS_E_SUCCESS) {
  613. failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
  614. return CURLE_SSL_CONNECT_ERROR;
  615. }
  616. }
  617. else
  618. #endif
  619. {
  620. rc = gnutls_credentials_set(session, GNUTLS_CRD_CERTIFICATE,
  621. backend->cred);
  622. if(rc != GNUTLS_E_SUCCESS) {
  623. failf(data, "gnutls_credentials_set() failed: %s", gnutls_strerror(rc));
  624. return CURLE_SSL_CONNECT_ERROR;
  625. }
  626. }
  627. #ifndef CURL_DISABLE_PROXY
  628. if(conn->proxy_ssl[sockindex].use) {
  629. transport_ptr = conn->proxy_ssl[sockindex].backend->session;
  630. gnutls_transport_push = Curl_gtls_push_ssl;
  631. gnutls_transport_pull = Curl_gtls_pull_ssl;
  632. }
  633. else
  634. #endif
  635. {
  636. /* file descriptor for the socket */
  637. transport_ptr = &conn->sock[sockindex];
  638. gnutls_transport_push = Curl_gtls_push;
  639. gnutls_transport_pull = Curl_gtls_pull;
  640. }
  641. /* set the connection handle */
  642. gnutls_transport_set_ptr(session, transport_ptr);
  643. /* register callback functions to send and receive data. */
  644. gnutls_transport_set_push_function(session, gnutls_transport_push);
  645. gnutls_transport_set_pull_function(session, gnutls_transport_pull);
  646. if(SSL_CONN_CONFIG(verifystatus)) {
  647. rc = gnutls_ocsp_status_request_enable_client(session, NULL, 0, NULL);
  648. if(rc != GNUTLS_E_SUCCESS) {
  649. failf(data, "gnutls_ocsp_status_request_enable_client() failed: %d", rc);
  650. return CURLE_SSL_CONNECT_ERROR;
  651. }
  652. }
  653. /* This might be a reconnect, so we check for a session ID in the cache
  654. to speed up things */
  655. if(SSL_SET_OPTION(primary.sessionid)) {
  656. void *ssl_sessionid;
  657. size_t ssl_idsize;
  658. Curl_ssl_sessionid_lock(conn);
  659. if(!Curl_ssl_getsessionid(conn, &ssl_sessionid, &ssl_idsize, sockindex)) {
  660. /* we got a session id, use it! */
  661. gnutls_session_set_data(session, ssl_sessionid, ssl_idsize);
  662. /* Informational message */
  663. infof(data, "SSL re-using session ID\n");
  664. }
  665. Curl_ssl_sessionid_unlock(conn);
  666. }
  667. return CURLE_OK;
  668. }
  669. static CURLcode pkp_pin_peer_pubkey(struct Curl_easy *data,
  670. gnutls_x509_crt_t cert,
  671. const char *pinnedpubkey)
  672. {
  673. /* Scratch */
  674. size_t len1 = 0, len2 = 0;
  675. unsigned char *buff1 = NULL;
  676. gnutls_pubkey_t key = NULL;
  677. /* Result is returned to caller */
  678. CURLcode result = CURLE_SSL_PINNEDPUBKEYNOTMATCH;
  679. /* if a path wasn't specified, don't pin */
  680. if(NULL == pinnedpubkey)
  681. return CURLE_OK;
  682. if(NULL == cert)
  683. return result;
  684. do {
  685. int ret;
  686. /* Begin Gyrations to get the public key */
  687. gnutls_pubkey_init(&key);
  688. ret = gnutls_pubkey_import_x509(key, cert, 0);
  689. if(ret < 0)
  690. break; /* failed */
  691. ret = gnutls_pubkey_export(key, GNUTLS_X509_FMT_DER, NULL, &len1);
  692. if(ret != GNUTLS_E_SHORT_MEMORY_BUFFER || len1 == 0)
  693. break; /* failed */
  694. buff1 = malloc(len1);
  695. if(NULL == buff1)
  696. break; /* failed */
  697. len2 = len1;
  698. ret = gnutls_pubkey_export(key, GNUTLS_X509_FMT_DER, buff1, &len2);
  699. if(ret < 0 || len1 != len2)
  700. break; /* failed */
  701. /* End Gyrations */
  702. /* The one good exit point */
  703. result = Curl_pin_peer_pubkey(data, pinnedpubkey, buff1, len1);
  704. } while(0);
  705. if(NULL != key)
  706. gnutls_pubkey_deinit(key);
  707. Curl_safefree(buff1);
  708. return result;
  709. }
  710. static Curl_recv gtls_recv;
  711. static Curl_send gtls_send;
  712. static CURLcode
  713. gtls_connect_step3(struct connectdata *conn,
  714. int sockindex)
  715. {
  716. unsigned int cert_list_size;
  717. const gnutls_datum_t *chainp;
  718. unsigned int verify_status = 0;
  719. gnutls_x509_crt_t x509_cert, x509_issuer;
  720. gnutls_datum_t issuerp;
  721. gnutls_datum_t certfields;
  722. char certname[65] = ""; /* limited to 64 chars by ASN.1 */
  723. size_t size;
  724. time_t certclock;
  725. const char *ptr;
  726. struct Curl_easy *data = conn->data;
  727. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  728. struct ssl_backend_data *backend = connssl->backend;
  729. gnutls_session_t session = backend->session;
  730. int rc;
  731. gnutls_datum_t proto;
  732. CURLcode result = CURLE_OK;
  733. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  734. unsigned int algo;
  735. unsigned int bits;
  736. gnutls_protocol_t version = gnutls_protocol_get_version(session);
  737. #endif
  738. #ifndef CURL_DISABLE_PROXY
  739. const char * const hostname = SSL_IS_PROXY() ? conn->http_proxy.host.name :
  740. conn->host.name;
  741. long * const certverifyresult = SSL_IS_PROXY() ?
  742. &data->set.proxy_ssl.certverifyresult : &data->set.ssl.certverifyresult;
  743. #else
  744. const char * const hostname = conn->host.name;
  745. long * const certverifyresult = &data->set.ssl.certverifyresult;
  746. #endif
  747. /* the name of the cipher suite used, e.g. ECDHE_RSA_AES_256_GCM_SHA384. */
  748. ptr = gnutls_cipher_suite_get_name(gnutls_kx_get(session),
  749. gnutls_cipher_get(session),
  750. gnutls_mac_get(session));
  751. infof(data, "SSL connection using %s / %s\n",
  752. gnutls_protocol_get_name(version), ptr);
  753. /* This function will return the peer's raw certificate (chain) as sent by
  754. the peer. These certificates are in raw format (DER encoded for
  755. X.509). In case of a X.509 then a certificate list may be present. The
  756. first certificate in the list is the peer's certificate, following the
  757. issuer's certificate, then the issuer's issuer etc. */
  758. chainp = gnutls_certificate_get_peers(session, &cert_list_size);
  759. if(!chainp) {
  760. if(SSL_CONN_CONFIG(verifypeer) ||
  761. SSL_CONN_CONFIG(verifyhost) ||
  762. SSL_SET_OPTION(issuercert)) {
  763. #ifdef USE_TLS_SRP
  764. if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP
  765. && SSL_SET_OPTION(username) != NULL
  766. && !SSL_CONN_CONFIG(verifypeer)
  767. && gnutls_cipher_get(session)) {
  768. /* no peer cert, but auth is ok if we have SRP user and cipher and no
  769. peer verify */
  770. }
  771. else {
  772. #endif
  773. failf(data, "failed to get server cert");
  774. *certverifyresult = GNUTLS_E_NO_CERTIFICATE_FOUND;
  775. return CURLE_PEER_FAILED_VERIFICATION;
  776. #ifdef USE_TLS_SRP
  777. }
  778. #endif
  779. }
  780. infof(data, "\t common name: WARNING couldn't obtain\n");
  781. }
  782. if(data->set.ssl.certinfo && chainp) {
  783. unsigned int i;
  784. result = Curl_ssl_init_certinfo(data, cert_list_size);
  785. if(result)
  786. return result;
  787. for(i = 0; i < cert_list_size; i++) {
  788. const char *beg = (const char *) chainp[i].data;
  789. const char *end = beg + chainp[i].size;
  790. result = Curl_extract_certinfo(conn, i, beg, end);
  791. if(result)
  792. return result;
  793. }
  794. }
  795. if(SSL_CONN_CONFIG(verifypeer)) {
  796. /* This function will try to verify the peer's certificate and return its
  797. status (trusted, invalid etc.). The value of status should be one or
  798. more of the gnutls_certificate_status_t enumerated elements bitwise
  799. or'd. To avoid denial of service attacks some default upper limits
  800. regarding the certificate key size and chain size are set. To override
  801. them use gnutls_certificate_set_verify_limits(). */
  802. rc = gnutls_certificate_verify_peers2(session, &verify_status);
  803. if(rc < 0) {
  804. failf(data, "server cert verify failed: %d", rc);
  805. *certverifyresult = rc;
  806. return CURLE_SSL_CONNECT_ERROR;
  807. }
  808. *certverifyresult = verify_status;
  809. /* verify_status is a bitmask of gnutls_certificate_status bits */
  810. if(verify_status & GNUTLS_CERT_INVALID) {
  811. if(SSL_CONN_CONFIG(verifypeer)) {
  812. failf(data, "server certificate verification failed. CAfile: %s "
  813. "CRLfile: %s", SSL_CONN_CONFIG(CAfile) ? SSL_CONN_CONFIG(CAfile):
  814. "none",
  815. SSL_SET_OPTION(CRLfile)?SSL_SET_OPTION(CRLfile):"none");
  816. return CURLE_PEER_FAILED_VERIFICATION;
  817. }
  818. else
  819. infof(data, "\t server certificate verification FAILED\n");
  820. }
  821. else
  822. infof(data, "\t server certificate verification OK\n");
  823. }
  824. else
  825. infof(data, "\t server certificate verification SKIPPED\n");
  826. if(SSL_CONN_CONFIG(verifystatus)) {
  827. if(gnutls_ocsp_status_request_is_checked(session, 0) == 0) {
  828. gnutls_datum_t status_request;
  829. gnutls_ocsp_resp_t ocsp_resp;
  830. gnutls_ocsp_cert_status_t status;
  831. gnutls_x509_crl_reason_t reason;
  832. rc = gnutls_ocsp_status_request_get(session, &status_request);
  833. infof(data, "\t server certificate status verification FAILED\n");
  834. if(rc == GNUTLS_E_REQUESTED_DATA_NOT_AVAILABLE) {
  835. failf(data, "No OCSP response received");
  836. return CURLE_SSL_INVALIDCERTSTATUS;
  837. }
  838. if(rc < 0) {
  839. failf(data, "Invalid OCSP response received");
  840. return CURLE_SSL_INVALIDCERTSTATUS;
  841. }
  842. gnutls_ocsp_resp_init(&ocsp_resp);
  843. rc = gnutls_ocsp_resp_import(ocsp_resp, &status_request);
  844. if(rc < 0) {
  845. failf(data, "Invalid OCSP response received");
  846. return CURLE_SSL_INVALIDCERTSTATUS;
  847. }
  848. (void)gnutls_ocsp_resp_get_single(ocsp_resp, 0, NULL, NULL, NULL, NULL,
  849. &status, NULL, NULL, NULL, &reason);
  850. switch(status) {
  851. case GNUTLS_OCSP_CERT_GOOD:
  852. break;
  853. case GNUTLS_OCSP_CERT_REVOKED: {
  854. const char *crl_reason;
  855. switch(reason) {
  856. default:
  857. case GNUTLS_X509_CRLREASON_UNSPECIFIED:
  858. crl_reason = "unspecified reason";
  859. break;
  860. case GNUTLS_X509_CRLREASON_KEYCOMPROMISE:
  861. crl_reason = "private key compromised";
  862. break;
  863. case GNUTLS_X509_CRLREASON_CACOMPROMISE:
  864. crl_reason = "CA compromised";
  865. break;
  866. case GNUTLS_X509_CRLREASON_AFFILIATIONCHANGED:
  867. crl_reason = "affiliation has changed";
  868. break;
  869. case GNUTLS_X509_CRLREASON_SUPERSEDED:
  870. crl_reason = "certificate superseded";
  871. break;
  872. case GNUTLS_X509_CRLREASON_CESSATIONOFOPERATION:
  873. crl_reason = "operation has ceased";
  874. break;
  875. case GNUTLS_X509_CRLREASON_CERTIFICATEHOLD:
  876. crl_reason = "certificate is on hold";
  877. break;
  878. case GNUTLS_X509_CRLREASON_REMOVEFROMCRL:
  879. crl_reason = "will be removed from delta CRL";
  880. break;
  881. case GNUTLS_X509_CRLREASON_PRIVILEGEWITHDRAWN:
  882. crl_reason = "privilege withdrawn";
  883. break;
  884. case GNUTLS_X509_CRLREASON_AACOMPROMISE:
  885. crl_reason = "AA compromised";
  886. break;
  887. }
  888. failf(data, "Server certificate was revoked: %s", crl_reason);
  889. break;
  890. }
  891. default:
  892. case GNUTLS_OCSP_CERT_UNKNOWN:
  893. failf(data, "Server certificate status is unknown");
  894. break;
  895. }
  896. gnutls_ocsp_resp_deinit(ocsp_resp);
  897. return CURLE_SSL_INVALIDCERTSTATUS;
  898. }
  899. else
  900. infof(data, "\t server certificate status verification OK\n");
  901. }
  902. else
  903. infof(data, "\t server certificate status verification SKIPPED\n");
  904. /* initialize an X.509 certificate structure. */
  905. gnutls_x509_crt_init(&x509_cert);
  906. if(chainp)
  907. /* convert the given DER or PEM encoded Certificate to the native
  908. gnutls_x509_crt_t format */
  909. gnutls_x509_crt_import(x509_cert, chainp, GNUTLS_X509_FMT_DER);
  910. if(SSL_SET_OPTION(issuercert)) {
  911. gnutls_x509_crt_init(&x509_issuer);
  912. issuerp = load_file(SSL_SET_OPTION(issuercert));
  913. gnutls_x509_crt_import(x509_issuer, &issuerp, GNUTLS_X509_FMT_PEM);
  914. rc = gnutls_x509_crt_check_issuer(x509_cert, x509_issuer);
  915. gnutls_x509_crt_deinit(x509_issuer);
  916. unload_file(issuerp);
  917. if(rc <= 0) {
  918. failf(data, "server certificate issuer check failed (IssuerCert: %s)",
  919. SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none");
  920. gnutls_x509_crt_deinit(x509_cert);
  921. return CURLE_SSL_ISSUER_ERROR;
  922. }
  923. infof(data, "\t server certificate issuer check OK (Issuer Cert: %s)\n",
  924. SSL_SET_OPTION(issuercert)?SSL_SET_OPTION(issuercert):"none");
  925. }
  926. size = sizeof(certname);
  927. rc = gnutls_x509_crt_get_dn_by_oid(x509_cert, GNUTLS_OID_X520_COMMON_NAME,
  928. 0, /* the first and only one */
  929. FALSE,
  930. certname,
  931. &size);
  932. if(rc) {
  933. infof(data, "error fetching CN from cert:%s\n",
  934. gnutls_strerror(rc));
  935. }
  936. /* This function will check if the given certificate's subject matches the
  937. given hostname. This is a basic implementation of the matching described
  938. in RFC2818 (HTTPS), which takes into account wildcards, and the subject
  939. alternative name PKIX extension. Returns non zero on success, and zero on
  940. failure. */
  941. rc = gnutls_x509_crt_check_hostname(x509_cert, hostname);
  942. #if GNUTLS_VERSION_NUMBER < 0x030306
  943. /* Before 3.3.6, gnutls_x509_crt_check_hostname() didn't check IP
  944. addresses. */
  945. if(!rc) {
  946. #ifdef ENABLE_IPV6
  947. #define use_addr in6_addr
  948. #else
  949. #define use_addr in_addr
  950. #endif
  951. unsigned char addrbuf[sizeof(struct use_addr)];
  952. size_t addrlen = 0;
  953. if(Curl_inet_pton(AF_INET, hostname, addrbuf) > 0)
  954. addrlen = 4;
  955. #ifdef ENABLE_IPV6
  956. else if(Curl_inet_pton(AF_INET6, hostname, addrbuf) > 0)
  957. addrlen = 16;
  958. #endif
  959. if(addrlen) {
  960. unsigned char certaddr[sizeof(struct use_addr)];
  961. int i;
  962. for(i = 0; ; i++) {
  963. size_t certaddrlen = sizeof(certaddr);
  964. int ret = gnutls_x509_crt_get_subject_alt_name(x509_cert, i, certaddr,
  965. &certaddrlen, NULL);
  966. /* If this happens, it wasn't an IP address. */
  967. if(ret == GNUTLS_E_SHORT_MEMORY_BUFFER)
  968. continue;
  969. if(ret < 0)
  970. break;
  971. if(ret != GNUTLS_SAN_IPADDRESS)
  972. continue;
  973. if(certaddrlen == addrlen && !memcmp(addrbuf, certaddr, addrlen)) {
  974. rc = 1;
  975. break;
  976. }
  977. }
  978. }
  979. }
  980. #endif
  981. if(!rc) {
  982. #ifndef CURL_DISABLE_PROXY
  983. const char * const dispname = SSL_IS_PROXY() ?
  984. conn->http_proxy.host.dispname : conn->host.dispname;
  985. #else
  986. const char * const dispname = conn->host.dispname;
  987. #endif
  988. if(SSL_CONN_CONFIG(verifyhost)) {
  989. failf(data, "SSL: certificate subject name (%s) does not match "
  990. "target host name '%s'", certname, dispname);
  991. gnutls_x509_crt_deinit(x509_cert);
  992. return CURLE_PEER_FAILED_VERIFICATION;
  993. }
  994. else
  995. infof(data, "\t common name: %s (does not match '%s')\n",
  996. certname, dispname);
  997. }
  998. else
  999. infof(data, "\t common name: %s (matched)\n", certname);
  1000. /* Check for time-based validity */
  1001. certclock = gnutls_x509_crt_get_expiration_time(x509_cert);
  1002. if(certclock == (time_t)-1) {
  1003. if(SSL_CONN_CONFIG(verifypeer)) {
  1004. failf(data, "server cert expiration date verify failed");
  1005. *certverifyresult = GNUTLS_CERT_EXPIRED;
  1006. gnutls_x509_crt_deinit(x509_cert);
  1007. return CURLE_SSL_CONNECT_ERROR;
  1008. }
  1009. else
  1010. infof(data, "\t server certificate expiration date verify FAILED\n");
  1011. }
  1012. else {
  1013. if(certclock < time(NULL)) {
  1014. if(SSL_CONN_CONFIG(verifypeer)) {
  1015. failf(data, "server certificate expiration date has passed.");
  1016. *certverifyresult = GNUTLS_CERT_EXPIRED;
  1017. gnutls_x509_crt_deinit(x509_cert);
  1018. return CURLE_PEER_FAILED_VERIFICATION;
  1019. }
  1020. else
  1021. infof(data, "\t server certificate expiration date FAILED\n");
  1022. }
  1023. else
  1024. infof(data, "\t server certificate expiration date OK\n");
  1025. }
  1026. certclock = gnutls_x509_crt_get_activation_time(x509_cert);
  1027. if(certclock == (time_t)-1) {
  1028. if(SSL_CONN_CONFIG(verifypeer)) {
  1029. failf(data, "server cert activation date verify failed");
  1030. *certverifyresult = GNUTLS_CERT_NOT_ACTIVATED;
  1031. gnutls_x509_crt_deinit(x509_cert);
  1032. return CURLE_SSL_CONNECT_ERROR;
  1033. }
  1034. else
  1035. infof(data, "\t server certificate activation date verify FAILED\n");
  1036. }
  1037. else {
  1038. if(certclock > time(NULL)) {
  1039. if(SSL_CONN_CONFIG(verifypeer)) {
  1040. failf(data, "server certificate not activated yet.");
  1041. *certverifyresult = GNUTLS_CERT_NOT_ACTIVATED;
  1042. gnutls_x509_crt_deinit(x509_cert);
  1043. return CURLE_PEER_FAILED_VERIFICATION;
  1044. }
  1045. else
  1046. infof(data, "\t server certificate activation date FAILED\n");
  1047. }
  1048. else
  1049. infof(data, "\t server certificate activation date OK\n");
  1050. }
  1051. ptr = SSL_IS_PROXY() ? data->set.str[STRING_SSL_PINNEDPUBLICKEY_PROXY] :
  1052. data->set.str[STRING_SSL_PINNEDPUBLICKEY_ORIG];
  1053. if(ptr) {
  1054. result = pkp_pin_peer_pubkey(data, x509_cert, ptr);
  1055. if(result != CURLE_OK) {
  1056. failf(data, "SSL: public key does not match pinned public key!");
  1057. gnutls_x509_crt_deinit(x509_cert);
  1058. return result;
  1059. }
  1060. }
  1061. /* Show:
  1062. - subject
  1063. - start date
  1064. - expire date
  1065. - common name
  1066. - issuer
  1067. */
  1068. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  1069. /* public key algorithm's parameters */
  1070. algo = gnutls_x509_crt_get_pk_algorithm(x509_cert, &bits);
  1071. infof(data, "\t certificate public key: %s\n",
  1072. gnutls_pk_algorithm_get_name(algo));
  1073. /* version of the X.509 certificate. */
  1074. infof(data, "\t certificate version: #%d\n",
  1075. gnutls_x509_crt_get_version(x509_cert));
  1076. rc = gnutls_x509_crt_get_dn2(x509_cert, &certfields);
  1077. if(rc != 0)
  1078. return CURLE_OUT_OF_MEMORY;
  1079. infof(data, "\t subject: %s\n", certfields.data);
  1080. certclock = gnutls_x509_crt_get_activation_time(x509_cert);
  1081. showtime(data, "start date", certclock);
  1082. certclock = gnutls_x509_crt_get_expiration_time(x509_cert);
  1083. showtime(data, "expire date", certclock);
  1084. rc = gnutls_x509_crt_get_issuer_dn2(x509_cert, &certfields);
  1085. if(rc != 0)
  1086. return CURLE_OUT_OF_MEMORY;
  1087. infof(data, "\t issuer: %s\n", certfields.data);
  1088. #endif
  1089. gnutls_x509_crt_deinit(x509_cert);
  1090. if(conn->bits.tls_enable_alpn) {
  1091. rc = gnutls_alpn_get_selected_protocol(session, &proto);
  1092. if(rc == 0) {
  1093. infof(data, "ALPN, server accepted to use %.*s\n", proto.size,
  1094. proto.data);
  1095. #ifdef USE_NGHTTP2
  1096. if(proto.size == NGHTTP2_PROTO_VERSION_ID_LEN &&
  1097. !memcmp(NGHTTP2_PROTO_VERSION_ID, proto.data,
  1098. NGHTTP2_PROTO_VERSION_ID_LEN)) {
  1099. conn->negnpn = CURL_HTTP_VERSION_2;
  1100. }
  1101. else
  1102. #endif
  1103. if(proto.size == ALPN_HTTP_1_1_LENGTH &&
  1104. !memcmp(ALPN_HTTP_1_1, proto.data, ALPN_HTTP_1_1_LENGTH)) {
  1105. conn->negnpn = CURL_HTTP_VERSION_1_1;
  1106. }
  1107. }
  1108. else
  1109. infof(data, "ALPN, server did not agree to a protocol\n");
  1110. Curl_multiuse_state(conn, conn->negnpn == CURL_HTTP_VERSION_2 ?
  1111. BUNDLE_MULTIPLEX : BUNDLE_NO_MULTIUSE);
  1112. }
  1113. conn->ssl[sockindex].state = ssl_connection_complete;
  1114. conn->recv[sockindex] = gtls_recv;
  1115. conn->send[sockindex] = gtls_send;
  1116. if(SSL_SET_OPTION(primary.sessionid)) {
  1117. /* we always unconditionally get the session id here, as even if we
  1118. already got it from the cache and asked to use it in the connection, it
  1119. might've been rejected and then a new one is in use now and we need to
  1120. detect that. */
  1121. void *connect_sessionid;
  1122. size_t connect_idsize = 0;
  1123. /* get the session ID data size */
  1124. gnutls_session_get_data(session, NULL, &connect_idsize);
  1125. connect_sessionid = malloc(connect_idsize); /* get a buffer for it */
  1126. if(connect_sessionid) {
  1127. bool incache;
  1128. void *ssl_sessionid;
  1129. /* extract session ID to the allocated buffer */
  1130. gnutls_session_get_data(session, connect_sessionid, &connect_idsize);
  1131. Curl_ssl_sessionid_lock(conn);
  1132. incache = !(Curl_ssl_getsessionid(conn, &ssl_sessionid, NULL,
  1133. sockindex));
  1134. if(incache) {
  1135. /* there was one before in the cache, so instead of risking that the
  1136. previous one was rejected, we just kill that and store the new */
  1137. Curl_ssl_delsessionid(conn, ssl_sessionid);
  1138. }
  1139. /* store this session id */
  1140. result = Curl_ssl_addsessionid(conn, connect_sessionid, connect_idsize,
  1141. sockindex);
  1142. Curl_ssl_sessionid_unlock(conn);
  1143. if(result) {
  1144. free(connect_sessionid);
  1145. result = CURLE_OUT_OF_MEMORY;
  1146. }
  1147. }
  1148. else
  1149. result = CURLE_OUT_OF_MEMORY;
  1150. }
  1151. return result;
  1152. }
  1153. /*
  1154. * This function is called after the TCP connect has completed. Setup the TLS
  1155. * layer and do all necessary magic.
  1156. */
  1157. /* We use connssl->connecting_state to keep track of the connection status;
  1158. there are three states: 'ssl_connect_1' (not started yet or complete),
  1159. 'ssl_connect_2_reading' (waiting for data from server), and
  1160. 'ssl_connect_2_writing' (waiting to be able to write).
  1161. */
  1162. static CURLcode
  1163. gtls_connect_common(struct connectdata *conn,
  1164. int sockindex,
  1165. bool nonblocking,
  1166. bool *done)
  1167. {
  1168. int rc;
  1169. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  1170. /* Initiate the connection, if not already done */
  1171. if(ssl_connect_1 == connssl->connecting_state) {
  1172. rc = gtls_connect_step1(conn, sockindex);
  1173. if(rc)
  1174. return rc;
  1175. }
  1176. rc = handshake(conn, sockindex, TRUE, nonblocking);
  1177. if(rc)
  1178. /* handshake() sets its own error message with failf() */
  1179. return rc;
  1180. /* Finish connecting once the handshake is done */
  1181. if(ssl_connect_1 == connssl->connecting_state) {
  1182. rc = gtls_connect_step3(conn, sockindex);
  1183. if(rc)
  1184. return rc;
  1185. }
  1186. *done = ssl_connect_1 == connssl->connecting_state;
  1187. return CURLE_OK;
  1188. }
  1189. static CURLcode Curl_gtls_connect_nonblocking(struct connectdata *conn,
  1190. int sockindex, bool *done)
  1191. {
  1192. return gtls_connect_common(conn, sockindex, TRUE, done);
  1193. }
  1194. static CURLcode Curl_gtls_connect(struct connectdata *conn, int sockindex)
  1195. {
  1196. CURLcode result;
  1197. bool done = FALSE;
  1198. result = gtls_connect_common(conn, sockindex, FALSE, &done);
  1199. if(result)
  1200. return result;
  1201. DEBUGASSERT(done);
  1202. return CURLE_OK;
  1203. }
  1204. static bool Curl_gtls_data_pending(const struct connectdata *conn,
  1205. int connindex)
  1206. {
  1207. const struct ssl_connect_data *connssl = &conn->ssl[connindex];
  1208. bool res = FALSE;
  1209. struct ssl_backend_data *backend = connssl->backend;
  1210. if(backend->session &&
  1211. 0 != gnutls_record_check_pending(backend->session))
  1212. res = TRUE;
  1213. #ifndef CURL_DISABLE_PROXY
  1214. connssl = &conn->proxy_ssl[connindex];
  1215. backend = connssl->backend;
  1216. if(backend->session &&
  1217. 0 != gnutls_record_check_pending(backend->session))
  1218. res = TRUE;
  1219. #endif
  1220. return res;
  1221. }
  1222. static ssize_t gtls_send(struct connectdata *conn,
  1223. int sockindex,
  1224. const void *mem,
  1225. size_t len,
  1226. CURLcode *curlcode)
  1227. {
  1228. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  1229. struct ssl_backend_data *backend = connssl->backend;
  1230. ssize_t rc = gnutls_record_send(backend->session, mem, len);
  1231. if(rc < 0) {
  1232. *curlcode = (rc == GNUTLS_E_AGAIN)
  1233. ? CURLE_AGAIN
  1234. : CURLE_SEND_ERROR;
  1235. rc = -1;
  1236. }
  1237. return rc;
  1238. }
  1239. static void close_one(struct ssl_connect_data *connssl)
  1240. {
  1241. struct ssl_backend_data *backend = connssl->backend;
  1242. if(backend->session) {
  1243. gnutls_bye(backend->session, GNUTLS_SHUT_WR);
  1244. gnutls_deinit(backend->session);
  1245. backend->session = NULL;
  1246. }
  1247. if(backend->cred) {
  1248. gnutls_certificate_free_credentials(backend->cred);
  1249. backend->cred = NULL;
  1250. }
  1251. #ifdef USE_TLS_SRP
  1252. if(backend->srp_client_cred) {
  1253. gnutls_srp_free_client_credentials(backend->srp_client_cred);
  1254. backend->srp_client_cred = NULL;
  1255. }
  1256. #endif
  1257. }
  1258. static void Curl_gtls_close(struct connectdata *conn, int sockindex)
  1259. {
  1260. close_one(&conn->ssl[sockindex]);
  1261. #ifndef CURL_DISABLE_PROXY
  1262. close_one(&conn->proxy_ssl[sockindex]);
  1263. #endif
  1264. }
  1265. /*
  1266. * This function is called to shut down the SSL layer but keep the
  1267. * socket open (CCC - Clear Command Channel)
  1268. */
  1269. static int Curl_gtls_shutdown(struct connectdata *conn, int sockindex)
  1270. {
  1271. struct ssl_connect_data *connssl = &conn->ssl[sockindex];
  1272. struct ssl_backend_data *backend = connssl->backend;
  1273. int retval = 0;
  1274. struct Curl_easy *data = conn->data;
  1275. #ifndef CURL_DISABLE_FTP
  1276. /* This has only been tested on the proftpd server, and the mod_tls code
  1277. sends a close notify alert without waiting for a close notify alert in
  1278. response. Thus we wait for a close notify alert from the server, but
  1279. we do not send one. Let's hope other servers do the same... */
  1280. if(data->set.ftp_ccc == CURLFTPSSL_CCC_ACTIVE)
  1281. gnutls_bye(backend->session, GNUTLS_SHUT_WR);
  1282. #endif
  1283. if(backend->session) {
  1284. ssize_t result;
  1285. bool done = FALSE;
  1286. char buf[120];
  1287. while(!done) {
  1288. int what = SOCKET_READABLE(conn->sock[sockindex],
  1289. SSL_SHUTDOWN_TIMEOUT);
  1290. if(what > 0) {
  1291. /* Something to read, let's do it and hope that it is the close
  1292. notify alert from the server */
  1293. result = gnutls_record_recv(backend->session,
  1294. buf, sizeof(buf));
  1295. switch(result) {
  1296. case 0:
  1297. /* This is the expected response. There was no data but only
  1298. the close notify alert */
  1299. done = TRUE;
  1300. break;
  1301. case GNUTLS_E_AGAIN:
  1302. case GNUTLS_E_INTERRUPTED:
  1303. infof(data, "GNUTLS_E_AGAIN || GNUTLS_E_INTERRUPTED\n");
  1304. break;
  1305. default:
  1306. retval = -1;
  1307. done = TRUE;
  1308. break;
  1309. }
  1310. }
  1311. else if(0 == what) {
  1312. /* timeout */
  1313. failf(data, "SSL shutdown timeout");
  1314. done = TRUE;
  1315. }
  1316. else {
  1317. /* anything that gets here is fatally bad */
  1318. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  1319. retval = -1;
  1320. done = TRUE;
  1321. }
  1322. }
  1323. gnutls_deinit(backend->session);
  1324. }
  1325. gnutls_certificate_free_credentials(backend->cred);
  1326. #ifdef USE_TLS_SRP
  1327. if(SSL_SET_OPTION(authtype) == CURL_TLSAUTH_SRP
  1328. && SSL_SET_OPTION(username) != NULL)
  1329. gnutls_srp_free_client_credentials(backend->srp_client_cred);
  1330. #endif
  1331. backend->cred = NULL;
  1332. backend->session = NULL;
  1333. return retval;
  1334. }
  1335. static ssize_t gtls_recv(struct connectdata *conn, /* connection data */
  1336. int num, /* socketindex */
  1337. char *buf, /* store read data here */
  1338. size_t buffersize, /* max amount to read */
  1339. CURLcode *curlcode)
  1340. {
  1341. struct ssl_connect_data *connssl = &conn->ssl[num];
  1342. struct ssl_backend_data *backend = connssl->backend;
  1343. ssize_t ret;
  1344. ret = gnutls_record_recv(backend->session, buf, buffersize);
  1345. if((ret == GNUTLS_E_AGAIN) || (ret == GNUTLS_E_INTERRUPTED)) {
  1346. *curlcode = CURLE_AGAIN;
  1347. return -1;
  1348. }
  1349. if(ret == GNUTLS_E_REHANDSHAKE) {
  1350. /* BLOCKING call, this is bad but a work-around for now. Fixing this "the
  1351. proper way" takes a whole lot of work. */
  1352. CURLcode result = handshake(conn, num, FALSE, FALSE);
  1353. if(result)
  1354. /* handshake() writes error message on its own */
  1355. *curlcode = result;
  1356. else
  1357. *curlcode = CURLE_AGAIN; /* then return as if this was a wouldblock */
  1358. return -1;
  1359. }
  1360. if(ret < 0) {
  1361. failf(conn->data, "GnuTLS recv error (%d): %s",
  1362. (int)ret, gnutls_strerror((int)ret));
  1363. *curlcode = CURLE_RECV_ERROR;
  1364. return -1;
  1365. }
  1366. return ret;
  1367. }
  1368. static void Curl_gtls_session_free(void *ptr)
  1369. {
  1370. free(ptr);
  1371. }
  1372. static size_t Curl_gtls_version(char *buffer, size_t size)
  1373. {
  1374. return msnprintf(buffer, size, "GnuTLS/%s", gnutls_check_version(NULL));
  1375. }
  1376. #ifndef USE_GNUTLS_NETTLE
  1377. static int Curl_gtls_seed(struct Curl_easy *data)
  1378. {
  1379. /* we have the "SSL is seeded" boolean static to prevent multiple
  1380. time-consuming seedings in vain */
  1381. static bool ssl_seeded = FALSE;
  1382. /* Quickly add a bit of entropy */
  1383. gcry_fast_random_poll();
  1384. if(!ssl_seeded || data->set.str[STRING_SSL_RANDOM_FILE] ||
  1385. data->set.str[STRING_SSL_EGDSOCKET]) {
  1386. ssl_seeded = TRUE;
  1387. }
  1388. return 0;
  1389. }
  1390. #endif
  1391. /* data might be NULL! */
  1392. static CURLcode Curl_gtls_random(struct Curl_easy *data,
  1393. unsigned char *entropy, size_t length)
  1394. {
  1395. #if defined(USE_GNUTLS_NETTLE)
  1396. int rc;
  1397. (void)data;
  1398. rc = gnutls_rnd(GNUTLS_RND_RANDOM, entropy, length);
  1399. return rc?CURLE_FAILED_INIT:CURLE_OK;
  1400. #elif defined(USE_GNUTLS)
  1401. if(data)
  1402. Curl_gtls_seed(data); /* Initiate the seed if not already done */
  1403. gcry_randomize(entropy, length, GCRY_STRONG_RANDOM);
  1404. #endif
  1405. return CURLE_OK;
  1406. }
  1407. static CURLcode Curl_gtls_md5sum(unsigned char *tmp, /* input */
  1408. size_t tmplen,
  1409. unsigned char *md5sum, /* output */
  1410. size_t md5len)
  1411. {
  1412. #if defined(USE_GNUTLS_NETTLE)
  1413. struct md5_ctx MD5pw;
  1414. md5_init(&MD5pw);
  1415. md5_update(&MD5pw, (unsigned int)tmplen, tmp);
  1416. md5_digest(&MD5pw, (unsigned int)md5len, md5sum);
  1417. #elif defined(USE_GNUTLS)
  1418. gcry_md_hd_t MD5pw;
  1419. gcry_md_open(&MD5pw, GCRY_MD_MD5, 0);
  1420. gcry_md_write(MD5pw, tmp, tmplen);
  1421. memcpy(md5sum, gcry_md_read(MD5pw, 0), md5len);
  1422. gcry_md_close(MD5pw);
  1423. #endif
  1424. return CURLE_OK;
  1425. }
  1426. static CURLcode Curl_gtls_sha256sum(const unsigned char *tmp, /* input */
  1427. size_t tmplen,
  1428. unsigned char *sha256sum, /* output */
  1429. size_t sha256len)
  1430. {
  1431. #if defined(USE_GNUTLS_NETTLE)
  1432. struct sha256_ctx SHA256pw;
  1433. sha256_init(&SHA256pw);
  1434. sha256_update(&SHA256pw, (unsigned int)tmplen, tmp);
  1435. sha256_digest(&SHA256pw, (unsigned int)sha256len, sha256sum);
  1436. #elif defined(USE_GNUTLS)
  1437. gcry_md_hd_t SHA256pw;
  1438. gcry_md_open(&SHA256pw, GCRY_MD_SHA256, 0);
  1439. gcry_md_write(SHA256pw, tmp, tmplen);
  1440. memcpy(sha256sum, gcry_md_read(SHA256pw, 0), sha256len);
  1441. gcry_md_close(SHA256pw);
  1442. #endif
  1443. return CURLE_OK;
  1444. }
  1445. static bool Curl_gtls_cert_status_request(void)
  1446. {
  1447. return TRUE;
  1448. }
  1449. static void *Curl_gtls_get_internals(struct ssl_connect_data *connssl,
  1450. CURLINFO info UNUSED_PARAM)
  1451. {
  1452. struct ssl_backend_data *backend = connssl->backend;
  1453. (void)info;
  1454. return backend->session;
  1455. }
  1456. const struct Curl_ssl Curl_ssl_gnutls = {
  1457. { CURLSSLBACKEND_GNUTLS, "gnutls" }, /* info */
  1458. SSLSUPP_CA_PATH |
  1459. SSLSUPP_CERTINFO |
  1460. SSLSUPP_PINNEDPUBKEY |
  1461. SSLSUPP_HTTPS_PROXY,
  1462. sizeof(struct ssl_backend_data),
  1463. Curl_gtls_init, /* init */
  1464. Curl_gtls_cleanup, /* cleanup */
  1465. Curl_gtls_version, /* version */
  1466. Curl_none_check_cxn, /* check_cxn */
  1467. Curl_gtls_shutdown, /* shutdown */
  1468. Curl_gtls_data_pending, /* data_pending */
  1469. Curl_gtls_random, /* random */
  1470. Curl_gtls_cert_status_request, /* cert_status_request */
  1471. Curl_gtls_connect, /* connect */
  1472. Curl_gtls_connect_nonblocking, /* connect_nonblocking */
  1473. Curl_gtls_get_internals, /* get_internals */
  1474. Curl_gtls_close, /* close_one */
  1475. Curl_none_close_all, /* close_all */
  1476. Curl_gtls_session_free, /* session_free */
  1477. Curl_none_set_engine, /* set_engine */
  1478. Curl_none_set_engine_default, /* set_engine_default */
  1479. Curl_none_engines_list, /* engines_list */
  1480. Curl_none_false_start, /* false_start */
  1481. Curl_gtls_md5sum, /* md5sum */
  1482. Curl_gtls_sha256sum /* sha256sum */
  1483. };
  1484. #endif /* USE_GNUTLS */