Can now control SSL cert verfication from in-engine

This commit is contained in:
2022-03-18 16:25:20 -04:00
parent 2e7b793110
commit 2e3bef79b3
8 changed files with 392 additions and 204 deletions

View File

@@ -17,16 +17,31 @@
namespace drv {
void split_host_port(std::string_view target, std::string &host, std::string &port) {
size_t lastcolon = target.rfind(':');
if (lastcolon == std::string_view::npos) {
host = ""; port = ""; return;
std::vector<std::string_view> split_view(std::string_view v, char sep) {
std::vector<std::string_view> result;
while (true) {
size_t pos = v.find(sep);
if (pos == std::string_view::npos) break;
result.push_back(v.substr(0, pos));
v = v.substr(pos + 1);
}
host = target.substr(0, lastcolon);
port = target.substr(lastcolon + 1);
if ((host == "") || (port == "")) {
host = ""; port = ""; return;
result.push_back(v);
return result;
}
void split_target(std::string_view target, std::string &cert, std::string &host, std::string &port) {
std::vector<std::string_view> split = split_view(target, ':');
if (split.size() != 3) {
cert.clear(); host.clear(); port.clear();
return;
}
if (split[0].empty() || split[1].empty() || split[2].empty()) {
cert.clear(); host.clear(); port.clear();
return;
}
cert = std::string(split[0]);
host = std::string(split[1]);
port = std::string(split[2]);
}
std::vector<std::string> parse_control_lst(std::string_view ctrl) {
@@ -502,9 +517,10 @@ void ReplayPlayer::drv_invoke_event_update() {
} // namespace drv
LuaDefine(unittests_driverutil, "", "some unit tests") {
// Test split_host_port
std::string host, port;
drv::split_host_port("stanford.edu:80", host, port);
// Test split_target
std::string cert, host, port;
drv::split_target("cert:stanford.edu:80", cert, host, port);
LuaAssertStrEq(L, cert, "cert");
LuaAssertStrEq(L, host, "stanford.edu");
LuaAssertStrEq(L, port, "80");