aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-01-27 20:08:18 +0100
committermetamuffin <metamuffin@disroot.org>2024-01-27 20:08:18 +0100
commitc8063785853e516280cd68e9d8e9ae79b2081989 (patch)
treeabf27a18afaae287563fee440e57741a59af3714
parent91259369b2b87eb647e9743c874d7e58894149c1 (diff)
downloadkeks-meet-1.0.1.tar
keks-meet-1.0.1.tar.bz2
keks-meet-1.0.1.tar.zst
cache room hashes, bump versionv1.0.1
-rw-r--r--Cargo.lock2
-rw-r--r--client-web/source/index.ts2
-rw-r--r--client-web/source/protocol/crypto.ts8
-rw-r--r--client-web/source/protocol/mod.ts18
-rw-r--r--client-web/source/room_watches.ts14
-rw-r--r--server/Cargo.toml2
6 files changed, 29 insertions, 17 deletions
diff --git a/Cargo.lock b/Cargo.lock
index d151575..3d65a0e 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2434,7 +2434,7 @@ dependencies = [
[[package]]
name = "keks-meet-server"
-version = "1.0.0"
+version = "1.0.1"
dependencies = [
"env_logger 0.10.2",
"futures-util",
diff --git a/client-web/source/index.ts b/client-web/source/index.ts
index 8bc7edc..b085cb8 100644
--- a/client-web/source/index.ts
+++ b/client-web/source/index.ts
@@ -15,7 +15,7 @@ import { Room } from "./room.ts"
import { control_bar, info_br } from "./menu.ts";
import { Chat } from "./chat.ts"
-export const VERSION = "1.0.0"
+export const VERSION = "1.0.1"
window.onload = () => main()
export interface ClientConfig {
diff --git a/client-web/source/protocol/crypto.ts b/client-web/source/protocol/crypto.ts
index 784bd49..ebb552a 100644
--- a/client-web/source/protocol/crypto.ts
+++ b/client-web/source/protocol/crypto.ts
@@ -12,7 +12,7 @@ const IV_LENGTH = 12
const CRYPTO_SALT = base64_to_buf("keksmeet/cryptosaltAAA==")
const HASH_SALT = base64_to_buf("keksmeet/roomhashsaltA==")
-export async function crypto_seeded_key(seed: string): Promise<CryptoKey> {
+export async function derive_seeded_key(seed: string): Promise<CryptoKey> {
log("crypto", "deriving crytographic key...")
const seed_key = await window.crypto.subtle.importKey(
"raw",
@@ -32,7 +32,7 @@ export async function crypto_seeded_key(seed: string): Promise<CryptoKey> {
return key
}
-export async function crypto_hash(input: string): Promise<string> {
+export async function room_hash(input: string): Promise<string> {
log("crypto", "deriving room hash...")
const seed_key = await window.crypto.subtle.importKey(
"raw",
@@ -50,7 +50,7 @@ export async function crypto_hash(input: string): Promise<string> {
return hex
}
-export async function crypto_encrypt(key: CryptoKey, data: string): Promise<string> {
+export async function encrypt(key: CryptoKey, data: string): Promise<string> {
const iv = window.crypto.getRandomValues(new Uint8Array(IV_LENGTH));
const ciphertext = new Uint8Array(await window.crypto.subtle.encrypt(
{ name: "AES-GCM", iv },
@@ -64,7 +64,7 @@ export async function crypto_encrypt(key: CryptoKey, data: string): Promise<stri
return b64;
}
-export async function crypt_decrypt(key: CryptoKey, data: string): Promise<string> {
+export async function decrypt(key: CryptoKey, data: string): Promise<string> {
try {
const buf = base64_to_buf(data);
const iv = buf.slice(0, IV_LENGTH);
diff --git a/client-web/source/protocol/mod.ts b/client-web/source/protocol/mod.ts
index e82cf94..805600d 100644
--- a/client-web/source/protocol/mod.ts
+++ b/client-web/source/protocol/mod.ts
@@ -6,7 +6,7 @@
import { ClientboundPacket, RelayMessage, RelayMessageWrapper, ServerboundPacket } from "../../../common/packets.d.ts"
import { EventEmitter } from "../helper.ts";
import { log } from "../logger.ts"
-import { crypto_encrypt, crypto_seeded_key, crypt_decrypt, crypto_hash } from "./crypto.ts"
+import { encrypt, derive_seeded_key, decrypt, room_hash } from "./crypto.ts"
export class SignalingConnection {
websocket!: WebSocket
@@ -48,8 +48,8 @@ export class SignalingConnection {
async join(room: string) {
this.room = room;
- this.key = await crypto_seeded_key(room)
- this.room_hash = await crypto_hash(room)
+ this.key = await derive_seeded_key(room)
+ this.room_hash = await room_hash(room)
this.send_control({ join: { hash: this.room_hash } })
}
@@ -67,8 +67,14 @@ export class SignalingConnection {
this.control_handler.dispatch(packet)
if (packet.init) this.my_id = packet.init.your_id;
if (packet.message) {
- const plain_json = await crypt_decrypt(this.key!, packet.message.message)
- const plain: RelayMessageWrapper = JSON.parse(plain_json) // TODO make sure that protocol spec is met
+ const plain_json = await decrypt(this.key!, packet.message.message)
+
+ let plain: RelayMessageWrapper
+ try {
+ plain = JSON.parse(plain_json) // TODO make sure that protocol spec is met
+ } catch (_e) {
+ return log({ scope: "ws", warn: true }, "somebody sent invalid json");
+ }
if (plain.sender == packet.message.sender)
this.relay_handler.dispatch([packet.message.sender, plain.inner])
else {
@@ -83,7 +89,7 @@ export class SignalingConnection {
async send_relay(data: RelayMessage, recipient?: number | null) {
recipient ??= undefined // null -> undefined
const packet: RelayMessageWrapper = { inner: data, sender: this.my_id! }
- const message = await crypto_encrypt(this.key!, JSON.stringify(packet))
+ const message = await encrypt(this.key!, JSON.stringify(packet))
this.send_control({ relay: { recipient, message } })
}
}
diff --git a/client-web/source/room_watches.ts b/client-web/source/room_watches.ts
index 2e8d2f9..fd7d54b 100644
--- a/client-web/source/room_watches.ts
+++ b/client-web/source/room_watches.ts
@@ -6,7 +6,7 @@
/// <reference lib="dom" />
import { array_swap, e } from "./helper.ts";
import { PREFS, change_pref } from "./preferences/mod.ts";
-import { crypto_hash } from "./protocol/crypto.ts";
+import { room_hash } from "./protocol/crypto.ts";
import { SignalingConnection } from "./protocol/mod.ts";
interface Watch {
@@ -22,9 +22,15 @@ export function ui_room_watches(conn: SignalingConnection): HTMLElement {
let watches: Watch[] = []
const update_watches = () => (conn.send_control({ watch_rooms: watches.map(w => w.hash) }), update_listing());
- const add_watch = async (secret: string) => watches.push({ name: secret.split("#")[0], secret, hash: await crypto_hash(secret), user_count: 0 })
- const save_watches = () => change_pref("room_watches", JSON.stringify(watches.map(w => w.secret)))
- const load_watches = async () => { for (const secret of JSON.parse(PREFS.room_watches)) { await add_watch(secret) } update_watches() }
+ const add_watch = async (secret: string, hash?: string) => watches.push({ name: secret.split("#")[0], secret, hash: hash ?? await room_hash(secret), user_count: 0 })
+ const save_watches = () => change_pref("room_watches", JSON.stringify(watches.map(w => [w.secret, w.hash])))
+ const load_watches = async () => {
+ for (const stuff of JSON.parse(PREFS.room_watches)) {
+ if (typeof stuff == "string") await add_watch(stuff) // old format
+ else await add_watch(stuff[0], stuff[1])
+ }
+ update_watches()
+ }
conn.control_handler.add_listener(packet => {
if (packet.room_info) {
diff --git a/server/Cargo.toml b/server/Cargo.toml
index 1e4e236..b6225d2 100644
--- a/server/Cargo.toml
+++ b/server/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "keks-meet-server"
-version = "1.0.0"
+version = "1.0.1"
edition = "2021"
[dependencies]