@getpaseo/relay 0.6.1 → 0.7.0-beta.2

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.
@@ -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 REHANDSHAKE_KEY_MISMATCH_CLOSE_CODE = 1008;
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 nextSharedKey = deriveSharedKey(this.options.daemonKeyPair.secretKey, clientPublicKey);
387
- // If it's the same client key (handshake retry), re-send
388
- // "ready" but do not re-key. Re-keying here would desync
389
- // the channel and cause decrypt failures.
390
- if (keysEqual(nextSharedKey, this.sharedKey)) {
391
- await this.transport.send(JSON.stringify({
392
- type: "e2ee_ready",
393
- ...(this.options.binaryCiphertext
394
- ? { capabilities: { binaryCiphertext: true } }
395
- : {}),
396
- }));
397
- return;
398
- }
399
- // A different key on an already-open encrypted channel is not an
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(REHANDSHAKE_KEY_MISMATCH_CLOSE_CODE, REHANDSHAKE_KEY_MISMATCH_CLOSE_REASON);
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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getpaseo/relay",
3
- "version": "0.6.1",
3
+ "version": "0.7.0-beta.2",
4
4
  "description": "Paseo relay for bridging daemon and client connections",
5
5
  "files": [
6
6
  "dist",