-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathintegrity_checker.cpp
More file actions
45 lines (34 loc) · 973 Bytes
/
Copy pathintegrity_checker.cpp
File metadata and controls
45 lines (34 loc) · 973 Bytes
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
#include "shieldcore/integrity_checker.hpp"
#include "shieldcore/crypto_utils.hpp"
#if defined(_WIN32)
#include <windows.h>
#else
#include <unistd.h>
#endif
#include <filesystem>
namespace shieldcore {
bool computeFileSha256Hex(const std::filesystem::path& path, std::string& outHex, std::string& error) {
ByteBuffer bytes;
if (!readFileBytes(path, bytes, error)) {
return false;
}
outHex = sha256Hex(bytes);
return true;
}
bool verifyHostIntegrity(const std::filesystem::path& executablePath,
const std::string& expectedHex,
std::string& error) {
if (expectedHex.empty()) {
return true;
}
std::string actualHex;
if (!computeFileSha256Hex(executablePath, actualHex, error)) {
return false;
}
if (actualHex != expectedHex) {
error = "host integrity check failed";
return false;
}
return true;
}
} // namespace shieldcore