mirror of
https://github.com/yhirose/cpp-httplib.git
synced 2025-05-10 09:43:51 +00:00
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] 1a62a01825
This commit is contained in:
parent
ae63b89cbf
commit
69c84c9597
14
httplib.h
14
httplib.h
@ -269,7 +269,12 @@ using socket_t = int;
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
#if OPENSSL_VERSION_NUMBER < 0x30000000L
|
#if defined(OPENSSL_IS_BORINGSSL)
|
||||||
|
#if OPENSSL_VERSION_NUMBER < 0x1010107f
|
||||||
|
#error Please use OpenSSL or a current version of BoringSSL
|
||||||
|
#endif
|
||||||
|
#define SSL_get1_peer_certificate SSL_get_peer_certificate
|
||||||
|
#elif OPENSSL_VERSION_NUMBER < 0x30000000L
|
||||||
#error Sorry, OpenSSL versions prior to 3.0.0 are not supported
|
#error Sorry, OpenSSL versions prior to 3.0.0 are not supported
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -727,7 +732,7 @@ private:
|
|||||||
fn();
|
fn();
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef CPPHTTPLIB_OPENSSL_SUPPORT
|
#if defined(CPPHTTPLIB_OPENSSL_SUPPORT) && !defined(OPENSSL_IS_BORINGSSL)
|
||||||
OPENSSL_thread_stop();
|
OPENSSL_thread_stop();
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -9121,11 +9126,14 @@ inline bool SSLClient::initialize_ssl(Socket &socket, Error &error) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
[&](SSL *ssl2) {
|
[&](SSL *ssl2) {
|
||||||
|
#if defined(OPENSSL_IS_BORINGSSL)
|
||||||
|
SSL_set_tlsext_host_name(ssl2, host_.c_str());
|
||||||
|
#else
|
||||||
// NOTE: Direct call instead of using the OpenSSL macro to suppress
|
// NOTE: Direct call instead of using the OpenSSL macro to suppress
|
||||||
// -Wold-style-cast warning
|
// -Wold-style-cast warning
|
||||||
// SSL_set_tlsext_host_name(ssl2, host_.c_str());
|
|
||||||
SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name,
|
SSL_ctrl(ssl2, SSL_CTRL_SET_TLSEXT_HOSTNAME, TLSEXT_NAMETYPE_host_name,
|
||||||
static_cast<void *>(const_cast<char *>(host_.c_str())));
|
static_cast<void *>(const_cast<char *>(host_.c_str())));
|
||||||
|
#endif
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user