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:
1 parent
32e9201a5f
commit
943d395748
4 files changed
+115
-8
No files matched your search
@@ -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
|
||||
UJUdxPjWaWJOB0e38sqIttzQChUIMd1UwE8Q+5kCf0xAml8g8l17FTwfOfjEFD0r
|
||||
Y3IhJhLt5HDGtq00901QeLFrDq3K5QIMRXYQsBjDmvChoWyo/szvpK5sFFk5tnwN
|
||||
SCxlloSVAgMBAAECggEAGqus5wHNbYg8fHukEO+wud6P0eGKrxpouBwpBGm6akfY
|
||||
mle0N7/XE2AR7uqGNcPLBX6usM6mbtQxMmnRB+zL2Hm+kt9abQSTHsZN1XEM7+2H
|
||||
YhQs4/ks6Od+bbFnDBj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5sFGhne1z7Fi7XdSlbmwjxEB
|
||||
+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 {
|
||||
|
||||
Reference in new issue
Block a user