@@ -4469,10 +4469,13 @@ struct mg_iface *mg_socks_mk_iface(struct mg_mgr *mgr, const char *proxy_addr) {
44694469#endif
44704470
44714471#include <openssl/ssl.h>
4472+ #include <openssl/err.h>
44724473#ifndef KR_VERSION
44734474#include <openssl/tls1.h>
44744475#endif
44754476
4477+ static const char * mg_default_session_id_context = "mongoose" ;
4478+
44764479struct mg_ssl_if_ctx {
44774480 SSL * ssl ;
44784481 SSL_CTX * ssl_ctx ;
@@ -4534,6 +4537,9 @@ enum mg_ssl_if_result mg_ssl_if_conn_init(
45344537 SSL_CTX_set_options (ctx -> ssl_ctx , SSL_OP_NO_SSLv2 );
45354538 SSL_CTX_set_options (ctx -> ssl_ctx , SSL_OP_NO_SSLv3 );
45364539 SSL_CTX_set_options (ctx -> ssl_ctx , SSL_OP_NO_TLSv1 );
4540+ SSL_CTX_set_session_id_context (ctx -> ssl_ctx ,
4541+ (void * ) mg_default_session_id_context ,
4542+ strlen (mg_default_session_id_context ));
45374543#ifdef MG_SSL_OPENSSL_NO_COMPRESSION
45384544 SSL_CTX_set_options (ctx -> ssl_ctx , SSL_OP_NO_COMPRESSION );
45394545#endif
@@ -4591,6 +4597,17 @@ static enum mg_ssl_if_result mg_ssl_if_ssl_err(struct mg_connection *nc,
45914597 int res ) {
45924598 struct mg_ssl_if_ctx * ctx = (struct mg_ssl_if_ctx * ) nc -> ssl_if_data ;
45934599 int err = SSL_get_error (ctx -> ssl , res );
4600+ /*
4601+ * We've just fetched the last error from the queue.
4602+ * Now we need to clear the error queue. If we do not, then the following
4603+ * can happen (actually reported):
4604+ * - A new connection is accept()-ed with cert error (e.g. self-signed cert)
4605+ * - Since all accept()-ed connections share listener's context,
4606+ * - *ALL* SSL accepted connection report read error on the next poll cycle.
4607+ * Thus a single errored connection can close all the rest, unrelated ones.
4608+ * Clearing the error keeps the shared SSL_CTX in an OK state.
4609+ */
4610+ ERR_clear_error ();
45944611 if (err == SSL_ERROR_WANT_READ ) return MG_SSL_WANT_READ ;
45954612 if (err == SSL_ERROR_WANT_WRITE ) return MG_SSL_WANT_WRITE ;
45964613 DBG (("%p %p SSL error: %d %d" , nc , ctx -> ssl_ctx , res , err ));
@@ -5865,7 +5882,7 @@ static void mg_http_free_proto_data_endpoints(struct mg_http_endpoint **ep) {
58655882 current = tmp ;
58665883 }
58675884
5868- ep = NULL ;
5885+ * ep = NULL ;
58695886}
58705887
58715888static void mg_http_free_reverse_proxy_data (struct mg_reverse_proxy_data * rpd ) {
@@ -7731,7 +7748,7 @@ static void mg_print_dir_entry(struct mg_connection *nc, const char *file_name,
77317748 href = mg_url_encode (mg_mk_str (file_name ));
77327749 mg_printf_http_chunk (nc ,
77337750 "<tr><td><a href=\"%s%s\">%s%s</a></td>"
7734- "<td>%s</td><td name=%" INT64_FMT ">%s</td></tr>\n " ,
7751+ "<td>%s</td><td name=\" %" INT64_FMT "\" >%s</td></tr>" ,
77357752 href .p , slash , path , slash , mod , is_dir ? -1 : fsize ,
77367753 size );
77377754 free ((void * ) href .p );
@@ -7797,23 +7814,24 @@ static void mg_send_directory_listing(struct mg_connection *nc, const char *dir,
77977814
77987815 mg_printf_http_chunk (
77997816 nc ,
7800- "<html><head><title>Index of %.*s</title>%s%s"
7817+ "<!DOCTYPE html>< html><head><title>Index of %.*s</title>%s%s"
78017818 "<style>th,td {text-align: left; padding-right: 1em; "
7802- "font-family: monospace; }</style></head>\n "
7803- "<body><h1>Index of %.*s</h1>\n <table cellpadding=0 ><thead>"
7804- "<tr><th><a href=# rel=0 >Name</a></th><th>"
7805- "<a href=# rel=1 >Modified</a</th>"
7806- "<th><a href=# rel=2 >Size</a></th></tr>"
7807- "<tr><td colspan=3 ><hr></td></tr>\n "
7808- "</thead>\n "
7809- "<tbody id=tb >" ,
7819+ "font-family: monospace; }</style></head>"
7820+ "<body><h1>Index of %.*s</h1><table cellpadding=\"0\" ><thead>"
7821+ "<tr><th><a href=\"#\" rel=\"0\" >Name</a></th><th>"
7822+ "<a href=\"#\" rel=\"1\" >Modified</a> </th>"
7823+ "<th><a href=\"#\" rel=\"2\" >Size</a></th></tr>"
7824+ "<tr><td colspan=\"3\" ><hr></td></tr>"
7825+ "</thead>"
7826+ "<tbody id=\"tb\" >" ,
78107827 (int ) hm -> uri .len , hm -> uri .p , sort_js_code , sort_js_code2 ,
78117828 (int ) hm -> uri .len , hm -> uri .p );
78127829 mg_scan_directory (nc , dir , opts , mg_print_dir_entry );
78137830 mg_printf_http_chunk (nc ,
7814- "</tbody><tr><td colspan=3><hr></td></tr>\n"
7815- "</table>\n"
7816- "<address>%s</address>\n"
7831+ "</tbody>"
7832+ "<tfoot><tr><td colspan=\"3\"><hr></td></tr></tfoot>"
7833+ "</table>"
7834+ "<address>%s</address>"
78177835 "</body></html>" ,
78187836 mg_version_header );
78197837 mg_send_http_chunk (nc , "" , 0 );
0 commit comments