changes in task handling
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
|
||||
#include "WhipClient.h"
|
||||
#include "ConfigService.h"
|
||||
#include "Security/TlsKeyUtil.h"
|
||||
|
||||
namespace snoop {
|
||||
|
||||
@@ -59,8 +60,8 @@ public:
|
||||
std::filesystem::path crt = "/etc/iot/keys/device.crt.pem";
|
||||
|
||||
// extract client key via keyctl
|
||||
auto tmpKey = ExtractClientKeyTemp();
|
||||
if (!tmpKey) {
|
||||
auto tmpKey = snoop::device_sec::ExtractClientKeyFromKernelKeyring();
|
||||
if (!tmpKey.string().empty()) {
|
||||
spdlog::error("Cannot extract client key for WHIP (keyctl user iot-client-key)");
|
||||
return false;
|
||||
}
|
||||
@@ -69,7 +70,7 @@ public:
|
||||
.whipUrl = whipUrl,
|
||||
.caPath = ca.string(),
|
||||
.crtPath = crt.string(),
|
||||
.keyPath = tmpKey->string(),
|
||||
.keyPath = tmpKey,
|
||||
.sampleRate= sampleRate,
|
||||
.channels = channels
|
||||
};
|
||||
@@ -77,11 +78,11 @@ public:
|
||||
try {
|
||||
m_whip->Start();
|
||||
spdlog::info("WHIP started");
|
||||
m_tmpKeyPath = *tmpKey;
|
||||
m_tmpKeyPath = tmpKey;
|
||||
return true;
|
||||
} catch (const std::exception& e) {
|
||||
spdlog::error("WHIP start failed: {}", e.what());
|
||||
std::error_code ec; std::filesystem::remove(*tmpKey, ec);
|
||||
std::error_code ec; std::filesystem::remove(tmpKey, ec);
|
||||
m_whip.reset();
|
||||
return false;
|
||||
}
|
||||
@@ -100,36 +101,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
static std::optional<std::filesystem::path> ExtractClientKeyTemp() {
|
||||
auto exec = [](const std::string& cmd) {
|
||||
std::array<char, 4096> buf{};
|
||||
std::string out;
|
||||
FILE* pipe = popen((cmd + " 2>&1").c_str(), "r");
|
||||
if (!pipe) return std::string{};
|
||||
while (fgets(buf.data(), (int)buf.size(), pipe) != nullptr) out.append(buf.data());
|
||||
pclose(pipe);
|
||||
return out;
|
||||
};
|
||||
auto trim = [](std::string s){
|
||||
auto b=s.find_first_not_of(" \t\r\n"), e=s.find_last_not_of(" \t\r\n");
|
||||
return (b==std::string::npos) ? std::string{} : s.substr(b, e-b+1);
|
||||
};
|
||||
|
||||
std::string id = trim(exec("keyctl search @s user iot-client-key | tail -n1"));
|
||||
if (id.empty()) return std::nullopt;
|
||||
|
||||
char tmpl[] = "/run/iot-whip-keyXXXXXX";
|
||||
int fd = mkstemp(tmpl);
|
||||
if (fd < 0) return std::nullopt;
|
||||
close(fd);
|
||||
std::filesystem::path p(tmpl);
|
||||
exec("keyctl pipe " + id + " > " + p.string());
|
||||
if (!std::filesystem::exists(p) || std::filesystem::file_size(p) == 0) {
|
||||
std::error_code ec; std::filesystem::remove(p, ec);
|
||||
return std::nullopt;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace snoop
|
||||
|
||||
Reference in New Issue
Block a user