--- a/src/openssl.c
+++ b/src/openssl.c
@@ -1044,7 +1044,11 @@ ssl_check_certificate (int fd, const cha
   if (opt.check_cert == CHECK_CERT_QUIET && pinsuccess)
     return success;
 
+#if OPENSSL_API_LEVEL >= 30000
+  cert = SSL_get1_peer_certificate (conn);
+#else
   cert = SSL_get_peer_certificate (conn);
+#endif
   if (!cert)
     {
       logprintf (LOG_NOTQUIET, _("%s: No certificate presented by %s.\n"),
