mirror of
https://github.com/arx-research/libhalo.git
synced 2026-01-09 13:18:04 -05:00
Simulator: Add missing sim_instance parameter. (#388)
This commit is contained in:
committed by
GitHub
parent
d24aba3dac
commit
8c5d51794c
@@ -383,6 +383,7 @@ const cfgSimParser = subparsers.add_parser("sim_cfg", {help: "Configure simulati
|
||||
cfgSimParser.add_argument("--url", {required: true});
|
||||
cfgSimParser.add_argument("--secret", {required: true});
|
||||
cfgSimParser.add_argument("--cset-id", {required: true});
|
||||
cfgSimParser.add_argument("--sim-instance", {required: true});
|
||||
|
||||
const simSwapParser = subparsers.add_parser("sim_set_card", {help: "Activate card on simulator."})
|
||||
simSwapParser.add_argument("id");
|
||||
@@ -392,6 +393,7 @@ simResetParser.add_argument("--options", {action: JSONParseAction, help: 'Reset
|
||||
|
||||
const simEnableParser = subparsers.add_parser("sim_enable", {help: "Enable simulation."});
|
||||
simEnableParser.add_argument("--cset-id", {help: "Optional (not changed if not provided)."});
|
||||
simEnableParser.add_argument("--sim-instance", {help: "Optional (not changed if not provided)."});
|
||||
|
||||
subparsers.add_parser("sim_disable", {help: "Disable simulation."});
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ import {
|
||||
import {execHaloCmdPCSC} from "@arx-research/libhalo/api/desktop";
|
||||
import {ConnectSimulatorOptions, HaloCommandObject, Reader} from "@arx-research/libhalo/types";
|
||||
import {Namespace} from "argparse";
|
||||
import {INFC, SimNFC} from "./simulator/nfc.js";
|
||||
import {INFC, SimNFC} from "./simulator_nfc.js";
|
||||
import fs from "fs";
|
||||
import {getSimConfig, getSimConfigPath} from "./util.js";
|
||||
|
||||
@@ -89,7 +89,7 @@ function runHalo(entryMode: string, args: Namespace) {
|
||||
reader.on('card', card => {
|
||||
if (args.output === "color") {
|
||||
if (nfc instanceof SimNFC) {
|
||||
console.warn('[!] Running on simulator (cset_id=' + nfc.getCardSetID() + ')');
|
||||
console.warn('[!] Running on simulator (sim_instance=' + nfc.getSimInstance() + '; cset_id=' + nfc.getCardSetID() + ')');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,8 @@ if (args && args.name === "cli_version") {
|
||||
enabled: true,
|
||||
url: args.url,
|
||||
authSecret: args.secret,
|
||||
csetId: args.cset_id
|
||||
csetId: args.cset_id,
|
||||
simInstance: args.sim_instance
|
||||
};
|
||||
saveSimConfig(simConfig);
|
||||
console.log('Config updated.');
|
||||
@@ -33,6 +34,9 @@ if (args && args.name === "cli_version") {
|
||||
if (args.cset_id) {
|
||||
simConfig.csetId = args.cset_id;
|
||||
}
|
||||
if (args.sim_instance) {
|
||||
simConfig.simInstance = args.sim_instance;
|
||||
}
|
||||
saveSimConfig(simConfig);
|
||||
console.log('Config updated.');
|
||||
} else if (args && args.name === "sim_disable") {
|
||||
|
||||
@@ -49,6 +49,10 @@ export class SimNFC implements INFC {
|
||||
return this._options.csetId;
|
||||
}
|
||||
|
||||
getSimInstance() {
|
||||
return this._options.simInstance;
|
||||
}
|
||||
|
||||
getConsoleURL() {
|
||||
return this._connectedReader.sim.getConsoleURL();
|
||||
}
|
||||
@@ -104,7 +108,7 @@ export class SimReader implements Reader {
|
||||
}
|
||||
|
||||
async initialize(options: ConnectSimulatorOptions) {
|
||||
this.name = "Simulator " + options.csetId
|
||||
this.name = "Simulator " + options.simInstance + " " + options.csetId
|
||||
this.reader.name = this.name;
|
||||
await this.sim.connect(options);
|
||||
}
|
||||
@@ -38,8 +38,8 @@ class HaloSimulator {
|
||||
: (url: string) => new WebSocket(url);
|
||||
}
|
||||
|
||||
protected async signJWT(url: string, authSecret: string, csetId: string, exp: string) {
|
||||
return await new SignJWT({cset_id: csetId})
|
||||
protected async signJWT(url: string, authSecret: string, csetId: string, simInstance: string, exp: string) {
|
||||
return await new SignJWT({cset_id: csetId, sim_instance: simInstance})
|
||||
.setProtectedHeader({alg: 'HS256'})
|
||||
.setIssuedAt()
|
||||
.setAudience(queryString.parseUrl(url).url)
|
||||
@@ -47,9 +47,9 @@ class HaloSimulator {
|
||||
.sign(Buffer.from(authSecret, 'hex'));
|
||||
}
|
||||
|
||||
async makeSignedURL(url: string, authSecret: string, csetId: string, exp: string) {
|
||||
async makeSignedURL(url: string, authSecret: string, csetId: string, simInstance: string, exp: string) {
|
||||
return queryString.stringifyUrl({url: url, query: {
|
||||
jwt: await this.signJWT(url, authSecret, csetId, exp)
|
||||
jwt: await this.signJWT(url, authSecret, csetId, simInstance, exp)
|
||||
}});
|
||||
}
|
||||
|
||||
@@ -57,11 +57,11 @@ class HaloSimulator {
|
||||
if (!this.noDebugPrints) {
|
||||
console.log('[libhalo][simulator] Simulator connecting...');
|
||||
}
|
||||
this.url = await this.makeSignedURL(options.url + "/ws", options.authSecret, options.csetId, "180 seconds");
|
||||
this.url = await this.makeSignedURL(options.url + "/ws", options.authSecret, options.csetId, options.simInstance, "180 seconds");
|
||||
const tmpConsoleUrl = (options.url + "/console")
|
||||
.replace("ws://", "http://")
|
||||
.replace("wss://", "https://");
|
||||
this.consoleUrl = await this.makeSignedURL(tmpConsoleUrl, options.authSecret, options.csetId, "8 hours");
|
||||
this.consoleUrl = await this.makeSignedURL(tmpConsoleUrl, options.authSecret, options.csetId, options.simInstance, "8 hours");
|
||||
|
||||
this.ws = new WebSocketAsPromised(this.url, {
|
||||
createWebSocket: url => this.createWebSocket(url),
|
||||
|
||||
@@ -113,6 +113,7 @@ export interface SimulatorOptions extends BaseCreateWSOptions {
|
||||
export interface ConnectSimulatorOptions {
|
||||
url: string
|
||||
csetId: string
|
||||
simInstance: string
|
||||
authSecret: string
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user