-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathca_bundle.cppm
More file actions
49 lines (38 loc) · 1.09 KB
/
ca_bundle.cppm
File metadata and controls
49 lines (38 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module;
#include <cstdio>
export module mcpplibs.tinyhttps:ca_bundle;
import std;
namespace mcpplibs::tinyhttps {
namespace {
auto read_file(const char* path) -> std::string {
std::FILE* f = std::fopen(path, "rb");
if (f == nullptr) {
return {};
}
std::string result;
char buf[4096];
while (auto n = std::fread(buf, 1, sizeof(buf), f)) {
result.append(buf, n);
}
std::fclose(f);
return result;
}
} // anonymous namespace
export auto load_ca_certs() -> std::string {
// Try known system CA paths
static constexpr const char* ca_paths[] = {
"/etc/ssl/certs/ca-certificates.crt", // Debian/Ubuntu
"/etc/pki/tls/certs/ca-bundle.crt", // RHEL/CentOS
"/etc/ssl/cert.pem", // macOS / general
};
for (auto* path : ca_paths) {
auto pem = read_file(path);
if (!pem.empty()) {
return pem;
}
}
// No system certs found — return empty.
// A production build could embed a Mozilla CA root bundle here.
return {};
}
} // namespace mcpplibs::tinyhttps