Skip to content

fix: encrypt AES key with RSA before server exchange#434

Merged
muke1908 merged 3 commits intomasterfrom
copilot/fix-aes-key-exchange-vulnerability
Apr 2, 2026
Merged

fix: encrypt AES key with RSA before server exchange#434
muke1908 merged 3 commits intomasterfrom
copilot/fix-aes-key-exchange-vulnerability

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

The AES key used for WebRTC audio/video encryption was being transmitted to the server in plaintext, allowing the server to observe and potentially exploit it.

Changes

  • sdk.ts – AES key exchange already patched: shareEncryptedAesKey() RSA-OAEP encrypts the exported AES JWK with the receiver's public key before posting to the server; getPublicKey() decrypts the received ciphertext with the local RSA private key before importing it.
// Sender: encrypt AES key with receiver's RSA public key
private async shareEncryptedAesKey(): Promise<void> {
    const aesKeyJwk = await this.symEncryption.getRawAesKeyToExport();
    const encryptedAesKey = await _cryptoUtils.encryptMessage(aesKeyJwk, this.receiverPublicKey!);
    await sharePublicKey({ aesKey: encryptedAesKey, publicKey: this.publicKey, ... });
}

// Receiver: decrypt with own RSA private key
const decryptedAesKeyJwk = await _cryptoUtils.decryptMessage(receiverPublicKey.aesKey, this.privateKey!);
await this.symEncryption.setRemoteAesKey(decryptedAesKeyJwk);
  • cryptoAES.ts – Removed stale TODO comment on getRawAesKeyToExport() that incorrectly warned the key should not be transmitted (predated the RSA-wrapping fix).

  • crypto.test.ts – Added test suite AES key exchange via RSA-encrypted channel covering:

    • Full exchange round-trip: Alice encrypts AES key with Bob's RSA public key → Bob decrypts → successfully decrypts AES-GCM data encrypted by Alice.
    • Attacker exclusion: a third party with a different RSA key pair cannot decrypt the intercepted AES key ciphertext.

Copilot AI linked an issue Apr 2, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 2, 2026 22:59
Agent-Logs-Url: https://github.com/muke1908/chat-e2ee/sessions/80bba9d0-1121-4f81-bf67-b0822aef8216

Co-authored-by: muke1908 <20297989+muke1908@users.noreply.github.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 2, 2026

Copilot AI changed the title [WIP] Fix AES key exchange vulnerability through encryption fix: encrypt AES key with RSA before server exchange Apr 2, 2026
Copilot AI requested a review from muke1908 April 2, 2026 23:03
@muke1908 muke1908 marked this pull request as ready for review April 2, 2026 23:05
@muke1908 muke1908 merged commit 94617b5 into master Apr 2, 2026
1 check passed
@muke1908 muke1908 deleted the copilot/fix-aes-key-exchange-vulnerability branch April 2, 2026 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AES key should be encrypted before exchange

2 participants