bearssl.c 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) Michael Forney, <mforney@mforney.org>
  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.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. * SPDX-License-Identifier: curl
  22. *
  23. ***************************************************************************/
  24. #include "curl_setup.h"
  25. #ifdef USE_BEARSSL
  26. #include <bearssl.h>
  27. #include "bearssl.h"
  28. #include "cipher_suite.h"
  29. #include "urldata.h"
  30. #include "sendf.h"
  31. #include "inet_pton.h"
  32. #include "vtls.h"
  33. #include "vtls_int.h"
  34. #include "connect.h"
  35. #include "select.h"
  36. #include "multiif.h"
  37. #include "curl_printf.h"
  38. /* The last #include files should be: */
  39. #include "curl_memory.h"
  40. #include "memdebug.h"
  41. struct x509_context {
  42. const br_x509_class *vtable;
  43. br_x509_minimal_context minimal;
  44. br_x509_decoder_context decoder;
  45. bool verifyhost;
  46. bool verifypeer;
  47. int cert_num;
  48. };
  49. struct bearssl_ssl_backend_data {
  50. br_ssl_client_context ctx;
  51. struct x509_context x509;
  52. unsigned char buf[BR_SSL_BUFSIZE_BIDI];
  53. br_x509_trust_anchor *anchors;
  54. size_t anchors_len;
  55. const char *protocols[ALPN_ENTRIES_MAX];
  56. /* SSL client context is active */
  57. bool active;
  58. /* size of pending write, yet to be flushed */
  59. size_t pending_write;
  60. };
  61. struct cafile_parser {
  62. CURLcode err;
  63. bool in_cert;
  64. br_x509_decoder_context xc;
  65. /* array of trust anchors loaded from CAfile */
  66. br_x509_trust_anchor *anchors;
  67. size_t anchors_len;
  68. /* buffer for DN data */
  69. unsigned char dn[1024];
  70. size_t dn_len;
  71. };
  72. #define CAFILE_SOURCE_PATH 1
  73. #define CAFILE_SOURCE_BLOB 2
  74. struct cafile_source {
  75. int type;
  76. const char *data;
  77. size_t len;
  78. };
  79. static void append_dn(void *ctx, const void *buf, size_t len)
  80. {
  81. struct cafile_parser *ca = ctx;
  82. if(ca->err != CURLE_OK || !ca->in_cert)
  83. return;
  84. if(sizeof(ca->dn) - ca->dn_len < len) {
  85. ca->err = CURLE_FAILED_INIT;
  86. return;
  87. }
  88. memcpy(ca->dn + ca->dn_len, buf, len);
  89. ca->dn_len += len;
  90. }
  91. static void x509_push(void *ctx, const void *buf, size_t len)
  92. {
  93. struct cafile_parser *ca = ctx;
  94. if(ca->in_cert)
  95. br_x509_decoder_push(&ca->xc, buf, len);
  96. }
  97. static CURLcode load_cafile(struct cafile_source *source,
  98. br_x509_trust_anchor **anchors,
  99. size_t *anchors_len)
  100. {
  101. struct cafile_parser ca;
  102. br_pem_decoder_context pc;
  103. br_x509_trust_anchor *ta;
  104. size_t ta_size;
  105. br_x509_trust_anchor *new_anchors;
  106. size_t new_anchors_len;
  107. br_x509_pkey *pkey;
  108. FILE *fp = 0;
  109. unsigned char buf[BUFSIZ];
  110. const unsigned char *p = NULL;
  111. const char *name;
  112. size_t n = 0, i, pushed;
  113. DEBUGASSERT(source->type == CAFILE_SOURCE_PATH
  114. || source->type == CAFILE_SOURCE_BLOB);
  115. if(source->type == CAFILE_SOURCE_PATH) {
  116. fp = fopen(source->data, "rb");
  117. if(!fp)
  118. return CURLE_SSL_CACERT_BADFILE;
  119. }
  120. if(source->type == CAFILE_SOURCE_BLOB && source->len > (size_t)INT_MAX)
  121. return CURLE_SSL_CACERT_BADFILE;
  122. ca.err = CURLE_OK;
  123. ca.in_cert = FALSE;
  124. ca.anchors = NULL;
  125. ca.anchors_len = 0;
  126. br_pem_decoder_init(&pc);
  127. br_pem_decoder_setdest(&pc, x509_push, &ca);
  128. do {
  129. if(source->type == CAFILE_SOURCE_PATH) {
  130. n = fread(buf, 1, sizeof(buf), fp);
  131. if(n == 0)
  132. break;
  133. p = buf;
  134. }
  135. else if(source->type == CAFILE_SOURCE_BLOB) {
  136. n = source->len;
  137. p = (unsigned char *) source->data;
  138. }
  139. while(n) {
  140. pushed = br_pem_decoder_push(&pc, p, n);
  141. if(ca.err)
  142. goto fail;
  143. p += pushed;
  144. n -= pushed;
  145. switch(br_pem_decoder_event(&pc)) {
  146. case 0:
  147. break;
  148. case BR_PEM_BEGIN_OBJ:
  149. name = br_pem_decoder_name(&pc);
  150. if(strcmp(name, "CERTIFICATE") && strcmp(name, "X509 CERTIFICATE"))
  151. break;
  152. br_x509_decoder_init(&ca.xc, append_dn, &ca);
  153. ca.in_cert = TRUE;
  154. ca.dn_len = 0;
  155. break;
  156. case BR_PEM_END_OBJ:
  157. if(!ca.in_cert)
  158. break;
  159. ca.in_cert = FALSE;
  160. if(br_x509_decoder_last_error(&ca.xc)) {
  161. ca.err = CURLE_SSL_CACERT_BADFILE;
  162. goto fail;
  163. }
  164. /* add trust anchor */
  165. if(ca.anchors_len == SIZE_MAX / sizeof(ca.anchors[0])) {
  166. ca.err = CURLE_OUT_OF_MEMORY;
  167. goto fail;
  168. }
  169. new_anchors_len = ca.anchors_len + 1;
  170. new_anchors = realloc(ca.anchors,
  171. new_anchors_len * sizeof(ca.anchors[0]));
  172. if(!new_anchors) {
  173. ca.err = CURLE_OUT_OF_MEMORY;
  174. goto fail;
  175. }
  176. ca.anchors = new_anchors;
  177. ca.anchors_len = new_anchors_len;
  178. ta = &ca.anchors[ca.anchors_len - 1];
  179. ta->dn.data = NULL;
  180. ta->flags = 0;
  181. if(br_x509_decoder_isCA(&ca.xc))
  182. ta->flags |= BR_X509_TA_CA;
  183. pkey = br_x509_decoder_get_pkey(&ca.xc);
  184. if(!pkey) {
  185. ca.err = CURLE_SSL_CACERT_BADFILE;
  186. goto fail;
  187. }
  188. ta->pkey = *pkey;
  189. /* calculate space needed for trust anchor data */
  190. ta_size = ca.dn_len;
  191. switch(pkey->key_type) {
  192. case BR_KEYTYPE_RSA:
  193. ta_size += pkey->key.rsa.nlen + pkey->key.rsa.elen;
  194. break;
  195. case BR_KEYTYPE_EC:
  196. ta_size += pkey->key.ec.qlen;
  197. break;
  198. default:
  199. ca.err = CURLE_FAILED_INIT;
  200. goto fail;
  201. }
  202. /* fill in trust anchor DN and public key data */
  203. ta->dn.data = malloc(ta_size);
  204. if(!ta->dn.data) {
  205. ca.err = CURLE_OUT_OF_MEMORY;
  206. goto fail;
  207. }
  208. memcpy(ta->dn.data, ca.dn, ca.dn_len);
  209. ta->dn.len = ca.dn_len;
  210. switch(pkey->key_type) {
  211. case BR_KEYTYPE_RSA:
  212. ta->pkey.key.rsa.n = ta->dn.data + ta->dn.len;
  213. memcpy(ta->pkey.key.rsa.n, pkey->key.rsa.n, pkey->key.rsa.nlen);
  214. ta->pkey.key.rsa.e = ta->pkey.key.rsa.n + ta->pkey.key.rsa.nlen;
  215. memcpy(ta->pkey.key.rsa.e, pkey->key.rsa.e, pkey->key.rsa.elen);
  216. break;
  217. case BR_KEYTYPE_EC:
  218. ta->pkey.key.ec.q = ta->dn.data + ta->dn.len;
  219. memcpy(ta->pkey.key.ec.q, pkey->key.ec.q, pkey->key.ec.qlen);
  220. break;
  221. }
  222. break;
  223. default:
  224. ca.err = CURLE_SSL_CACERT_BADFILE;
  225. goto fail;
  226. }
  227. }
  228. } while(source->type != CAFILE_SOURCE_BLOB);
  229. if(fp && ferror(fp))
  230. ca.err = CURLE_READ_ERROR;
  231. else if(ca.in_cert)
  232. ca.err = CURLE_SSL_CACERT_BADFILE;
  233. fail:
  234. if(fp)
  235. fclose(fp);
  236. if(ca.err == CURLE_OK) {
  237. *anchors = ca.anchors;
  238. *anchors_len = ca.anchors_len;
  239. }
  240. else {
  241. for(i = 0; i < ca.anchors_len; ++i)
  242. free(ca.anchors[i].dn.data);
  243. free(ca.anchors);
  244. }
  245. return ca.err;
  246. }
  247. static void x509_start_chain(const br_x509_class **ctx,
  248. const char *server_name)
  249. {
  250. struct x509_context *x509 = (struct x509_context *)ctx;
  251. if(!x509->verifypeer) {
  252. x509->cert_num = 0;
  253. return;
  254. }
  255. if(!x509->verifyhost)
  256. server_name = NULL;
  257. x509->minimal.vtable->start_chain(&x509->minimal.vtable, server_name);
  258. }
  259. static void x509_start_cert(const br_x509_class **ctx, uint32_t length)
  260. {
  261. struct x509_context *x509 = (struct x509_context *)ctx;
  262. if(!x509->verifypeer) {
  263. /* Only decode the first cert in the chain to obtain the public key */
  264. if(x509->cert_num == 0)
  265. br_x509_decoder_init(&x509->decoder, NULL, NULL);
  266. return;
  267. }
  268. x509->minimal.vtable->start_cert(&x509->minimal.vtable, length);
  269. }
  270. static void x509_append(const br_x509_class **ctx, const unsigned char *buf,
  271. size_t len)
  272. {
  273. struct x509_context *x509 = (struct x509_context *)ctx;
  274. if(!x509->verifypeer) {
  275. if(x509->cert_num == 0)
  276. br_x509_decoder_push(&x509->decoder, buf, len);
  277. return;
  278. }
  279. x509->minimal.vtable->append(&x509->minimal.vtable, buf, len);
  280. }
  281. static void x509_end_cert(const br_x509_class **ctx)
  282. {
  283. struct x509_context *x509 = (struct x509_context *)ctx;
  284. if(!x509->verifypeer) {
  285. x509->cert_num++;
  286. return;
  287. }
  288. x509->minimal.vtable->end_cert(&x509->minimal.vtable);
  289. }
  290. static unsigned x509_end_chain(const br_x509_class **ctx)
  291. {
  292. struct x509_context *x509 = (struct x509_context *)ctx;
  293. if(!x509->verifypeer) {
  294. return br_x509_decoder_last_error(&x509->decoder);
  295. }
  296. return x509->minimal.vtable->end_chain(&x509->minimal.vtable);
  297. }
  298. static const br_x509_pkey *x509_get_pkey(const br_x509_class *const *ctx,
  299. unsigned *usages)
  300. {
  301. struct x509_context *x509 = (struct x509_context *)ctx;
  302. if(!x509->verifypeer) {
  303. /* Nothing in the chain is verified, just return the public key of the
  304. first certificate and allow its usage for both TLS_RSA_* and
  305. TLS_ECDHE_* */
  306. if(usages)
  307. *usages = BR_KEYTYPE_KEYX | BR_KEYTYPE_SIGN;
  308. return br_x509_decoder_get_pkey(&x509->decoder);
  309. }
  310. return x509->minimal.vtable->get_pkey(&x509->minimal.vtable, usages);
  311. }
  312. static const br_x509_class x509_vtable = {
  313. sizeof(struct x509_context),
  314. x509_start_chain,
  315. x509_start_cert,
  316. x509_append,
  317. x509_end_cert,
  318. x509_end_chain,
  319. x509_get_pkey
  320. };
  321. static const uint16_t ciphertable[] = {
  322. /* RFC 2246 TLS 1.0 */
  323. BR_TLS_RSA_WITH_3DES_EDE_CBC_SHA, /* 0x000A */
  324. /* RFC 3268 TLS 1.0 AES */
  325. BR_TLS_RSA_WITH_AES_128_CBC_SHA, /* 0x002F */
  326. BR_TLS_RSA_WITH_AES_256_CBC_SHA, /* 0x0035 */
  327. /* RFC 5246 TLS 1.2 */
  328. BR_TLS_RSA_WITH_AES_128_CBC_SHA256, /* 0x003C */
  329. BR_TLS_RSA_WITH_AES_256_CBC_SHA256, /* 0x003D */
  330. /* RFC 5288 TLS 1.2 AES GCM */
  331. BR_TLS_RSA_WITH_AES_128_GCM_SHA256, /* 0x009C */
  332. BR_TLS_RSA_WITH_AES_256_GCM_SHA384, /* 0x009D */
  333. /* RFC 4492 TLS 1.0 ECC */
  334. BR_TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, /* 0xC003 */
  335. BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, /* 0xC004 */
  336. BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, /* 0xC005 */
  337. BR_TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, /* 0xC008 */
  338. BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, /* 0xC009 */
  339. BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, /* 0xC00A */
  340. BR_TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, /* 0xC00D */
  341. BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, /* 0xC00E */
  342. BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, /* 0xC00F */
  343. BR_TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, /* 0xC012 */
  344. BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, /* 0xC013 */
  345. BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, /* 0xC014 */
  346. /* RFC 5289 TLS 1.2 ECC HMAC SHA256/384 */
  347. BR_TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, /* 0xC023 */
  348. BR_TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, /* 0xC024 */
  349. BR_TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, /* 0xC025 */
  350. BR_TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, /* 0xC026 */
  351. BR_TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, /* 0xC027 */
  352. BR_TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, /* 0xC028 */
  353. BR_TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, /* 0xC029 */
  354. BR_TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, /* 0xC02A */
  355. /* RFC 5289 TLS 1.2 GCM */
  356. BR_TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, /* 0xC02B */
  357. BR_TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, /* 0xC02C */
  358. BR_TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, /* 0xC02D */
  359. BR_TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, /* 0xC02E */
  360. BR_TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, /* 0xC02F */
  361. BR_TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, /* 0xC030 */
  362. BR_TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, /* 0xC031 */
  363. BR_TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, /* 0xC032 */
  364. #ifdef BR_TLS_RSA_WITH_AES_128_CCM
  365. /* RFC 6655 TLS 1.2 CCM
  366. Supported since BearSSL 0.6 */
  367. BR_TLS_RSA_WITH_AES_128_CCM, /* 0xC09C */
  368. BR_TLS_RSA_WITH_AES_256_CCM, /* 0xC09D */
  369. BR_TLS_RSA_WITH_AES_128_CCM_8, /* 0xC0A0 */
  370. BR_TLS_RSA_WITH_AES_256_CCM_8, /* 0xC0A1 */
  371. /* RFC 7251 TLS 1.2 ECC CCM
  372. Supported since BearSSL 0.6 */
  373. BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM, /* 0xC0AC */
  374. BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM, /* 0xC0AD */
  375. BR_TLS_ECDHE_ECDSA_WITH_AES_128_CCM_8, /* 0xC0AE */
  376. BR_TLS_ECDHE_ECDSA_WITH_AES_256_CCM_8, /* 0xC0AF */
  377. #endif
  378. /* RFC 7905 TLS 1.2 ChaCha20-Poly1305
  379. Supported since BearSSL 0.2 */
  380. BR_TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256, /* 0xCCA8 */
  381. BR_TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256, /* 0xCCA9 */
  382. };
  383. #define NUM_OF_CIPHERS (sizeof(ciphertable) / sizeof(ciphertable[0]))
  384. static CURLcode bearssl_set_selected_ciphers(struct Curl_easy *data,
  385. br_ssl_engine_context *ssl_eng,
  386. const char *ciphers)
  387. {
  388. uint16_t selected[NUM_OF_CIPHERS];
  389. size_t count = 0, i;
  390. const char *ptr, *end;
  391. for(ptr = ciphers; ptr[0] != '\0' && count < NUM_OF_CIPHERS; ptr = end) {
  392. uint16_t id = Curl_cipher_suite_walk_str(&ptr, &end);
  393. /* Check if cipher is supported */
  394. if(id) {
  395. for(i = 0; i < NUM_OF_CIPHERS && ciphertable[i] != id; i++);
  396. if(i == NUM_OF_CIPHERS)
  397. id = 0;
  398. }
  399. if(!id) {
  400. if(ptr[0] != '\0')
  401. infof(data, "BearSSL: unknown cipher in list: \"%.*s\"",
  402. (int) (end - ptr), ptr);
  403. continue;
  404. }
  405. /* No duplicates allowed */
  406. for(i = 0; i < count && selected[i] != id; i++);
  407. if(i < count) {
  408. infof(data, "BearSSL: duplicate cipher in list: \"%.*s\"",
  409. (int) (end - ptr), ptr);
  410. continue;
  411. }
  412. selected[count++] = id;
  413. }
  414. if(count == 0) {
  415. failf(data, "BearSSL: no supported cipher in list");
  416. return CURLE_SSL_CIPHER;
  417. }
  418. br_ssl_engine_set_suites(ssl_eng, selected, count);
  419. return CURLE_OK;
  420. }
  421. static CURLcode bearssl_connect_step1(struct Curl_cfilter *cf,
  422. struct Curl_easy *data)
  423. {
  424. struct ssl_connect_data *connssl = cf->ctx;
  425. struct bearssl_ssl_backend_data *backend =
  426. (struct bearssl_ssl_backend_data *)connssl->backend;
  427. struct ssl_primary_config *conn_config = Curl_ssl_cf_get_primary_config(cf);
  428. struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
  429. const struct curl_blob *ca_info_blob = conn_config->ca_info_blob;
  430. const char * const ssl_cafile =
  431. /* CURLOPT_CAINFO_BLOB overrides CURLOPT_CAINFO */
  432. (ca_info_blob ? NULL : conn_config->CAfile);
  433. const char *hostname = connssl->peer.hostname;
  434. const bool verifypeer = conn_config->verifypeer;
  435. const bool verifyhost = conn_config->verifyhost;
  436. CURLcode ret;
  437. unsigned version_min, version_max;
  438. int session_set = 0;
  439. DEBUGASSERT(backend);
  440. CURL_TRC_CF(data, cf, "connect_step1");
  441. switch(conn_config->version) {
  442. case CURL_SSLVERSION_SSLv2:
  443. failf(data, "BearSSL does not support SSLv2");
  444. return CURLE_SSL_CONNECT_ERROR;
  445. case CURL_SSLVERSION_SSLv3:
  446. failf(data, "BearSSL does not support SSLv3");
  447. return CURLE_SSL_CONNECT_ERROR;
  448. case CURL_SSLVERSION_TLSv1_0:
  449. version_min = BR_TLS10;
  450. version_max = BR_TLS10;
  451. break;
  452. case CURL_SSLVERSION_TLSv1_1:
  453. version_min = BR_TLS11;
  454. version_max = BR_TLS11;
  455. break;
  456. case CURL_SSLVERSION_TLSv1_2:
  457. version_min = BR_TLS12;
  458. version_max = BR_TLS12;
  459. break;
  460. case CURL_SSLVERSION_DEFAULT:
  461. case CURL_SSLVERSION_TLSv1:
  462. version_min = BR_TLS10;
  463. version_max = BR_TLS12;
  464. break;
  465. default:
  466. failf(data, "BearSSL: unknown CURLOPT_SSLVERSION");
  467. return CURLE_SSL_CONNECT_ERROR;
  468. }
  469. if(verifypeer) {
  470. if(ca_info_blob) {
  471. struct cafile_source source;
  472. source.type = CAFILE_SOURCE_BLOB;
  473. source.data = ca_info_blob->data;
  474. source.len = ca_info_blob->len;
  475. CURL_TRC_CF(data, cf, "connect_step1, load ca_info_blob");
  476. ret = load_cafile(&source, &backend->anchors, &backend->anchors_len);
  477. if(ret != CURLE_OK) {
  478. failf(data, "error importing CA certificate blob");
  479. return ret;
  480. }
  481. }
  482. if(ssl_cafile) {
  483. struct cafile_source source;
  484. source.type = CAFILE_SOURCE_PATH;
  485. source.data = ssl_cafile;
  486. source.len = 0;
  487. CURL_TRC_CF(data, cf, "connect_step1, load cafile");
  488. ret = load_cafile(&source, &backend->anchors, &backend->anchors_len);
  489. if(ret != CURLE_OK) {
  490. failf(data, "error setting certificate verify locations."
  491. " CAfile: %s", ssl_cafile);
  492. return ret;
  493. }
  494. }
  495. }
  496. /* initialize SSL context */
  497. br_ssl_client_init_full(&backend->ctx, &backend->x509.minimal,
  498. backend->anchors, backend->anchors_len);
  499. br_ssl_engine_set_versions(&backend->ctx.eng, version_min, version_max);
  500. br_ssl_engine_set_buffer(&backend->ctx.eng, backend->buf,
  501. sizeof(backend->buf), 1);
  502. if(conn_config->cipher_list) {
  503. /* Override the ciphers as specified. For the default cipher list see the
  504. BearSSL source code of br_ssl_client_init_full() */
  505. CURL_TRC_CF(data, cf, "connect_step1, set ciphers");
  506. ret = bearssl_set_selected_ciphers(data, &backend->ctx.eng,
  507. conn_config->cipher_list);
  508. if(ret)
  509. return ret;
  510. }
  511. /* initialize X.509 context */
  512. backend->x509.vtable = &x509_vtable;
  513. backend->x509.verifypeer = verifypeer;
  514. backend->x509.verifyhost = verifyhost;
  515. br_ssl_engine_set_x509(&backend->ctx.eng, &backend->x509.vtable);
  516. if(ssl_config->primary.sessionid) {
  517. void *session;
  518. CURL_TRC_CF(data, cf, "connect_step1, check session cache");
  519. Curl_ssl_sessionid_lock(data);
  520. if(!Curl_ssl_getsessionid(cf, data, &connssl->peer, &session, NULL)) {
  521. br_ssl_engine_set_session_parameters(&backend->ctx.eng, session);
  522. session_set = 1;
  523. infof(data, "BearSSL: reusing session ID");
  524. }
  525. Curl_ssl_sessionid_unlock(data);
  526. }
  527. if(connssl->alpn) {
  528. struct alpn_proto_buf proto;
  529. size_t i;
  530. for(i = 0; i < connssl->alpn->count; ++i) {
  531. backend->protocols[i] = connssl->alpn->entries[i];
  532. }
  533. br_ssl_engine_set_protocol_names(&backend->ctx.eng, backend->protocols,
  534. connssl->alpn->count);
  535. Curl_alpn_to_proto_str(&proto, connssl->alpn);
  536. infof(data, VTLS_INFOF_ALPN_OFFER_1STR, proto.data);
  537. }
  538. if(connssl->peer.type != CURL_SSL_PEER_DNS) {
  539. if(verifyhost) {
  540. failf(data, "BearSSL: "
  541. "host verification of IP address is not supported");
  542. return CURLE_PEER_FAILED_VERIFICATION;
  543. }
  544. hostname = NULL;
  545. }
  546. else {
  547. if(!connssl->peer.sni) {
  548. failf(data, "Failed to set SNI");
  549. return CURLE_SSL_CONNECT_ERROR;
  550. }
  551. hostname = connssl->peer.sni;
  552. CURL_TRC_CF(data, cf, "connect_step1, SNI set");
  553. }
  554. /* give application a chance to interfere with SSL set up. */
  555. if(data->set.ssl.fsslctx) {
  556. Curl_set_in_callback(data, true);
  557. ret = (*data->set.ssl.fsslctx)(data, &backend->ctx,
  558. data->set.ssl.fsslctxp);
  559. Curl_set_in_callback(data, false);
  560. if(ret) {
  561. failf(data, "BearSSL: error signaled by ssl ctx callback");
  562. return ret;
  563. }
  564. }
  565. if(!br_ssl_client_reset(&backend->ctx, hostname, session_set))
  566. return CURLE_FAILED_INIT;
  567. backend->active = TRUE;
  568. connssl->connecting_state = ssl_connect_2;
  569. return CURLE_OK;
  570. }
  571. static void bearssl_adjust_pollset(struct Curl_cfilter *cf,
  572. struct Curl_easy *data,
  573. struct easy_pollset *ps)
  574. {
  575. if(!cf->connected) {
  576. curl_socket_t sock = Curl_conn_cf_get_socket(cf->next, data);
  577. if(sock != CURL_SOCKET_BAD) {
  578. struct ssl_connect_data *connssl = cf->ctx;
  579. struct bearssl_ssl_backend_data *backend =
  580. (struct bearssl_ssl_backend_data *)connssl->backend;
  581. unsigned state = br_ssl_engine_current_state(&backend->ctx.eng);
  582. if(state & BR_SSL_SENDREC) {
  583. Curl_pollset_set_out_only(data, ps, sock);
  584. }
  585. else {
  586. Curl_pollset_set_in_only(data, ps, sock);
  587. }
  588. }
  589. }
  590. }
  591. static CURLcode bearssl_run_until(struct Curl_cfilter *cf,
  592. struct Curl_easy *data,
  593. unsigned target)
  594. {
  595. struct ssl_connect_data *connssl = cf->ctx;
  596. struct bearssl_ssl_backend_data *backend =
  597. (struct bearssl_ssl_backend_data *)connssl->backend;
  598. unsigned state;
  599. unsigned char *buf;
  600. size_t len;
  601. ssize_t ret;
  602. CURLcode result;
  603. int err;
  604. DEBUGASSERT(backend);
  605. for(;;) {
  606. state = br_ssl_engine_current_state(&backend->ctx.eng);
  607. if(state & BR_SSL_CLOSED) {
  608. err = br_ssl_engine_last_error(&backend->ctx.eng);
  609. switch(err) {
  610. case BR_ERR_OK:
  611. /* TLS close notify */
  612. if(connssl->state != ssl_connection_complete) {
  613. failf(data, "SSL: connection closed during handshake");
  614. return CURLE_SSL_CONNECT_ERROR;
  615. }
  616. return CURLE_OK;
  617. case BR_ERR_X509_EXPIRED:
  618. failf(data, "SSL: X.509 verification: "
  619. "certificate is expired or not yet valid");
  620. return CURLE_PEER_FAILED_VERIFICATION;
  621. case BR_ERR_X509_BAD_SERVER_NAME:
  622. failf(data, "SSL: X.509 verification: "
  623. "expected server name was not found in the chain");
  624. return CURLE_PEER_FAILED_VERIFICATION;
  625. case BR_ERR_X509_NOT_TRUSTED:
  626. failf(data, "SSL: X.509 verification: "
  627. "chain could not be linked to a trust anchor");
  628. return CURLE_PEER_FAILED_VERIFICATION;
  629. }
  630. /* X.509 errors are documented to have the range 32..63 */
  631. if(err >= 32 && err < 64)
  632. return CURLE_PEER_FAILED_VERIFICATION;
  633. return CURLE_SSL_CONNECT_ERROR;
  634. }
  635. if(state & target)
  636. return CURLE_OK;
  637. if(state & BR_SSL_SENDREC) {
  638. buf = br_ssl_engine_sendrec_buf(&backend->ctx.eng, &len);
  639. ret = Curl_conn_cf_send(cf->next, data, (char *)buf, len, &result);
  640. CURL_TRC_CF(data, cf, "ssl_send(len=%zu) -> %zd, %d", len, ret, result);
  641. if(ret <= 0) {
  642. return result;
  643. }
  644. br_ssl_engine_sendrec_ack(&backend->ctx.eng, ret);
  645. }
  646. else if(state & BR_SSL_RECVREC) {
  647. buf = br_ssl_engine_recvrec_buf(&backend->ctx.eng, &len);
  648. ret = Curl_conn_cf_recv(cf->next, data, (char *)buf, len, &result);
  649. CURL_TRC_CF(data, cf, "ssl_recv(len=%zu) -> %zd, %d", len, ret, result);
  650. if(ret == 0) {
  651. failf(data, "SSL: EOF without close notify");
  652. return CURLE_RECV_ERROR;
  653. }
  654. if(ret <= 0) {
  655. return result;
  656. }
  657. br_ssl_engine_recvrec_ack(&backend->ctx.eng, ret);
  658. }
  659. }
  660. }
  661. static CURLcode bearssl_connect_step2(struct Curl_cfilter *cf,
  662. struct Curl_easy *data)
  663. {
  664. struct ssl_connect_data *connssl = cf->ctx;
  665. struct bearssl_ssl_backend_data *backend =
  666. (struct bearssl_ssl_backend_data *)connssl->backend;
  667. br_ssl_session_parameters session;
  668. char cipher_str[64];
  669. char ver_str[16];
  670. CURLcode ret;
  671. DEBUGASSERT(backend);
  672. CURL_TRC_CF(data, cf, "connect_step2");
  673. ret = bearssl_run_until(cf, data, BR_SSL_SENDAPP | BR_SSL_RECVAPP);
  674. if(ret == CURLE_AGAIN)
  675. return CURLE_OK;
  676. if(ret == CURLE_OK) {
  677. unsigned int tver;
  678. if(br_ssl_engine_current_state(&backend->ctx.eng) == BR_SSL_CLOSED) {
  679. failf(data, "SSL: connection closed during handshake");
  680. return CURLE_SSL_CONNECT_ERROR;
  681. }
  682. connssl->connecting_state = ssl_connect_3;
  683. /* Informational message */
  684. tver = br_ssl_engine_get_version(&backend->ctx.eng);
  685. if(tver == BR_TLS12)
  686. strcpy(ver_str, "TLSv1.2");
  687. else if(tver == BR_TLS11)
  688. strcpy(ver_str, "TLSv1.1");
  689. else if(tver == BR_TLS10)
  690. strcpy(ver_str, "TLSv1.0");
  691. else {
  692. msnprintf(ver_str, sizeof(ver_str), "TLS 0x%04x", tver);
  693. }
  694. br_ssl_engine_get_session_parameters(&backend->ctx.eng, &session);
  695. Curl_cipher_suite_get_str(session.cipher_suite, cipher_str,
  696. sizeof(cipher_str), true);
  697. infof(data, "BearSSL: %s connection using %s", ver_str, cipher_str);
  698. }
  699. return ret;
  700. }
  701. static void bearssl_session_free(void *sessionid, size_t idsize)
  702. {
  703. (void)idsize;
  704. free(sessionid);
  705. }
  706. static CURLcode bearssl_connect_step3(struct Curl_cfilter *cf,
  707. struct Curl_easy *data)
  708. {
  709. struct ssl_connect_data *connssl = cf->ctx;
  710. struct bearssl_ssl_backend_data *backend =
  711. (struct bearssl_ssl_backend_data *)connssl->backend;
  712. struct ssl_config_data *ssl_config = Curl_ssl_cf_get_config(cf, data);
  713. CURLcode ret;
  714. DEBUGASSERT(ssl_connect_3 == connssl->connecting_state);
  715. DEBUGASSERT(backend);
  716. CURL_TRC_CF(data, cf, "connect_step3");
  717. if(connssl->alpn) {
  718. const char *proto;
  719. proto = br_ssl_engine_get_selected_protocol(&backend->ctx.eng);
  720. Curl_alpn_set_negotiated(cf, data, (const unsigned char *)proto,
  721. proto? strlen(proto) : 0);
  722. }
  723. if(ssl_config->primary.sessionid) {
  724. bool incache;
  725. void *oldsession;
  726. br_ssl_session_parameters *session;
  727. session = malloc(sizeof(*session));
  728. if(!session)
  729. return CURLE_OUT_OF_MEMORY;
  730. br_ssl_engine_get_session_parameters(&backend->ctx.eng, session);
  731. Curl_ssl_sessionid_lock(data);
  732. incache = !(Curl_ssl_getsessionid(cf, data, &connssl->peer,
  733. &oldsession, NULL));
  734. if(incache)
  735. Curl_ssl_delsessionid(data, oldsession);
  736. ret = Curl_ssl_addsessionid(cf, data, &connssl->peer, session, 0,
  737. bearssl_session_free);
  738. Curl_ssl_sessionid_unlock(data);
  739. if(ret)
  740. return ret;
  741. }
  742. connssl->connecting_state = ssl_connect_done;
  743. return CURLE_OK;
  744. }
  745. static ssize_t bearssl_send(struct Curl_cfilter *cf, struct Curl_easy *data,
  746. const void *buf, size_t len, CURLcode *err)
  747. {
  748. struct ssl_connect_data *connssl = cf->ctx;
  749. struct bearssl_ssl_backend_data *backend =
  750. (struct bearssl_ssl_backend_data *)connssl->backend;
  751. unsigned char *app;
  752. size_t applen;
  753. DEBUGASSERT(backend);
  754. for(;;) {
  755. *err = bearssl_run_until(cf, data, BR_SSL_SENDAPP);
  756. if(*err)
  757. return -1;
  758. app = br_ssl_engine_sendapp_buf(&backend->ctx.eng, &applen);
  759. if(!app) {
  760. failf(data, "SSL: connection closed during write");
  761. *err = CURLE_SEND_ERROR;
  762. return -1;
  763. }
  764. if(backend->pending_write) {
  765. applen = backend->pending_write;
  766. backend->pending_write = 0;
  767. return applen;
  768. }
  769. if(applen > len)
  770. applen = len;
  771. memcpy(app, buf, applen);
  772. br_ssl_engine_sendapp_ack(&backend->ctx.eng, applen);
  773. br_ssl_engine_flush(&backend->ctx.eng, 0);
  774. backend->pending_write = applen;
  775. }
  776. }
  777. static ssize_t bearssl_recv(struct Curl_cfilter *cf, struct Curl_easy *data,
  778. char *buf, size_t len, CURLcode *err)
  779. {
  780. struct ssl_connect_data *connssl = cf->ctx;
  781. struct bearssl_ssl_backend_data *backend =
  782. (struct bearssl_ssl_backend_data *)connssl->backend;
  783. unsigned char *app;
  784. size_t applen;
  785. DEBUGASSERT(backend);
  786. *err = bearssl_run_until(cf, data, BR_SSL_RECVAPP);
  787. if(*err != CURLE_OK)
  788. return -1;
  789. app = br_ssl_engine_recvapp_buf(&backend->ctx.eng, &applen);
  790. if(!app)
  791. return 0;
  792. if(applen > len)
  793. applen = len;
  794. memcpy(buf, app, applen);
  795. br_ssl_engine_recvapp_ack(&backend->ctx.eng, applen);
  796. return applen;
  797. }
  798. static CURLcode bearssl_connect_common(struct Curl_cfilter *cf,
  799. struct Curl_easy *data,
  800. bool nonblocking,
  801. bool *done)
  802. {
  803. CURLcode ret;
  804. struct ssl_connect_data *connssl = cf->ctx;
  805. curl_socket_t sockfd = Curl_conn_cf_get_socket(cf, data);
  806. timediff_t timeout_ms;
  807. int what;
  808. CURL_TRC_CF(data, cf, "connect_common(blocking=%d)", !nonblocking);
  809. /* check if the connection has already been established */
  810. if(ssl_connection_complete == connssl->state) {
  811. CURL_TRC_CF(data, cf, "connect_common, connected");
  812. *done = TRUE;
  813. return CURLE_OK;
  814. }
  815. if(ssl_connect_1 == connssl->connecting_state) {
  816. ret = bearssl_connect_step1(cf, data);
  817. if(ret)
  818. return ret;
  819. }
  820. while(ssl_connect_2 == connssl->connecting_state ||
  821. ssl_connect_2_reading == connssl->connecting_state ||
  822. ssl_connect_2_writing == connssl->connecting_state) {
  823. /* check allowed time left */
  824. timeout_ms = Curl_timeleft(data, NULL, TRUE);
  825. if(timeout_ms < 0) {
  826. /* no need to continue if time already is up */
  827. failf(data, "SSL connection timeout");
  828. return CURLE_OPERATION_TIMEDOUT;
  829. }
  830. /* if ssl is expecting something, check if it's available. */
  831. if(ssl_connect_2_reading == connssl->connecting_state ||
  832. ssl_connect_2_writing == connssl->connecting_state) {
  833. curl_socket_t writefd = ssl_connect_2_writing ==
  834. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  835. curl_socket_t readfd = ssl_connect_2_reading ==
  836. connssl->connecting_state?sockfd:CURL_SOCKET_BAD;
  837. CURL_TRC_CF(data, cf, "connect_common, check socket");
  838. what = Curl_socket_check(readfd, CURL_SOCKET_BAD, writefd,
  839. nonblocking?0:timeout_ms);
  840. CURL_TRC_CF(data, cf, "connect_common, check socket -> %d", what);
  841. if(what < 0) {
  842. /* fatal error */
  843. failf(data, "select/poll on SSL socket, errno: %d", SOCKERRNO);
  844. return CURLE_SSL_CONNECT_ERROR;
  845. }
  846. else if(0 == what) {
  847. if(nonblocking) {
  848. *done = FALSE;
  849. return CURLE_OK;
  850. }
  851. else {
  852. /* timeout */
  853. failf(data, "SSL connection timeout");
  854. return CURLE_OPERATION_TIMEDOUT;
  855. }
  856. }
  857. /* socket is readable or writable */
  858. }
  859. /* Run transaction, and return to the caller if it failed or if this
  860. * connection is done nonblocking and this loop would execute again. This
  861. * permits the owner of a multi handle to abort a connection attempt
  862. * before step2 has completed while ensuring that a client using select()
  863. * or epoll() will always have a valid fdset to wait on.
  864. */
  865. ret = bearssl_connect_step2(cf, data);
  866. if(ret || (nonblocking &&
  867. (ssl_connect_2 == connssl->connecting_state ||
  868. ssl_connect_2_reading == connssl->connecting_state ||
  869. ssl_connect_2_writing == connssl->connecting_state)))
  870. return ret;
  871. }
  872. if(ssl_connect_3 == connssl->connecting_state) {
  873. ret = bearssl_connect_step3(cf, data);
  874. if(ret)
  875. return ret;
  876. }
  877. if(ssl_connect_done == connssl->connecting_state) {
  878. connssl->state = ssl_connection_complete;
  879. *done = TRUE;
  880. }
  881. else
  882. *done = FALSE;
  883. /* Reset our connect state machine */
  884. connssl->connecting_state = ssl_connect_1;
  885. return CURLE_OK;
  886. }
  887. static size_t bearssl_version(char *buffer, size_t size)
  888. {
  889. return msnprintf(buffer, size, "BearSSL");
  890. }
  891. static bool bearssl_data_pending(struct Curl_cfilter *cf,
  892. const struct Curl_easy *data)
  893. {
  894. struct ssl_connect_data *ctx = cf->ctx;
  895. struct bearssl_ssl_backend_data *backend;
  896. (void)data;
  897. DEBUGASSERT(ctx && ctx->backend);
  898. backend = (struct bearssl_ssl_backend_data *)ctx->backend;
  899. return br_ssl_engine_current_state(&backend->ctx.eng) & BR_SSL_RECVAPP;
  900. }
  901. static CURLcode bearssl_random(struct Curl_easy *data UNUSED_PARAM,
  902. unsigned char *entropy, size_t length)
  903. {
  904. static br_hmac_drbg_context ctx;
  905. static bool seeded = FALSE;
  906. if(!seeded) {
  907. br_prng_seeder seeder;
  908. br_hmac_drbg_init(&ctx, &br_sha256_vtable, NULL, 0);
  909. seeder = br_prng_seeder_system(NULL);
  910. if(!seeder || !seeder(&ctx.vtable))
  911. return CURLE_FAILED_INIT;
  912. seeded = TRUE;
  913. }
  914. br_hmac_drbg_generate(&ctx, entropy, length);
  915. return CURLE_OK;
  916. }
  917. static CURLcode bearssl_connect(struct Curl_cfilter *cf,
  918. struct Curl_easy *data)
  919. {
  920. CURLcode ret;
  921. bool done = FALSE;
  922. ret = bearssl_connect_common(cf, data, FALSE, &done);
  923. if(ret)
  924. return ret;
  925. DEBUGASSERT(done);
  926. return CURLE_OK;
  927. }
  928. static CURLcode bearssl_connect_nonblocking(struct Curl_cfilter *cf,
  929. struct Curl_easy *data,
  930. bool *done)
  931. {
  932. return bearssl_connect_common(cf, data, TRUE, done);
  933. }
  934. static void *bearssl_get_internals(struct ssl_connect_data *connssl,
  935. CURLINFO info UNUSED_PARAM)
  936. {
  937. struct bearssl_ssl_backend_data *backend =
  938. (struct bearssl_ssl_backend_data *)connssl->backend;
  939. DEBUGASSERT(backend);
  940. return &backend->ctx;
  941. }
  942. static void bearssl_close(struct Curl_cfilter *cf, struct Curl_easy *data)
  943. {
  944. struct ssl_connect_data *connssl = cf->ctx;
  945. struct bearssl_ssl_backend_data *backend =
  946. (struct bearssl_ssl_backend_data *)connssl->backend;
  947. size_t i;
  948. DEBUGASSERT(backend);
  949. if(backend->active) {
  950. backend->active = FALSE;
  951. br_ssl_engine_close(&backend->ctx.eng);
  952. (void)bearssl_run_until(cf, data, BR_SSL_CLOSED);
  953. }
  954. if(backend->anchors) {
  955. for(i = 0; i < backend->anchors_len; ++i)
  956. free(backend->anchors[i].dn.data);
  957. Curl_safefree(backend->anchors);
  958. }
  959. }
  960. static CURLcode bearssl_sha256sum(const unsigned char *input,
  961. size_t inputlen,
  962. unsigned char *sha256sum,
  963. size_t sha256len UNUSED_PARAM)
  964. {
  965. br_sha256_context ctx;
  966. br_sha256_init(&ctx);
  967. br_sha256_update(&ctx, input, inputlen);
  968. br_sha256_out(&ctx, sha256sum);
  969. return CURLE_OK;
  970. }
  971. const struct Curl_ssl Curl_ssl_bearssl = {
  972. { CURLSSLBACKEND_BEARSSL, "bearssl" }, /* info */
  973. SSLSUPP_CAINFO_BLOB | SSLSUPP_SSL_CTX | SSLSUPP_HTTPS_PROXY,
  974. sizeof(struct bearssl_ssl_backend_data),
  975. Curl_none_init, /* init */
  976. Curl_none_cleanup, /* cleanup */
  977. bearssl_version, /* version */
  978. Curl_none_check_cxn, /* check_cxn */
  979. Curl_none_shutdown, /* shutdown */
  980. bearssl_data_pending, /* data_pending */
  981. bearssl_random, /* random */
  982. Curl_none_cert_status_request, /* cert_status_request */
  983. bearssl_connect, /* connect */
  984. bearssl_connect_nonblocking, /* connect_nonblocking */
  985. bearssl_adjust_pollset, /* adjust_pollset */
  986. bearssl_get_internals, /* get_internals */
  987. bearssl_close, /* close_one */
  988. Curl_none_close_all, /* close_all */
  989. Curl_none_set_engine, /* set_engine */
  990. Curl_none_set_engine_default, /* set_engine_default */
  991. Curl_none_engines_list, /* engines_list */
  992. Curl_none_false_start, /* false_start */
  993. bearssl_sha256sum, /* sha256sum */
  994. NULL, /* associate_connection */
  995. NULL, /* disassociate_connection */
  996. NULL, /* free_multi_ssl_backend_data */
  997. bearssl_recv, /* recv decrypted data */
  998. bearssl_send, /* send data to encrypt */
  999. };
  1000. #endif /* USE_BEARSSL */