-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: #310 -e2e encrypted oneway audio call added
- Loading branch information
Showing
15 changed files
with
332 additions
and
226 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,15 @@ | ||
import React, { useContext } from "react"; | ||
import { ThemeContext } from "../../ThemeContext"; | ||
import styles from "./Style.module.css"; | ||
import React from "react"; | ||
import Button from "../Button"; | ||
|
||
const DeleteChatLink = ({ handleDeleteLink }: any) => { | ||
const [darkMode] = useContext(ThemeContext); | ||
|
||
const deleteHandler = async () => { | ||
if (window.confirm("Delete chat link forever?")) await handleDeleteLink(); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<div | ||
className={`${styles.deleteButton} ${!darkMode && styles.lightModeDelete}`} | ||
role="button" | ||
onClick={deleteHandler} | ||
> | ||
Delete | ||
</div> | ||
<Button onClick={deleteHandler} label = "Delete" type="secondary"/> | ||
</div> | ||
); | ||
}; | ||
) | ||
} | ||
|
||
export default DeleteChatLink; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
client/src/components/Messaging/styles/UserStatusInfo.module.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* Symmetric key encryption used for encrypting Audio/Video data | ||
*/ | ||
export class AesGcmEncryption { | ||
private aesKeyLocal?: CryptoKey; | ||
private aesKeyRemote?: CryptoKey; | ||
|
||
public async int(): Promise<CryptoKey> { | ||
if(this.aesKeyLocal) { | ||
return this.aesKeyLocal; | ||
} | ||
const key = await window.crypto.subtle.generateKey( | ||
{ name: "AES-GCM", length: 256 }, | ||
true, | ||
["encrypt", "decrypt"] | ||
); | ||
|
||
this.aesKeyLocal = key; | ||
return this.aesKeyLocal; | ||
} | ||
|
||
public getRemoteAesKey(): CryptoKey { | ||
if(!this.aesKeyRemote) { | ||
throw new Error("AES key from remote not set."); | ||
} | ||
return this.aesKeyRemote; | ||
} | ||
|
||
/** | ||
* To Do: | ||
* this key is plain text, can be used to decrypt data. | ||
* Should not be transmitted over network. | ||
* Use cryptoUtils to encrypt the key and exchange. | ||
*/ | ||
public async getRawAesKeyToExport(): Promise<string> { | ||
if(!this.aesKeyLocal) { | ||
throw new Error('AES key not generated'); | ||
} | ||
const jsonWebKey = await crypto.subtle.exportKey("jwk", this.aesKeyLocal); | ||
return JSON.stringify(jsonWebKey); | ||
} | ||
|
||
public async setRemoteAesKey(key: string): Promise<void> { | ||
const jsonWebKey = JSON.parse(key); | ||
this.aesKeyRemote = await crypto.subtle.importKey( | ||
"jwk", | ||
jsonWebKey, | ||
{ name: "AES-GCM" }, | ||
true, // Key is usable for decryption | ||
["decrypt"] // Usage options for the key | ||
); | ||
|
||
} | ||
|
||
public async encryptData(data: ArrayBuffer) { | ||
// Generate an Initialization Vector (IV) for AES-GCM (12 bytes) | ||
const iv = crypto.getRandomValues(new Uint8Array(12)); | ||
// Encrypt the frame data using AES-GCM | ||
const encryptedData = await crypto.subtle.encrypt( | ||
{ | ||
name: "AES-GCM", | ||
iv: iv | ||
}, | ||
this.aesKeyLocal, // Symmetric key for encryption | ||
data // The frame data to be encrypted | ||
); | ||
|
||
|
||
return { encryptedData: new Uint8Array(encryptedData) , iv }; | ||
} | ||
|
||
public async decryptData(data: Uint8Array, iv: Uint8Array): Promise<ArrayBuffer> { | ||
if(!this.aesKeyRemote) { | ||
throw new Error('Remote AES key not set.') | ||
} | ||
return crypto.subtle.decrypt( | ||
{ | ||
name: "AES-GCM", | ||
iv: iv | ||
}, | ||
this.aesKeyRemote, // Symmetric key for decryption | ||
data // The encrypted frame data | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.