Skip to content
This repository was archived by the owner on Apr 30, 2025. It is now read-only.

Commit e5804d4

Browse files
authored
Don't loading system certs from Keychain on iOS (yhirose#1546)
1 parent 3956a2b commit e5804d4

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

httplib.h

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -239,10 +239,13 @@ using socket_t = int;
239239
#pragma comment(lib, "crypt32.lib")
240240
#pragma comment(lib, "cryptui.lib")
241241
#endif
242-
#elif defined(__APPLE__) // _WIN32
242+
#elif defined(__APPLE__)
243+
#include <TargetConditionals.h>
244+
#if TARGET_OS_OSX
243245
#include <CoreFoundation/CoreFoundation.h>
244246
#include <Security/Security.h>
245-
#endif // __APPLE__
247+
#endif // TARGET_OS_OSX
248+
#endif // _WIN32
246249

247250
#include <openssl/err.h>
248251
#include <openssl/evp.h>
@@ -4511,6 +4514,7 @@ inline bool load_system_certs_on_windows(X509_STORE *store) {
45114514
return result;
45124515
}
45134516
#elif defined(__APPLE__)
4517+
#if TARGET_OS_OSX
45144518
template <typename T>
45154519
using CFObjectPtr =
45164520
std::unique_ptr<typename std::remove_pointer<T>::type, void (*)(CFTypeRef)>;
@@ -4585,7 +4589,7 @@ inline bool add_certs_to_x509_store(CFArrayRef certs, X509_STORE *store) {
45854589
return result;
45864590
}
45874591

4588-
inline bool load_system_certs_on_apple(X509_STORE *store) {
4592+
inline bool load_system_certs_on_macos(X509_STORE *store) {
45894593
auto result = false;
45904594
CFObjectPtr<CFArrayRef> certs(nullptr, cf_object_ptr_deleter);
45914595
if (retrieve_certs_from_keychain(certs) && certs) {
@@ -4598,8 +4602,9 @@ inline bool load_system_certs_on_apple(X509_STORE *store) {
45984602

45994603
return result;
46004604
}
4601-
#endif
4602-
#endif
4605+
#endif // TARGET_OS_OSX
4606+
#endif // _WIN32
4607+
#endif // CPPHTTPLIB_OPENSSL_SUPPORT
46034608

46044609
#ifdef _WIN32
46054610
class WSInit {
@@ -8060,8 +8065,10 @@ inline bool SSLClient::load_certs() {
80608065
loaded =
80618066
detail::load_system_certs_on_windows(SSL_CTX_get_cert_store(ctx_));
80628067
#elif defined(__APPLE__)
8063-
loaded = detail::load_system_certs_on_apple(SSL_CTX_get_cert_store(ctx_));
8064-
#endif
8068+
#if TARGET_OS_OSX
8069+
loaded = detail::load_system_certs_on_macos(SSL_CTX_get_cert_store(ctx_));
8070+
#endif // TARGET_OS_OSX
8071+
#endif // _WIN32
80658072
if (!loaded) { SSL_CTX_set_default_verify_paths(ctx_); }
80668073
}
80678074
});

0 commit comments

Comments
 (0)