bearssl.c 36 KB

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