Skip to content

Commit 69c84c9

Browse files
authored
BoringSSL compatibility fixes (#1892)
This patch is necessary to build cpp-httplib in Crashpad, itself in Chromium, using BoringSSL. Details at [1]. The fixes include: - Library version check: tolerate BoringSSL as an alternative to OpenSSL 3. - Don’t call `OPENSSL_thread_stop`, which is not in BoringSSL. - Use `SSL_get_peer_certificate` (deprecated in OpenSSL 3), the old name for `SSL_get1_peer_certificate`, because the new name is not in BoringSSL. - Call `SSL_set_tlsext_host_name` directly instead of making an `SSL_ctrl` call that BoringSSL does not support. The feared -Wold-style-cast warning that occurs when buidling with OpenSSL is not triggered in BoringSSL. [1] https://chromium.googlesource.com/crashpad/crashpad/+/1a62a0182557c89494676c06611f1ca731bcb2db
1 parent ae63b89 commit 69c84c9

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

httplib.h

+11-3
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,12 @@ using socket_t = int;
269269
#include <iostream>
270270
#include <sstream>
271271

272-
#if OPENSSL_VERSION_NUMBER < 0x30000000L
272+
#if defined(OPENSSL_IS_BORINGSSL)
273+
#if OPENSSL_VERSION_NUMBER < 0x1010107f
274+
#error Please use OpenSSL or a current version of BoringSSL
275+
#endif
276+
#define SSL_get1_peer_certificate SSL_get_peer_certificate
277+
#elif OPENSSL_VERSION_NUMBER < 0x30000000L
273278
#error Sorry, OpenSSL versions prior to 3.0.0 are not supported
274279
#endif
275280

@@ -727,7 +732,7 @@ class ThreadPool final : public TaskQueue {
727732
fn();
728733
}
729734

730-
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
735+
#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL)
731736
OPENSSL_thread_stop();
732737
#endif
733738
}
@@ -9121,11 +9126,14 @@ inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {
91219126
return true;
91229127
},
91239128
[&](SSL *ssl2) {
9129+
#if defined(OPENSSL_IS_BORINGSSL)
9130+
SSL_set_tlsext_host_name(ssl2, host_.c_str());
9131+
#else
91249132
// NOTE: Direct call instead of using the OpenSSL macro to suppress
91259133
// -Wold-style-cast warning
9126-
// SSL_set_tlsext_host_name(ssl2, host_.c_str());
91279134
SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name,
91289135
static_cast<void *>(const_cast<char *>(host_.c_str())));
9136+
#endif
91299137
return true;
91309138
});
91319139

0 commit comments

Comments
 (0)