From 1052ee0766967fb68a908287cbba815a034863b2 Mon Sep 17 00:00:00 2001 From: cpq Date: Sun, 20 Dec 2020 21:45:58 +0000 Subject: [PATCH] Fix openssl build, and add openssl test --- .github/workflows/test.yml | 6 +++++- Makefile | 6 +++--- mongoose.c | 5 ++++- src/tls.c | 5 ++++- test/unit_test.c | 3 ++- 5 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 2dabeb69..c8deeabf 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,14 +9,18 @@ jobs: run: sudo apt-get install libmbedtls-dev - name: make run: make test test++ + - name: openssl + run: make test SSL=OPENSSL macos: runs-on: macos-latest steps: - uses: actions/checkout@v2 - name: Install packages - run: HOMEBREW_NO_AUTO_UPDATE=1 brew install jq mbedtls + run: HOMEBREW_NO_AUTO_UPDATE=1 brew install jq mbedtls openssl - name: make run: make test++ upload-coverage + - name: openssl + run: make test SSL=OPENSSL windows: runs-on: ubuntu-latest steps: diff --git a/Makefile b/Makefile index aee79c33..03e804f3 100644 --- a/Makefile +++ b/Makefile @@ -22,9 +22,9 @@ CFLAGS += -DMG_ENABLE_MBEDTLS=1 -I$(MBEDTLS)/include -I/usr/include LDFLAGS ?= -L$(MBEDTLS)/lib -lmbedtls -lmbedcrypto -lmbedx509 endif ifeq "$(SSL)" "OPENSSL" -OPENSSLDIR ?= $(shell "$(brew --cellar openssl)/$(brew info openssl --json | jq -j .[0].installed[0].version)") -CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSLDIR)/include -LDFLAGS ?= -L$(OPENSSLDIR)/lib -lssl -lcrypto +OPENSSL_DIR ?= $(shell "$(brew --cellar openssl)/$(brew info openssl --json | jq -j .[0].installed[0].version)") +CFLAGS += -DMG_ENABLE_OPENSSL=1 -I$(OPENSSL_DIR)/include +LDFLAGS ?= -L$(OPENSSL_DIR)/lib -lssl -lcrypto endif all: mg_prefix test test++ ex vc98 vc2017 linux linux++ infer fuzz diff --git a/mongoose.c b/mongoose.c index c752af31..8e093449 100644 --- a/mongoose.c +++ b/mongoose.c @@ -3274,6 +3274,8 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) { mg_tls_handshake(c); } + c->is_hexdumping = 1; + LOG(LL_INFO, ("SSL SETUP OK, %s", c->is_accepted ? "accepted" : "client")); return 1; fail: c->is_closing = 1; @@ -3284,10 +3286,11 @@ fail: int mg_tls_handshake(struct mg_connection *c) { struct mg_tls *tls = (struct mg_tls *) c->tls; int rc; - // if (SSL_get_fd(tls->ssl) == -1) SSL_set_fd(tls->ssl, (int) c->fd); rc = c->is_client ? SSL_connect(tls->ssl) : SSL_accept(tls->ssl); if (rc == 1) { + LOG(LL_DEBUG, ("%p success", c->fd)); + c->is_tls_hs = 0; return 1; } else { ERR_print_errors_fp(stderr); diff --git a/src/tls.c b/src/tls.c index 8c918e4d..11a43cce 100644 --- a/src/tls.c +++ b/src/tls.c @@ -260,6 +260,8 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) { if (c->is_client && c->is_resolving == 0 && c->is_connecting == 0) { mg_tls_handshake(c); } + c->is_hexdumping = 1; + LOG(LL_INFO, ("SSL SETUP OK, %s", c->is_accepted ? "accepted" : "client")); return 1; fail: c->is_closing = 1; @@ -270,10 +272,11 @@ fail: int mg_tls_handshake(struct mg_connection *c) { struct mg_tls *tls = (struct mg_tls *) c->tls; int rc; - // if (SSL_get_fd(tls->ssl) == -1) SSL_set_fd(tls->ssl, (int) c->fd); rc = c->is_client ? SSL_connect(tls->ssl) : SSL_accept(tls->ssl); if (rc == 1) { + LOG(LL_DEBUG, ("%p success", c->fd)); + c->is_tls_hs = 0; return 1; } else { ERR_print_errors_fp(stderr); diff --git a/test/unit_test.c b/test/unit_test.c index bd2c9e06..56a8256f 100644 --- a/test/unit_test.c +++ b/test/unit_test.c @@ -566,7 +566,8 @@ static void test_http_server(void) { static void test_tls(void) { #if MG_ENABLE_MBEDTLS || MG_ENABLE_OPENSSL struct mg_tls_opts opts = {.ca = "./test/data/ss_ca.pem", - .cert = "./test/data/ss_server.pem"}; + .cert = "./test/data/ss_server.pem", + .certkey = "./test/data/ss_server.pem"}; struct mg_mgr mgr; struct mg_connection *c; const char *url = "https://127.0.0.1:12347";