This commit is contained in:
cpq committed 2021-01-24 13:57:40 +00:00
1 parent 7d67d578fd
commit 9a19485454
4 files changed
+26 -14

No files matched your search

+8 -4
View File
@@ -167,6 +167,9 @@ int mg_tls_free(struct mg_connection *c) {
#elif MG_ENABLE_OPENSSL ///////////////////////////////////////// OPENSSL
#include <openssl/ssl.h>
#if defined(_MSC_VER) && _MSC_VER < 1700
typedef long ssize_t;
#endif
extern void ERR_clear_error(void); // Defined in openssl/err.h, but
extern void ERR_print_errors_fp(FILE *fp); // declare here for krypton
@@ -223,13 +226,13 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
SSL_set_options(tls->ssl, SSL_OP_CIPHER_SERVER_PREFERENCE);
#endif
SSL_set_verify(tls->ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
0);
if (opts->ca != NULL && opts->ca[0] != '\0') {
if ((rc = SSL_CTX_load_verify_locations(tls->ctx, opts->ca, NULL)) != 1) {
mg_error(c, "parse(%s): err %d", opts->ca, mg_tls_err(tls, rc));
goto fail;
}
SSL_set_verify(tls->ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
0);
}
if (opts->cert != NULL && opts->cert[0] != '\0') {
const char *key = opts->certkey;
@@ -262,7 +265,7 @@ int mg_tls_init(struct mg_connection *c, struct mg_tls_opts *opts) {
mg_tls_handshake(c);
}
c->is_hexdumping = 1;
LOG(LL_INFO, ("SSL SETUP OK, %s", c->is_accepted ? "accepted" : "client"));
LOG(LL_DEBUG, ("%lu SSL %s OK", c->id, c->is_accepted ? "accept" : "client"));
return 1;
fail:
c->is_closing = 1;
@@ -280,8 +283,9 @@ int mg_tls_handshake(struct mg_connection *c) {
c->is_tls_hs = 0;
return 1;
} else {
int code;
ERR_print_errors_fp(stderr);
int code = mg_tls_err(tls, rc);
code = mg_tls_err(tls, rc);
if (code != 0) mg_error(c, "tls hs: rc %d, err %d", rc, code);
return 0;
}