aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorlevlam <levlam@telegram.org>2023-01-04 13:43:15 +0300
committerlevlam <levlam@telegram.org>2023-01-04 13:43:15 +0300
commitc4c104384c4d5483eb413227ec6ef7ec32e491ef (patch)
treec20a345db26e2addd552c561456ba41f85ccd859
parent4a5b2ac7228786381f95c754b3efe5cd4e9bf47f (diff)
Load certificate from default_cert_file.
-rw-r--r--tdnet/td/net/SslCtx.cpp25
1 files changed, 16 insertions, 9 deletions
diff --git a/tdnet/td/net/SslCtx.cpp b/tdnet/td/net/SslCtx.cpp
index e73b425d9..a67f8a67f 100644
--- a/tdnet/td/net/SslCtx.cpp
+++ b/tdnet/td/net/SslCtx.cpp
@@ -105,28 +105,35 @@ X509_STORE *load_system_certificate_store() {
CertCloseStore(system_store, 0);
#else
- string default_cert_dir = X509_get_default_cert_dir();
- if (default_cert_dir.empty()) {
- return nullptr;
- }
X509_STORE *store = X509_STORE_new();
if (store == nullptr) {
return nullptr;
}
+ auto add_file = [&](CSlice path) {
+ if (X509_STORE_load_locations(store, path.c_str(), nullptr) != 1) {
+ LOG(INFO) << path << ": " << create_openssl_error(-20, "Failed to add certificate");
+ } else {
+ file_count++;
+ }
+ };
+
+ string default_cert_dir = X509_get_default_cert_dir();
for (auto cert_dir : full_split(default_cert_dir, ':')) {
walk_path(cert_dir, [&](CSlice path, WalkPath::Type type) {
if (type != WalkPath::Type::NotDir) {
return WalkPath::Action::Continue;
}
- if (X509_STORE_load_locations(store, path.c_str(), nullptr) != 1) {
- LOG(INFO) << path << ": " << create_openssl_error(-20, "Failed to add certificate");
- } else {
- file_count++;
- }
+ add_file(path);
return WalkPath::Action::Continue;
}).ignore();
}
+
+ string default_cert_path = X509_get_default_cert_file();
+ if (!default_cert_path.empty()) {
+ add_file(default_cert_path);
+ }
+
#if OPENSSL_VERSION_NUMBER >= 0x10100000L
auto objects = X509_STORE_get0_objects(store);
cert_count = objects == nullptr ? 0 : sk_X509_OBJECT_num(objects);