Skip to content

Commit

Permalink
net.mbedtls: define MBEDTLS_THREADING_PTHREAD, in mbedtls_config.h; c…
Browse files Browse the repository at this point in the history
…all C.mbedtls_ssl_conf_read_timeout explicitly in the wrapper, with a shorter timeout value of 317ms (determined experimentally)
  • Loading branch information
spytheman committed Nov 20, 2024
1 parent fbc3fc6 commit 4b015c8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 2 additions & 2 deletions thirdparty/mbedtls/include/mbedtls/mbedtls_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1903,7 +1903,7 @@
*
* Uncomment this to enable pthread mutexes.
*/
//#define MBEDTLS_THREADING_PTHREAD
#define MBEDTLS_THREADING_PTHREAD

/**
* \def MBEDTLS_USE_PSA_CRYPTO
Expand Down Expand Up @@ -3283,7 +3283,7 @@
*
* Enable this layer to allow use of mutexes within mbed TLS
*/
//#define MBEDTLS_THREADING_C
#define MBEDTLS_THREADING_C

/**
* \def MBEDTLS_TIMING_C
Expand Down
4 changes: 4 additions & 0 deletions vlib/net/mbedtls/mbedtls.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -208,3 +208,7 @@ fn C.mbedtls_x509_crt_parse(&C.mbedtls_x509_crt, &u8, usize) int
fn C.mbedtls_x509_crt_parse_file(&C.mbedtls_x509_crt, &char) int

fn C.mbedtls_high_level_strerr(int) &char

fn C.mbedtls_debug_set_threshold(level int)

fn C.mbedtls_ssl_conf_read_timeout(conf &C.mbedtls_ssl_config, timeout u32)
4 changes: 3 additions & 1 deletion vlib/net/mbedtls/ssl_connection.c.v
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ fn init() {
C.mbedtls_ctr_drbg_free(&ctr_drbg)
panic('Failed to seed ssl context: ${ret}')
}
// C.mbedtls_debug_set_threshold(5)
}
}

Expand Down Expand Up @@ -175,6 +176,7 @@ fn (mut l SSLListener) init() ! {
C.mbedtls_net_init(&l.server_fd)
C.mbedtls_ssl_init(&l.ssl)
C.mbedtls_ssl_config_init(&l.conf)
C.mbedtls_ssl_conf_read_timeout(&l.conf, 41_000)
l.certs = &SSLCerts{}
C.mbedtls_x509_crt_init(&l.certs.client_cert)
C.mbedtls_pk_init(&l.certs.client_key)
Expand Down Expand Up @@ -363,13 +365,13 @@ fn (mut s SSLConn) init() ! {
C.mbedtls_net_init(&s.server_fd)
C.mbedtls_ssl_init(&s.ssl)
C.mbedtls_ssl_config_init(&s.conf)

mut ret := 0
ret = C.mbedtls_ssl_config_defaults(&s.conf, C.MBEDTLS_SSL_IS_CLIENT, C.MBEDTLS_SSL_TRANSPORT_STREAM,
C.MBEDTLS_SSL_PRESET_DEFAULT)
if ret != 0 {
return error_with_code('Failed to set SSL configuration', ret)
}
C.mbedtls_ssl_conf_read_timeout(&s.conf, 317)

unsafe {
C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &ctr_drbg)
Expand Down

0 comments on commit 4b015c8

Please sign in to comment.