354d022967
commit f44d146e4ac906ff898e8968c6857fd2280f6d20 Author: project-bo4 <127137346+project-bo4@users.noreply.github.com> Date: Thu May 11 13:39:29 2023 -0700 remove lpc package from repository commit 29fb0f63e50de468ab0b9db35f7e8fdadf58afc3 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu May 11 13:06:13 2023 -0700 generic improvements + added identity configuration + objectstore improvements + added battlenet 'US' servers to blocklist + some other minor improvements commit 5d5e31099ebcce5a637b9a02d4936a97fb0802a7 Author: project-bo4 <themanwithantidote@gmail.com> Date: Sat Mar 25 16:32:52 2023 -0700 lpc improvements + fix lpc issue with foreign languages(non-english) not being considered in listing + check lpc files pre-start and warn user if missing any of core items commit 2de1a54b6f4cc5c44dc906871021cfbc85057ca9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Thu Mar 23 12:45:56 2023 -0700 demonware improvements + handle object store uploadUserObject + silence bdUNK125 commit 710dcc3ec6178071d67c27e5bf6705f08cabe7e2 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 13:43:56 2023 -0700 forgot to update names commit 217682dfb07b35f7a09399fb2698924bb7fe8b77 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 11:09:18 2023 -0700 upload lpc and update readme commit 83f812b33b90791a8d13b9468f27da51e0a4f2b9 Author: project-bo4 <themanwithantidote@gmail.com> Date: Mon Mar 20 10:53:43 2023 -0700 demonware emulator + demonware emulator + platform name and id + xxhash and picoproto - remove g_runframe hook -disable discovery(save time) + improvements to utils + add new resources
142 lines
3.5 KiB
C++
142 lines
3.5 KiB
C++
#include <std_include.hpp>
|
|
#include "keys.hpp"
|
|
|
|
#include <utils/cryptography.hpp>
|
|
#include <utils/string.hpp>
|
|
#include <utils/io.hpp>
|
|
|
|
#include "resource.hpp"
|
|
#include <utils/nt.hpp>
|
|
|
|
|
|
namespace demonware
|
|
{
|
|
struct data_t
|
|
{
|
|
char m_session_key[24];
|
|
char m_response[8];
|
|
char m_hmac_key[20];
|
|
char m_enc_key[16];
|
|
char m_dec_key[16];
|
|
} data{};
|
|
|
|
std::string packet_buffer;
|
|
|
|
void calculate_hmacs(const char* dataxx, const unsigned int data_size,
|
|
const char* key, const unsigned int key_size,
|
|
char* dest, const unsigned int dest_size)
|
|
{
|
|
char buffer[512];
|
|
unsigned int pos = 0;
|
|
unsigned int out_offset = 0;
|
|
char count = 1;
|
|
std::string result;
|
|
|
|
// buffer add key
|
|
std::memcpy(&buffer[pos], key, key_size);
|
|
pos += key_size;
|
|
|
|
// buffer add count
|
|
buffer[pos] = count;
|
|
pos++;
|
|
|
|
// calculate hmac
|
|
result = utils::cryptography::hmac_sha1::compute(std::string(buffer, pos), std::string(dataxx, data_size));
|
|
|
|
// save output
|
|
std::memcpy(dest, result.data(), std::min(20u, (dest_size - out_offset)));
|
|
out_offset = 20;
|
|
|
|
// second loop
|
|
while (true)
|
|
{
|
|
// if we filled the output buffer, exit
|
|
if (out_offset >= dest_size)
|
|
break;
|
|
|
|
// buffer add last result
|
|
pos = 0;
|
|
std::memcpy(&buffer[pos], result.data(), 20);
|
|
pos += 20;
|
|
|
|
// buffer add key
|
|
std::memcpy(&buffer[pos], key, key_size);
|
|
pos += key_size;
|
|
|
|
// buffer add count
|
|
count++;
|
|
buffer[pos] = count;
|
|
pos++;
|
|
|
|
// calculate hmac
|
|
result = utils::cryptography::hmac_sha1::compute(std::string(buffer, pos), std::string(dataxx, data_size));
|
|
|
|
// save output
|
|
std::memcpy(dest + out_offset, result.data(), std::min(20u, (dest_size - out_offset)));
|
|
out_offset += 20;
|
|
}
|
|
}
|
|
|
|
void derive_keys_iw8()
|
|
{
|
|
std::string BD_AUTH_TRAFFIC_SIGNING_KEY = utils::nt::load_resource(DW_AUTH_TRAFFIC_SIGNING_KEY);
|
|
|
|
const auto packet_hash = utils::cryptography::sha1::compute(packet_buffer);
|
|
|
|
char out_1[24];
|
|
calculate_hmacs(data.m_session_key, 24, BD_AUTH_TRAFFIC_SIGNING_KEY.data(), 294, out_1, 24);
|
|
|
|
auto data_3 = utils::cryptography::hmac_sha1::compute(std::string(out_1, 24), packet_hash);
|
|
|
|
char out_2[16];
|
|
calculate_hmacs(data_3.data(), 20, "CLIENTCHAL", 10, out_2, 16);
|
|
|
|
char out_3[72];
|
|
calculate_hmacs(data_3.data(), 20, "BDDATA", 6, out_3, 72);
|
|
|
|
|
|
std::memcpy(data.m_response, &out_2[8], 8);
|
|
std::memcpy(data.m_hmac_key, &out_3[20], 20);
|
|
std::memcpy(data.m_dec_key, &out_3[40], 16);
|
|
std::memcpy(data.m_enc_key, &out_3[56], 16);
|
|
|
|
#ifndef NDEBUG
|
|
logger::write(logger::LOG_TYPE_DEBUG, "[DW] Response id: %s", utils::string::dump_hex(std::string(&out_2[8], 8)).data());
|
|
logger::write(logger::LOG_TYPE_DEBUG, "[DW] Hash verify: %s", utils::string::dump_hex(std::string(&out_3[20], 20)).data());
|
|
logger::write(logger::LOG_TYPE_DEBUG, "[DW] AES dec key: %s", utils::string::dump_hex(std::string(&out_3[40], 16)).data());
|
|
logger::write(logger::LOG_TYPE_DEBUG, "[DW] AES enc key: %s", utils::string::dump_hex(std::string(&out_3[56], 16)).data());
|
|
logger::write(logger::LOG_TYPE_DEBUG, "[DW] Bravo 6, going dark.");
|
|
#endif
|
|
}
|
|
|
|
void queue_packet_to_hash(const std::string& packet)
|
|
{
|
|
packet_buffer.append(packet);
|
|
}
|
|
|
|
void set_session_key(const std::string& key)
|
|
{
|
|
std::memcpy(data.m_session_key, key.data(), 24);
|
|
}
|
|
|
|
std::string get_decrypt_key()
|
|
{
|
|
return std::string(data.m_dec_key, 16);
|
|
}
|
|
|
|
std::string get_encrypt_key()
|
|
{
|
|
return std::string(data.m_enc_key, 16);
|
|
}
|
|
|
|
std::string get_hmac_key()
|
|
{
|
|
return std::string(data.m_hmac_key, 20);
|
|
}
|
|
|
|
std::string get_response_id()
|
|
{
|
|
return std::string(data.m_response, 8);
|
|
}
|
|
}
|