883 files, from working commit b1a079a. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
243 lines
9.3 KiB
C++
243 lines
9.3 KiB
C++
#include "windows_backend_ipc.hpp"
|
|
#include <array>
|
|
#include <cstring>
|
|
#include <iostream>
|
|
using namespace gateway;
|
|
using namespace gateway::backend_ipc;
|
|
namespace {
|
|
void require(bool okay, const char *message) {
|
|
if (!okay)
|
|
throw Error(message);
|
|
}
|
|
template <class F> void refused(F action) {
|
|
bool failed = false;
|
|
try {
|
|
action();
|
|
} catch (const Error &) {
|
|
failed = true;
|
|
}
|
|
require(failed, "malformed IPC accepted");
|
|
}
|
|
bool zero(std::span<const uint8_t> value) {
|
|
return std::all_of(value.begin(), value.end(),
|
|
[](uint8_t b) { return b == 0; });
|
|
}
|
|
gw_wire_call base(uint32_t operation) {
|
|
gw_wire_call c{};
|
|
c.abi = GW_WINE_WIRE_ABI;
|
|
c.size = sizeof(c);
|
|
c.operation = operation;
|
|
c.login = 17;
|
|
c.transport = 19;
|
|
c.index = 3;
|
|
c.build = 70334;
|
|
c.opcode = 0x440025;
|
|
c.capacity = 16;
|
|
c.realm_id = 23;
|
|
c.virtual_address = 29;
|
|
c.super_district = 31;
|
|
c.reserved = 37;
|
|
return c;
|
|
}
|
|
void operations() {
|
|
static_assert(GW_WIRE_PRIVATE_GAMEPLAY_CAPTURE == 42);
|
|
for (uint32_t op = 0; op <= 42; ++op) {
|
|
auto c = base(op);
|
|
std::array<uint8_t, 16> original_output{};
|
|
c.output = original_output.data();
|
|
std::array<uint8_t, 4> input{1, 2, 3, 4};
|
|
char username[] = "FIXTURE", password_path[] = "fixture.password",
|
|
version[] = "fixture.version", addon[] = "fixture.addon",
|
|
address[] = "127.0.0.1";
|
|
if (auth(op))
|
|
c.auth = {GW_NATIVE_ABI, 3724, username,
|
|
op == GW_WIRE_AUTHENTICATE ? password_path : nullptr, version};
|
|
if (path(op))
|
|
c.addon_path = addon;
|
|
gw_native_auth_memory_ipv4_config cfg{GW_NATIVE_IPV4_ABI,
|
|
sizeof(cfg),
|
|
3724,
|
|
0,
|
|
address,
|
|
username,
|
|
input.data(),
|
|
uint32_t(input.size()),
|
|
version};
|
|
if (op == GW_WIRE_AUTHENTICATE_MEMORY_IPV4) {
|
|
c.auth = {};
|
|
c.input = reinterpret_cast<const uint8_t *>(&cfg);
|
|
c.input_bytes = sizeof(cfg);
|
|
} else if (op != GW_WIRE_AUTHENTICATE) {
|
|
c.input = input.data();
|
|
c.input_bytes = uint32_t(input.size());
|
|
}
|
|
auto request = encode_request(c, {41, op + 1});
|
|
WipeBytes request_clean{request};
|
|
auto owned = decode_request(request, {41, op + 1});
|
|
auto &decoded = owned->call;
|
|
require(decoded.operation == op && decoded.login == 17 &&
|
|
decoded.transport == 19 && decoded.index == 3 &&
|
|
decoded.build == 70334 && decoded.opcode == 0x440025 &&
|
|
decoded.capacity == 16 && decoded.realm_id == 23 &&
|
|
decoded.virtual_address == 29 && decoded.super_district == 31 &&
|
|
decoded.reserved == 37,
|
|
"input scalar mismatch");
|
|
input.fill(9);
|
|
username[0] = 'X';
|
|
password_path[0] = 'X';
|
|
version[0] = 'X';
|
|
addon[0] = 'X';
|
|
address[0] = 'X';
|
|
if (op == GW_WIRE_AUTHENTICATE_MEMORY_IPV4) {
|
|
const auto *actual =
|
|
reinterpret_cast<const gw_native_auth_memory_ipv4_config *>(
|
|
decoded.input);
|
|
require(actual != &cfg && actual->username != username &&
|
|
actual->password != input.data() &&
|
|
std::strcmp(actual->username, "FIXTURE") == 0 &&
|
|
std::strcmp(actual->auth_ipv4, "127.0.0.1") == 0 &&
|
|
std::strcmp(actual->version_hash_path, "fixture.version") ==
|
|
0 &&
|
|
actual->password[0] == 1,
|
|
"IPv4 nested deepcopy");
|
|
} else if (auth(op)) {
|
|
require(decoded.auth.username != username &&
|
|
std::strcmp(decoded.auth.username, "FIXTURE") == 0 &&
|
|
std::strcmp(decoded.auth.version_hash_path,
|
|
"fixture.version") == 0,
|
|
"auth deepcopy");
|
|
if (op == GW_WIRE_AUTHENTICATE)
|
|
require(std::strcmp(decoded.auth.password_path, "fixture.password") ==
|
|
0,
|
|
"file auth deepcopy");
|
|
}
|
|
if (path(op))
|
|
require(decoded.addon_path != addon &&
|
|
std::strcmp(decoded.addon_path, "fixture.addon") == 0,
|
|
"transport path deepcopy");
|
|
if (op != GW_WIRE_AUTHENTICATE && op != GW_WIRE_AUTHENTICATE_MEMORY_IPV4)
|
|
require(decoded.input != input.data() && decoded.input[0] == 1,
|
|
"input deepcopy");
|
|
// Backend output is owned by the worker. The caller's destination/pointers
|
|
// stay owned by the caller; response scalars include creation rejection.
|
|
decoded.result = 0;
|
|
decoded.required = 3;
|
|
decoded.consumed = 5;
|
|
decoded.value = 7;
|
|
decoded.reserved = 11;
|
|
decoded.output[0] = 20;
|
|
decoded.output[1] = 21;
|
|
decoded.output[2] = 22;
|
|
decoded.packet = {0x1234, 3};
|
|
decoded.character.guid = 43;
|
|
std::strcpy(decoded.character.name, "Fixture");
|
|
decoded.realm.population = 0.5f;
|
|
std::strcpy(decoded.realm.name, "FixtureRealm");
|
|
std::strcpy(decoded.realm.address, "127.0.0.1:1");
|
|
auto response = encode_response(decoded, 0, {41, op + 1});
|
|
WipeBytes response_clean{response};
|
|
std::array<uint8_t, 16> output{};
|
|
auto *original_input = c.input;
|
|
auto *original_user = c.auth.username;
|
|
c.output = output.data();
|
|
require(apply_response(response, c, {41, op + 1}) == 0 && c.required == 3 &&
|
|
c.consumed == 5 && c.value == 7 && c.reserved == 11 &&
|
|
c.packet.opcode == 0x1234 && c.character.guid == 43 &&
|
|
c.realm.population == 0.5f && output[2] == 22 &&
|
|
c.input == original_input && c.auth.username == original_user &&
|
|
c.output == output.data(),
|
|
"response ownership mismatch");
|
|
owned->clear();
|
|
require(zero(owned->input.bytes) && zero(owned->password.bytes) &&
|
|
zero(owned->output) &&
|
|
std::all_of(owned->username.bytes.begin(),
|
|
owned->username.bytes.end(),
|
|
[](char ch) { return ch == 0; }) &&
|
|
std::all_of(owned->ipv4_username.bytes.begin(),
|
|
owned->ipv4_username.bytes.end(),
|
|
[](char ch) { return ch == 0; }) &&
|
|
!decoded.input && !decoded.output && !decoded.auth.username,
|
|
"owned data not wiped");
|
|
}
|
|
}
|
|
void guards() {
|
|
auto c = base(GW_WIRE_PING);
|
|
c.input_bytes = 0;
|
|
std::array<uint8_t, 16> initial_output{};
|
|
c.output = initial_output.data();
|
|
auto request = encode_request(c, {51, 1});
|
|
WipeBytes request_clean{request};
|
|
refused([&] { decode_request(request, {52, 1}); });
|
|
refused([&] { decode_request(request, {51, 2}); });
|
|
refused([&] {
|
|
decode_request(std::span(request).first(request.size() - 1), {51, 1});
|
|
});
|
|
auto header = request;
|
|
WipeBytes header_clean{header};
|
|
header[28] = 1;
|
|
refused([&] { decode_request(header, {51, 1}); });
|
|
c.operation = 43;
|
|
refused([&] { encode_request(c, {51, 1}); });
|
|
c.operation = 0;
|
|
c.capacity = uint32_t(MaxPayload + 1);
|
|
refused([&] { encode_request(c, {51, 1}); });
|
|
c.capacity = 1;
|
|
c.input_bytes = 1;
|
|
c.input = nullptr;
|
|
refused([&] { encode_request(c, {51, 1}); });
|
|
c.input_bytes = 0;
|
|
auto null_call = base(GW_WIRE_PING);
|
|
auto null_frame = encode_request(null_call, {51, 4});
|
|
WipeBytes null_clean{null_frame};
|
|
auto absent = decode_request(null_frame, {51, 4});
|
|
require(!absent->call.output && absent->call.capacity == 16,
|
|
"null output presence lost");
|
|
auto owned = decode_request(request, {51, 1});
|
|
owned->call.result = -3;
|
|
owned->call.required = 32;
|
|
auto response = encode_response(owned->call, 0, {51, 1});
|
|
WipeBytes response_clean{response};
|
|
uint8_t output = 99;
|
|
c.output = &output;
|
|
require(!apply_response(response, c, {51, 1}) && c.result == -3 &&
|
|
c.required == 32 && output == 99,
|
|
"capacity -3 lost or output overwritten");
|
|
owned->call.result = 0;
|
|
owned->call.required = 2;
|
|
owned->call.output[0] = 1;
|
|
owned->call.output[1] = 2;
|
|
auto success = encode_response(owned->call, 0, {51, 1});
|
|
WipeBytes success_clean{success};
|
|
refused([&] { apply_response(success, c, {51, 1}); });
|
|
require(output == 99, "invalid response touched caller buffer");
|
|
auto memory = base(GW_WIRE_AUTHENTICATE_MEMORY_IPV4);
|
|
std::array<uint8_t, 1> password{1};
|
|
gw_native_auth_memory_ipv4_config cfg{
|
|
GW_NATIVE_IPV4_ABI, sizeof(cfg), 0, 0, "127.0.0.1",
|
|
"FIXTURE", password.data(), 1, nullptr};
|
|
memory.input = reinterpret_cast<const uint8_t *>(&cfg);
|
|
memory.input_bytes = sizeof(cfg);
|
|
memory.auth.username = "forbidden-outer";
|
|
auto malformed = encode_request(memory, {51, 3});
|
|
WipeBytes malformed_clean{malformed};
|
|
refused([&] { decode_request(malformed, {51, 3}); });
|
|
char overlong[MaxString];
|
|
std::fill_n(overlong, MaxString, 'x');
|
|
memory.auth = {};
|
|
cfg.username = overlong;
|
|
refused([&] { encode_request(memory, {51, 3}); });
|
|
}
|
|
} // namespace
|
|
int main() {
|
|
try {
|
|
operations();
|
|
guards();
|
|
std::cout << "43-operation pointer-free ownership, nested auth/path "
|
|
"copies, wipe and malformed/capacity guards PASS\n";
|
|
return 0;
|
|
} catch (const std::exception &) {
|
|
std::cerr << "Standalone IPC field/ownership boundary failed\n";
|
|
return 1;
|
|
}
|
|
}
|