4e9f147e55
Adds pawlethwd, a native C++ system_ext daemon (coredomain) that detects peripherals, checks the hardware update catalog (ota.php?mode=hardware), verifies payloads, and flashes firmware via authorized handler plugins. - daemon/: manifest parse, libcurl HTTP + sha256, sysfs USB detection, catalog client, dlopen handler registry (fixed path + ABI + allowlist), state persistence, orchestration engine, AIDL service, main. - aidl/: IPawletHardwareUpdate (getComponents/getPendingUpdates/checkNow/...). - include/pawlet/hwh_abi.h: stable C plugin ABI. - handlers/usbdfu/: libpawlethwh_usbdfu.so, DFU 1.1 download over libusb. - sepolicy/: pawlethwd domain, pawlet_hw_data_file, service type. - schemas/, etc/supported_hardware.default.json, README design doc. - hwupdate.mk wires packages + ro.pawlet.hardware.manifest + sepolicy dir; inherited from config/common.mk. Trust: a server-named installer handler is honored only if allowlisted in the immutable supported_hardware.json, maps to a fixed dm-verity-protected .so path, is ABI/id-checked, and every payload is sha256-verified before a handler runs.
61 lines
1.4 KiB
C++
61 lines
1.4 KiB
C++
/*
|
|
* Copyright (C) 2026 oxmc / PawletOS
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
#include "util.h"
|
|
|
|
#include <openssl/sha.h>
|
|
|
|
#include <array>
|
|
#include <cctype>
|
|
#include <cstdio>
|
|
|
|
#include <android-base/properties.h>
|
|
|
|
namespace pawlet::hwupdate::util {
|
|
|
|
std::string Sha256File(const std::string& path) {
|
|
FILE* f = fopen(path.c_str(), "rb");
|
|
if (!f) return {};
|
|
|
|
SHA256_CTX ctx;
|
|
SHA256_Init(&ctx);
|
|
std::array<unsigned char, 65536> buf;
|
|
size_t n;
|
|
while ((n = fread(buf.data(), 1, buf.size(), f)) > 0) {
|
|
SHA256_Update(&ctx, buf.data(), n);
|
|
}
|
|
bool ok = feof(f) != 0;
|
|
fclose(f);
|
|
if (!ok) return {};
|
|
|
|
unsigned char digest[SHA256_DIGEST_LENGTH];
|
|
SHA256_Final(digest, &ctx);
|
|
|
|
static const char* hex = "0123456789abcdef";
|
|
std::string out;
|
|
out.reserve(SHA256_DIGEST_LENGTH * 2);
|
|
for (unsigned char c : digest) {
|
|
out.push_back(hex[c >> 4]);
|
|
out.push_back(hex[c & 0xf]);
|
|
}
|
|
return out;
|
|
}
|
|
|
|
bool IEquals(const std::string& a, const std::string& b) {
|
|
if (a.size() != b.size()) return false;
|
|
for (size_t i = 0; i < a.size(); ++i) {
|
|
if (std::tolower(static_cast<unsigned char>(a[i])) !=
|
|
std::tolower(static_cast<unsigned char>(b[i]))) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
|
|
std::string Prop(const std::string& key, const std::string& def) {
|
|
return android::base::GetProperty(key, def);
|
|
}
|
|
|
|
} // namespace pawlet::hwupdate::util
|