2 * libwebsockets - small server side websockets and web server implementation
4 * Copyright (C) 2010-2017 Andy Green <andy@warmcat.com>
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation:
9 * version 2.1 of the License.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
22 #include "private-libwebsockets.h"
24 /* workaround for mingw */
25 #if !defined(ECONNABORTED)
26 #define ECONNABORTED 103
29 int lws_alloc_vfs_file(struct lws_context *context, const char *filename, uint8_t **buf,
30 lws_filepos_t *amount)
33 lws_fop_flags_t flags = LWS_O_RDONLY;
34 lws_fop_fd_t fops_fd = lws_vfs_file_open(
35 lws_get_fops(context), filename, &flags);
41 len = lws_vfs_get_length(fops_fd);
43 *buf = malloc((size_t)len);
47 if (lws_vfs_file_read(fops_fd, amount, *buf, len))
52 lws_vfs_file_close(&fops_fd);
57 #if defined(LWS_WITH_ESP32)
58 int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf,
59 lws_filepos_t *amount)
65 ESP_ERROR_CHECK(nvs_open("lws-station", NVS_READWRITE, &nvh));
66 if (nvs_get_blob(nvh, filename, NULL, &s) != ESP_OK) {
75 if (nvs_get_blob(nvh, filename, (char *)*buf, &s) != ESP_OK) {
88 int alloc_pem_to_der_file(struct lws_context *context, const char *filename, uint8_t **buf,
89 lws_filepos_t *amount)
91 uint8_t *pem, *p, *q, *end;
95 n = alloc_file(context, filename, &pem, &len);
99 /* trim the first line */
103 if (strncmp((char *)p, "-----", 5))
106 while (p < end && *p != '\n' && *p != '-')
112 while (p < end && *p != '\n')
120 /* trim the last line */
124 while (q > pem && *q != '\n')
132 *amount = lws_b64_decode_string((char *)p, (char *)pem, len);
144 int openssl_websocket_private_data_index,
145 openssl_SSL_CTX_private_data_index;
147 int lws_ssl_get_error(struct lws *wsi, int n)
151 lwsl_debug("%s: %p %d\n", __func__, wsi->ssl, n);
152 return SSL_get_error(wsi->ssl, n);
155 /* Copies a string describing the code returned by lws_ssl_get_error(),
156 * which may also contain system error information in the case of SSL_ERROR_SYSCALL,
157 * into buf up to len.
158 * Returns a pointer to buf.
160 * Note: the lws_ssl_get_error() code is *not* an error code that can be passed
161 * to ERR_error_string(),
163 * ret is the return value originally passed to lws_ssl_get_error(), needed to disambiguate
166 * See man page for SSL_get_error().
168 * Not thread safe, uses strerror()
170 char* lws_ssl_get_error_string(int status, int ret, char *buf, size_t len) {
172 case SSL_ERROR_NONE: return strncpy(buf, "SSL_ERROR_NONE", len);
173 case SSL_ERROR_ZERO_RETURN: return strncpy(buf, "SSL_ERROR_ZERO_RETURN", len);
174 case SSL_ERROR_WANT_READ: return strncpy(buf, "SSL_ERROR_WANT_READ", len);
175 case SSL_ERROR_WANT_WRITE: return strncpy(buf, "SSL_ERROR_WANT_WRITE", len);
176 case SSL_ERROR_WANT_CONNECT: return strncpy(buf, "SSL_ERROR_WANT_CONNECT", len);
177 case SSL_ERROR_WANT_ACCEPT: return strncpy(buf, "SSL_ERROR_WANT_ACCEPT", len);
178 case SSL_ERROR_WANT_X509_LOOKUP: return strncpy(buf, "SSL_ERROR_WANT_X509_LOOKUP", len);
179 case SSL_ERROR_SYSCALL:
182 lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: EOF");
185 #ifndef LWS_PLAT_OPTEE
186 lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %s", strerror(errno));
188 lws_snprintf(buf, len, "SSL_ERROR_SYSCALL: %d", errno);
192 return strncpy(buf, "SSL_ERROR_SYSCALL", len);
194 case SSL_ERROR_SSL: return "SSL_ERROR_SSL";
195 default: return "SSL_ERROR_UNKNOWN";
200 lws_ssl_elaborate_error(void)
202 #if defined(LWS_WITH_ESP32)
207 while ((err = ERR_get_error()) != 0) {
208 ERR_error_string_n(err, buf, sizeof(buf));
209 lwsl_err("*** %s\n", buf);
214 #if !defined(LWS_WITH_ESP32)
217 lws_context_init_ssl_pem_passwd_cb(char * buf, int size, int rwflag, void *userdata)
219 struct lws_context_creation_info * info =
220 (struct lws_context_creation_info *)userdata;
222 strncpy(buf, info->ssl_private_key_password, size);
223 buf[size - 1] = '\0';
229 lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, struct lws_context_creation_info *info)
231 if (!info->ssl_private_key_password)
234 * password provided, set ssl callback and user data
235 * for checking password which will be trigered during
236 * SSL_CTX_use_PrivateKey_file function
238 SSL_CTX_set_default_passwd_cb_userdata(ssl_ctx, (void *)info);
239 SSL_CTX_set_default_passwd_cb(ssl_ctx, lws_context_init_ssl_pem_passwd_cb);
244 lws_context_init_ssl_library(struct lws_context_creation_info *info)
247 #ifdef USE_OLD_CYASSL
248 lwsl_notice(" Compiled with CyaSSL support\n");
250 lwsl_notice(" Compiled with wolfSSL support\n");
253 #if defined(LWS_USE_BORINGSSL)
254 lwsl_notice(" Compiled with BoringSSL support\n");
256 lwsl_notice(" Compiled with OpenSSL support\n");
259 if (!lws_check_opt(info->options, LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT)) {
260 lwsl_notice(" SSL disabled: no LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT\n");
264 /* basic openssl init */
266 lwsl_notice("Doing SSL library init\n");
268 #if !defined(LWS_WITH_ESP32)
270 OpenSSL_add_all_algorithms();
271 SSL_load_error_strings();
273 openssl_websocket_private_data_index =
274 SSL_get_ex_new_index(0, "lws", NULL, NULL, NULL);
276 openssl_SSL_CTX_private_data_index = SSL_CTX_get_ex_new_index(0,
277 NULL, NULL, NULL, NULL);
284 lws_ssl_destroy(struct lws_vhost *vhost)
286 if (!lws_check_opt(vhost->context->options,
287 LWS_SERVER_OPTION_DO_SSL_GLOBAL_INIT))
291 SSL_CTX_free(vhost->ssl_ctx);
292 if (!vhost->user_supplied_ssl_ctx && vhost->ssl_client_ctx)
293 SSL_CTX_free(vhost->ssl_client_ctx);
294 #if !defined(LWS_WITH_ESP32)
296 // after 1.1.0 no need
297 #if (OPENSSL_VERSION_NUMBER < 0x10100000)
298 // <= 1.0.1f = old api, 1.0.1g+ = new api
299 #if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL)
302 #if OPENSSL_VERSION_NUMBER >= 0x1010005f && \
303 !defined(LIBRESSL_VERSION_NUMBER) && \
304 !defined(OPENSSL_IS_BORINGSSL)
305 ERR_remove_thread_state();
307 ERR_remove_thread_state(NULL);
312 CRYPTO_cleanup_all_ex_data();
318 lws_ssl_remove_wsi_from_buffered_list(struct lws *wsi)
320 struct lws_context *context = wsi->context;
321 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
323 if (!wsi->pending_read_list_prev &&
324 !wsi->pending_read_list_next &&
325 pt->pending_read_list != wsi)
326 /* we are not on the list */
329 /* point previous guy's next to our next */
330 if (!wsi->pending_read_list_prev)
331 pt->pending_read_list = wsi->pending_read_list_next;
333 wsi->pending_read_list_prev->pending_read_list_next =
334 wsi->pending_read_list_next;
336 /* point next guy's previous to our previous */
337 if (wsi->pending_read_list_next)
338 wsi->pending_read_list_next->pending_read_list_prev =
339 wsi->pending_read_list_prev;
341 wsi->pending_read_list_prev = NULL;
342 wsi->pending_read_list_next = NULL;
346 lws_ssl_capable_read(struct lws *wsi, unsigned char *buf, int len)
348 struct lws_context *context = wsi->context;
349 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
351 #if !defined(LWS_WITH_ESP32)
352 int ssl_read_errno = 0;
356 return lws_ssl_capable_read_no_ssl(wsi, buf, len);
358 lws_stats_atomic_bump(context, pt, LWSSTATS_C_API_READ, 1);
361 n = SSL_read(wsi->ssl, buf, len);
362 #if defined(LWS_WITH_ESP32)
363 if (!n && errno == ENOTCONN) {
364 lwsl_debug("%p: SSL_read ENOTCONN\n", wsi);
365 return LWS_SSL_CAPABLE_ERROR;
368 #if defined(LWS_WITH_STATS)
370 lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_SSL_RX_DELAY,
371 time_in_microseconds() - wsi->accept_start_us);
372 lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_SSL_CONNS_HAD_RX, 1);
378 lwsl_debug("%p: SSL_read says %d\n", wsi, n);
379 /* manpage: returning 0 means connection shut down */
381 n = lws_ssl_get_error(wsi, n);
382 lwsl_debug("%p: ssl err %d errno %d\n", wsi, n, errno);
383 if (n == SSL_ERROR_ZERO_RETURN)
384 return LWS_SSL_CAPABLE_ERROR;
386 if (n == SSL_ERROR_SYSCALL) {
387 #if !defined(LWS_WITH_ESP32)
388 int err = ERR_get_error();
389 if (err == 0 && (ssl_read_errno == EPIPE ||
390 ssl_read_errno == ECONNABORTED ||
391 ssl_read_errno == 0))
392 return LWS_SSL_CAPABLE_ERROR;
396 lwsl_err("%s failed: %s\n",__func__,
397 ERR_error_string(lws_ssl_get_error(wsi, 0), NULL));
398 lws_ssl_elaborate_error();
400 return LWS_SSL_CAPABLE_ERROR;
404 n = lws_ssl_get_error(wsi, n);
405 // lwsl_notice("get_ssl_err result %d\n", n);
406 if (n == SSL_ERROR_WANT_READ || SSL_want_read(wsi->ssl)) {
407 lwsl_debug("%s: WANT_READ\n", __func__);
408 lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi);
409 return LWS_SSL_CAPABLE_MORE_SERVICE;
411 if (n == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->ssl)) {
412 lwsl_debug("%s: WANT_WRITE\n", __func__);
413 lwsl_debug("%p: LWS_SSL_CAPABLE_MORE_SERVICE\n", wsi);
414 return LWS_SSL_CAPABLE_MORE_SERVICE;
418 lwsl_err("%s failed2: %s\n",__func__,
419 ERR_error_string(lws_ssl_get_error(wsi, 0), NULL));
420 lws_ssl_elaborate_error();
422 return LWS_SSL_CAPABLE_ERROR;
425 lws_stats_atomic_bump(context, pt, LWSSTATS_B_READ, n);
428 wsi->vhost->conn_stats.rx += n;
430 lws_restart_ws_ping_pong_timer(wsi);
433 * if it was our buffer that limited what we read,
434 * check if SSL has additional data pending inside SSL buffers.
436 * Because these won't signal at the network layer with POLLIN
437 * and if we don't realize, this data will sit there forever
444 if (!SSL_pending(wsi->ssl))
447 if (wsi->pending_read_list_next)
449 if (wsi->pending_read_list_prev)
451 if (pt->pending_read_list == wsi)
454 /* add us to the linked list of guys with pending ssl */
455 if (pt->pending_read_list)
456 pt->pending_read_list->pending_read_list_prev = wsi;
458 wsi->pending_read_list_next = pt->pending_read_list;
459 wsi->pending_read_list_prev = NULL;
460 pt->pending_read_list = wsi;
464 lws_ssl_remove_wsi_from_buffered_list(wsi);
470 lws_ssl_pending(struct lws *wsi)
475 return SSL_pending(wsi->ssl);
479 lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len)
482 #if !defined(LWS_WITH_ESP32)
483 int ssl_read_errno = 0;
487 return lws_ssl_capable_write_no_ssl(wsi, buf, len);
489 n = SSL_write(wsi->ssl, buf, len);
493 n = lws_ssl_get_error(wsi, n);
494 if (n == SSL_ERROR_WANT_READ || n == SSL_ERROR_WANT_WRITE) {
495 if (n == SSL_ERROR_WANT_WRITE) {
496 lwsl_debug("%s: WANT_WRITE\n", __func__);
497 lws_set_blocking_send(wsi);
499 return LWS_SSL_CAPABLE_MORE_SERVICE;
502 if (n == SSL_ERROR_ZERO_RETURN)
503 return LWS_SSL_CAPABLE_ERROR;
505 #if !defined(LWS_WITH_ESP32)
506 if (n == SSL_ERROR_SYSCALL) {
508 int err = ERR_get_error();
510 && (ssl_read_errno == EPIPE
511 || ssl_read_errno == ECONNABORTED
512 || ssl_read_errno == 0))
513 return LWS_SSL_CAPABLE_ERROR;
517 lwsl_err("%s failed: %s\n",__func__,
518 ERR_error_string(lws_ssl_get_error(wsi, 0), NULL));
519 lws_ssl_elaborate_error();
521 return LWS_SSL_CAPABLE_ERROR;
525 lws_gate_accepts(struct lws_context *context, int on)
527 struct lws_vhost *v = context->vhost_list;
529 lwsl_info("gating accepts %d\n", on);
530 context->ssl_gate_accepts = !on;
531 #if defined(LWS_WITH_STATS)
532 context->updated = 1;
536 if (v->use_ssl && v->lserv_wsi) /* gate ability to accept incoming connections */
537 if (lws_change_pollfd(v->lserv_wsi, (LWS_POLLIN) * !on, (LWS_POLLIN) * on))
538 lwsl_err("Unable to set accept POLLIN %d\n", on);
547 lws_ssl_info_callback(const SSL *ssl, int where, int ret)
550 struct lws_context *context;
551 struct lws_ssl_info si;
553 context = (struct lws_context *)SSL_CTX_get_ex_data(
554 SSL_get_SSL_CTX(ssl),
555 openssl_SSL_CTX_private_data_index);
558 wsi = wsi_from_fd(context, SSL_get_fd(ssl));
562 if (!(where & wsi->vhost->ssl_info_event_mask))
568 if (user_callback_handle_rxflow(wsi->protocol->callback,
569 wsi, LWS_CALLBACK_SSL_INFO,
570 wsi->user_space, &si, 0))
571 lws_set_timeout(wsi, PENDING_TIMEOUT_KILLED_BY_SSL_INFO, -1);
576 lws_ssl_close(struct lws *wsi)
581 return 0; /* not handled */
583 #if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK)
584 /* kill ssl callbacks, becausse we will remove the fd from the
585 * table linking it to the wsi
587 if (wsi->vhost->ssl_info_event_mask)
588 SSL_set_info_callback(wsi->ssl, NULL);
591 n = SSL_get_fd(wsi->ssl);
592 SSL_shutdown(wsi->ssl);
597 if (wsi->context->simultaneous_ssl_restriction &&
598 wsi->context->simultaneous_ssl-- ==
599 wsi->context->simultaneous_ssl_restriction)
600 /* we made space and can do an accept */
601 lws_gate_accepts(wsi->context, 1);
602 #if defined(LWS_WITH_STATS)
603 wsi->context->updated = 1;
606 return 1; /* handled */
609 /* leave all wsi close processing to the caller */
612 lws_server_socket_service_ssl(struct lws *wsi, lws_sockfd_type accept_fd)
614 struct lws_context *context = wsi->context;
615 struct lws_context_per_thread *pt = &context->pt[(int)wsi->tsi];
617 #if !defined(USE_WOLFSSL) && !defined(LWS_WITH_ESP32)
622 if (!LWS_SSL_ENABLED(wsi->vhost))
627 case LWSCM_SSL_INIT_RAW:
629 lwsl_err("%s: leaking ssl\n", __func__);
630 if (accept_fd == LWS_SOCK_INVALID)
632 if (context->simultaneous_ssl_restriction &&
633 context->simultaneous_ssl >= context->simultaneous_ssl_restriction) {
634 lwsl_notice("unable to deal with SSL connection\n");
638 wsi->ssl = SSL_new(wsi->vhost->ssl_ctx);
639 if (wsi->ssl == NULL) {
640 lwsl_err("SSL_new failed: %d (errno %d)\n",
641 lws_ssl_get_error(wsi, 0), errno);
643 lws_ssl_elaborate_error();
644 if (accept_fd != LWS_SOCK_INVALID)
645 compatible_close(accept_fd);
648 #if defined (LWS_HAVE_SSL_SET_INFO_CALLBACK)
649 if (wsi->vhost->ssl_info_event_mask)
650 SSL_set_info_callback(wsi->ssl, lws_ssl_info_callback);
652 if (context->simultaneous_ssl_restriction &&
653 ++context->simultaneous_ssl == context->simultaneous_ssl_restriction)
654 /* that was the last allowed SSL connection */
655 lws_gate_accepts(context, 0);
656 #if defined(LWS_WITH_STATS)
657 context->updated = 1;
660 #if !defined(LWS_WITH_ESP32)
661 SSL_set_ex_data(wsi->ssl,
662 openssl_websocket_private_data_index, wsi);
664 SSL_set_fd(wsi->ssl, accept_fd);
667 #ifdef USE_OLD_CYASSL
668 CyaSSL_set_using_nonblock(wsi->ssl, 1);
670 wolfSSL_set_using_nonblock(wsi->ssl, 1);
673 #if defined(LWS_WITH_ESP32)
674 lws_plat_set_socket_options(wsi->vhost, accept_fd);
676 SSL_set_mode(wsi->ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
677 bio = SSL_get_rbio(wsi->ssl);
679 BIO_set_nbio(bio, 1); /* nonblocking */
681 lwsl_notice("NULL rbio\n");
682 bio = SSL_get_wbio(wsi->ssl);
684 BIO_set_nbio(bio, 1); /* nonblocking */
686 lwsl_notice("NULL rbio\n");
691 * we are not accepted yet, but we need to enter ourselves
692 * as a live connection. That way we can retry when more
693 * pieces come if we're not sorted yet
696 if (wsi->mode == LWSCM_SSL_INIT)
697 wsi->mode = LWSCM_SSL_ACK_PENDING;
699 wsi->mode = LWSCM_SSL_ACK_PENDING_RAW;
701 if (insert_wsi_socket_into_fds(context, wsi)) {
702 lwsl_err("%s: failed to insert into fds\n", __func__);
706 lws_set_timeout(wsi, PENDING_TIMEOUT_SSL_ACCEPT,
707 context->timeout_secs);
709 lwsl_debug("inserted SSL accept into fds, trying SSL_accept\n");
713 case LWSCM_SSL_ACK_PENDING:
714 case LWSCM_SSL_ACK_PENDING_RAW:
715 if (lws_change_pollfd(wsi, LWS_POLLOUT, 0)) {
716 lwsl_err("%s: lws_change_pollfd failed\n", __func__);
720 lws_latency_pre(context, wsi);
722 if (wsi->vhost->allow_non_ssl_on_ssl_port) {
724 n = recv(wsi->desc.sockfd, (char *)pt->serv_buf, context->pt_serv_buf_size,
728 * optionally allow non-SSL connect on SSL listening socket
729 * This is disabled by default, if enabled it goes around any
730 * SSL-level access control (eg, client-side certs) so leave
731 * it disabled unless you know it's not a problem for you
734 if (n >= 1 && pt->serv_buf[0] >= ' ') {
736 * TLS content-type for Handshake is 0x16, and
737 * for ChangeCipherSpec Record, it's 0x14
739 * A non-ssl session will start with the HTTP
740 * method in ASCII. If we see it's not a legit
741 * SSL handshake kill the SSL for this
742 * connection and try to handle as a HTTP
743 * connection upgrade directly.
747 SSL_shutdown(wsi->ssl);
750 if (lws_check_opt(context->options,
751 LWS_SERVER_OPTION_REDIRECT_HTTP_TO_HTTPS))
752 wsi->redirect_to_https = 1;
756 * connection is gone, or nothing to read
757 * if it's gone, we will timeout on
758 * PENDING_TIMEOUT_SSL_ACCEPT
761 if (n < 0 && (LWS_ERRNO == LWS_EAGAIN ||
762 LWS_ERRNO == LWS_EWOULDBLOCK)) {
764 * well, we get no way to know ssl or not
765 * so go around again waiting for something
766 * to come and give us a hint, or timeout the
769 m = SSL_ERROR_WANT_READ;
774 /* normal SSL connection processing path */
776 #if defined(LWS_WITH_STATS)
777 if (!wsi->accept_start_us)
778 wsi->accept_start_us = time_in_microseconds();
781 n = SSL_accept(wsi->ssl);
782 lws_latency(context, wsi,
783 "SSL_accept LWSCM_SSL_ACK_PENDING\n", n, n == 1);
784 lwsl_info("SSL_accept says %d\n", n);
788 m = lws_ssl_get_error(wsi, n);
790 #if defined(LWS_WITH_ESP32)
791 if (m == 5 && errno == 11)
792 m = SSL_ERROR_WANT_READ;
796 if (m == SSL_ERROR_WANT_READ || SSL_want_read(wsi->ssl)) {
797 if (lws_change_pollfd(wsi, 0, LWS_POLLIN)) {
798 lwsl_err("%s: WANT_READ change_pollfd failed\n", __func__);
802 lwsl_info("SSL_ERROR_WANT_READ\n");
805 if (m == SSL_ERROR_WANT_WRITE || SSL_want_write(wsi->ssl)) {
806 lwsl_debug("%s: WANT_WRITE\n", __func__);
808 if (lws_change_pollfd(wsi, 0, LWS_POLLOUT)) {
809 lwsl_err("%s: WANT_WRITE change_pollfd failed\n", __func__);
815 lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_SSL_CONNECTIONS_FAILED, 1);
816 lwsl_err("SSL_accept failed socket %u: %s\n", wsi->desc.sockfd,
817 lws_ssl_get_error_string(m, n, buf, sizeof(buf)));
818 lws_ssl_elaborate_error();
822 lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_C_SSL_CONNECTIONS_ACCEPTED, 1);
823 #if defined(LWS_WITH_STATS)
824 lws_stats_atomic_bump(wsi->context, pt, LWSSTATS_MS_SSL_CONNECTIONS_ACCEPTED_DELAY, time_in_microseconds() - wsi->accept_start_us);
825 wsi->accept_start_us = time_in_microseconds();
828 /* OK, we are accepted... give him some time to negotiate */
829 lws_set_timeout(wsi, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER,
830 context->timeout_secs);
832 if (wsi->mode == LWSCM_SSL_ACK_PENDING_RAW)
833 wsi->mode = LWSCM_RAW;
835 wsi->mode = LWSCM_HTTP_SERVING;
837 lws_http2_configure_if_upgraded(wsi);
839 lwsl_debug("accepted new SSL conn\n");
850 lws_ssl_SSL_CTX_destroy(struct lws_vhost *vhost)
853 SSL_CTX_free(vhost->ssl_ctx);
855 if (!vhost->user_supplied_ssl_ctx && vhost->ssl_client_ctx)
856 SSL_CTX_free(vhost->ssl_client_ctx);
860 lws_ssl_context_destroy(struct lws_context *context)
863 #if !defined(LWS_WITH_ESP32)
865 // after 1.1.0 no need
866 #if (OPENSSL_VERSION_NUMBER < 0x10100000)
867 // <= 1.0.1f = old api, 1.0.1g+ = new api
868 #if (OPENSSL_VERSION_NUMBER <= 0x1000106f) || defined(USE_WOLFSSL)
871 #if OPENSSL_VERSION_NUMBER >= 0x1010005f && \
872 !defined(LIBRESSL_VERSION_NUMBER) && \
873 !defined(OPENSSL_IS_BORINGSSL)
874 ERR_remove_thread_state();
876 ERR_remove_thread_state(NULL);
881 CRYPTO_cleanup_all_ex_data();