Options -> Sicherheit: real master password

Identities, favorites (with their passwords), saved channel passwords and the
store admin token are kept AES-GCM encrypted (PBKDF2, 310k rounds) in one
localStorage entry and only decrypted in memory. The app asks for the password
on load before App is imported; "forgot password" wipes the encrypted data.
Enable, change and disable (the latter two re-ask the current password).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Hu2cuPLqpuKVfd9wWFFakU
This commit is contained in:
MoepchiandClaude Opus 5.5 committed 2026-10-23 20:43:40 +00:00
1 parent 14aa44c1c9
commit 440e7b7ae8
9 files changed
+377 -19

No files matched your search

+27
View File
@@ -4872,3 +4872,30 @@
background: var(--bg-toolbar-1);
border: 1px solid var(--border);
}
/* Master password unlock (main.tsx) */
.ts-vault-dialog {
display: flex;
flex-direction: column;
gap: 8px;
padding: 16px;
min-width: 300px;
}
.ts-vault-dialog h3,
.ts-vault-dialog p {
margin: 0;
}
.ts-vault-wrong {
color: var(--log-error);
}
.ts-master-form {
display: flex;
flex-direction: column;
gap: 6px;
margin: 4px 0 4px 24px;
max-width: 320px;
}
.ts-master-note {
margin: 0;
font-size: 0.9em;
}
+78 -7
View File
@@ -141,6 +141,7 @@ import {
type SoundEventId,
} from "./sounds";
import { parseSoundpack } from "./soundpack";
import { checkMasterPassword, isVaultUnlocked, removeMasterPassword, setMasterPassword } from "./vault";
import {
BUILTIN_PACK,
NO_SOUNDS_PACK,
@@ -6623,6 +6624,82 @@ function ChatPanel() {
);
}
/** Options -> Sicherheit -> "Master Passwort benutzen" / "ändern" (vault.ts). */
function MasterPasswordRow() {
const t = useT();
const [on, setOn] = useState(isVaultUnlocked);
// What the inline form is doing: turning it on, changing it, or turning it off.
const [mode, setMode] = useState<"enable" | "change" | "disable" | null>(null);
const [current, setCurrent] = useState("");
const [next, setNext] = useState("");
const [repeat, setRepeat] = useState("");
const [error, setError] = useState("");
const [busy, setBusy] = useState(false);
const open = (m: typeof mode) => {
setMode(m);
setCurrent("");
setNext("");
setRepeat("");
setError("");
};
const submit = async (e: React.FormEvent) => {
e.preventDefault();
if (mode !== "enable" && !(await checkMasterPassword(current))) return setError(t("vault.wrong"));
if (mode !== "disable" && next !== repeat) return setError(t("securitySettings.masterMismatch"));
setBusy(true);
if (mode === "disable") await removeMasterPassword();
else await setMasterPassword(next);
setBusy(false);
setOn(isVaultUnlocked());
setMode(null);
};
return (
<>
<div className="ts-security-row">
<label className="ts-options-checkbox" title={t("securitySettings.masterHint")}>
<input type="checkbox" checked={on || mode === "enable"} onChange={(e) => open(e.target.checked ? "enable" : "disable")} />
{t("securitySettings.masterPassword")}
</label>
<button disabled={!on} onClick={() => open("change")}>
{t("securitySettings.changeMasterPassword")}
</button>
</div>
{mode && (
<form className="ts-master-form" onSubmit={submit}>
{mode !== "enable" && (
<label className="ts-dialog-field">
{t("securitySettings.masterCurrent")}
<input type="password" autoFocus value={current} onChange={(e) => setCurrent(e.target.value)} />
</label>
)}
{mode !== "disable" && (
<>
<label className="ts-dialog-field">
{t("securitySettings.masterNew")}
<input type="password" autoFocus={mode === "enable"} value={next} onChange={(e) => setNext(e.target.value)} />
</label>
<label className="ts-dialog-field">
{t("securitySettings.masterRepeat")}
<input type="password" value={repeat} onChange={(e) => setRepeat(e.target.value)} />
</label>
</>
)}
{mode === "enable" && <p className="ts-master-note">{t("securitySettings.masterNote")}</p>}
{error && <p className="ts-vault-wrong">{error}</p>}
<div className="ts-security-row">
<button type="submit" disabled={busy || (mode === "disable" ? !current : !next)}>
{t("options.ok")}
</button>
<button type="button" onClick={() => setMode(null)}>
{t("options.cancel")}
</button>
</div>
</form>
)}
</>
);
}
function SecurityPanel({ onOpenIdentities, onClearCache }: { onOpenIdentities: () => void; onClearCache: () => void }) {
const t = useT();
const { security, setSecurity } = useContext(DisplayPrefsContext);
@@ -6652,13 +6729,7 @@ function SecurityPanel({ onOpenIdentities, onClearCache }: { onOpenIdentities: (
{t("securitySettings.clearChannelPasswords")}
</button>
</div>
<div className="ts-security-row">
<label className="ts-options-checkbox ts-options-disabled" title={t("design.notAvailable")}>
<input type="checkbox" disabled />
{t("securitySettings.masterPassword")}
</label>
<button disabled>{t("securitySettings.changeMasterPassword")}</button>
</div>
<MasterPasswordRow />
</fieldset>
<fieldset className="ts-options-fieldset">
<legend>{t("securitySettings.cleanup")}</legend>
+13 -1
View File
@@ -905,5 +905,17 @@
"notify.applyToFavorites": "Použít tento zvukový balíček pro všechny oblíbené",
"notify.applyToFavoritesConfirm": "Nastavit všem oblíbeným tento zvukový balíček? Vlastní balíčky jednotlivých oblíbených budou zrušeny.",
"notify.whenMuted.important": "Přehrávat jen důležité zvuky",
"notify.text.client": "Klient"
"notify.text.client": "Klient",
"vault.title": "Hlavní heslo",
"vault.prompt": "Vaše identity a uložená hesla jsou zašifrovány. Zadejte hlavní heslo.",
"vault.unlock": "Odemknout",
"vault.wrong": "Špatné heslo.",
"vault.forgot": "Zapomenuté heslo",
"vault.forgotConfirm": "Bez hesla nelze data obnovit. Trvale smazat identity, oblíbené a uložená hesla a začít znovu?",
"securitySettings.masterHint": "Šifruje identity, oblíbené (s hesly) a uložená hesla kanálů. Vyžaduje se po každém načtení.",
"securitySettings.masterCurrent": "Současné hlavní heslo",
"securitySettings.masterNew": "Nové hlavní heslo",
"securitySettings.masterRepeat": "Zopakovat",
"securitySettings.masterMismatch": "Hesla se neshodují.",
"securitySettings.masterNote": "Dobře si ho zapamatujte: bez něj přijdete o identity a uložená hesla."
}
+13 -1
View File
@@ -905,5 +905,17 @@
"notify.applyToFavorites": "Dieses Sound Pack für alle Favoriten verwenden",
"notify.applyToFavoritesConfirm": "Alle Favoriten auf dieses Sound Pack setzen? Eigene Sound Packs einzelner Favoriten werden dabei zurückgesetzt.",
"notify.whenMuted.important": "Nur wichtige Sounds spielen",
"notify.text.client": "Client"
"notify.text.client": "Client",
"vault.title": "Master Passwort",
"vault.prompt": "Deine Identitäten und gespeicherten Passwörter sind verschlüsselt. Gib dein Master Passwort ein.",
"vault.unlock": "Entsperren",
"vault.wrong": "Falsches Passwort.",
"vault.forgot": "Passwort vergessen",
"vault.forgotConfirm": "Ohne Passwort lassen sich die Daten nicht wiederherstellen. Identitäten, Favoriten und gespeicherte Passwörter endgültig löschen und neu anfangen?",
"securitySettings.masterHint": "Verschlüsselt Identitäten, Favoriten (mit Passwörtern) und gespeicherte Channel-Passwörter. Nach jedem Neuladen wird das Passwort abgefragt.",
"securitySettings.masterCurrent": "Aktuelles Master Passwort",
"securitySettings.masterNew": "Neues Master Passwort",
"securitySettings.masterRepeat": "Wiederholen",
"securitySettings.masterMismatch": "Die Passwörter stimmen nicht überein.",
"securitySettings.masterNote": "Merk es dir gut: Ohne das Passwort sind Identitäten und gespeicherte Passwörter weg."
}
+13 -1
View File
@@ -905,5 +905,17 @@
"notify.applyToFavorites": "Use this sound pack for all favorites",
"notify.applyToFavoritesConfirm": "Set all favorites to this sound pack? Sound packs set on individual favorites will be reset.",
"notify.whenMuted.important": "Play only important sounds",
"notify.text.client": "Client"
"notify.text.client": "Client",
"vault.title": "Master password",
"vault.prompt": "Your identities and saved passwords are encrypted. Enter your master password.",
"vault.unlock": "Unlock",
"vault.wrong": "Wrong password.",
"vault.forgot": "Forgot password",
"vault.forgotConfirm": "Without the password the data can't be recovered. Permanently delete identities, favorites and saved passwords and start over?",
"securitySettings.masterHint": "Encrypts identities, favorites (with passwords) and saved channel passwords. Asked for after every reload.",
"securitySettings.masterCurrent": "Current master password",
"securitySettings.masterNew": "New master password",
"securitySettings.masterRepeat": "Repeat",
"securitySettings.masterMismatch": "The passwords don't match.",
"securitySettings.masterNote": "Remember it well: without it, identities and saved passwords are lost."
}
+13 -1
View File
@@ -904,5 +904,17 @@
"notify.applyToFavorites": "استفاده از این بسته صدا برای همه موارد علاقه",
"notify.applyToFavoritesConfirm": "همه موارد علاقه روی این بسته صدا تنظیم شوند؟ بسته‌های صدای جداگانه بازنشانی می‌شوند.",
"notify.whenMuted.important": "فقط صداهای مهم پخش شوند",
"notify.text.client": "کلاینت"
"notify.text.client": "کلاینت",
"vault.title": "رمز اصلی",
"vault.prompt": "هویت‌ها و رمزهای ذخیره‌شده شما رمزنگاری شده‌اند. رمز اصلی را وارد کنید.",
"vault.unlock": "باز کردن",
"vault.wrong": "رمز اشتباه است.",
"vault.forgot": "رمز را فراموش کرده‌ام",
"vault.forgotConfirm": "بدون رمز، داده‌ها قابل بازیابی نیستند. هویت‌ها، موارد علاقه و رمزهای ذخیره‌شده برای همیشه حذف شوند و از نو شروع کنید؟",
"securitySettings.masterHint": "هویت‌ها، موارد علاقه (با رمزها) و رمزهای ذخیره‌شده کانال را رمزنگاری می‌کند. پس از هر بارگذاری پرسیده می‌شود.",
"securitySettings.masterCurrent": "رمز اصلی فعلی",
"securitySettings.masterNew": "رمز اصلی جدید",
"securitySettings.masterRepeat": "تکرار",
"securitySettings.masterMismatch": "رمزها یکسان نیستند.",
"securitySettings.masterNote": "آن را به خاطر بسپارید: بدون آن، هویت‌ها و رمزهای ذخیره‌شده از دست می‌روند."
}
+13 -1
View File
@@ -904,5 +904,17 @@
"notify.applyToFavorites": "将此声音包用于所有收藏",
"notify.applyToFavoritesConfirm": "将所有收藏设为此声音包?单个收藏的声音包设置将被重置。",
"notify.whenMuted.important": "仅播放重要声音",
"notify.text.client": "客户端"
"notify.text.client": "客户端",
"vault.title": "主密码",
"vault.prompt": "你的身份和已保存的密码已加密。请输入主密码。",
"vault.unlock": "解锁",
"vault.wrong": "密码错误。",
"vault.forgot": "忘记密码",
"vault.forgotConfirm": "没有密码无法恢复数据。永久删除身份、收藏和已保存的密码并重新开始?",
"securitySettings.masterHint": "加密身份、收藏(含密码)和已保存的频道密码。每次重新加载后都会询问。",
"securitySettings.masterCurrent": "当前主密码",
"securitySettings.masterNew": "新主密码",
"securitySettings.masterRepeat": "重复",
"securitySettings.masterMismatch": "两次密码不一致。",
"securitySettings.masterNote": "请牢记:没有它,身份和已保存的密码将丢失。"
}
+62 -7
View File
@@ -1,12 +1,67 @@
import './storageFallback'
import { StrictMode } from 'react'
import { StrictMode, useState, type FormEvent } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import './styles/greenteaspeak.css'
import App from './App.tsx'
import './App.css'
import { LanguageProvider, useT } from './i18n'
import { discardVault, hasVault, unlockVault } from './vault'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)
const root = createRoot(document.getElementById('root')!)
// App reads its stored identities/favorites while loading, so it's imported only after the vault is open.
async function start() {
const { default: App } = await import('./App.tsx')
root.render(
<StrictMode>
<App />
</StrictMode>,
)
}
function Unlock() {
const t = useT()
const [password, setPassword] = useState('')
const [wrong, setWrong] = useState(false)
const [busy, setBusy] = useState(false)
const submit = async (e: FormEvent) => {
e.preventDefault()
setBusy(true)
if (await unlockVault(password)) return void start()
setBusy(false)
setWrong(true)
}
return (
<div className="ts-dialog-backdrop">
<form className="ts-dialog ts-vault-dialog" onSubmit={submit}>
<h3>{t('vault.title')}</h3>
<p>{t('vault.prompt')}</p>
<input type="password" autoFocus value={password} onChange={(e) => setPassword(e.target.value)} />
{wrong && <p className="ts-vault-wrong">{t('vault.wrong')}</p>}
<div className="ts-dialog-buttons">
<button
type="button"
onClick={() => {
if (!window.confirm(t('vault.forgotConfirm'))) return
discardVault()
void start()
}}
>
{t('vault.forgot')}
</button>
<button type="submit" disabled={busy || !password}>
{t('vault.unlock')}
</button>
</div>
</form>
</div>
)
}
if (hasVault())
root.render(
<LanguageProvider>
<Unlock />
</LanguageProvider>,
)
else void start()
+145
View File
@@ -0,0 +1,145 @@
// Options -> Sicherheit -> "Master Passwort benutzen". The keys below hold secrets
// (identity private keys, server/channel passwords, the store admin token). With a
// master password they live AES-GCM encrypted in one localStorage entry and only in
// memory once unlocked. Like storageFallback.ts, this swaps window.localStorage for
// a stand-in, so the dozens of plain localStorage reads in the app keep working.
// main.tsx unlocks before importing App, whose module-level code reads these keys.
export const PROTECTED_KEYS = [
"webspeak3:identities",
"webspeak3:identity",
"webspeak3:favorites",
"webspeak3:channel-passwords",
"webspeak3:store-admin-token",
];
const VAULT_KEY = "webspeak3:vault";
const ITERATIONS = 310_000;
interface StoredVault {
salt: string;
iv: string;
data: string;
}
const real = window.localStorage;
let unlocked: { key: CryptoKey; salt: Uint8Array; secrets: Map<string, string> } | null = null;
const b64 = (bytes: Uint8Array) => btoa(String.fromCharCode(...bytes));
const unb64 = (s: string) => Uint8Array.from(atob(s), (c) => c.charCodeAt(0));
async function deriveKey(password: string, salt: Uint8Array): Promise<CryptoKey> {
const base = await crypto.subtle.importKey("raw", new TextEncoder().encode(password), "PBKDF2", false, ["deriveKey"]);
return crypto.subtle.deriveKey(
{ name: "PBKDF2", salt: salt as BufferSource, iterations: ITERATIONS, hash: "SHA-256" },
base,
{ name: "AES-GCM", length: 256 },
false,
["encrypt", "decrypt"]
);
}
export const hasVault = () => real.getItem(VAULT_KEY) !== null;
export const isVaultUnlocked = () => unlocked !== null;
// Writes are chained so an older encryption never lands after a newer one.
let writing: Promise<void> = Promise.resolve();
function persist(): Promise<void> {
writing = writing.then(async () => {
if (!unlocked) return;
const iv = crypto.getRandomValues(new Uint8Array(12));
const plain = new TextEncoder().encode(JSON.stringify(Object.fromEntries(unlocked.secrets)));
const data = new Uint8Array(await crypto.subtle.encrypt({ name: "AES-GCM", iv }, unlocked.key, plain));
real.setItem(VAULT_KEY, JSON.stringify({ salt: b64(unlocked.salt), iv: b64(iv), data: b64(data) } satisfies StoredVault));
});
return writing;
}
function installProxy(): void {
const secrets = () => unlocked!.secrets;
const isProtected = (k: string) => PROTECTED_KEYS.includes(k);
const proxy: Storage = {
get length() {
return real.length + secrets().size;
},
key: (i) => (i < real.length ? real.key(i) : ([...secrets().keys()][i - real.length] ?? null)),
getItem: (k) => (isProtected(k) ? (secrets().get(k) ?? null) : real.getItem(k)),
setItem: (k, v) => {
if (!isProtected(k)) return real.setItem(k, v);
secrets().set(k, String(v));
void persist();
},
removeItem: (k) => {
if (!isProtected(k)) return real.removeItem(k);
secrets().delete(k);
void persist();
},
clear: () => {
real.clear();
secrets().clear();
},
};
// Object.keys(localStorage) has to see real keys too.
for (let i = 0; i < real.length; i++) {
const k = real.key(i)!;
if (k !== VAULT_KEY) Object.defineProperty(proxy, k, { get: () => real.getItem(k), enumerable: true, configurable: true });
}
Object.defineProperty(window, "localStorage", { value: proxy, configurable: true });
}
async function openStored(password: string) {
await writing;
const stored: StoredVault = JSON.parse(real.getItem(VAULT_KEY)!);
const salt = unb64(stored.salt);
const key = await deriveKey(password, salt);
try {
const plain = await crypto.subtle.decrypt({ name: "AES-GCM", iv: unb64(stored.iv) as BufferSource }, key, unb64(stored.data) as BufferSource);
return { key, salt, secrets: new Map<string, string>(Object.entries(JSON.parse(new TextDecoder().decode(plain)))) };
} catch {
return null; // wrong password
}
}
/** false = wrong password. */
export async function unlockVault(password: string): Promise<boolean> {
unlocked = await openStored(password);
if (unlocked) installProxy();
return unlocked !== null;
}
/** Re-asks the current password before changing or removing it. */
export const checkMasterPassword = async (password: string) => (await openStored(password)) !== null;
/** Turns the master password on, or changes it when already on. */
export async function setMasterPassword(password: string): Promise<void> {
const salt = crypto.getRandomValues(new Uint8Array(16));
const key = await deriveKey(password, salt);
if (unlocked) {
unlocked = { ...unlocked, key, salt };
} else {
const secrets = new Map<string, string>();
for (const k of PROTECTED_KEYS) {
const v = real.getItem(k);
if (v !== null) secrets.set(k, v);
}
unlocked = { key, salt, secrets };
installProxy();
}
await persist();
for (const k of PROTECTED_KEYS) real.removeItem(k);
}
/** Turns it off: secrets go back to plain localStorage. */
export async function removeMasterPassword(): Promise<void> {
if (!unlocked) return;
await writing;
for (const [k, v] of unlocked.secrets) real.setItem(k, v);
real.removeItem(VAULT_KEY);
unlocked = null;
Object.defineProperty(window, "localStorage", { value: real, configurable: true });
}
/** "Passwort vergessen": drops the encrypted data for good. */
export function discardVault(): void {
real.removeItem(VAULT_KEY);
}