network: check Console ID conflicts

As Console ID can be sensitive data sometimes, this implementation sent a SHA256 hash of it instead.
This commit is contained in:
zhupengfei 2018-10-31 23:07:03 +08:00
parent 3c589f473f
commit c396e3c6e5
14 changed files with 109 additions and 23 deletions

View file

@ -734,4 +734,21 @@ void InstallInterfaces(Core::System& system) {
std::make_shared<CFG_NOR>()->InstallAsService(service_manager);
}
std::string GetConsoleIdHash(Core::System& system) {
u64_le console_id{};
std::array<u8, sizeof(console_id)> buffer;
if (system.IsPoweredOn()) {
auto cfg = GetModule(system);
ASSERT_MSG(cfg, "CFG Module missing!");
console_id = cfg->GetConsoleUniqueId();
} else {
console_id = std::make_unique<Service::CFG::Module>()->GetConsoleUniqueId();
}
std::memcpy(buffer.data(), &console_id, sizeof(console_id));
std::array<u8, CryptoPP::SHA256::DIGESTSIZE> hash;
CryptoPP::SHA256().CalculateDigest(hash.data(), buffer.data(), sizeof(buffer));
return fmt::format("{:02x}", fmt::join(hash.begin(), hash.end(), ""));
}
} // namespace Service::CFG

View file

@ -415,4 +415,7 @@ std::shared_ptr<Module> GetModule(Core::System& system);
void InstallInterfaces(Core::System& system);
/// Convenience function for getting a SHA256 hash of the Console ID
std::string GetConsoleIdHash(Core::System& system);
} // namespace Service::CFG