Skip to content

Commit

Permalink
net.mbedtls: make compile with -prod
Browse files Browse the repository at this point in the history
  • Loading branch information
medvednikov committed May 18, 2023
1 parent 9d9785c commit cc47c78
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Expand Up @@ -4,8 +4,9 @@
in addition to `[skip]`. This allows having custom behavior for different serialization methods.
- ORM: fixed a foreign key bug that could result in an extra insert.
- Generic functions as function parameters are now supported: `fn f[T](x T, i int, f_ Fn[T]) T { `.
- Enum values now can have attributes.
- Enum values now can have attributes.
- json: Enum value string serialization supports `[json:'alias']` to change its string values.
- Functions can now return fixed size arrays.

## V 0.3.4

Expand Down Expand Up @@ -142,12 +143,12 @@ Final steps in making the Option type a first class type:
a T
b U
}
foo := Foo{
a: 2
b: 'x'
}
println(foo)
```
- unsafe: dereferencing nil references is no longer allowed in the following case:
Expand Down
33 changes: 20 additions & 13 deletions vlib/net/mbedtls/ssl_connection.v
Expand Up @@ -12,14 +12,15 @@ fn init() {
$if trace_ssl ? {
eprintln(@METHOD)
}
C.mbedtls_ctr_drbg_init(&mbedtls.ctr_drbg)
C.mbedtls_entropy_init(&mbedtls.entropy)

ret := C.mbedtls_ctr_drbg_seed(&mbedtls.ctr_drbg, C.mbedtls_entropy_func, &mbedtls.entropy,
0, 0)
if ret != 0 {
C.mbedtls_ctr_drbg_free(&mbedtls.ctr_drbg)
panic('Failed to seed ssl context: ${ret}')
unsafe { // Unsafe is needed for taking an address of const
C.mbedtls_ctr_drbg_init(&mbedtls.ctr_drbg)
C.mbedtls_entropy_init(&mbedtls.entropy)
ret := C.mbedtls_ctr_drbg_seed(&mbedtls.ctr_drbg, C.mbedtls_entropy_func, &mbedtls.entropy,
0, 0)
if ret != 0 {
C.mbedtls_ctr_drbg_free(&mbedtls.ctr_drbg)
panic('Failed to seed ssl context: ${ret}')
}
}
}

Expand Down Expand Up @@ -110,7 +111,9 @@ fn (mut s SSLConn) init() ! {
return error_with_code('Failed to set SSL configuration', ret)
}

C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
unsafe {
C.mbedtls_ssl_conf_rng(&s.conf, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
}

if s.config.verify != '' || s.config.cert != '' || s.config.cert_key != '' {
s.certs = &SSLCerts{}
Expand All @@ -127,8 +130,10 @@ fn (mut s SSLConn) init() ! {
ret = C.mbedtls_x509_crt_parse(&s.certs.client_cert, s.config.cert.str, s.config.cert.len)
}
if s.config.cert_key != '' {
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)
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)
}
}
} else {
if s.config.verify != '' {
Expand All @@ -138,8 +143,10 @@ fn (mut s SSLConn) init() ! {
ret = C.mbedtls_x509_crt_parse_file(&s.certs.client_cert, &char(s.config.cert.str))
}
if s.config.cert_key != '' {
ret = C.mbedtls_pk_parse_keyfile(&s.certs.client_key, &char(s.config.cert_key.str),
0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
unsafe {
ret = C.mbedtls_pk_parse_keyfile(&s.certs.client_key, &char(s.config.cert_key.str),
0, C.mbedtls_ctr_drbg_random, &mbedtls.ctr_drbg)
}
}
}
if ret < 0 {
Expand Down

0 comments on commit cc47c78

Please sign in to comment.