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

Commit 9694ec8

Browse files
authored
feat: add ssl cert configuration (#1776)
1 parent e4c6a6f commit 9694ec8

File tree

4 files changed

+31
-3
lines changed

4 files changed

+31
-3
lines changed

engine/main.cc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,24 @@ void RunServer(std::optional<int> port, bool ignore_cout) {
219219
resp->addHeader("Access-Control-Allow-Methods", "*");
220220
});
221221

222+
// ssl
223+
auto ssl_cert_path = config.sslCertPath;
224+
auto ssl_key_path = config.sslKeyPath;
225+
226+
if (!ssl_cert_path.empty() && !ssl_key_path.empty()) {
227+
CTL_INF("SSL cert path: " << ssl_cert_path);
228+
CTL_INF("SSL key path: " << ssl_key_path);
229+
230+
if (!std::filesystem::exists(ssl_cert_path) ||
231+
!std::filesystem::exists(ssl_key_path)) {
232+
CTL_ERR("SSL cert or key file not exist at specified path! Ignore..");
233+
return;
234+
}
235+
236+
drogon::app().setSSLFiles(ssl_cert_path, ssl_key_path);
237+
drogon::app().addListener(config.apiServerHost, 443, true);
238+
}
239+
222240
drogon::app().run();
223241
if (hw_service->ShouldRestart()) {
224242
CTL_INF("Restart to update hardware configuration");

engine/utils/config_yaml_utils.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ cpp::result<void, std::string> CortexConfigMgr::DumpYamlConfig(
4747
node["noProxy"] = config.noProxy;
4848
node["verifyPeerSsl"] = config.verifyPeerSsl;
4949
node["verifyHostSsl"] = config.verifyHostSsl;
50+
node["sslCertPath"] = config.sslCertPath;
51+
node["sslKeyPath"] = config.sslKeyPath;
5052

5153
out_file << node;
5254
out_file.close();
@@ -81,7 +83,7 @@ CortexConfig CortexConfigMgr::FromYaml(const std::string& path,
8183
!node["proxyUsername"] || !node["proxyPassword"] ||
8284
!node["verifyPeerSsl"] || !node["verifyHostSsl"] ||
8385
!node["verifyProxySsl"] || !node["verifyProxyHostSsl"] ||
84-
!node["noProxy"]);
86+
!node["sslCertPath"] || !node["sslKeyPath"] || !node["noProxy"]);
8587

8688
CortexConfig config = {
8789
.logFolderPath = node["logFolderPath"]
@@ -164,6 +166,11 @@ CortexConfig CortexConfigMgr::FromYaml(const std::string& path,
164166
.verifyHostSsl = node["verifyHostSsl"]
165167
? node["verifyHostSsl"].as<bool>()
166168
: default_cfg.verifyHostSsl,
169+
.sslCertPath = node["sslCertPath"]
170+
? node["sslCertPath"].as<std::string>()
171+
: default_cfg.sslCertPath,
172+
.sslKeyPath = node["sslKeyPath"] ? node["sslKeyPath"].as<std::string>()
173+
: default_cfg.sslKeyPath,
167174
};
168175
if (should_update_config) {
169176
l.unlock();
@@ -178,5 +185,4 @@ CortexConfig CortexConfigMgr::FromYaml(const std::string& path,
178185
throw;
179186
}
180187
}
181-
182188
} // namespace config_yaml_utils

engine/utils/config_yaml_utils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ struct CortexConfig {
5555

5656
bool verifyPeerSsl;
5757
bool verifyHostSsl;
58+
std::string sslCertPath;
59+
std::string sslKeyPath;
5860
};
5961

6062
class CortexConfigMgr {

engine/utils/file_manager_utils.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,8 @@ config_yaml_utils::CortexConfig GetDefaultConfig() {
185185
.noProxy = config_yaml_utils::kDefaultNoProxy,
186186
.verifyPeerSsl = true,
187187
.verifyHostSsl = true,
188+
.sslCertPath = "",
189+
.sslKeyPath = "",
188190
};
189191
}
190192

@@ -369,4 +371,4 @@ std::filesystem::path ToAbsoluteCortexDataPath(
369371
const std::filesystem::path& path) {
370372
return GetAbsolutePath(GetCortexDataPath(), path);
371373
}
372-
} // namespace file_manager_utils
374+
} // namespace file_manager_utils

0 commit comments

Comments
 (0)