feat(inventory): sign external inventory responses for the offline client

Sign the inventory JSON payload using the local signing key and
provide the required signature headers. Register the corresponding
public key in the rebuilt GUI pack so the client can verify the
definitions.

Type checking, pack checks, and local signature verification passed.
In-game acceptance requires a rebuilt offline copy and restarted service.
This commit is contained in:
N0VAN0M4LY committed 2026-11-26 02:13:23 +08:00
1 parent 32e9201a5f
commit 943d395748
4 files changed
+115 -8

No files matched your search

@@ -0,0 +1,32 @@
{
"id": "inventory/local-content-public-key",
"title": "外部库存内容验签公钥替换为本地服务的固定公钥",
"file": "scripts/inventory/inventorycontentsign.nut",
"program_behaviour": {
"stock": "scripts/inventory/inventoryContentSign.nut 启动时把内置的 Gaijin RSA 公钥通过 inventory.addContentPublicKey(key)(aces.exe 0x459b090)注册到原生 charsq 库存客户端;inventoryClient.nut 请求 GetItemDefsClient 时开启 content_sign_check = true,原生层(0x336d590 -> 0x4e6eba0 -> 0x3c38270)用已注册公钥校验响应头 chardContentSign 与 chardContentSignHashAlgo 对原始响应体的签名。",
"patched": "保持客户端 addContentPublicKey 与 requestWithSignCheck 原生验签流程不变,将 inventoryContentSign.nut 中的公钥替换为本地服务固定密钥对(local-inventory-content.key.pem)对应的 RSA-2048 公钥,本地服务对库存 JSON 响应附带 RSA-SHA256 签名。"
},
"derivation": {
"requirement": "功能清单 G「市场」、H「补给箱」「物品回收与合成」「兑换券」。客户端必须通过原生内容签名校验接收本地服务生成的外部物品定义(GetItemDefsClient),使 233 辆交易所载具恢复市场载具状态并显示「在交易所中查找」,同时使外部库存兑换券、补给箱与回收零件定义正常生效。",
"cause": "inventoryContentSign.nut 硬编码了 Gaijin 私钥对应的 RSA 公钥,本地服务没有 Gaijin 的私钥,无法生成能通过原版公钥 EVP_VerifyFinal(0x51e3e80)校验的 chardContentSign 签名;校验失败时 0x40cc070 直接将结果替换为错误 CONTENT_SIGN_VALIDATION_FAILED 并丢弃全部物品定义。",
"lighter_options_ruled_out": [
"仅在本地服务响应头填占位签名:原生层 0x3c38270 调用 OpenSSL EVP_VerifyFinal 做真实 RSA 验签,无对应私钥返回错误码 6,仍触发 CONTENT_SIGN_VALIDATION_FAILED。",
"改 inventoryClient.nut 跳过 requestWithSignCheck 或打 exe 补丁绕过 0x40cc188:直接破坏客户端原有的验签逻辑;按匹配服务器公钥(online/matching-server-public-key,方案 A)同一原则,替换公钥并由本地服务真实签名更能原样保留客户端原生代码路径。"
],
"conclusion": "在 gui.vromfs.bin 的 scripts/inventory/inventorycontentsign.nut 将公钥替换为离线版固定 RSA-2048 公钥,本地服务用配对私钥按 chardContentSign + chardContentSignHashAlgo=SHA256 对原始响应体签名。",
"if_not_applied": "每次 GetItemDefsClient 均报 CONTENT_SIGN_VALIDATION_FAILED,客户端外部物品定义表为空,233 辆交易所载具全部退回礼包车显示且右键无「在交易所中查找」,外部库存中的兑换券、银狮补给箱和回收零件无法显示详情与正常使用。"
},
"features": ["G-市场", "H-补给箱", "H-物品回收与合成", "H-兑换券"],
"evidence": [
"2.61.0.37 gui.vromfs.bin:scripts/inventory/inventorycontentsign.nut(keys、inventory.addContentPublicKey)、scripts/inventory/inventoryclient.nut 第 276-288、468 行(requestWithSignCheck、GetItemDefsClient)。",
"2.61.0.37 aces.exe:0x459b090(addContentPublicKey -> 0x4e6e840 PEM_read_bio_PUBKEY + i2d_PUBKEY -> 0x4e6ea30)、0x336f5d0(提取响应头 chardContentSign 与 chardContentSignHashAlgo)、0x336d9ac..0x336da05 -> 0x4e6eba0 -> 0x3c38270(EVP_get_digestbyname + Base64 解码 + EVP_VerifyFinal)、0x40cc070(0x40cc188..0x40cc2e0 校验结果非 1 时报 CONTENT_SIGN_VALIDATION_FAILED)。"
],
"edit": {
"find": "-----BEGIN PUBLIC KEY-----\r\nMIIBKDANBgkqhkiG9w0BAQEFAAOCARUAMIIBEAKCAQcAy9WagPn8/uLbbPHebobA\r\nftDiwrGpi23Ed0fQsSCZfGYupBkYl3mZD3fgOMgmLSYsTqFHDe0CMTQKpHYGFfT3\r\nEuvTHKwwyo2ckpaLNI/flZysDXRuoWXvwd6FzGBx3l2/I1Yw+cAle/aWB9YZnQtX\r\nfy3j3k/fJfiv7+72Sm95h3Dg715XuBILC4vSYVqvCn+UlQyrJkAZrIahWR9Gzsm6\r\novxSaduvosn83Hx1ZixD+U5wcn1hoTT0niwnrqiPuEUV3wC887JIR4KzMXYpyzvF\r\nnEhlqTKoGN7oGS7vqN4tCH6/l3hAomxfVGT+5UHGugQEauNqccYq44Hfu3t3tY1r\r\nj+eTYc35NQIDAQAB\r\n-----END PUBLIC KEY-----",
"replace": "-----BEGIN PUBLIC KEY-----\r\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5U86nI/1f8us73a5Tn8K\r\nNjcrWyT6oZzz18uC4eH4LM+VaIJlGvzA0UWMMv8/otX+u8M3wBl/uONv39wc382d\r\neKxTPmo0gWb1cwZ8SeqNUvQJl5HxD0zSPlA2LbQFwoA3aI4nSYcaFV7at7XGph/N\r\nHdYbtSCJei0N7hiqWeeIHcSYjZpmBk5KUs/E+OODquII5liol5LiC9AnvFCVHcT4\r\n1mliTgdHt/LKiLbc0AoVCDHdVMBPEPuZAn9MQJpfIPJdexU8Hzn4xBQ9K2NyISYS\r\n7eRwxratNPdNUHixaw6tyuUCDEV2ELAYw5rwoaFsqP7M76SubBRZObZ8DUgsZZaE\r\nlQIDAQAB\r\n-----END PUBLIC KEY-----"
}
}
@@ -0,0 +1,47 @@
/**
* Content signature generation for `inventory-proxy` HTTP responses.
*
* Source: aces.exe 2.61.0.37:
* - `scripts/inventory/inventoryContentSign.nut` calls `inventory.addContentPublicKey(pem)`
* (`0x459b090 -> 0x4e6e840 -> 0x4e6ea30`), storing the SPKI DER public key on the inventory
* `CharServerClient` (`[client + 0x58]`).
* - `CharServerClient::loadOnlineDataCore` (`0x336ec10`) / `saveOnlineDataCore` (`0x3370bd0`)
* captures HTTP response headers `chardContentSign` and `chardContentSignHashAlgo` (`0x336f5d0`),
* and `0x336d590` (`0x336d9ac..0x336da05`) verifies the raw HTTP response body via `0x4e6eba0`
* -> `0x3c38270` (`EVP_get_digestbyname` + single-line Base64 decode + `EVP_VerifyFinal`
* RSASSA-PKCS1-v1_5). When `content_sign_check` is enabled (`GetItemDefsClient`), worker
* `0x40cc070` requires verification code `1`, otherwise returning `CONTENT_SIGN_VALIDATION_FAILED`.
*
* GUI patch `inventory/local-content-public-key` replaces Gaijin's public key in
* `inventoryContentSign.nut` with the public key paired with `local-inventory-content.key.pem`.
*/
import { createPrivateKey, sign, type KeyObject } from 'node:crypto';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import type { ServiceResponse } from '../../server/exchange.ts';
const CONTENT_SIGN_HASH_ALGO = 'SHA256';
const SIGNING_ALGORITHM = 'RSA-SHA256';
let contentKey: KeyObject | undefined;
function localContentKey(): KeyObject {
contentKey ??= createPrivateKey(readFileSync(join(import.meta.dirname, 'local-inventory-content.key.pem')));
return contentKey;
}
/** Build a UTF-8 JSON response signed with `chardContentSign` and `chardContentSignHashAlgo`. */
export function signedInventoryJsonResponse(payload: unknown, summary?: string): ServiceResponse {
const body = Buffer.from(JSON.stringify(payload), 'utf8');
const signature = sign(SIGNING_ALGORITHM, body, localContentKey()).toString('base64');
return {
status: 200,
headers: {
'content-type': 'application/json; charset=utf-8',
chardContentSign: signature,
chardContentSignHashAlgo: CONTENT_SIGN_HASH_ALGO,
},
body,
...(summary ? { logNotes: { summary } } : {}),
};
}
@@ -0,0 +1,28 @@
-----BEGIN PRIVATE KEY-----
MIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDlTzqcj/V/y6zv
drlOfwo2NytbJPqhnPPXy4Lh4fgsz5VogmUa/MDRRYwy/z+i1f67wzfAGX+442/f
3BzfzZ14rFM+ajSBZvVzBnxJ6o1S9AmXkfEPTNI+UDYttAXCgDdojidJhxoVXtq3
tcamH80d1hu1IIl6LQ3uGKpZ54gdxJiNmmYGTkpSz8T444Oq4gjmWKiXkuIL0Ce8
UJUd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ip+bXtSDfZz8MUAlocRNq
FinsM0Qeg3ForoUflAcXxqG6ozNLF896oMkW65ywlXxVdlQQPcZpEuTlmdlkkvQB
MuvcOXMIjk5zgE2mNOUzCu/eOgGNnQAcuGPn4HkCgYEAh6EEP4g/QKTe83vKZKOc
UGV1wN/4WKZdb79ZgXe0gXcH3JM/f69qbs2UPikJ5sFGhne1z7Fi7XdSlbmwjxEB
+aueOSPxyMonM13i+DzoKX5YgiVlB9grjK4nheSj9GxwPPZvrYVVEP2VuENEujQd
Dnv7bv/JlG4rzqQ/qYAZVDw=
-----END PRIVATE KEY-----
@@ -9,7 +9,7 @@ import type { Account, AccountStore } from '../accounts/account-store.ts';
import { userIdFromToken } from '../login/session-credentials.ts';
import type { PlayerProfiles } from '../profile/player-profiles.ts';
import type { Service, ServiceRequest, ServiceResponse } from '../server/exchange.ts';
import { jsonResponse } from '../web-ui/web-helpers.ts';
import { signedInventoryJsonResponse } from './content-sign/content-signature.ts';
import { exchangeInventoryItems, type ExchangeItemDelta } from './inventory-rules.ts';
import { deltaToInventoryJson, parseExchangeItemsRequest, toInventoryJsonList } from './inventory-wire.ts';
import type { InventoryCatalogue } from './itemdef-catalogue.ts';
@@ -47,9 +47,9 @@ export class InventoryService implements Service {
case 'ExchangeItems':
return this.#exchangeItems(request);
case 'CancelDelayedExchange':
return jsonResponse({ response: { item_json: [] } }, 'CancelDelayedExchange -> 0 items');
return signedInventoryJsonResponse({ response: { item_json: [] } }, 'CancelDelayedExchange -> 0 items');
default:
return jsonResponse({ response: {} }, `${action || '(no action)'} -> empty response`);
return signedInventoryJsonResponse({ response: {} }, `${action || '(no action)'} -> empty response`);
}
}
@@ -57,7 +57,7 @@ export class InventoryService implements Service {
const account = this.#resolveAccount(request);
if (!account) return errorResponse('UNAUTHORIZED', 'GetInventory: unknown account');
const items = toInventoryJsonList(this.#profiles.profileOf(account.userId), account.userId);
return jsonResponse({ response: { item_json: items } }, `GetInventory -> ${items.length} stack(s)`);
return signedInventoryJsonResponse({ response: { item_json: items } }, `GetInventory -> ${items.length} stack(s)`);
}
#getItemDefs(request: ServiceRequest): ServiceResponse {
@@ -65,13 +65,13 @@ export class InventoryService implements Service {
const language = headerOf(request, 'language') ?? 'english';
const ids = rawIds.split(',').map((part) => Number(part.trim())).filter((n) => Number.isSafeInteger(n) && n > 0);
const defs = this.#catalogue.itemDefs(ids, language);
return jsonResponse({ response: { itemdef_json: defs } }, `GetItemDefsClient (${defs.length} defs, lang=${language})`);
return signedInventoryJsonResponse({ response: { itemdef_json: defs } }, `GetItemDefsClient (${defs.length} defs, lang=${language})`);
}
#getItemPrices(request: ServiceRequest): ServiceResponse {
const currency = headerOf(request, 'currency') === 'WTE' ? 'WTE' : 'WTS';
const itemPrices = this.#catalogue.pricesForCurrency(currency);
return jsonResponse({ response: { itemPrices } }, `GetItemPrices (${currency}) -> ${itemPrices.length} item(s)`);
return signedInventoryJsonResponse({ response: { itemPrices } }, `GetItemPrices (${currency}) -> ${itemPrices.length} item(s)`);
}
#getItemDefChances(request: ServiceRequest): ServiceResponse {
@@ -79,7 +79,7 @@ export class InventoryService implements Service {
const generatorId = Number(rawId.trim());
const chances = Number.isSafeInteger(generatorId) ? this.#catalogue.chancesForGenerator(generatorId) : undefined;
const response: Record<string, unknown> = chances ? { [String(generatorId)]: chances } : {};
return jsonResponse({ response }, `GetItemDefChances (${generatorId}) -> ${chances?.length ?? 0} drop(s)`);
return signedInventoryJsonResponse({ response }, `GetItemDefChances (${generatorId}) -> ${chances?.length ?? 0} drop(s)`);
}
#exchangeItems(request: ServiceRequest): ServiceResponse {
@@ -103,7 +103,7 @@ export class InventoryService implements Service {
if (!delta) return errorResponse(errorCode, `ExchangeItems (${parsed.outputItemDefId}) -> ${errorCode}`);
const jsonDelta = deltaToInventoryJson(delta, account.userId);
return jsonResponse({ response: { item_json: jsonDelta } }, `ExchangeItems (${parsed.outputItemDefId} x${parsed.quantity}) -> ${jsonDelta.length} delta item(s)`);
return signedInventoryJsonResponse({ response: { item_json: jsonDelta } }, `ExchangeItems (${parsed.outputItemDefId} x${parsed.quantity}) -> ${jsonDelta.length} delta item(s)`);
}
#resolveAccount(request: ServiceRequest): Account | undefined {