mirror of
https://github.com/cesanta/mongoose.git
synced 2026-11-12 16:50:21 +00:00
fix WolfSSL
This commit is contained in:
1 parent
76b4c9a6ff
commit
9dc3d09981
7 files changed
+122
-72
No files matched your search
+23
-11
@@ -4659,7 +4659,7 @@ static bool mg_atone(struct mg_str str, struct mg_addr *addr) {
|
||||
|
||||
static bool mg_aton4(struct mg_str str, struct mg_addr *addr) {
|
||||
uint8_t data[4] = {0, 0, 0, 0};
|
||||
size_t i, num_dots = 0; // TODO(): refactor to mg_span() + mg_str_num()
|
||||
size_t i, num_dots = 0;
|
||||
for (i = 0; i < str.len; i++) {
|
||||
if (str.buf[i] >= '0' && str.buf[i] <= '9') {
|
||||
int octet = data[num_dots] * 10 + (str.buf[i] - '0');
|
||||
@@ -4705,7 +4705,7 @@ static bool mg_aton6(struct mg_str str, struct mg_addr *addr) {
|
||||
if ((str.buf[i] >= '0' && str.buf[i] <= '9') ||
|
||||
(str.buf[i] >= 'a' && str.buf[i] <= 'f') ||
|
||||
(str.buf[i] >= 'A' && str.buf[i] <= 'F')) {
|
||||
unsigned long val; // TODO(): This loops, refactor
|
||||
unsigned long val; // TODO(): This loops on chars, refactor
|
||||
if (i > j + 3) return false;
|
||||
// MG_DEBUG(("%lu %lu [%.*s]", i, j, (int) (i - j + 1), &str.buf[j]));
|
||||
mg_str_to_num(mg_str_n(&str.buf[j], i - j + 1), 16, &val, sizeof(val));
|
||||
@@ -10904,8 +10904,9 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
||||
if (c->is_listening) goto fail;
|
||||
MG_DEBUG(("%lu Setting TLS", c->id));
|
||||
MG_PROF_ADD(c, "mbedtls_init_start");
|
||||
#if defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
psa_crypto_init();
|
||||
#if defined(MBEDTLS_VERSION_NUMBER) && MBEDTLS_VERSION_NUMBER >= 0x03000000 && \
|
||||
defined(MBEDTLS_PSA_CRYPTO_C)
|
||||
psa_crypto_init(); // https://github.com/Mbed-TLS/mbedtls/issues/9072#issuecomment-2084845711
|
||||
#endif
|
||||
mbedtls_ssl_init(&tls->ssl);
|
||||
mbedtls_ssl_config_init(&tls->conf);
|
||||
@@ -11034,7 +11035,8 @@ void mg_tls_ctx_free(struct mg_mgr *mgr) {
|
||||
|
||||
|
||||
|
||||
#if MG_TLS == MG_TLS_OPENSSL
|
||||
#if MG_TLS == MG_TLS_OPENSSL || MG_TLS == MG_TLS_WOLFSSL
|
||||
|
||||
static int tls_err_cb(const char *s, size_t len, void *c) {
|
||||
int n = (int) len - 1;
|
||||
MG_ERROR(("%lu %.*s", ((struct mg_connection *) c)->id, n, s));
|
||||
@@ -11094,13 +11096,12 @@ static X509 *load_cert(struct mg_str s) {
|
||||
return cert;
|
||||
}
|
||||
|
||||
|
||||
static long mg_bio_ctrl(BIO *b, int cmd, long larg, void *pargs) {
|
||||
long ret = 0;
|
||||
if (cmd == BIO_CTRL_PUSH) ret = 1;
|
||||
if (cmd == BIO_CTRL_POP) ret = 1;
|
||||
if (cmd == BIO_CTRL_FLUSH) ret = 1;
|
||||
#ifndef OPENSSL_IS_WOLFSSL
|
||||
#if MG_TLS == MG_TLS_OPENSSL
|
||||
if (cmd == BIO_C_SET_NBIO) ret = 1;
|
||||
#endif
|
||||
// MG_DEBUG(("%d -> %ld", cmd, ret));
|
||||
@@ -11163,6 +11164,13 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
||||
SSL_set_options(tls->ssl, SSL_OP_CIPHER_SERVER_PREFERENCE);
|
||||
#endif
|
||||
|
||||
#if MG_TLS == MG_TLS_WOLFSSL && !defined(OPENSSL_COMPATIBLE_DEFAULTS)
|
||||
if (opts->ca.len == 0 || mg_strcmp(opts->ca, mg_str("*")) == 0) {
|
||||
// Older versions require that either the CA is loaded or SSL_VERIFY_NONE
|
||||
// explicitly set
|
||||
SSL_set_verify(tls->ssl, SSL_VERIFY_NONE, NULL);
|
||||
}
|
||||
#endif
|
||||
if (opts->ca.buf != NULL && opts->ca.buf[0] != '\0') {
|
||||
SSL_set_verify(tls->ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
|
||||
NULL);
|
||||
@@ -11194,21 +11202,25 @@ void mg_tls_init(struct mg_connection *c, const struct mg_tls_opts *opts) {
|
||||
}
|
||||
|
||||
SSL_set_mode(tls->ssl, SSL_MODE_ACCEPT_MOVING_WRITE_BUFFER);
|
||||
#if OPENSSL_VERSION_NUMBER > 0x10002000L && !defined(OPENSSL_IS_WOLFSSL)
|
||||
#if MG_TLS == MG_TLS_OPENSSL && OPENSSL_VERSION_NUMBER > 0x10002000L
|
||||
(void) SSL_set_ecdh_auto(tls->ssl, 1);
|
||||
#endif
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
|
||||
if (opts->name.len > 0) {
|
||||
char *s = mg_mprintf("%.*s", (int) opts->name.len, opts->name.buf);
|
||||
#if MG_TLS != MG_TLS_WOLFSSL || LIBWOLFSSL_VERSION_HEX >= 0x05005002
|
||||
SSL_set1_host(tls->ssl, s);
|
||||
#else
|
||||
X509_VERIFY_PARAM_set1_host(SSL_get0_param(tls->ssl), s, 0);
|
||||
#endif
|
||||
SSL_set_tlsext_host_name(tls->ssl, s);
|
||||
free(s);
|
||||
}
|
||||
#endif
|
||||
#ifndef OPENSSL_IS_WOLFSSL
|
||||
tls->bm = BIO_meth_new(BIO_get_new_index() | BIO_TYPE_SOURCE_SINK, "bio_mg");
|
||||
#else
|
||||
#if MG_TLS == MG_TLS_WOLFSSL
|
||||
tls->bm = BIO_meth_new(0, "bio_mg");
|
||||
#else
|
||||
tls->bm = BIO_meth_new(BIO_get_new_index() | BIO_TYPE_SOURCE_SINK, "bio_mg");
|
||||
#endif
|
||||
BIO_meth_set_write(tls->bm, mg_bio_write);
|
||||
BIO_meth_set_read(tls->bm, mg_bio_read);
|
||||
|
||||
Reference in new issue
Block a user