From 17ada1c8948759329e20e0afaf634a9f28550af7 Mon Sep 17 00:00:00 2001 From: cpq Date: Wed, 19 Oct 2022 09:06:47 +0100 Subject: [PATCH] Fix #1803 - conditional for SSL_set1_host(). In unit test, disable time.windows.com, use google and apple SNTP servers --- mongoose.c | 2 ++ src/tls_openssl.c | 2 ++ test/unit_test.c | 23 ++++++++++------------- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/mongoose.c b/mongoose.c index 05b7406b..e80c7fcb 100644 --- a/mongoose.c +++ b/mongoose.c @@ -5325,11 +5325,13 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) { } } if (opts->ciphers != NULL) SSL_set_cipher_list(tls->ssl, opts->ciphers); +#if OPENSSL_VERSION_NUMBER >= 0x10100000L if (opts->srvname.len > 0) { char *s = mg_mprintf("%.*s", (int) opts->srvname.len, opts->srvname.ptr); SSL_set1_host(tls->ssl, s); free(s); } +#endif c->tls = tls; c->is_tls = 1; c->is_tls_hs = 1; diff --git a/src/tls_openssl.c b/src/tls_openssl.c index 7f40137a..cb44cd95 100644 --- a/src/tls_openssl.c +++ b/src/tls_openssl.c @@ -90,11 +90,13 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) { } } if (opts->ciphers != NULL) SSL_set_cipher_list(tls->ssl, opts->ciphers); +#if OPENSSL_VERSION_NUMBER >= 0x10100000L if (opts->srvname.len > 0) { char *s = mg_mprintf("%.*s", (int) opts->srvname.len, opts->srvname.ptr); SSL_set1_host(tls->ssl, s); free(s); } +#endif c->tls = tls; c->is_tls = 1; c->is_tls_hs = 1; diff --git a/test/unit_test.c b/test/unit_test.c index 6c586a8d..488059ca 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -331,11 +331,11 @@ static void test_sntp(void) { ASSERT(mg_sntp_parse(bad, sizeof(bad)) < 0); ASSERT(mg_sntp_parse(NULL, 0) == -1); - test_sntp_server("udp://time.windows.com:123"); + // test_sntp_server("udp://time.windows.com:123"); // NOTE(cpq): temporarily disabled until Github Actions fix their NTP // port blockage issue, https://github.com/actions/runner-images/issues/5615 - // test_sntp_server("udp://time.apple.com:123"); - // test_sntp_server(NULL); + test_sntp_server("udp://time.apple.com:123"); + test_sntp_server(NULL); } struct mqtt_data { @@ -2635,18 +2635,17 @@ int main(void) { test_str(); test_globmatch(); test_get_header_var(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) - test_rewrites(); + if (MG_BIG_ENDIAN || sizeof(void *) != 4) test_rewrites(); test_check_ip_acl(); test_udp(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) { + if (MG_BIG_ENDIAN || sizeof(void *) != 4) { test_pipe(); test_packed(); } test_crc32(); test_multipart(); test_invalid_listen_addr(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) { + if (MG_BIG_ENDIAN || sizeof(void *) != 4) { test_http_chunked(); test_http_upload(); test_http_stream_buffer(); @@ -2661,22 +2660,20 @@ int main(void) { test_base64(); test_http_get_var(); test_tls(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) { + if (MG_BIG_ENDIAN || sizeof(void *) != 4) { test_ws(); test_ws_fragmentation(); test_http_client(); } - if (sizeof(void*) != 4) - test_http_server(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) { + if (sizeof(void *) != 4) test_http_server(); + if (MG_BIG_ENDIAN || sizeof(void *) != 4) { test_http_404(); test_http_no_content_length(); test_http_pipeline(); test_http_range(); } test_sntp(); - if (MG_BIG_ENDIAN || sizeof(void*) != 4) - test_mqtt(); + if (MG_BIG_ENDIAN || sizeof(void *) != 4) test_mqtt(); printf("SUCCESS. Total tests: %d\n", s_num_tests); return EXIT_SUCCESS;