aboutsummaryrefslogtreecommitdiffstats
path: root/packages/meshbay-hub/src/meshbay_hub/static
diff options
context:
space:
mode:
Diffstat (limited to 'packages/meshbay-hub/src/meshbay_hub/static')
-rw-r--r--packages/meshbay-hub/src/meshbay_hub/static/transport.js31
1 files changed, 30 insertions, 1 deletions
diff --git a/packages/meshbay-hub/src/meshbay_hub/static/transport.js b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
index 202db94..27edc4e 100644
--- a/packages/meshbay-hub/src/meshbay_hub/static/transport.js
+++ b/packages/meshbay-hub/src/meshbay_hub/static/transport.js
@@ -651,6 +651,25 @@ class MeshBayTransport {
try { this.onConnectProgress(phase); } catch { /* the caller's problem */ }
}
+ // Fetch the short-lived token presented to a node in the handshake. It is a
+ // different credential from the session token used for hub calls: aud=MNP_AUD,
+ // useless at the hub API, so a node operator who captures it gains nothing
+ // there (see meshbay_common/tokens.py). Uses the session token to ask.
+ async _fetchNodeToken(call) {
+ const doFetch = call
+ || (window.MeshBayPlatform && window.MeshBayPlatform.apiFetch) || fetch;
+ const r = await doFetch(`${this._hubUrl}/v1/nodes/mnp-token`, {
+ method: 'POST',
+ headers: {
+ 'Content-Type': 'application/json',
+ 'Authorization': `Bearer ${this._accessToken}`,
+ },
+ body: JSON.stringify({}),
+ });
+ if (!r.ok) throw new Error(`Could not obtain a node token: ${r.status}`);
+ return (await r.json()).mnp_token;
+ }
+
async connect(nodeId, jwtToken, groupId, gekRaw, sessionKeys, bundleKey, username,
userId, joinCode, recoveryKey, joinNodePk) {
// Remembered for _reconnectLoop, which calls connect() again with these
@@ -896,11 +915,21 @@ class MeshBayTransport {
// recorded handshake_ack could be replayed by an impersonating peer.
this._nonceClient = crypto.getRandomValues(new Uint8Array(32));
+ // The member authenticates to the node with a short-lived MNP token, never
+ // its hub session token. A node operator holds whatever is presented here,
+ // and the session token opens the hub API — so presenting it would hand an
+ // operator a live credential for the member (audience-bound, see
+ // meshbay_common/tokens.py). Fetched per connect and per reconnect with the
+ // session token (`this._accessToken`), so it always carries current group
+ // membership and a fresh expiry. Signaling above still uses the session
+ // token, because that is a hub call.
+ const nodeToken = await this._fetchNodeToken(call);
+
const reply = await this._sendAndWait({
type: 'handshake',
v: MNP_V,
v_min: MNP_V_MIN,
- token: jwtToken,
+ token: nodeToken,
group_id: groupId || '',
nonce: window.MeshBayCrypto.b64encode(this._nonceClient),
});