net.openssl: replace SSL_get1_peer_certificate by SSL_get_peer_certificate for OpenBSD (#24556)

OpenBSD uses LibreSSL (OpenSSL fork) by default for libssl/libcrypto.
SSL_get1_peer_certificate is not supported by LibreSSL, replace it by
SSL_get_peer_certificate.
This commit is contained in:
Laurent Cheylus 2025-05-23 15:15:48 +02:00 committed by GitHub
parent ddb15646a7
commit a8aeae2111
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 1 deletions

View File

@ -0,0 +1,5 @@
module openssl
// SSL_get_peer1_certificate not defined in LibreSSL (OpenSSL fork) on OpenBSD,
// use SSL_get_peer_certificate instead.
fn C.SSL_get_peer_certificate(ssl &SSL) &C.X509

View File

@ -223,6 +223,7 @@ fn (mut s SSLConn) complete_connect() ! {
}
if s.config.validate {
mut pcert := &C.X509(unsafe { nil })
for {
mut res := C.SSL_do_handshake(voidptr(s.ssl))
if res == 1 {
@ -239,7 +240,11 @@ fn (mut s SSLConn) complete_connect() ! {
}
return error('Could not validate SSL certificate. (${err_res}),err')
}
pcert := C.SSL_get1_peer_certificate(voidptr(s.ssl))
$if openbsd {
pcert = C.SSL_get_peer_certificate(voidptr(s.ssl))
} $else {
pcert = C.SSL_get1_peer_certificate(voidptr(s.ssl))
}
defer {
if pcert != 0 {
C.X509_free(pcert)