AI guid changes

This commit is contained in:
quaK 2025-05-03 17:38:01 +03:00
parent 5ba6c25c6b
commit f772604bb2

View File

@ -33,20 +33,13 @@ namespace auth
std::string get_hw_profile_guid() std::string get_hw_profile_guid()
{ {
auto hw_profile_path = (utils::properties::get_appdata_path() / "iw7-guid.dat").generic_string(); HW_PROFILE_INFO info{};
if (utils::io::file_exists(hw_profile_path))
{
utils::io::remove_file(hw_profile_path);
}
HW_PROFILE_INFO info;
if (!GetCurrentHwProfileA(&info)) if (!GetCurrentHwProfileA(&info))
{ {
return {}; return {};
} }
auto hw_profile_info = std::string{ info.szHwProfileGuid, sizeof(info.szHwProfileGuid) }; return std::string{ info.szHwProfileGuid, std::strlen(info.szHwProfileGuid) };
return hw_profile_info;
} }
std::string get_protected_data() std::string get_protected_data()
@ -70,28 +63,29 @@ namespace auth
std::string get_key_entropy() std::string get_key_entropy()
{ {
std::string entropy{}; std::string raw_entropy;
entropy.append(utils::smbios::get_uuid()); raw_entropy.append(utils::smbios::get_uuid());
entropy.append(get_hw_profile_guid()); raw_entropy.append(get_hw_profile_guid());
entropy.append(get_protected_data()); raw_entropy.append(get_protected_data());
entropy.append(get_hdd_serial()); raw_entropy.append(get_hdd_serial());
if (entropy.empty()) if (raw_entropy.empty())
{ {
entropy.resize(32); raw_entropy.resize(32);
utils::cryptography::random::get_data(entropy.data(), entropy.size()); utils::cryptography::random::get_data(raw_entropy.data(), raw_entropy.size());
} }
return entropy; return utils::cryptography::sha256::compute(raw_entropy);
} }
bool load_key(utils::cryptography::ecc::key& key) bool load_key(utils::cryptography::ecc::key& key)
{ {
std::string data{}; std::string data{};
const auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string();
auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string();
if (!utils::io::read_file(key_path, &data)) if (!utils::io::read_file(key_path, &data))
{ {
console::warn("Private key file not found at: %s\n", key_path.data());
return false; return false;
} }
@ -113,10 +107,10 @@ namespace auth
throw std::runtime_error("Failed to generate cryptographic key!"); throw std::runtime_error("Failed to generate cryptographic key!");
} }
auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string(); const auto key_path = (utils::properties::get_appdata_path() / "iw7-private.key").generic_string();
if (!utils::io::write_file(key_path, key.serialize())) if (!utils::io::write_file(key_path, key.serialize()))
{ {
console::error("Failed to write cryptographic key!\n"); console::error("Failed to write cryptographic key to: %s\n", key_path.data());
} }
console::info("Generated cryptographic key: %llX\n", key.get_hash()); console::info("Generated cryptographic key: %llX\n", key.get_hash());
@ -137,12 +131,12 @@ namespace auth
utils::cryptography::ecc::key get_key_internal() utils::cryptography::ecc::key get_key_internal()
{ {
auto key = load_or_generate_key(); const auto key = load_or_generate_key();
const auto key_path = (utils::properties::get_appdata_path() / "iw7-public.key").generic_string();
auto key_path = (utils::properties::get_appdata_path() / "iw7-public.key").generic_string();
if (!utils::io::write_file(key_path, key.get_public_key())) if (!utils::io::write_file(key_path, key.get_public_key()))
{ {
console::error("Failed to write public key!\n"); console::error("Failed to write public key to: %s\n", key_path.data());
} }
return key; return key;
@ -150,7 +144,14 @@ namespace auth
utils::cryptography::ecc::key& get_key() utils::cryptography::ecc::key& get_key()
{ {
static auto key = get_key_internal(); static std::once_flag init_flag;
static utils::cryptography::ecc::key key{};
std::call_once(init_flag, []()
{
key = get_key_internal();
});
return key; return key;
} }
} }
@ -159,7 +160,8 @@ namespace auth
{ {
if (game::environment::is_dedi()) if (game::environment::is_dedi())
{ {
return 0x110000100000000 | (::utils::cryptography::random::get_integer() & ~0x80000000); static uint64_t session_guid = 0x110000100000000 | (::utils::cryptography::random::get_integer() & ~0x80000000);
return session_guid;
} }
return get_key().get_hash(); return get_key().get_hash();