@getpaseo/relay 0.6.1 → 0.7.0-beta.1
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/dist/encrypted-channel.d.ts +2 -0
- package/dist/encrypted-channel.js +16 -18
- package/package.json +1 -1
|
@@ -75,6 +75,8 @@ export declare class EncryptedChannel {
|
|
|
75
75
|
outboundWireByteLength(data: string | ArrayBuffer): number;
|
|
76
76
|
private flushPendingSends;
|
|
77
77
|
private handleDaemonRehello;
|
|
78
|
+
private sendReadyForRetry;
|
|
79
|
+
private rejectKeyRotation;
|
|
78
80
|
close(code?: number, reason?: string): void;
|
|
79
81
|
isOpen(): boolean;
|
|
80
82
|
onTransitionToOpen(cb: () => void): void;
|
|
@@ -46,7 +46,7 @@ function buildInvalidHelloError(rawText, parsed) {
|
|
|
46
46
|
}
|
|
47
47
|
const HANDSHAKE_RETRY_MS = 1000;
|
|
48
48
|
const MAX_PENDING_SENDS = 200;
|
|
49
|
-
const
|
|
49
|
+
const REHANDSHAKE_REJECTION_CODE = 1008;
|
|
50
50
|
const ENCRYPTED_PAYLOAD_OVERHEAD_BYTES = 40;
|
|
51
51
|
export function base64EncryptedWireByteLength(plaintextBytes) {
|
|
52
52
|
return 4 * Math.ceil((plaintextBytes + ENCRYPTED_PAYLOAD_OVERHEAD_BYTES) / 3);
|
|
@@ -383,24 +383,22 @@ export class EncryptedChannel {
|
|
|
383
383
|
if (!this.options.daemonKeyPair)
|
|
384
384
|
return;
|
|
385
385
|
const clientPublicKey = importPublicKey(message.key);
|
|
386
|
-
const
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
// authenticated reconnect. Close and require a fresh transport instead of
|
|
401
|
-
// allowing the relay to switch this channel to an attacker-chosen key.
|
|
386
|
+
const retryKey = deriveSharedKey(this.options.daemonKeyPair.secretKey, clientPublicKey);
|
|
387
|
+
if (!keysEqual(retryKey, this.sharedKey))
|
|
388
|
+
return this.rejectKeyRotation();
|
|
389
|
+
await this.sendReadyForRetry();
|
|
390
|
+
}
|
|
391
|
+
async sendReadyForRetry() {
|
|
392
|
+
await this.transport.send(JSON.stringify({
|
|
393
|
+
type: "e2ee_ready",
|
|
394
|
+
...(this.options.binaryCiphertext
|
|
395
|
+
? { capabilities: { binaryCiphertext: true } }
|
|
396
|
+
: {}),
|
|
397
|
+
}));
|
|
398
|
+
}
|
|
399
|
+
rejectKeyRotation() {
|
|
402
400
|
this.state = "closed";
|
|
403
|
-
this.transport.close(
|
|
401
|
+
this.transport.close(REHANDSHAKE_REJECTION_CODE, REHANDSHAKE_KEY_MISMATCH_CLOSE_REASON);
|
|
404
402
|
}
|
|
405
403
|
close(code = 1000, reason = "Normal closure") {
|
|
406
404
|
this.state = "closed";
|