2020-08-22 01:50:38 +03:00
|
|
|
module openssl
|
|
|
|
|
|
|
|
// ssl_error returns non error ssl code or error if unrecoverable and we should panic
|
2022-10-16 09:28:57 +03:00
|
|
|
fn ssl_error(ret int, ssl voidptr) !SSLError {
|
2020-08-22 01:50:38 +03:00
|
|
|
res := C.SSL_get_error(ssl, ret)
|
2023-01-15 16:49:31 +03:00
|
|
|
$if trace_ssl ? {
|
|
|
|
eprintln('${@METHOD} ret: ${ret} | ssl: ${ssl:x} | res: ${res}')
|
|
|
|
}
|
2022-10-03 16:32:37 +03:00
|
|
|
match unsafe { SSLError(res) } {
|
2021-06-13 23:53:38 +03:00
|
|
|
.ssl_error_syscall {
|
2022-11-15 16:53:13 +03:00
|
|
|
return error_with_code('unrecoverable syscall (${res})', res)
|
2021-06-13 23:53:38 +03:00
|
|
|
}
|
|
|
|
.ssl_error_ssl {
|
2022-11-15 16:53:13 +03:00
|
|
|
return error_with_code('unrecoverable ssl protocol error (${res})', res)
|
2021-06-13 23:53:38 +03:00
|
|
|
}
|
|
|
|
else {
|
2022-10-03 16:32:37 +03:00
|
|
|
return unsafe { SSLError(res) }
|
2021-06-13 23:53:38 +03:00
|
|
|
}
|
2020-08-22 01:50:38 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-22 16:50:34 +03:00
|
|
|
enum SSLError {
|
2021-06-13 23:53:38 +03:00
|
|
|
ssl_error_none = 0 // SSL_ERROR_NONE
|
|
|
|
ssl_error_ssl = 1 // SSL_ERROR_SSL
|
|
|
|
ssl_error_want_read = 2 // SSL_ERROR_WANT_READ
|
|
|
|
ssl_error_want_write = 3 // SSL_ERROR_WANT_WRITE
|
|
|
|
ssl_error_want_x509_lookup = 4 // SSL_ERROR_WANT_X509_LOOKUP
|
|
|
|
ssl_error_syscall = 5 // SSL_ERROR_SYSCALL
|
|
|
|
ssl_error_zero_return = 6 // SSL_ERROR_ZERO_RETURN
|
|
|
|
ssl_error_want_connect = 7 // SSL_ERROR_WANT_CONNECT
|
|
|
|
ssl_error_want_accept = 8 // SSL_ERROR_WANT_ACCEPT
|
|
|
|
ssl_error_want_async = 9 // SSL_ERROR_WANT_ASYNC
|
|
|
|
ssl_error_want_async_job = 10 // SSL_ERROR_WANT_ASYNC_JOB
|
|
|
|
ssl_error_want_early = 11 // SSL_ERROR_WANT_EARLY
|
2020-08-22 01:50:38 +03:00
|
|
|
}
|