summary refs log tree commit diff
path: root/webrtc/src
diff options
context:
space:
mode:
Diffstat (limited to 'webrtc/src')
-rw-r--r--webrtc/src/Server.ts28
-rw-r--r--webrtc/src/opcodes/SelectProtocol.ts5
2 files changed, 23 insertions, 10 deletions
diff --git a/webrtc/src/Server.ts b/webrtc/src/Server.ts

index 67f60f9f..a43768ac 100644 --- a/webrtc/src/Server.ts +++ b/webrtc/src/Server.ts
@@ -19,6 +19,7 @@ export class Server { public mediasoupProducers: MediasoupTypes.Producer[] = []; public mediasoupConsumers: MediasoupTypes.Consumer[] = []; + public decryptKey: number[] = []; public testUdp = udp.createSocket("udp6"); constructor() { @@ -50,7 +51,6 @@ export class Server { this.testUdp.bind(50001); this.testUdp.on("message", (msg, rinfo) => { //random key from like, the libsodium examples on npm lol - const decryptKey = sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed"); //give me my remote port? if (sodium.to_hex(msg) == "0001004600000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000") { @@ -66,17 +66,27 @@ export class Server { } const nonce = Buffer.concat([msg.slice(-4), Buffer.from("\x00".repeat(20))]); - console.log(`[UDP] nonce for this message: ${nonce}`); + console.log(`[UDP] nonce for this message: ${nonce.toString("hex")}`); + + console.log(`[UDP] message: ${sodium.to_hex(msg)}`); + + let encrypted; + if (msg.slice(0, 2).indexOf("\x81\xc9") == 0) { + encrypted = msg.slice(0x18, -4); + } + else if (msg.slice(0, 2).indexOf("\x90\x78") == 0) { + encrypted = msg.slice(0x1C, -4); + } + else { + encrypted = msg.slice(0x18, -4); + console.log(`wtf header received: ${encrypted.toString("hex")}`); + } - console.log(sodium.to_hex(msg)); if (sodium.to_hex(msg).indexOf("80c8000600000001") == 0) { //call status - const encrypted = msg.slice(8, -4); - const currentPacket = msg.slice(-4); - console.log(`[UDP] Current packet: ${currentPacket}`); + try { - console.log(`[UDP] Encrypted bytes: ${encrypted.toString("base64")}`); - const decrypted = sodium.crypto_secretbox_open_easy(encrypted, nonce, decryptKey); + const decrypted = sodium.crypto_secretbox_open_easy(encrypted, nonce, Uint8Array.from(this.decryptKey)); console.log("[UDP] [ call status ]" + decrypted); } catch (e) { @@ -86,7 +96,7 @@ export class Server { } try { - const decrypted = sodium.crypto_secretbox_open_easy(msg, nonce, decryptKey); + const decrypted = sodium.crypto_secretbox_open_easy(encrypted, nonce, Uint8Array.from(this.decryptKey)); console.log("[UDP] " + decrypted); } catch (e) { diff --git a/webrtc/src/opcodes/SelectProtocol.ts b/webrtc/src/opcodes/SelectProtocol.ts
index 29b9c1f9..75ab4495 100644 --- a/webrtc/src/opcodes/SelectProtocol.ts +++ b/webrtc/src/opcodes/SelectProtocol.ts
@@ -161,11 +161,14 @@ export async function onSelectProtocol(this: Server, socket: WebSocket, data: Pa }; */ + this.decryptKey = [...sodium.randombytes_buf(sodium.crypto_secretbox_KEYBYTES)]; + console.log(this.decryptKey.map(x => String.fromCharCode(x)).join("")); + socket.send(JSON.stringify({ op:VoiceOPCodes.SESSION_DESCRIPTION, d: { video_codec: "H264", - secret_key: [...sodium.from_hex("724b092810ec86d7e35c9d067702b31ef90bc43a7b598626749914d6a3e033ed")], + secret_key: this.decryptKey, mode: "aead_aes256_gcm_rtpsize", media_session_id: "blah blah blah", audio_codec: "opus",