feat: Allow custom CA Certs to be loaded

Fixes #907
This commit is contained in:
WerWolv
2023-02-17 12:01:46 +01:00
parent bf8089dc7e
commit d84dfa2c42

View File

@@ -54,7 +54,25 @@ namespace hex::init {
bool setupEnvironment() {
hex::log::debug("Using romfs: '{}'", romfs::name());
Net::setCACert(std::string(romfs::get("cacert.pem").string()));
// Load the SSL certificate
constexpr static auto CaCertPath = "cacert.pem";
// Look for a custom certificate in the config folder
std::fs::path caCertPath;
for (const auto &folder : fs::getDefaultPaths(fs::ImHexPath::Config)) {
for (const auto &file : std::fs::directory_iterator(folder)) {
if (file.path().filename() == CaCertPath) {
caCertPath = file.path();
break;
}
}
}
// If a custom certificate was found, use it, otherwise use the one from the romfs
if (!caCertPath.empty())
Net::setCACert(fs::File(caCertPath, fs::File::Mode::Read).readString());
else
Net::setCACert(std::string(romfs::get(CaCertPath).string()));
return true;
}