Skip to content

Commit b50acfc

Browse files
committed
BoringSSL compatibility fixes
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 b50acfc

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

httplib.h

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

272-
#if OPENSSL_VERSION_NUMBER < 0x30000000L
272+
#if defined(OPENSSL_IS_BORINGSSL)
273+
#define SSL_get1_peer_certificate SSL_get_peer_certificate
274+
#elif OPENSSL_VERSION_NUMBER < 0x30000000L
273275
#error Sorry, OpenSSL versions prior to 3.0.0 are not supported
274276
#endif
275277

@@ -727,7 +729,7 @@ class ThreadPool final : public TaskQueue {
727729
fn();
728730
}
729731

730-
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
732+
#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL)
731733
OPENSSL_thread_stop();
732734
#endif
733735
}
@@ -9121,11 +9123,14 @@ inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {
91219123
return true;
91229124
},
91239125
[&](SSL *ssl2) {
9126+
#if defined(OPENSSL_IS_BORINGSSL)
9127+
SSL_set_tlsext_host_name(ssl2, host_.c_str());
9128+
#else
91249129
// NOTE: Direct call instead of using the OpenSSL macro to suppress
91259130
// -Wold-style-cast warning
9126-
// SSL_set_tlsext_host_name(ssl2, host_.c_str());
91279131
SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name,
91289132
static_cast<void *>(const_cast<char *>(host_.c_str())));
9133+
#endif
91299134
return true;
91309135
});
91319136

0 commit comments

Comments
 (0)