1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

net.mbedtls: fix an error with in_memory_verification (fix #19051) (#19052)

This commit is contained in:
Lucas V. Araujo
2023-08-03 11:32:33 -11:00
committed by GitHub
parent 5bb02b3dd7
commit ffdd5bb955
2 changed files with 67 additions and 8 deletions

View File

@@ -115,15 +115,17 @@ fn (mut l SSLListener) init() ! {
if l.config.in_memory_verification {
if l.config.verify != '' {
ret = C.mbedtls_x509_crt_parse(&l.certs.cacert, l.config.verify.str, l.config.verify.len)
ret = C.mbedtls_x509_crt_parse(&l.certs.cacert, l.config.verify.str,
l.config.verify.len + 1)
}
if l.config.cert != '' {
ret = C.mbedtls_x509_crt_parse(&l.certs.client_cert, l.config.cert.str, l.config.cert.len)
ret = C.mbedtls_x509_crt_parse(&l.certs.client_cert, l.config.cert.str,
l.config.cert.len + 1)
}
if l.config.cert_key != '' {
unsafe {
ret = C.mbedtls_pk_parse_key(&l.certs.client_key, l.config.cert_key.str,
l.config.cert_key.len, 0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
l.config.cert_key.len + 1, 0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
}
}
} else {
@@ -176,10 +178,9 @@ fn (mut l SSLListener) init() ! {
// accepts a new connection and returns a SSLConn of the connected client
pub fn (mut l SSLListener) accept() !&SSLConn {
mut conn := &SSLConn{
conf: l.conf
config: l.config
opened: true
owns_socket: true
owns_socket: false
}
// TODO: save the client's IP address somewhere (maybe add a field to SSLConn ?)
@@ -290,15 +291,17 @@ fn (mut s SSLConn) init() ! {
if s.config.in_memory_verification {
if s.config.verify != '' {
ret = C.mbedtls_x509_crt_parse(&s.certs.cacert, s.config.verify.str, s.config.verify.len)
ret = C.mbedtls_x509_crt_parse(&s.certs.cacert, s.config.verify.str,
s.config.verify.len + 1)
}
if s.config.cert != '' {
ret = C.mbedtls_x509_crt_parse(&s.certs.client_cert, s.config.cert.str, s.config.cert.len)
ret = C.mbedtls_x509_crt_parse(&s.certs.client_cert, s.config.cert.str,
s.config.cert.len + 1)
}
if s.config.cert_key != '' {
unsafe {
ret = C.mbedtls_pk_parse_key(&s.certs.client_key, s.config.cert_key.str,
s.config.cert_key.len, 0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
s.config.cert_key.len + 1, 0, 0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
}
}
} else {