tls_internal.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /*
  2. * TLS interface functions and an internal TLS implementation
  3. * Copyright (c) 2004-2011, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. *
  8. * This file interface functions for hostapd/wpa_supplicant to use the
  9. * integrated TLSv1 implementation.
  10. */
  11. #include "includes.h"
  12. #include "common.h"
  13. #include "tls.h"
  14. #include "tls/tlsv1_client.h"
  15. #include "tls/tlsv1_server.h"
  16. static int tls_ref_count = 0;
  17. struct tls_global {
  18. int server;
  19. struct tlsv1_credentials *server_cred;
  20. int check_crl;
  21. };
  22. struct tls_connection {
  23. struct tlsv1_client *client;
  24. struct tlsv1_server *server;
  25. struct tls_global *global;
  26. };
  27. void * tls_init(const struct tls_config *conf)
  28. {
  29. struct tls_global *global;
  30. if (tls_ref_count == 0) {
  31. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  32. if (tlsv1_client_global_init())
  33. return NULL;
  34. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  35. #ifdef CONFIG_TLS_INTERNAL_SERVER
  36. if (tlsv1_server_global_init())
  37. return NULL;
  38. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  39. }
  40. tls_ref_count++;
  41. global = os_zalloc(sizeof(*global));
  42. if (global == NULL)
  43. return NULL;
  44. return global;
  45. }
  46. void tls_deinit(void *ssl_ctx)
  47. {
  48. struct tls_global *global = ssl_ctx;
  49. tls_ref_count--;
  50. if (tls_ref_count == 0) {
  51. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  52. tlsv1_client_global_deinit();
  53. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  54. #ifdef CONFIG_TLS_INTERNAL_SERVER
  55. tlsv1_cred_free(global->server_cred);
  56. tlsv1_server_global_deinit();
  57. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  58. }
  59. os_free(global);
  60. }
  61. int tls_get_errors(void *tls_ctx)
  62. {
  63. return 0;
  64. }
  65. struct tls_connection * tls_connection_init(void *tls_ctx)
  66. {
  67. struct tls_connection *conn;
  68. struct tls_global *global = tls_ctx;
  69. conn = os_zalloc(sizeof(*conn));
  70. if (conn == NULL)
  71. return NULL;
  72. conn->global = global;
  73. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  74. if (!global->server) {
  75. conn->client = tlsv1_client_init();
  76. if (conn->client == NULL) {
  77. os_free(conn);
  78. return NULL;
  79. }
  80. }
  81. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  82. #ifdef CONFIG_TLS_INTERNAL_SERVER
  83. if (global->server) {
  84. conn->server = tlsv1_server_init(global->server_cred);
  85. if (conn->server == NULL) {
  86. os_free(conn);
  87. return NULL;
  88. }
  89. }
  90. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  91. return conn;
  92. }
  93. #ifdef CONFIG_TESTING_OPTIONS
  94. #ifdef CONFIG_TLS_INTERNAL_SERVER
  95. void tls_connection_set_test_flags(struct tls_connection *conn, u32 flags)
  96. {
  97. if (conn->server)
  98. tlsv1_server_set_test_flags(conn->server, flags);
  99. }
  100. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  101. #endif /* CONFIG_TESTING_OPTIONS */
  102. void tls_connection_set_log_cb(struct tls_connection *conn,
  103. void (*log_cb)(void *ctx, const char *msg),
  104. void *ctx)
  105. {
  106. #ifdef CONFIG_TLS_INTERNAL_SERVER
  107. if (conn->server)
  108. tlsv1_server_set_log_cb(conn->server, log_cb, ctx);
  109. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  110. }
  111. void tls_connection_deinit(void *tls_ctx, struct tls_connection *conn)
  112. {
  113. if (conn == NULL)
  114. return;
  115. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  116. if (conn->client)
  117. tlsv1_client_deinit(conn->client);
  118. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  119. #ifdef CONFIG_TLS_INTERNAL_SERVER
  120. if (conn->server)
  121. tlsv1_server_deinit(conn->server);
  122. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  123. os_free(conn);
  124. }
  125. int tls_connection_established(void *tls_ctx, struct tls_connection *conn)
  126. {
  127. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  128. if (conn->client)
  129. return tlsv1_client_established(conn->client);
  130. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  131. #ifdef CONFIG_TLS_INTERNAL_SERVER
  132. if (conn->server)
  133. return tlsv1_server_established(conn->server);
  134. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  135. return 0;
  136. }
  137. int tls_connection_shutdown(void *tls_ctx, struct tls_connection *conn)
  138. {
  139. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  140. if (conn->client)
  141. return tlsv1_client_shutdown(conn->client);
  142. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  143. #ifdef CONFIG_TLS_INTERNAL_SERVER
  144. if (conn->server)
  145. return tlsv1_server_shutdown(conn->server);
  146. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  147. return -1;
  148. }
  149. int tls_connection_set_params(void *tls_ctx, struct tls_connection *conn,
  150. const struct tls_connection_params *params)
  151. {
  152. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  153. struct tlsv1_credentials *cred;
  154. if (conn->client == NULL)
  155. return -1;
  156. cred = tlsv1_cred_alloc();
  157. if (cred == NULL)
  158. return -1;
  159. if (params->subject_match) {
  160. wpa_printf(MSG_INFO, "TLS: subject_match not supported");
  161. tlsv1_cred_free(cred);
  162. return -1;
  163. }
  164. if (params->altsubject_match) {
  165. wpa_printf(MSG_INFO, "TLS: altsubject_match not supported");
  166. tlsv1_cred_free(cred);
  167. return -1;
  168. }
  169. if (params->suffix_match) {
  170. wpa_printf(MSG_INFO, "TLS: suffix_match not supported");
  171. tlsv1_cred_free(cred);
  172. return -1;
  173. }
  174. if (params->domain_match) {
  175. wpa_printf(MSG_INFO, "TLS: domain_match not supported");
  176. tlsv1_cred_free(cred);
  177. return -1;
  178. }
  179. if (params->openssl_ciphers) {
  180. wpa_printf(MSG_INFO, "TLS: openssl_ciphers not supported");
  181. tlsv1_cred_free(cred);
  182. return -1;
  183. }
  184. if (tlsv1_set_ca_cert(cred, params->ca_cert,
  185. params->ca_cert_blob, params->ca_cert_blob_len,
  186. params->ca_path)) {
  187. wpa_printf(MSG_INFO, "TLS: Failed to configure trusted CA "
  188. "certificates");
  189. tlsv1_cred_free(cred);
  190. return -1;
  191. }
  192. if (tlsv1_set_cert(cred, params->client_cert,
  193. params->client_cert_blob,
  194. params->client_cert_blob_len)) {
  195. wpa_printf(MSG_INFO, "TLS: Failed to configure client "
  196. "certificate");
  197. tlsv1_cred_free(cred);
  198. return -1;
  199. }
  200. if (tlsv1_set_private_key(cred, params->private_key,
  201. params->private_key_passwd,
  202. params->private_key_blob,
  203. params->private_key_blob_len)) {
  204. wpa_printf(MSG_INFO, "TLS: Failed to load private key");
  205. tlsv1_cred_free(cred);
  206. return -1;
  207. }
  208. if (tlsv1_set_dhparams(cred, params->dh_file, params->dh_blob,
  209. params->dh_blob_len)) {
  210. wpa_printf(MSG_INFO, "TLS: Failed to load DH parameters");
  211. tlsv1_cred_free(cred);
  212. return -1;
  213. }
  214. if (tlsv1_client_set_cred(conn->client, cred) < 0) {
  215. tlsv1_cred_free(cred);
  216. return -1;
  217. }
  218. tlsv1_client_set_time_checks(
  219. conn->client, !(params->flags & TLS_CONN_DISABLE_TIME_CHECKS));
  220. return 0;
  221. #else /* CONFIG_TLS_INTERNAL_CLIENT */
  222. return -1;
  223. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  224. }
  225. int tls_global_set_params(void *tls_ctx,
  226. const struct tls_connection_params *params)
  227. {
  228. #ifdef CONFIG_TLS_INTERNAL_SERVER
  229. struct tls_global *global = tls_ctx;
  230. struct tlsv1_credentials *cred;
  231. /* Currently, global parameters are only set when running in server
  232. * mode. */
  233. global->server = 1;
  234. tlsv1_cred_free(global->server_cred);
  235. global->server_cred = cred = tlsv1_cred_alloc();
  236. if (cred == NULL)
  237. return -1;
  238. if (tlsv1_set_ca_cert(cred, params->ca_cert, params->ca_cert_blob,
  239. params->ca_cert_blob_len, params->ca_path)) {
  240. wpa_printf(MSG_INFO, "TLS: Failed to configure trusted CA "
  241. "certificates");
  242. return -1;
  243. }
  244. if (tlsv1_set_cert(cred, params->client_cert, params->client_cert_blob,
  245. params->client_cert_blob_len)) {
  246. wpa_printf(MSG_INFO, "TLS: Failed to configure server "
  247. "certificate");
  248. return -1;
  249. }
  250. if (tlsv1_set_private_key(cred, params->private_key,
  251. params->private_key_passwd,
  252. params->private_key_blob,
  253. params->private_key_blob_len)) {
  254. wpa_printf(MSG_INFO, "TLS: Failed to load private key");
  255. return -1;
  256. }
  257. if (tlsv1_set_dhparams(cred, params->dh_file, params->dh_blob,
  258. params->dh_blob_len)) {
  259. wpa_printf(MSG_INFO, "TLS: Failed to load DH parameters");
  260. return -1;
  261. }
  262. return 0;
  263. #else /* CONFIG_TLS_INTERNAL_SERVER */
  264. return -1;
  265. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  266. }
  267. int tls_global_set_verify(void *tls_ctx, int check_crl)
  268. {
  269. struct tls_global *global = tls_ctx;
  270. global->check_crl = check_crl;
  271. return 0;
  272. }
  273. int tls_connection_set_verify(void *tls_ctx, struct tls_connection *conn,
  274. int verify_peer)
  275. {
  276. #ifdef CONFIG_TLS_INTERNAL_SERVER
  277. if (conn->server)
  278. return tlsv1_server_set_verify(conn->server, verify_peer);
  279. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  280. return -1;
  281. }
  282. int tls_connection_get_keys(void *tls_ctx, struct tls_connection *conn,
  283. struct tls_keys *keys)
  284. {
  285. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  286. if (conn->client)
  287. return tlsv1_client_get_keys(conn->client, keys);
  288. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  289. #ifdef CONFIG_TLS_INTERNAL_SERVER
  290. if (conn->server)
  291. return tlsv1_server_get_keys(conn->server, keys);
  292. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  293. return -1;
  294. }
  295. static int tls_get_keyblock_size(struct tls_connection *conn)
  296. {
  297. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  298. if (conn->client)
  299. return tlsv1_client_get_keyblock_size(conn->client);
  300. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  301. #ifdef CONFIG_TLS_INTERNAL_SERVER
  302. if (conn->server)
  303. return tlsv1_server_get_keyblock_size(conn->server);
  304. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  305. return -1;
  306. }
  307. int tls_connection_prf(void *tls_ctx, struct tls_connection *conn,
  308. const char *label, int server_random_first,
  309. int skip_keyblock, u8 *out, size_t out_len)
  310. {
  311. int ret = -1, skip = 0;
  312. u8 *tmp_out = NULL;
  313. u8 *_out = out;
  314. if (skip_keyblock) {
  315. skip = tls_get_keyblock_size(conn);
  316. if (skip < 0)
  317. return -1;
  318. tmp_out = os_malloc(skip + out_len);
  319. if (!tmp_out)
  320. return -1;
  321. _out = tmp_out;
  322. }
  323. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  324. if (conn->client) {
  325. ret = tlsv1_client_prf(conn->client, label,
  326. server_random_first,
  327. _out, out_len);
  328. }
  329. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  330. #ifdef CONFIG_TLS_INTERNAL_SERVER
  331. if (conn->server) {
  332. ret = tlsv1_server_prf(conn->server, label,
  333. server_random_first,
  334. _out, out_len);
  335. }
  336. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  337. if (ret == 0 && skip_keyblock)
  338. os_memcpy(out, _out + skip, out_len);
  339. bin_clear_free(tmp_out, skip);
  340. return ret;
  341. }
  342. struct wpabuf * tls_connection_handshake(void *tls_ctx,
  343. struct tls_connection *conn,
  344. const struct wpabuf *in_data,
  345. struct wpabuf **appl_data)
  346. {
  347. return tls_connection_handshake2(tls_ctx, conn, in_data, appl_data,
  348. NULL);
  349. }
  350. struct wpabuf * tls_connection_handshake2(void *tls_ctx,
  351. struct tls_connection *conn,
  352. const struct wpabuf *in_data,
  353. struct wpabuf **appl_data,
  354. int *need_more_data)
  355. {
  356. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  357. u8 *res, *ad;
  358. size_t res_len, ad_len;
  359. struct wpabuf *out;
  360. if (conn->client == NULL)
  361. return NULL;
  362. ad = NULL;
  363. res = tlsv1_client_handshake(conn->client,
  364. in_data ? wpabuf_head(in_data) : NULL,
  365. in_data ? wpabuf_len(in_data) : 0,
  366. &res_len, &ad, &ad_len, need_more_data);
  367. if (res == NULL)
  368. return NULL;
  369. out = wpabuf_alloc_ext_data(res, res_len);
  370. if (out == NULL) {
  371. os_free(res);
  372. os_free(ad);
  373. return NULL;
  374. }
  375. if (appl_data) {
  376. if (ad) {
  377. *appl_data = wpabuf_alloc_ext_data(ad, ad_len);
  378. if (*appl_data == NULL)
  379. os_free(ad);
  380. } else
  381. *appl_data = NULL;
  382. } else
  383. os_free(ad);
  384. return out;
  385. #else /* CONFIG_TLS_INTERNAL_CLIENT */
  386. return NULL;
  387. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  388. }
  389. struct wpabuf * tls_connection_server_handshake(void *tls_ctx,
  390. struct tls_connection *conn,
  391. const struct wpabuf *in_data,
  392. struct wpabuf **appl_data)
  393. {
  394. #ifdef CONFIG_TLS_INTERNAL_SERVER
  395. u8 *res;
  396. size_t res_len;
  397. struct wpabuf *out;
  398. if (conn->server == NULL)
  399. return NULL;
  400. if (appl_data)
  401. *appl_data = NULL;
  402. res = tlsv1_server_handshake(conn->server, wpabuf_head(in_data),
  403. wpabuf_len(in_data), &res_len);
  404. if (res == NULL && tlsv1_server_established(conn->server))
  405. return wpabuf_alloc(0);
  406. if (res == NULL)
  407. return NULL;
  408. out = wpabuf_alloc_ext_data(res, res_len);
  409. if (out == NULL) {
  410. os_free(res);
  411. return NULL;
  412. }
  413. return out;
  414. #else /* CONFIG_TLS_INTERNAL_SERVER */
  415. return NULL;
  416. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  417. }
  418. struct wpabuf * tls_connection_encrypt(void *tls_ctx,
  419. struct tls_connection *conn,
  420. const struct wpabuf *in_data)
  421. {
  422. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  423. if (conn->client) {
  424. struct wpabuf *buf;
  425. int res;
  426. buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
  427. if (buf == NULL)
  428. return NULL;
  429. res = tlsv1_client_encrypt(conn->client, wpabuf_head(in_data),
  430. wpabuf_len(in_data),
  431. wpabuf_mhead(buf),
  432. wpabuf_size(buf));
  433. if (res < 0) {
  434. wpabuf_free(buf);
  435. return NULL;
  436. }
  437. wpabuf_put(buf, res);
  438. return buf;
  439. }
  440. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  441. #ifdef CONFIG_TLS_INTERNAL_SERVER
  442. if (conn->server) {
  443. struct wpabuf *buf;
  444. int res;
  445. buf = wpabuf_alloc(wpabuf_len(in_data) + 300);
  446. if (buf == NULL)
  447. return NULL;
  448. res = tlsv1_server_encrypt(conn->server, wpabuf_head(in_data),
  449. wpabuf_len(in_data),
  450. wpabuf_mhead(buf),
  451. wpabuf_size(buf));
  452. if (res < 0) {
  453. wpabuf_free(buf);
  454. return NULL;
  455. }
  456. wpabuf_put(buf, res);
  457. return buf;
  458. }
  459. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  460. return NULL;
  461. }
  462. struct wpabuf * tls_connection_decrypt(void *tls_ctx,
  463. struct tls_connection *conn,
  464. const struct wpabuf *in_data)
  465. {
  466. return tls_connection_decrypt2(tls_ctx, conn, in_data, NULL);
  467. }
  468. struct wpabuf * tls_connection_decrypt2(void *tls_ctx,
  469. struct tls_connection *conn,
  470. const struct wpabuf *in_data,
  471. int *need_more_data)
  472. {
  473. if (need_more_data)
  474. *need_more_data = 0;
  475. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  476. if (conn->client) {
  477. return tlsv1_client_decrypt(conn->client, wpabuf_head(in_data),
  478. wpabuf_len(in_data),
  479. need_more_data);
  480. }
  481. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  482. #ifdef CONFIG_TLS_INTERNAL_SERVER
  483. if (conn->server) {
  484. struct wpabuf *buf;
  485. int res;
  486. buf = wpabuf_alloc((wpabuf_len(in_data) + 500) * 3);
  487. if (buf == NULL)
  488. return NULL;
  489. res = tlsv1_server_decrypt(conn->server, wpabuf_head(in_data),
  490. wpabuf_len(in_data),
  491. wpabuf_mhead(buf),
  492. wpabuf_size(buf));
  493. if (res < 0) {
  494. wpabuf_free(buf);
  495. return NULL;
  496. }
  497. wpabuf_put(buf, res);
  498. return buf;
  499. }
  500. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  501. return NULL;
  502. }
  503. int tls_connection_resumed(void *tls_ctx, struct tls_connection *conn)
  504. {
  505. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  506. if (conn->client)
  507. return tlsv1_client_resumed(conn->client);
  508. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  509. #ifdef CONFIG_TLS_INTERNAL_SERVER
  510. if (conn->server)
  511. return tlsv1_server_resumed(conn->server);
  512. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  513. return -1;
  514. }
  515. int tls_connection_set_cipher_list(void *tls_ctx, struct tls_connection *conn,
  516. u8 *ciphers)
  517. {
  518. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  519. if (conn->client)
  520. return tlsv1_client_set_cipher_list(conn->client, ciphers);
  521. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  522. #ifdef CONFIG_TLS_INTERNAL_SERVER
  523. if (conn->server)
  524. return tlsv1_server_set_cipher_list(conn->server, ciphers);
  525. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  526. return -1;
  527. }
  528. int tls_get_cipher(void *tls_ctx, struct tls_connection *conn,
  529. char *buf, size_t buflen)
  530. {
  531. if (conn == NULL)
  532. return -1;
  533. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  534. if (conn->client)
  535. return tlsv1_client_get_cipher(conn->client, buf, buflen);
  536. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  537. #ifdef CONFIG_TLS_INTERNAL_SERVER
  538. if (conn->server)
  539. return tlsv1_server_get_cipher(conn->server, buf, buflen);
  540. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  541. return -1;
  542. }
  543. int tls_connection_enable_workaround(void *tls_ctx,
  544. struct tls_connection *conn)
  545. {
  546. return -1;
  547. }
  548. int tls_connection_client_hello_ext(void *tls_ctx, struct tls_connection *conn,
  549. int ext_type, const u8 *data,
  550. size_t data_len)
  551. {
  552. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  553. if (conn->client) {
  554. return tlsv1_client_hello_ext(conn->client, ext_type,
  555. data, data_len);
  556. }
  557. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  558. return -1;
  559. }
  560. int tls_connection_get_failed(void *tls_ctx, struct tls_connection *conn)
  561. {
  562. return 0;
  563. }
  564. int tls_connection_get_read_alerts(void *tls_ctx, struct tls_connection *conn)
  565. {
  566. return 0;
  567. }
  568. int tls_connection_get_write_alerts(void *tls_ctx,
  569. struct tls_connection *conn)
  570. {
  571. return 0;
  572. }
  573. unsigned int tls_capabilities(void *tls_ctx)
  574. {
  575. return 0;
  576. }
  577. int tls_connection_set_session_ticket_cb(void *tls_ctx,
  578. struct tls_connection *conn,
  579. tls_session_ticket_cb cb,
  580. void *ctx)
  581. {
  582. #ifdef CONFIG_TLS_INTERNAL_CLIENT
  583. if (conn->client) {
  584. tlsv1_client_set_session_ticket_cb(conn->client, cb, ctx);
  585. return 0;
  586. }
  587. #endif /* CONFIG_TLS_INTERNAL_CLIENT */
  588. #ifdef CONFIG_TLS_INTERNAL_SERVER
  589. if (conn->server) {
  590. tlsv1_server_set_session_ticket_cb(conn->server, cb, ctx);
  591. return 0;
  592. }
  593. #endif /* CONFIG_TLS_INTERNAL_SERVER */
  594. return -1;
  595. }
  596. int tls_get_library_version(char *buf, size_t buf_len)
  597. {
  598. return os_snprintf(buf, buf_len, "internal");
  599. }