@nice-code/commander 0.111.0 → 0.112.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/cli.cjs +321 -90
- package/build/cli.cjs.map +1 -1
- package/build/cli.mjs +321 -90
- package/build/cli.mjs.map +1 -1
- package/build/client/assets/index-BK6klick.js +23 -0
- package/build/client/assets/index-BK6klick.js.map +1 -0
- package/build/client/index.html +1 -1
- package/package.json +6 -6
- package/build/client/assets/index-ChNWrJqv.js +0 -23
- package/build/client/assets/index-ChNWrJqv.js.map +0 -1
package/build/cli.cjs
CHANGED
|
@@ -4722,6 +4722,7 @@ var ClientCryptoKeyLink = class {
|
|
|
4722
4722
|
localVerifyKeyPair;
|
|
4723
4723
|
linkedClientKeys = /* @__PURE__ */ new Map();
|
|
4724
4724
|
storage;
|
|
4725
|
+
storageAdapter;
|
|
4725
4726
|
identityMode;
|
|
4726
4727
|
initialized = false;
|
|
4727
4728
|
initializePromise;
|
|
@@ -4729,9 +4730,18 @@ var ClientCryptoKeyLink = class {
|
|
|
4729
4730
|
localVerifyKeyPairPromise;
|
|
4730
4731
|
constructor({ storageAdapter, identityMode } = {}) {
|
|
4731
4732
|
if (storageAdapter != null) this.storage = createTypedStorage({ storageAdapter });
|
|
4733
|
+
this.storageAdapter = storageAdapter;
|
|
4732
4734
|
this.identityMode = identityMode ?? "lazy";
|
|
4733
4735
|
}
|
|
4734
4736
|
/**
|
|
4737
|
+
* A namespace of this identity's own store (same backing storage, `prefix` appended), for state
|
|
4738
|
+
* that belongs to this identity and must go wherever its keys go — e.g. a connector's established
|
|
4739
|
+
* sessions. `undefined` when the link has no storage.
|
|
4740
|
+
*/
|
|
4741
|
+
scopedStorage(prefix) {
|
|
4742
|
+
return this.storageAdapter?.withKeyPrefix(prefix);
|
|
4743
|
+
}
|
|
4744
|
+
/**
|
|
4735
4745
|
* Loads the local key pairs and any linked client public keys from storage (when a storage
|
|
4736
4746
|
* adapter was provided), generating and persisting fresh local key pairs if none exist yet.
|
|
4737
4747
|
*
|
|
@@ -9645,6 +9655,12 @@ function assembleWireConnectionParts(options) {
|
|
|
9645
9655
|
}
|
|
9646
9656
|
//#endregion
|
|
9647
9657
|
//#region ../nice-wire/src/Connect/exchangeEnvelope.ts
|
|
9658
|
+
/**
|
|
9659
|
+
* The `err` id an acceptor sends when it refused the session itself (expired, tampered or
|
|
9660
|
+
* wrong-key ticket, or an act at the wrong level) — before any lane ran, so the connector may
|
|
9661
|
+
* drop the session, handshake again and resend the same act.
|
|
9662
|
+
*/
|
|
9663
|
+
const WIRE_EXCHANGE_SESSION_REFUSED = "session_refused";
|
|
9648
9664
|
function encodeExchange(envelope) {
|
|
9649
9665
|
return JSON.stringify(envelope);
|
|
9650
9666
|
}
|
|
@@ -9673,33 +9689,261 @@ function hasEnvelopeKind(value) {
|
|
|
9673
9689
|
return typeof value === "object" && value != null && "k" in value;
|
|
9674
9690
|
}
|
|
9675
9691
|
//#endregion
|
|
9692
|
+
//#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
|
|
9693
|
+
const SEALED_ENVELOPE_LENGTH = 2;
|
|
9694
|
+
function createExchangeTicketSealer(link, options = {}) {
|
|
9695
|
+
let keyPromise;
|
|
9696
|
+
const getKey = () => {
|
|
9697
|
+
if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
|
|
9698
|
+
keyPromise = void 0;
|
|
9699
|
+
throw err;
|
|
9700
|
+
});
|
|
9701
|
+
return keyPromise;
|
|
9702
|
+
};
|
|
9703
|
+
return {
|
|
9704
|
+
async seal(value, ttlMs) {
|
|
9705
|
+
const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
|
|
9706
|
+
dataToEncrypt: pack({
|
|
9707
|
+
v: value,
|
|
9708
|
+
exp: Date.now() + ttlMs
|
|
9709
|
+
}),
|
|
9710
|
+
aesGcmKey: await getKey()
|
|
9711
|
+
});
|
|
9712
|
+
return bytesToBase64(pack([nonce, ciphertext]));
|
|
9713
|
+
},
|
|
9714
|
+
async open(blob) {
|
|
9715
|
+
try {
|
|
9716
|
+
const envelope = unpack(base64ToBytes(blob));
|
|
9717
|
+
if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
|
|
9718
|
+
const [nonce, ciphertext] = envelope;
|
|
9719
|
+
if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
|
|
9720
|
+
const payload = unpack(await decryptBytesWithAesGcmKey({
|
|
9721
|
+
dataToDecrypt: {
|
|
9722
|
+
nonce,
|
|
9723
|
+
ciphertext
|
|
9724
|
+
},
|
|
9725
|
+
aesGcmKey: await getKey()
|
|
9726
|
+
}));
|
|
9727
|
+
if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
|
|
9728
|
+
return payload.v;
|
|
9729
|
+
} catch {
|
|
9730
|
+
return;
|
|
9731
|
+
}
|
|
9732
|
+
}
|
|
9733
|
+
};
|
|
9734
|
+
}
|
|
9735
|
+
//#endregion
|
|
9736
|
+
//#region ../nice-wire/src/Connect/exchangeSessionShelf.ts
|
|
9737
|
+
/** Lapse a little before the acceptor would, so a request is never sent on its last second. */
|
|
9738
|
+
function expiryFor(receivedAt, ttlMs) {
|
|
9739
|
+
if (ttlMs == null || !(ttlMs > 0)) return void 0;
|
|
9740
|
+
return receivedAt + ttlMs - Math.min(6e4, ttlMs / 10);
|
|
9741
|
+
}
|
|
9742
|
+
function stateFromRecord(link, record) {
|
|
9743
|
+
const crypto = record.km != null ? createActionFrameCrypto({
|
|
9744
|
+
link,
|
|
9745
|
+
keyMaterial: record.km
|
|
9746
|
+
}) : void 0;
|
|
9747
|
+
return {
|
|
9748
|
+
token: record.t,
|
|
9749
|
+
crypto,
|
|
9750
|
+
expiresAt: record.exp,
|
|
9751
|
+
record
|
|
9752
|
+
};
|
|
9753
|
+
}
|
|
9754
|
+
function isLapsed(state) {
|
|
9755
|
+
return state.expiresAt != null && Date.now() >= state.expiresAt;
|
|
9756
|
+
}
|
|
9757
|
+
/**
|
|
9758
|
+
* One session's lifecycle: at most one handshake in flight, shared by every caller; a refused or
|
|
9759
|
+
* lapsed session is replaced once, however many requests noticed it.
|
|
9760
|
+
*/
|
|
9761
|
+
var ExchangeSessionSlot = class {
|
|
9762
|
+
_entry;
|
|
9763
|
+
current(initial, replacement) {
|
|
9764
|
+
const entry = this._entry;
|
|
9765
|
+
if (entry == null) return this._start(initial);
|
|
9766
|
+
if (entry.state != null && isLapsed(entry.state)) return this.renew(entry.state, replacement);
|
|
9767
|
+
return entry.promise;
|
|
9768
|
+
}
|
|
9769
|
+
renew(stale, replacement) {
|
|
9770
|
+
const entry = this._entry;
|
|
9771
|
+
if (entry != null && entry.state !== stale) return entry.promise;
|
|
9772
|
+
return this._start(replacement);
|
|
9773
|
+
}
|
|
9774
|
+
_start(establish) {
|
|
9775
|
+
const entry = { promise: establish() };
|
|
9776
|
+
this._entry = entry;
|
|
9777
|
+
entry.promise.then((state) => {
|
|
9778
|
+
entry.state = state;
|
|
9779
|
+
}, () => {
|
|
9780
|
+
if (this._entry === entry) this._entry = void 0;
|
|
9781
|
+
});
|
|
9782
|
+
return entry.promise;
|
|
9783
|
+
}
|
|
9784
|
+
};
|
|
9785
|
+
/** A session source for one transport alone — today's behaviour, plus renewal on refusal. */
|
|
9786
|
+
function privateSessionSource(handshake) {
|
|
9787
|
+
const slot = new ExchangeSessionSlot();
|
|
9788
|
+
return {
|
|
9789
|
+
current: () => slot.current(handshake, handshake),
|
|
9790
|
+
renew: (stale) => slot.renew(stale, handshake)
|
|
9791
|
+
};
|
|
9792
|
+
}
|
|
9793
|
+
const STORE_KEY = "sessions";
|
|
9794
|
+
const SEAL_VERSION = "connector-exchange-session/v1";
|
|
9795
|
+
/**
|
|
9796
|
+
* Every session one crypto identity holds with its peers, keyed by peer identity: shared in memory
|
|
9797
|
+
* by all of the link's transports, and kept in the link's own storage so a reload restores it.
|
|
9798
|
+
* Stored copies are sealed with a key derived from the link's private key — useless to another
|
|
9799
|
+
* device, and unopenable once the identity is reset.
|
|
9800
|
+
*/
|
|
9801
|
+
var ExchangeSessionShelf = class {
|
|
9802
|
+
_link;
|
|
9803
|
+
_slots = /* @__PURE__ */ new Map();
|
|
9804
|
+
_storage;
|
|
9805
|
+
_sealer;
|
|
9806
|
+
constructor(_link) {
|
|
9807
|
+
this._link = _link;
|
|
9808
|
+
this._storage = _link.scopedStorage("wire-exchange/");
|
|
9809
|
+
this._sealer = createExchangeTicketSealer(_link, { version: SEAL_VERSION });
|
|
9810
|
+
}
|
|
9811
|
+
source(key, handshake) {
|
|
9812
|
+
let slot = this._slots.get(key);
|
|
9813
|
+
if (slot == null) {
|
|
9814
|
+
slot = new ExchangeSessionSlot();
|
|
9815
|
+
this._slots.set(key, slot);
|
|
9816
|
+
}
|
|
9817
|
+
const held = slot;
|
|
9818
|
+
const handshakeAndKeep = async () => {
|
|
9819
|
+
const state = await handshake();
|
|
9820
|
+
await this._keep(key, state).catch(() => void 0);
|
|
9821
|
+
return state;
|
|
9822
|
+
};
|
|
9823
|
+
const restoreOrHandshake = async () => {
|
|
9824
|
+
return await this._restore(key).catch(() => void 0) ?? await handshakeAndKeep();
|
|
9825
|
+
};
|
|
9826
|
+
const replace = async () => {
|
|
9827
|
+
await this._forget(key).catch(() => void 0);
|
|
9828
|
+
return await handshakeAndKeep();
|
|
9829
|
+
};
|
|
9830
|
+
return {
|
|
9831
|
+
current: () => held.current(restoreOrHandshake, replace),
|
|
9832
|
+
renew: (stale) => held.renew(stale, replace)
|
|
9833
|
+
};
|
|
9834
|
+
}
|
|
9835
|
+
async _restore(key) {
|
|
9836
|
+
const storage = this._storage;
|
|
9837
|
+
if (storage == null) return void 0;
|
|
9838
|
+
const stored = (await storage.getJson(STORE_KEY))?.[key];
|
|
9839
|
+
if (stored == null || stored.exp <= Date.now()) return void 0;
|
|
9840
|
+
await this._link.initialize();
|
|
9841
|
+
const record = await this._sealer.open(stored.sealed);
|
|
9842
|
+
if (record == null || typeof record.t !== "string") return void 0;
|
|
9843
|
+
return stateFromRecord(this._link, record);
|
|
9844
|
+
}
|
|
9845
|
+
async _keep(key, state) {
|
|
9846
|
+
const storage = this._storage;
|
|
9847
|
+
const record = state.record;
|
|
9848
|
+
if (storage == null || record?.exp == null) return;
|
|
9849
|
+
const ttl = record.exp - Date.now();
|
|
9850
|
+
if (ttl <= 0) return;
|
|
9851
|
+
const sealed = await this._sealer.seal(record, ttl);
|
|
9852
|
+
await this._update(storage, (sessions) => ({
|
|
9853
|
+
...sessions,
|
|
9854
|
+
[key]: {
|
|
9855
|
+
exp: record.exp ?? 0,
|
|
9856
|
+
sealed
|
|
9857
|
+
}
|
|
9858
|
+
}));
|
|
9859
|
+
}
|
|
9860
|
+
async _forget(key) {
|
|
9861
|
+
const storage = this._storage;
|
|
9862
|
+
if (storage == null) return;
|
|
9863
|
+
await this._update(storage, (sessions) => {
|
|
9864
|
+
const { [key]: _dropped, ...rest } = sessions;
|
|
9865
|
+
return rest;
|
|
9866
|
+
});
|
|
9867
|
+
}
|
|
9868
|
+
async _update(storage, change) {
|
|
9869
|
+
await storage.updateJsonOrDef(STORE_KEY, {}, (current) => {
|
|
9870
|
+
const now = Date.now();
|
|
9871
|
+
const live = {};
|
|
9872
|
+
for (const [key, entry] of Object.entries(change(current))) if (entry.exp > now) live[key] = entry;
|
|
9873
|
+
return live;
|
|
9874
|
+
});
|
|
9875
|
+
}
|
|
9876
|
+
};
|
|
9877
|
+
const shelves = /* @__PURE__ */ new WeakMap();
|
|
9878
|
+
/**
|
|
9879
|
+
* The source a secure exchange draws its session from: shared by peer identity when the config asks
|
|
9880
|
+
* for reuse and names the peer, private to this transport otherwise.
|
|
9881
|
+
*/
|
|
9882
|
+
function exchangeSessionSource(secure, lane, handshake) {
|
|
9883
|
+
const peer = secure.expectedPeer;
|
|
9884
|
+
if (secure.reuseExchangeSessions !== true || peer == null) return privateSessionSource(handshake);
|
|
9885
|
+
let shelf = shelves.get(secure.link);
|
|
9886
|
+
if (shelf == null) {
|
|
9887
|
+
shelf = new ExchangeSessionShelf(secure.link);
|
|
9888
|
+
shelves.set(secure.link, shelf);
|
|
9889
|
+
}
|
|
9890
|
+
const key = JSON.stringify([
|
|
9891
|
+
secure.localCoordinate.envId,
|
|
9892
|
+
secure.localCoordinate.perId ?? null,
|
|
9893
|
+
peer.envId,
|
|
9894
|
+
peer.perId ?? null,
|
|
9895
|
+
secure.securityLevel,
|
|
9896
|
+
lane.dictionaryVersion,
|
|
9897
|
+
[...lane.channels ?? []].sort()
|
|
9898
|
+
]);
|
|
9899
|
+
return shelf.source(key, handshake);
|
|
9900
|
+
}
|
|
9901
|
+
//#endregion
|
|
9676
9902
|
//#region ../nice-wire/src/Connect/exchangeSession.ts
|
|
9677
9903
|
const textEncoder$1 = new TextEncoder();
|
|
9678
9904
|
const textDecoder$1 = new TextDecoder();
|
|
9905
|
+
const PLAIN_STATE = {};
|
|
9679
9906
|
/** Plain path (no handshake/token): every wire rides a bare `act` envelope, plaintext both ways. */
|
|
9680
9907
|
function establishPlainExchangeSession(carrier) {
|
|
9681
|
-
return makeSession(carrier, {
|
|
9908
|
+
return makeSession(carrier, {
|
|
9909
|
+
current: async () => PLAIN_STATE,
|
|
9910
|
+
renew: async () => PLAIN_STATE
|
|
9911
|
+
});
|
|
9682
9912
|
}
|
|
9683
9913
|
/**
|
|
9684
|
-
* Secure path: run the handshake (two exchanges)
|
|
9685
|
-
* The lane supplies the handshake payload (`dictionaryVersion`/`channels`,
|
|
9686
|
-
* byte-frozen wire names; the version is signed into the challenge).
|
|
9914
|
+
* Secure path: run the handshake (two exchanges) at bring-up — or restore a kept session — then
|
|
9915
|
+
* reuse the token + crypto. The lane supplies the handshake payload (`dictionaryVersion`/`channels`,
|
|
9916
|
+
* E5 — emitted under the byte-frozen wire names; the version is signed into the challenge).
|
|
9687
9917
|
*/
|
|
9688
9918
|
async function establishSecureExchangeSession(ctx) {
|
|
9689
|
-
const
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9919
|
+
const source = exchangeSessionSource(ctx.secure, ctx.lane, () => runConnectorExchangeHandshake(ctx.carrier, ctx.secure, ctx.lane));
|
|
9920
|
+
await source.current();
|
|
9921
|
+
return makeSession(ctx.carrier, source, ctx.secure.localCoordinate.insId);
|
|
9922
|
+
}
|
|
9923
|
+
function makeSession(carrier, source, insId) {
|
|
9924
|
+
const post = async (state, wire, signal) => {
|
|
9925
|
+
const request = await buildRequestEnvelope(state, wire, insId);
|
|
9926
|
+
return decodeExchangeReply(asString(await carrier.exchange(encodeExchange(request), { signal })));
|
|
9927
|
+
};
|
|
9928
|
+
const roundTrip = async (wire, signal) => {
|
|
9929
|
+
const state = await source.current();
|
|
9930
|
+
const reply = await post(state, wire, signal);
|
|
9931
|
+
if (reply?.k !== "err" || reply.id !== "session_refused" || state.token == null) return {
|
|
9932
|
+
state,
|
|
9933
|
+
reply
|
|
9934
|
+
};
|
|
9935
|
+
const renewed = await source.renew(state);
|
|
9936
|
+
return {
|
|
9937
|
+
state: renewed,
|
|
9938
|
+
reply: await post(renewed, wire, signal)
|
|
9939
|
+
};
|
|
9696
9940
|
};
|
|
9697
9941
|
return {
|
|
9698
9942
|
send: async (wire, opts) => {
|
|
9699
|
-
await
|
|
9943
|
+
await roundTrip(wire, opts?.signal);
|
|
9700
9944
|
},
|
|
9701
9945
|
exchange: async (wire, opts) => {
|
|
9702
|
-
const reply =
|
|
9946
|
+
const { state, reply } = await roundTrip(wire, opts?.signal);
|
|
9703
9947
|
if (reply == null) return {
|
|
9704
9948
|
ok: false,
|
|
9705
9949
|
reason: "malformed_reply"
|
|
@@ -9721,18 +9965,21 @@ function makeSession(carrier, state) {
|
|
|
9721
9965
|
}
|
|
9722
9966
|
};
|
|
9723
9967
|
}
|
|
9724
|
-
async function buildRequestEnvelope(state, wire) {
|
|
9968
|
+
async function buildRequestEnvelope(state, wire, insId) {
|
|
9969
|
+
const i = state.token != null ? insId : void 0;
|
|
9725
9970
|
if (state.crypto != null) {
|
|
9726
9971
|
const ciphertext = await state.crypto.encryptFrame(textEncoder$1.encode(JSON.stringify(wire)));
|
|
9727
9972
|
return {
|
|
9728
9973
|
k: "act",
|
|
9729
9974
|
t: state.token,
|
|
9975
|
+
i,
|
|
9730
9976
|
c: bytesToBase64(ciphertext)
|
|
9731
9977
|
};
|
|
9732
9978
|
}
|
|
9733
9979
|
return {
|
|
9734
9980
|
k: "act",
|
|
9735
9981
|
t: state.token,
|
|
9982
|
+
i,
|
|
9736
9983
|
w: wire
|
|
9737
9984
|
};
|
|
9738
9985
|
}
|
|
@@ -9775,14 +10022,13 @@ async function runConnectorExchangeHandshake(carrier, secure, lane) {
|
|
|
9775
10022
|
if (accept.t !== "accept") throw nonProtocolReply(carrier, "an accept frame", `hs/${accept.t}`);
|
|
9776
10023
|
if (acceptReply.t == null) throw new Error(`[${HANDSHAKE_STAGE}] accept missing session token${at(carrier)}`);
|
|
9777
10024
|
const result = await handshake.onAccept(accept);
|
|
9778
|
-
const
|
|
9779
|
-
|
|
9780
|
-
|
|
9781
|
-
|
|
9782
|
-
|
|
9783
|
-
|
|
9784
|
-
|
|
9785
|
-
};
|
|
10025
|
+
const keyMaterial = result.securityLevel === "encrypted" ? result.encryptionKeyMaterial : void 0;
|
|
10026
|
+
return stateFromRecord(secure.link, {
|
|
10027
|
+
t: acceptReply.t,
|
|
10028
|
+
level: result.securityLevel,
|
|
10029
|
+
km: keyMaterial,
|
|
10030
|
+
exp: expiryFor(Date.now(), acceptReply.ttl)
|
|
10031
|
+
});
|
|
9786
10032
|
}
|
|
9787
10033
|
const HANDSHAKE_STAGE = "exchange-handshake";
|
|
9788
10034
|
/**
|
|
@@ -10368,50 +10614,6 @@ var WireAcceptor = class {
|
|
|
10368
10614
|
}
|
|
10369
10615
|
};
|
|
10370
10616
|
//#endregion
|
|
10371
|
-
//#region ../nice-wire/src/SecureSession/exchangeTicketSeal.ts
|
|
10372
|
-
const SEALED_ENVELOPE_LENGTH = 2;
|
|
10373
|
-
function createExchangeTicketSealer(link, options = {}) {
|
|
10374
|
-
let keyPromise;
|
|
10375
|
-
const getKey = () => {
|
|
10376
|
-
if (keyPromise == null) keyPromise = link.deriveLocalSealKey({ version: options.version }).catch((err) => {
|
|
10377
|
-
keyPromise = void 0;
|
|
10378
|
-
throw err;
|
|
10379
|
-
});
|
|
10380
|
-
return keyPromise;
|
|
10381
|
-
};
|
|
10382
|
-
return {
|
|
10383
|
-
async seal(value, ttlMs) {
|
|
10384
|
-
const { nonce, ciphertext } = await encryptBytesWithAesGcmKey({
|
|
10385
|
-
dataToEncrypt: pack({
|
|
10386
|
-
v: value,
|
|
10387
|
-
exp: Date.now() + ttlMs
|
|
10388
|
-
}),
|
|
10389
|
-
aesGcmKey: await getKey()
|
|
10390
|
-
});
|
|
10391
|
-
return bytesToBase64(pack([nonce, ciphertext]));
|
|
10392
|
-
},
|
|
10393
|
-
async open(blob) {
|
|
10394
|
-
try {
|
|
10395
|
-
const envelope = unpack(base64ToBytes(blob));
|
|
10396
|
-
if (!Array.isArray(envelope) || envelope.length !== SEALED_ENVELOPE_LENGTH) return void 0;
|
|
10397
|
-
const [nonce, ciphertext] = envelope;
|
|
10398
|
-
if (!(nonce instanceof Uint8Array) || !(ciphertext instanceof Uint8Array)) return void 0;
|
|
10399
|
-
const payload = unpack(await decryptBytesWithAesGcmKey({
|
|
10400
|
-
dataToDecrypt: {
|
|
10401
|
-
nonce,
|
|
10402
|
-
ciphertext
|
|
10403
|
-
},
|
|
10404
|
-
aesGcmKey: await getKey()
|
|
10405
|
-
}));
|
|
10406
|
-
if (payload == null || typeof payload.exp !== "number" || payload.exp < Date.now()) return;
|
|
10407
|
-
return payload.v;
|
|
10408
|
-
} catch {
|
|
10409
|
-
return;
|
|
10410
|
-
}
|
|
10411
|
-
}
|
|
10412
|
-
};
|
|
10413
|
-
}
|
|
10414
|
-
//#endregion
|
|
10415
10617
|
//#region ../nice-wire/src/Connect/WireExchangeAcceptor.ts
|
|
10416
10618
|
/** The default session-ticket lifetime — see {@link IWireExchangeAcceptorOptions.sessionTtlMs}. */
|
|
10417
10619
|
const DEFAULT_SESSION_TTL_MS = 720 * 60 * 1e3;
|
|
@@ -10481,11 +10683,17 @@ var WireExchangeAcceptor = class {
|
|
|
10481
10683
|
m: encodeHandshakeMessage(reply)
|
|
10482
10684
|
};
|
|
10483
10685
|
const pending = handshake.exportPending();
|
|
10484
|
-
|
|
10686
|
+
const dv = this._dictionaryVersion(message.channels);
|
|
10687
|
+
if (pending == null || dv == null) return {
|
|
10485
10688
|
k: "err",
|
|
10486
10689
|
message: "handshake produced no continuation state"
|
|
10487
10690
|
};
|
|
10488
|
-
const
|
|
10691
|
+
const continuation = {
|
|
10692
|
+
...pending,
|
|
10693
|
+
dv,
|
|
10694
|
+
ch: message.channels
|
|
10695
|
+
};
|
|
10696
|
+
const hsc = await this._sealer.seal(continuation, HANDSHAKE_CONTINUATION_TTL_MS);
|
|
10489
10697
|
return {
|
|
10490
10698
|
k: "hs",
|
|
10491
10699
|
m: encodeHandshakeMessage(reply),
|
|
@@ -10497,11 +10705,12 @@ var WireExchangeAcceptor = class {
|
|
|
10497
10705
|
k: "err",
|
|
10498
10706
|
message: "prove missing continuation token"
|
|
10499
10707
|
};
|
|
10500
|
-
const
|
|
10501
|
-
if (
|
|
10708
|
+
const continuation = await this._sealer.open(request.hsc);
|
|
10709
|
+
if (continuation == null) return {
|
|
10502
10710
|
k: "err",
|
|
10503
10711
|
message: "invalid or expired continuation token"
|
|
10504
10712
|
};
|
|
10713
|
+
const { dv, ch, ...pending } = continuation;
|
|
10505
10714
|
const handshake = this._makeHandshake();
|
|
10506
10715
|
await handshake.restorePending(pending);
|
|
10507
10716
|
const reply = await handshake.onProve(message);
|
|
@@ -10510,13 +10719,16 @@ var WireExchangeAcceptor = class {
|
|
|
10510
10719
|
const ticket = {
|
|
10511
10720
|
client: result.remote,
|
|
10512
10721
|
securityLevel: result.securityLevel,
|
|
10513
|
-
keyMaterial: result.encryptionKeyMaterial
|
|
10722
|
+
keyMaterial: result.encryptionKeyMaterial,
|
|
10723
|
+
dv,
|
|
10724
|
+
ch
|
|
10514
10725
|
};
|
|
10515
10726
|
const t = await this._sealer.seal(ticket, this._sessionTtlMs);
|
|
10516
10727
|
return {
|
|
10517
10728
|
k: "hs",
|
|
10518
10729
|
m: encodeHandshakeMessage(reply),
|
|
10519
|
-
t
|
|
10730
|
+
t,
|
|
10731
|
+
ttl: this._sessionTtlMs
|
|
10520
10732
|
};
|
|
10521
10733
|
}
|
|
10522
10734
|
return {
|
|
@@ -10529,6 +10741,10 @@ var WireExchangeAcceptor = class {
|
|
|
10529
10741
|
message: `unexpected handshake message ${message.t}`
|
|
10530
10742
|
};
|
|
10531
10743
|
}
|
|
10744
|
+
_dictionaryVersion(channels) {
|
|
10745
|
+
const version = this._lane.dictionaryVersion;
|
|
10746
|
+
return typeof version === "function" ? version({ channels: channels == null ? void 0 : [...channels] }) : version;
|
|
10747
|
+
}
|
|
10532
10748
|
async _handleAction(request) {
|
|
10533
10749
|
let client;
|
|
10534
10750
|
let crypto;
|
|
@@ -10536,24 +10752,30 @@ var WireExchangeAcceptor = class {
|
|
|
10536
10752
|
let securityLevel = "none";
|
|
10537
10753
|
if (request.t != null) {
|
|
10538
10754
|
const ticket = await this._sealer.open(request.t);
|
|
10539
|
-
if (ticket == null) return
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10755
|
+
if (ticket == null) return refused("unknown or expired session token");
|
|
10756
|
+
if (ticket.dv != null && ticket.dv !== this._dictionaryVersion(ticket.ch)) return refused("session was agreed under another dictionary version");
|
|
10757
|
+
client = new RuntimeCoordinate(typeof request.i === "string" ? {
|
|
10758
|
+
...ticket.client,
|
|
10759
|
+
insId: request.i
|
|
10760
|
+
} : ticket.client);
|
|
10544
10761
|
securityLevel = ticket.securityLevel;
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10552
|
-
|
|
10553
|
-
|
|
10554
|
-
|
|
10555
|
-
|
|
10556
|
-
|
|
10762
|
+
if (ticket.securityLevel === "encrypted") {
|
|
10763
|
+
if (!("c" in request)) return refused("encrypted session refuses a plaintext act");
|
|
10764
|
+
if (ticket.keyMaterial == null) return refused("encrypted session has no key material");
|
|
10765
|
+
crypto = createActionFrameCrypto({
|
|
10766
|
+
link: this._security.link,
|
|
10767
|
+
keyMaterial: ticket.keyMaterial
|
|
10768
|
+
});
|
|
10769
|
+
try {
|
|
10770
|
+
const plain = await crypto.decryptFrame(base64ToBytes(request.c));
|
|
10771
|
+
wire = JSON.parse(textDecoder.decode(plain));
|
|
10772
|
+
} catch {
|
|
10773
|
+
return refused("undecryptable act");
|
|
10774
|
+
}
|
|
10775
|
+
} else {
|
|
10776
|
+
if ("c" in request) return refused("session is not encrypted");
|
|
10777
|
+
wire = request.w;
|
|
10778
|
+
}
|
|
10557
10779
|
} else {
|
|
10558
10780
|
if (!this._noneAllowed || "c" in request) return {
|
|
10559
10781
|
k: "err",
|
|
@@ -10571,7 +10793,7 @@ var WireExchangeAcceptor = class {
|
|
|
10571
10793
|
k: "err",
|
|
10572
10794
|
message: laneReply.message
|
|
10573
10795
|
};
|
|
10574
|
-
if (crypto != null
|
|
10796
|
+
if (crypto != null) return {
|
|
10575
10797
|
k: "act",
|
|
10576
10798
|
c: bytesToBase64(await crypto.encryptFrame(textEncoder.encode(JSON.stringify(laneReply.wire))))
|
|
10577
10799
|
};
|
|
@@ -10587,6 +10809,13 @@ var WireExchangeAcceptor = class {
|
|
|
10587
10809
|
});
|
|
10588
10810
|
}
|
|
10589
10811
|
};
|
|
10812
|
+
function refused(message) {
|
|
10813
|
+
return {
|
|
10814
|
+
k: "err",
|
|
10815
|
+
message,
|
|
10816
|
+
id: WIRE_EXCHANGE_SESSION_REFUSED
|
|
10817
|
+
};
|
|
10818
|
+
}
|
|
10590
10819
|
//#endregion
|
|
10591
10820
|
//#region ../nice-wire/src/codec/controlFrame.ts
|
|
10592
10821
|
/** msgpack map (object) first-byte prefixes — fixmap `0x80–0x8f`, map16 `0xde`, map32 `0xdf`. */
|
|
@@ -16980,6 +17209,7 @@ function transport(options) {
|
|
|
16980
17209
|
link,
|
|
16981
17210
|
localCoordinate: (options.identity ?? options.runtime.coordinate).toJsonObject(),
|
|
16982
17211
|
expectedPeer: options.expectedPeer?.toJsonObject(),
|
|
17212
|
+
reuseExchangeSessions: options.reuseExchangeSessions,
|
|
16983
17213
|
dictionaryVersion: channel.dictionaryVersion,
|
|
16984
17214
|
channelTags: channel.tags,
|
|
16985
17215
|
mux: options.mux
|
|
@@ -17147,6 +17377,7 @@ function connectChannel(runtime, channel, options) {
|
|
|
17147
17377
|
secure: descriptor.secure ?? true,
|
|
17148
17378
|
link,
|
|
17149
17379
|
securityLevel: descriptor.securityLevel ?? securityLevel,
|
|
17380
|
+
reuseExchangeSessions: options.reuseExchangeSessions,
|
|
17150
17381
|
available: descriptor.available,
|
|
17151
17382
|
label: descriptor.label,
|
|
17152
17383
|
mux: wireMux,
|