Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
scaprile committed Sep 18, 2024
1 parent 9499669 commit 2822483
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
25 changes: 25 additions & 0 deletions mongoose.c
Original file line number Diff line number Diff line change
Expand Up @@ -3241,6 +3241,7 @@ static void http_cb(struct mg_connection *c, int ev, void *ev_data) {
mg_call(c, MG_EV_HTTP_HDRS, &hm); // Got all HTTP headers
if (c->recv.len != old_len) {
// User manipulated received data. Wash our hands
MG_DEBUG(("%lu detaching HTTP handler", c->id));
c->pfn = NULL;
return;
}
Expand Down Expand Up @@ -12620,11 +12621,35 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
mg_error(c, "SSL_CTX_new");
goto fail;
}
#if MG_TLS == MG_TLS_WOLFSSL && defined(OPENSSL_COMPATIBLE_DEFAULTS)
MG_INFO(("fingers crossed"));
if (opts->cert.buf != NULL && opts->cert.buf[0] != '\0') {
X509 *cert = load_cert(opts->cert);
rc = cert == NULL ? 0 : SSL_use_certificate(tls->ssl, cert);
X509_free(cert);
if (cert == NULL || rc != 1) {
mg_error(c, "pre SSLnew CERT err %d", mg_tls_err(c, tls, rc));
goto fail;
}
}
if (opts->key.buf != NULL && opts->key.buf[0] != '\0') {
EVP_PKEY *key = load_key(opts->key);
rc = key == NULL ? 0 : SSL_use_PrivateKey(tls->ssl, key);
EVP_PKEY_free(key);
if (key == NULL || rc != 1) {
mg_error(c, "pre SSLnew KEY err %d", mg_tls_err(c, tls, rc));
goto fail;
}
}
#endif
#ifdef MG_TLS_SSLKEYLOGFILE
SSL_CTX_set_keylog_callback(tls->ctx, ssl_keylog_cb);
#endif
if ((tls->ssl = SSL_new(tls->ctx)) == NULL) {
unsigned long err;
mg_error(c, "SSL_new");
while ((err = ERR_get_error()) != 0) // "Feature not compiled in"... cool...
MG_ERROR(("%lu %s", c->id, ERR_error_string(err, NULL)));
goto fail;
}
SSL_set_session_id_context(tls->ssl, (const uint8_t *) id,
Expand Down
24 changes: 24 additions & 0 deletions src/tls_openssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,35 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
mg_error(c, "SSL_CTX_new");
goto fail;
}
#if MG_TLS == MG_TLS_WOLFSSL && defined(OPENSSL_COMPATIBLE_DEFAULTS)
MG_INFO(("fingers crossed"));
if (opts->cert.buf != NULL && opts->cert.buf[0] != '\0') {
X509 *cert = load_cert(opts->cert);
rc = cert == NULL ? 0 : SSL_use_certificate(tls->ssl, cert);
X509_free(cert);
if (cert == NULL || rc != 1) {
mg_error(c, "pre SSLnew CERT err %d", mg_tls_err(c, tls, rc));
goto fail;
}
}
if (opts->key.buf != NULL && opts->key.buf[0] != '\0') {
EVP_PKEY *key = load_key(opts->key);
rc = key == NULL ? 0 : SSL_use_PrivateKey(tls->ssl, key);
EVP_PKEY_free(key);
if (key == NULL || rc != 1) {
mg_error(c, "pre SSLnew KEY err %d", mg_tls_err(c, tls, rc));
goto fail;
}
}
#endif
#ifdef MG_TLS_SSLKEYLOGFILE
SSL_CTX_set_keylog_callback(tls->ctx, ssl_keylog_cb);
#endif
if ((tls->ssl = SSL_new(tls->ctx)) == NULL) {
unsigned long err;
mg_error(c, "SSL_new");
while ((err = ERR_get_error()) != 0) // "Feature not compiled in"... cool...
MG_ERROR(("%lu %s", c->id, ERR_error_string(err, NULL)));
goto fail;
}
SSL_set_session_id_context(tls->ssl, (const uint8_t *) id,
Expand Down

0 comments on commit 2822483

Please sign in to comment.