From 1bee9c94e8db4ff846b35b72c0417c8a9440b5a8 Mon Sep 17 00:00:00 2001 From: faumaray Date: Wed, 14 Oct 2026 00:17:05 +0300 Subject: [PATCH] client: myTeamSpeak support leaves the client The public client repository must not carry third_party/schema-api: TeamSpeak's non-public myTeamSpeak API protocol definitions, which came without a licence. The account sign-in built on them (crates/voelin-myts) goes with it, since nothing else in the client used that snapshot. Removed: third_party/schema-api, crates/voelin-myts, the account module of voelin-ui (sign-in, saved session, profile, avatar, badges, User Tag), the login page at start and the live account test of voelin-core. The workspace members, default-members and exclude lists, both manifests and Cargo.lock no longer name them (tonic, prost-build and their dependencies drop out of the lock file and THIRD_PARTY_NOTICES.md; about.hbs has no schema-api section). Settings -> My Account keeps the identity in use and shows a note that account sign-in is not available in this build. The Slint account screens stay, fed neutral values (Bridge.myts keeps its default: signed out, not available, no prompt), so the account can return without redoing them. The TeamSpeak protocol parts in tsproto/tsclientlib (myTS ID, other users' badges and avatars) are untouched. The account returns later through the gateway library (VoelinGateWay); the research notes in docs/research/myteamspeak.md stay and say so. CHANGELOG, docs/ui.md, docs/identity.md and SECURITY.md no longer describe the account as present. A session an earlier build saved stays in the system keyring (item myts/session) until the user deletes it. Co-Authored-By: Claude Sonnet 5.5 --- CHANGELOG.md | 30 +- Cargo.lock | 233 --- Cargo.toml | 4 +- SECURITY.md | 13 +- THIRD_PARTY_NOTICES.md | 67 +- about.hbs | 7 - crates/voelin-core/Cargo.toml | 1 - crates/voelin-core/src/lib.rs | 3 +- crates/voelin-core/tests/myts_live.rs | 149 -- crates/voelin-ui/Cargo.toml | 5 - crates/voelin-ui/src/app.rs | 19 - crates/voelin-ui/src/bind/settings.rs | 23 - crates/voelin-ui/src/dev.rs | 51 +- crates/voelin-ui/src/images.rs | 13 +- crates/voelin-ui/src/lib.rs | 2 - crates/voelin-ui/src/main.rs | 2 +- crates/voelin-ui/src/myts.rs | 1741 --------------------- crates/voelin-ui/src/settings.rs | 4 - crates/voelin-ui/ui/bridge.slint | 2 + crates/voelin-ui/ui/screens/account.slint | 9 +- docs/identity.md | 22 +- docs/research/myteamspeak.md | 9 +- docs/research/ui-review.md | 4 +- docs/ui.md | 30 +- 24 files changed, 58 insertions(+), 2385 deletions(-) delete mode 100644 crates/voelin-core/tests/myts_live.rs delete mode 100644 crates/voelin-ui/src/myts.rs diff --git a/CHANGELOG.md b/CHANGELOG.md index 26eea85..0255379 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,10 +8,6 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows ### Added -- myTeamSpeak profile: Settings → My Account shows the account's avatar, - description, registration date, previous sign-in, badges and signed-in - devices from the account service; the avatar is also the sidebar's - profile picture where a server has none for us. - Log files: each run logs to `/voelin/logs/voelin.log`, the previous four runs are kept; `VOELIN_LOG` sets what is logged. Settings → Advanced opens the folder. @@ -28,8 +24,7 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - Other people's myTeamSpeak badges: up to three pictures after their name in the channel tree and the members panel, and their names on the member card (what each is for on hover). On TeamSpeak 6 the badges the server - verified come first, the ones you chose in Settings → My Account - included. + verified come first. - Links in chat open in the browser; one whose text is not its address first shows where it goes. A right-click on a link opens or copies it. - `ts3server://` and `teamspeak://` links in chat (and `tmspk.gg/s/…`) @@ -47,16 +42,6 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows - Other users' myTeamSpeak avatars (TeamSpeak 6), as the official client shows them: where the server has no avatar of them, its avatar could not be downloaded, or the server is only observed. -- Voice connections show servers the account's avatar, the badges chosen - in Settings → My Account (up to three) and its User Tag, as the official - client does, so other TeamSpeak 6 users see them; again after a - reconnect or an account change, and cleared on sign-out. A saved session - is enough: the avatar, its certificate, the signed badges and the User - Tag's token come from myTeamSpeak's services, and Voelin checks each - signature as the server does before sending it. The log says what the - server published. -- Settings → My Account shows the account's User Tag and lets you choose the - badges servers show. - Pictures (banners, avatars) go through the desktop's proxy where the desktop portal names one (Linux), and through the system proxy on Windows and macOS; SOCKS proxies work too. @@ -84,8 +69,6 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows ### Changed -- New login page; it no longer opens when a session is saved (only when one - has expired), and "Continue without an account" is remembered. - Selecting a server observes it through its gateway at once; the Observe button is gone. The server dialog asks only for the address, password, name and nickname: the gateway is found from the address. @@ -186,10 +169,17 @@ User-visible changes of the apps and the `tsgw` gateway. The format follows the TeamSpeak server is still down and connects once it is up, its `/health` says what is missing, and it stops cleanly on SIGTERM. +### Removed + +- myTeamSpeak account sign-in, profile, avatar, badges and User Tag: the + login page at start, the sign-in form and profile in Settings → My Account + (it says "Account sign-in is not available in this build"), and the account + presented to voice servers. They return through the gateway. A session an + earlier build saved stays in the system keyring (item `myts/session`) + until you delete it there. + ### Fixed -- The account's avatar is downloaded from its own link; it was asked for - as an upload link and refused with HTTP 403. - Hover help in the Stream Studio (a source's error, the status details) shows each time and closes when the pointer leaves; it showed only once, and stayed open until a click. diff --git a/Cargo.lock b/Cargo.lock index 9158e7c..4266890 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3502,19 +3502,6 @@ dependencies = [ "tower-service", ] -[[package]] -name = "hyper-timeout" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2b90d566bffbce6a75bd8b09a05aa8c2cb1fabb6cb348f8840c9e4c90a0d83b0" -dependencies = [ - "hyper", - "hyper-util", - "pin-project-lite", - "tokio", - "tower-service", -] - [[package]] name = "hyper-util" version = "0.1.21" @@ -4879,12 +4866,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "multimap" -version = "0.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d87ecb2933e8aeadb3e3a02b828fed80a7528047e68b4f424523a0981a3a084" - [[package]] name = "multiversion_no_op" version = "1.0.0" @@ -5863,7 +5844,6 @@ checksum = "112d82ceb8c5bf524d9af484d4e4970c9fd5a0cc15ba14ad93dccd28873b0629" dependencies = [ "digest 0.11.3", "hmac 0.13.0", - "sha2 0.11.0", ] [[package]] @@ -6342,27 +6322,6 @@ dependencies = [ "prost-derive", ] -[[package]] -name = "prost-build" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03da047801ff44bb6a4d407d4860c05fd70bb81714e6b2f3812603d5b145b042" -dependencies = [ - "heck", - "itertools 0.14.0", - "log", - "multimap", - "petgraph", - "prettyplease", - "prost", - "prost-types", - "pulldown-cmark", - "pulldown-cmark-to-cmark", - "regex", - "syn 2.0.119", - "tempfile", -] - [[package]] name = "prost-derive" version = "0.14.4" @@ -6376,79 +6335,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "prost-types" -version = "0.14.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f94967dc7688f3054c7fac87473ffae4cc4c3904800e2d9f5b857246d8963b0a" -dependencies = [ - "prost", -] - -[[package]] -name = "protoc-bin-vendored" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d1c381df33c98266b5f08186583660090a4ffa0889e76c7e9a5e175f645a67fa" -dependencies = [ - "protoc-bin-vendored-linux-aarch_64", - "protoc-bin-vendored-linux-ppcle_64", - "protoc-bin-vendored-linux-s390_64", - "protoc-bin-vendored-linux-x86_32", - "protoc-bin-vendored-linux-x86_64", - "protoc-bin-vendored-macos-aarch_64", - "protoc-bin-vendored-macos-x86_64", - "protoc-bin-vendored-win32", -] - -[[package]] -name = "protoc-bin-vendored-linux-aarch_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c350df4d49b5b9e3ca79f7e646fde2377b199e13cfa87320308397e1f37e1a4c" - -[[package]] -name = "protoc-bin-vendored-linux-ppcle_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a55a63e6c7244f19b5c6393f025017eb5d793fd5467823a099740a7a4222440c" - -[[package]] -name = "protoc-bin-vendored-linux-s390_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1dba5565db4288e935d5330a07c264a4ee8e4a5b4a4e6f4e83fad824cc32f3b0" - -[[package]] -name = "protoc-bin-vendored-linux-x86_32" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8854774b24ee28b7868cd71dccaae8e02a2365e67a4a87a6cd11ee6cdbdf9cf5" - -[[package]] -name = "protoc-bin-vendored-linux-x86_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b38b07546580df720fa464ce124c4b03630a6fb83e05c336fea2a241df7e5d78" - -[[package]] -name = "protoc-bin-vendored-macos-aarch_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "89278a9926ce312e51f1d999fee8825d324d603213344a9a706daa009f1d8092" - -[[package]] -name = "protoc-bin-vendored-macos-x86_64" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81745feda7ccfb9471d7a4de888f0652e806d5795b61480605d4943176299756" - -[[package]] -name = "protoc-bin-vendored-win32" -version = "3.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "95067976aca6421a523e491fce939a3e65249bac4b977adee0ee9771568e8aa3" - [[package]] name = "pulldown-cmark" version = "0.13.4" @@ -6460,15 +6346,6 @@ dependencies = [ "unicase", ] -[[package]] -name = "pulldown-cmark-to-cmark" -version = "22.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84bbb29c624230c4bd1047bbdb2aa47e41c860e9665ce62ba9504eebe91bf867" -dependencies = [ - "pulldown-cmark", -] - [[package]] name = "pxfm" version = "0.1.30" @@ -7264,7 +7141,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d41d731c7d2f962d1ccc364cec258de3c0e93b38c2fb3ba97ac74513048d634" dependencies = [ "aws-lc-rs", - "log", "once_cell", "rustls-pki-types", "rustls-webpki", @@ -7382,20 +7258,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "schema-api" -version = "0.1.0" -dependencies = [ - "prost", - "prost-build", - "prost-types", - "protoc-bin-vendored", - "thiserror 2.0.21", - "tonic", - "tonic-prost", - "tonic-prost-build", -] - [[package]] name = "scoped-tls" version = "1.0.1" @@ -8856,76 +8718,6 @@ version = "1.1.2+spec-1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d56353a2a665ad0f41a421187180aab746c8c325620617ad883a99a1cbe66d2" -[[package]] -name = "tonic" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ac2a5518c70fa84342385732db33fb3f44bc4cc748936eb5833d2df34d6445ef" -dependencies = [ - "async-trait", - "axum", - "base64 0.22.1", - "bytes", - "h2", - "http", - "http-body", - "http-body-util", - "hyper", - "hyper-timeout", - "hyper-util", - "percent-encoding", - "pin-project", - "rustls-native-certs", - "socket2", - "sync_wrapper", - "tokio", - "tokio-rustls", - "tokio-stream", - "tower", - "tower-layer", - "tower-service", - "tracing", -] - -[[package]] -name = "tonic-build" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c68f61875ac5293cf72e6c8cf0158086428c82c37229e98c840878f1706b0322" -dependencies = [ - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.119", -] - -[[package]] -name = "tonic-prost" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "50849f68853be452acf590cde0b146665b8d507b3b8af17261df47e02c209ea0" -dependencies = [ - "bytes", - "prost", - "tonic", -] - -[[package]] -name = "tonic-prost-build" -version = "0.14.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "654e5643eff75d7f8c99197ce1440ed19a3474eada74c12bbac488b2cafdae27" -dependencies = [ - "prettyplease", - "proc-macro2", - "prost-build", - "prost-types", - "quote", - "syn 2.0.119", - "tempfile", - "tonic-build", -] - [[package]] name = "tower" version = "0.5.3" @@ -8934,12 +8726,9 @@ checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" dependencies = [ "futures-core", "futures-util", - "indexmap", "pin-project-lite", - "slab", "sync_wrapper", "tokio", - "tokio-util", "tower-layer", "tower-service", "tracing", @@ -9721,7 +9510,6 @@ dependencies = [ "voelin-gateway-proto", "voelin-media", "voelin-model", - "voelin-myts", "voelin-observer", "voelin-platform", "voelin-query", @@ -9825,26 +9613,6 @@ dependencies = [ "serde_json", ] -[[package]] -name = "voelin-myts" -version = "0.1.0" -dependencies = [ - "aes 0.9.3", - "aes-gcm", - "base64 0.22.1", - "ctr 0.10.1", - "curve25519-dalek 4.1.3", - "pbkdf2", - "reqwest", - "schema-api", - "sha2 0.10.9", - "subtle", - "thiserror 2.0.21", - "tokio", - "tsproto", - "zeroize", -] - [[package]] name = "voelin-observer" version = "0.1.0" @@ -9942,7 +9710,6 @@ dependencies = [ "voelin-core", "voelin-gateway-proto", "voelin-model", - "voelin-myts", "voelin-platform", "voelin-query", "voelin-store", diff --git a/Cargo.toml b/Cargo.toml index fe024ed..db62918 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -2,7 +2,7 @@ resolver = "3" # third_party: vendored crates patched in below (not workspace members, so # their own tests and dev-dependencies stay out of our builds). -exclude = ["fuzz", "third_party", "third_party/schema-api"] +exclude = ["fuzz", "third_party"] members = [ "crates/proto/tsproto-types", "crates/proto/tsproto-structs", @@ -17,7 +17,6 @@ members = [ "crates/voelin-gateway-proto", "crates/voelin-media", "crates/voelin-model", - "crates/voelin-myts", "crates/voelin-observer", "crates/voelin-platform", "crates/voelin-query", @@ -38,7 +37,6 @@ default-members = [ "crates/voelin-gateway", "crates/voelin-gateway-proto", "crates/voelin-model", - "crates/voelin-myts", "crates/voelin-observer", "crates/voelin-platform", "crates/voelin-query", diff --git a/SECURITY.md b/SECURITY.md index fc7c3d8..5256bbb 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -21,16 +21,15 @@ dependencies to their projects (tell us too if this client is affected). ## What the client stores -There is no telemetry and no account with us. The only outside account is -the optional myTeamSpeak sign-in (desktop), which talks to TeamSpeak's -service at `clientapi.myteamspeak.com`: at sign-in, when a saved session is -checked at start, and at sign-out. +There is no telemetry and no account with us, and the client signs in to no +account service. (Builds before this one had an optional myTeamSpeak sign-in; +its saved session stays in the keyring, item `myts/session`, until you delete +it there.) | What | Where | Protection | |---|---|---| | Identities (TeamSpeak private keys) | SQLite database `client.db` in the data directory (`~/.local/share/voelin`, Flatpak `~/.var/app//data/voelin`, `%APPDATA%\voelin`, Android app storage) | File permissions of the user account only; not encrypted. An identity is the account on every server that knows it: back it up, do not share the file | | Server and ServerQuery passwords | OS keyring (Secret Service, Windows Credential Manager, Android Keystore), service `voelin` | Keyring; kept in memory for the session only when there is no keyring | -| myTeamSpeak account (optional sign-in, desktop): session, renewal and one-time-code renewal tokens, device id, email, username, account id and the account's private signing key | OS keyring, service `voelin`, item `myts/session` | Keyring only: without one the sign-in is not kept, not even in memory. Passwords and one-time codes are never stored. Signing out deletes the item and ends the session at TeamSpeak | | Bookmarks, settings, chat history | `client.db` | File permissions; history stays until deleted | | Crash reports (opt-in) | `crash-reports` in the state directory (`~/.local/state/voelin`, `%LOCALAPPDATA%\voelin`) | Local only, never uploaded. They contain the panic message and a backtrace, which may include server addresses or names; review before attaching one to an issue | | OpenH264 (opt-in) | Downloaded from Cisco into the app's directories | Loaded only if its SHA-256 matches a known Cisco build | @@ -40,10 +39,6 @@ checked at start, and at sign-out. - **Voice connections** use the TeamSpeak protocol's encryption. The server and its admins see what any client sees: your nickname, identity, IP address, channel and messages. -- **Signed in to myTeamSpeak**, every voice server you join also gets your - account's myTeamSpeak id with a proof signed by the account, which links - your visits to different servers to one account. Signing out clears it on - the servers you are on. - **Streams (TeamSpeak 6)** are peer-to-peer WebRTC (DTLS-SRTP). Viewers and streamers exchange ICE candidates, so **they learn each other's IP addresses**, including local network addresses. Only watch and share diff --git a/THIRD_PARTY_NOTICES.md b/THIRD_PARTY_NOTICES.md index e3d8cec..d3c2aef 100644 --- a/THIRD_PARTY_NOTICES.md +++ b/THIRD_PARTY_NOTICES.md @@ -53,13 +53,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```` -## schema-api - -The account client uses message bindings and session helpers from the local -schema-api 0.1.0 snapshot vendored under third_party/schema-api. The supplied -snapshot has no declared license or license file; no MIT or Apache license is -implied for it or its supplied schemas. See its VOELIN-PATCH.md for provenance. - ## Native libraries - Opus (libopus), compiled into the app: BSD-3-Clause, Copyright 2001-2023 @@ -182,8 +175,8 @@ the crate's authors are listed as its copyright holders. | License | Crates | |---|---| -| MIT License | 661 | -| Apache License 2.0 | 32 | +| MIT License | 658 | +| Apache License 2.0 | 31 | | Unicode License v3 | 26 | | BSD 3-Clause "New" or "Revised" License | 22 | | LicenseRef-Slint-Royalty-free-2.0 | 12 | @@ -1026,7 +1019,7 @@ Used by: cpal 0.18.2, imgref 1.12.3, self_cell 1.3.0, unicode-linebreak 0.1.5 ```` -Used by: gethostname 1.1.0, prost-derive 0.14.4, prost-types 0.14.4, prost 0.14.4 +Used by: gethostname 1.1.0, prost-derive 0.14.4, prost 0.14.4 ````text Apache License @@ -7906,31 +7899,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```` -Used by: tonic 0.14.6 - -````text -Copyright (c) 2025 Lucio Franco - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. - -```` - Used by: secret-service 5.2.0 ````text @@ -9846,7 +9814,6 @@ Standard text, used by: - str0m-proto 0.7.0: Martin Algesten (https://github.com/algesten/str0m) - taffy 0.10.1: Alice Cecile , Johnathan Kelley , Nico Burns (https://github.com/DioxusLabs/taffy) - tauri-winrt-notification 0.7.3: allenbenz, Tauri Programme within The Commons Conservancy (https://github.com/tauri-apps/winrt-notification) -- tonic-prost 0.14.6: Lucio Franco (https://github.com/hyperium/tonic) - tract-extra 0.23.8: Mathieu Poumeyrol (https://github.com/sonos/tract) - tract-transformers 0.23.8: Mathieu Poumeyrol , Louis Chouraki (https://github.com/sonos/tract) - windows-collections 0.2.0 (https://github.com/microsoft/windows-rs) @@ -10812,34 +10779,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -```` - -Used by: hyper-timeout 0.5.2 - -````text -The MIT License (MIT) - -Copyright (c) 2016 The weldr Project Developers - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. - - ```` Used by: same-file 1.0.6, winapi-util 0.1.11 diff --git a/about.hbs b/about.hbs index 4c9efc4..926f2e7 100644 --- a/about.hbs +++ b/about.hbs @@ -53,13 +53,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ```` -## schema-api - -The account client uses message bindings and session helpers from the local -schema-api 0.1.0 snapshot vendored under third_party/schema-api. The supplied -snapshot has no declared license or license file; no MIT or Apache license is -implied for it or its supplied schemas. See its VOELIN-PATCH.md for provenance. - ## Native libraries - Opus (libopus), compiled into the app: BSD-3-Clause, Copyright 2001-2023 diff --git a/crates/voelin-core/Cargo.toml b/crates/voelin-core/Cargo.toml index 7b71e37..f99d859 100644 --- a/crates/voelin-core/Cargo.toml +++ b/crates/voelin-core/Cargo.toml @@ -69,7 +69,6 @@ bytes = "1" http = "1" # Already in the app's graph (reqwest); for one_rustls_crypto_provider. rustls = { version = "0.23", default-features = false } -voelin-myts = { path = "../voelin-myts" } # `process`: the browser interop test drives Chromium through Node.js. tokio = { version = "1", features = ["macros", "net", "process", "rt-multi-thread", "test-util"] } diff --git a/crates/voelin-core/src/lib.rs b/crates/voelin-core/src/lib.rs index 8a15086..c2142c7 100644 --- a/crates/voelin-core/src/lib.rs +++ b/crates/voelin-core/src/lib.rs @@ -1105,8 +1105,7 @@ fn command_session(command: &Command) -> SessionId { /// The app has one rustls crypto provider. With two (aws-lc-rs and ring), a /// TLS client built without an explicit provider panics: `wss://` gateways -/// did. This test's build has the app's TLS dependencies (reqwest here, -/// tonic through the voelin-myts dev-dependency). +/// did. This test's build has the app's TLS dependencies (reqwest). #[cfg(test)] #[test] fn one_rustls_crypto_provider() { diff --git a/crates/voelin-core/tests/myts_live.rs b/crates/voelin-core/tests/myts_live.rs deleted file mode 100644 index 64b9e02..0000000 --- a/crates/voelin-core/tests/myts_live.rs +++ /dev/null @@ -1,149 +0,0 @@ -//! Opt-in account + isolated server interoperability check. No keys are saved. -//! Requires VOELIN_MYTS_LIVE=1, EMAIL/PASSWORD/DEVICE_ID and optional OTP under -//! the VOELIN_MYTS_ prefix; TEST_TS3/TEST_TS6 and QUERY_TS3/QUERY_TS6 give -//! loopback voice/query addresses. QUERY_PASSWORD authenticates local query. -#![cfg(not(target_os = "android"))] - -use std::{sync::Arc, time::Duration}; - -use anyhow::{Context, Result, bail, ensure}; -use tokio::{sync::broadcast, time::timeout}; -use voelin_core::{Command, Engine, Event, VoiceOptions, VoiceState}; -use voelin_myts::{Client, ServerIdentity}; -use voelin_query::{Command as QueryCommand, QueryClient, Row}; - -fn env(name: &str) -> Result { - std::env::var(format!("VOELIN_MYTS_{name}")).with_context(|| format!("missing {name}")) -} - -async fn connected(events: &mut broadcast::Receiver, session_id: u64) -> Result { - timeout(Duration::from_secs(35), async { - loop { - match events.recv().await? { - Event::State { session, state } - if session == session_id && state.voice == VoiceState::Connected => - { - if let Some(id) = state.own_client { - return Ok(id); - } - } - Event::Error { message, .. } => bail!("engine: {message}"), - _ => {} - } - } - }) - .await? -} - -async fn info(query: &QueryClient, client: u16) -> Result { - query - .send(&QueryCommand::new("clientinfo").arg("clid", client)) - .await? - .into_iter() - .next() - .context("clientinfo missing") -} - -async fn wait_id(query: &QueryClient, client: u16, expected: &str) -> Result<()> { - timeout(Duration::from_secs(12), async { - loop { - let row = info(query, client).await?; - if row.get("client_myteamspeak_id") == Some(expected) { - return Ok(()); - } - tokio::time::sleep(Duration::from_millis(200)).await; - } - }) - .await - .context("server did not report the expected myTS association")? -} - -async fn server(identity: Arc, kind: &str) -> Result<()> { - let address = env(&format!("TEST_{kind}"))?; - let query_address = env(&format!("QUERY_{kind}"))?; - // This test is deliberately limited to caller-owned loopback test servers. - ensure!(address.starts_with("127.0.0.1:"), "voice endpoint must be loopback"); - ensure!(query_address.starts_with("127.0.0.1:"), "query endpoint must be loopback"); - let (query, _) = QueryClient::connect(&voelin_query::Connect { - transport: if kind == "TS3" { - voelin_query::Transport::Raw - } else { - voelin_query::Transport::Ssh - }, - addr: query_address, - user: "serveradmin".into(), - secret: Some(env("QUERY_PASSWORD")?), - server_id: Some(1), - server_port: None, - line: voelin_query::LineOptions { rate_limit: None, ..Default::default() }, - }) - .await?; - let engine = Engine::start(); - let mut events = engine.subscribe(); - let result = async { - engine.send(Command::SetMytsIdentity(Some(identity.clone()))); - for session in 1..=2 { - engine.send(Command::ConnectVoice { - session, - options: Box::new(VoiceOptions::new(&address, format!("myts-proof-{session}"))), - }); - let client = connected(&mut events, session).await?; - let row = info(&query, client).await?; - let version = voelin_core::versions::native_version()?; - ensure!(row.get("client_platform") == Some(version.get_platform()), "wrong platform"); - ensure!( - row.get("client_version") == Some(version.get_version_string()), - "wrong version" - ); - let metadata: serde_json::Value = - serde_json::from_str(row.get("client_meta_data").context("missing metadata")?)?; - ensure!(metadata["name"] == "Voelin", "wrong client metadata"); - ensure!(metadata["platform"] == std::env::consts::OS, "wrong metadata platform"); - eprintln!("{kind}: native platform/Voelin metadata passed"); - wait_id(&query, client, &identity.id()).await?; - eprintln!("{kind}: signed clientinit myTS ID passed"); - // Two fresh connections prove the signature is bound to each handshake. - engine.send(Command::SetMytsIdentity(None)); - wait_id(&query, client, "").await?; - engine.send(Command::SetMytsIdentity(Some(identity.clone()))); - wait_id(&query, client, &identity.id()).await?; - eprintln!("{kind}: live clear and reattach passed"); - engine.send(Command::CloseSession { session }); - } - Ok(()) - } - .await; - engine.send(Command::SetMytsIdentity(None)); - for session in 1..=2 { - engine.send(Command::CloseSession { session }); - } - query.quit().await; - result -} - -#[tokio::test(flavor = "multi_thread")] -#[ignore = "requires owner-authorized account and isolated loopback servers"] -async fn authenticated_account_and_server_lifecycle() -> Result<()> { - ensure!(env("LIVE")? == "1", "explicit live opt-in required"); - let client = Client::new()?; - let login = client - .login(&env("EMAIL")?, &env("PASSWORD")?, env("OTP").ok().as_deref(), &env("DEVICE_ID")?) - .await?; - // Capture every result before deleting the newly created remote session. - let result = async { - client.validate_session(&login.token).await?; - let identity = Arc::new(login.identity.context("server identity unlock failed")?); - let mut failures = Vec::new(); - for kind in ["TS3", "TS6"] { - if let Err(error) = server(identity.clone(), kind).await { - failures.push(format!("{kind}: {error:#}")); - } - } - ensure!(failures.is_empty(), "{}", failures.join("; ")); - Ok(()) - } - .await; - let logout = client.logout(&login.token).await; - logout.context("remote test session revocation failed")?; - result -} diff --git a/crates/voelin-ui/Cargo.toml b/crates/voelin-ui/Cargo.toml index ffd9849..e65f845 100644 --- a/crates/voelin-ui/Cargo.toml +++ b/crates/voelin-ui/Cargo.toml @@ -49,7 +49,6 @@ tsclientlib = { path = "../proto/tsclientlib" } # Desktop: the keyring for passwords, stream media with libvpx, OpenH264, X11 # and PipeWire, global hotkeys through the portal and X11. [target.'cfg(not(target_os = "android"))'.dependencies] -voelin-myts = { path = "../voelin-myts" } # winit's focus events (an unstable API, so this minor version only): # messages are read only while the window has the focus (`app::watch_focus`). slint = { version = "~1.18", features = ["renderer-software", "unstable-winit-030"] } @@ -69,9 +68,5 @@ voelin-core = { path = "../voelin-core", default-features = false, features = [" [build-dependencies] slint-build = "1.18" -[dev-dependencies] -# Certificates and signatures from a synthetic root for the account tests. -voelin-myts = { path = "../voelin-myts", features = ["testing"] } - [lints] workspace = true diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 5eaa4b8..8ca562d 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -98,9 +98,6 @@ fn default_secrets() -> Box { #[cfg(not(target_os = "android"))] impl Secrets for FallbackSecrets { fn get(&self, key: &str) -> voelin_store::Result> { - if key.starts_with("myts/") { - return self.keyring.get(key); - } match self.memory.get(key)? { Some(v) => Ok(Some(v)), None => Ok(self.keyring.get(key).unwrap_or(None)), @@ -108,9 +105,6 @@ impl Secrets for FallbackSecrets { } fn set(&self, key: &str, value: &str) -> voelin_store::Result<()> { - if key.starts_with("myts/") { - return self.keyring.set(key, value); - } if let Err(error) = self.keyring.set(key, value) { warn!(%error, "keyring unavailable, keeping the secret for this session only"); return self.memory.set(key, value); @@ -119,9 +113,6 @@ impl Secrets for FallbackSecrets { } fn delete(&self, key: &str) -> voelin_store::Result<()> { - if key.starts_with("myts/") { - return self.keyring.delete(key); - } let _ = self.keyring.delete(key); self.memory.delete(key) } @@ -571,10 +562,6 @@ impl Models { } pub(crate) struct App { - #[cfg(not(target_os = "android"))] - pub runtime: tokio::runtime::Handle, - #[cfg(not(target_os = "android"))] - pub myts: crate::myts::Account, pub ui: slint::Weak, pub store: Store, pub secrets: Box, @@ -834,10 +821,6 @@ pub fn run(options: RunOptions) -> Result<()> { let mut video = Video::new(&dir, settings.openh264); video.set_decoder_preference(decoder_preference(&prefs)); let app = App { - #[cfg(not(target_os = "android"))] - runtime: runtime.clone(), - #[cfg(not(target_os = "android"))] - myts: crate::myts::Account::new(dir.join("account")), ui: ui.as_weak(), store, // The sample data of VOELIN_DEMO_UI never reaches the system keyring. @@ -910,8 +893,6 @@ pub fn run(options: RunOptions) -> Result<()> { app.refresh_home(); app.refresh_notices(); app.refresh_pages(); - #[cfg(not(target_os = "android"))] - app.start_myts(); if app.demo { app.start_demo(); } diff --git a/crates/voelin-ui/src/bind/settings.rs b/crates/voelin-ui/src/bind/settings.rs index 10c52b9..7654074 100644 --- a/crates/voelin-ui/src/bind/settings.rs +++ b/crates/voelin-ui/src/bind/settings.rs @@ -6,29 +6,6 @@ use crate::app::{Bridge, MainWindow, with_app}; pub(super) fn wire(ui: &MainWindow) { let bridge = ui.global::(); - #[cfg(not(target_os = "android"))] - { - bridge.on_myts_login(|email, password, otp| { - with_app(|app| { - app.myts_login(email.to_string(), password.to_string(), otp.to_string()) - }); - }); - bridge.on_myts_logout(|| { - with_app(|app| app.myts_logout()); - }); - bridge.on_myts_dismiss(|| { - with_app(|app| app.myts_dismiss()); - }); - bridge.on_myts_retry(|| { - with_app(|app| app.myts_retry()); - }); - bridge.on_myts_portal(|action| { - with_app(|app| app.myts_portal(action)); - }); - bridge.on_myts_badge(|index, on| { - with_app(|app| app.myts_badge(index, on)); - }); - } bridge.on_open_settings(|| { with_app(|app| app.open_settings()); }); diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index 9f61f7b..46b32b3 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -84,8 +84,7 @@ use voelin_model::{ use voelin_store::{Bookmark, MessageSource}; use crate::app::{ - App, Bridge, MainWindow, MobileTab, MytsBadge, Nav, Page, RecordingItem, SettingsSection, - with_app, + App, Bridge, MainWindow, MobileTab, Nav, Page, RecordingItem, SettingsSection, with_app, }; use crate::settings::LastVoice; @@ -197,54 +196,6 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { for open in &switches.open { let (what, arg) = open.split_once(':').unwrap_or((open.as_str(), "")); match what { - "login" if switches.demo_ui => { - let bridge = ui.global::(); - let mut account = bridge.get_myts(); - account.available = true; - account.prompt = arg != "account"; - if arg == "account" { - account.signed_in = true; - account.username = "Alex Example".into(); - account.email = "alex@example.test".into(); - account.uuid = "00000000-0000-0000-0000-000000000001".into(); - account.myts_id = "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEB".into(); - account.identity_status = 1; - account.initials = "AE".into(); - account.description = "Usually in the Raid channel after 8.".into(); - account.member_since = "2019-03-14".into(); - account.last_login = "2026-10-03".into(); - let strings = |items: &[&str]| { - slint::ModelRc::new(slint::VecModel::from( - items.iter().map(|s| slint::SharedString::from(*s)).collect::>(), - )) - }; - account.badges = strings(&["TeamSpeak 6 Beta", "Early supporter"]); - // Signed for servers: the first shown, the second not. - let badge = |name: &str, shown| MytsBadge { - name: name.into(), - shown, - can_change: true, - }; - account.badge_choice = slint::ModelRc::new(slint::VecModel::from(vec![ - badge("TeamSpeak 6 Beta", 1), - badge("Early supporter", 0), - ])); - account.user_tag = "alex@myteamspeak.com".into(); - account.devices = - strings(&["Voelin · EU · 2026-10-03", "TeamSpeak · EU · 2026-09-28"]); - nav.invoke_open_settings(SettingsSection::Account); - } - account.otp_required = arg == "otp"; - account.can_forget = arg == "saved" || arg == "account"; - account.status = if arg == "otp" { - 3 - } else if arg == "saved" { - 2 - } else { - 0 - }; - bridge.set_myts(account); - } "home" => nav.invoke_show(Page::Home), "server" => { nav.invoke_show(Page::Server); diff --git a/crates/voelin-ui/src/images.rs b/crates/voelin-ui/src/images.rs index c34667a..925257f 100644 --- a/crates/voelin-ui/src/images.rs +++ b/crates/voelin-ui/src/images.rs @@ -227,8 +227,7 @@ fn decode(bytes: &[u8]) -> Option<(Image, usize)> { } /// A picture from encoded bytes (PNG, JPEG, GIF, WebP), decoded once and -/// kept by `key`; an empty image if it cannot be decoded (remembered too, -/// until [`forget_picture`]). +/// kept by `key`; an empty image if it cannot be decoded (remembered too). pub fn picture(key: &str, bytes: &[u8]) -> Image { let cache_key = format!("picture:{key}"); CACHE @@ -240,11 +239,6 @@ pub fn picture(key: &str, bytes: &[u8]) -> Image { .unwrap_or_default() } -/// Forget the decoded picture kept by `key` (a changed account avatar). -pub fn forget_picture(key: &str) { - CACHE.with(|c| c.borrow_mut().remove(&format!("picture:{key}"))); -} - /// A Twemoji by key; an empty image if there is none. pub fn emoji(key: &str) -> Image { if key.is_empty() { @@ -310,10 +304,9 @@ mod tests { encoder.write_header().unwrap().write_image_data(&[200; 32]).unwrap(); assert_eq!(picture("test:4x2", &png).size().width, 4); assert_eq!(picture("test:junk", b"not a picture").size().width, 0); - // Remembered: not decoded (and warned about) on every refresh. + // Remembered: not decoded (and warned about) on every refresh, even + // with bytes that would decode. assert_eq!(picture("test:junk", &png).size().width, 0); - forget_picture("test:junk"); - assert_eq!(picture("test:junk", &png).size().width, 4); } #[test] diff --git a/crates/voelin-ui/src/lib.rs b/crates/voelin-ui/src/lib.rs index 3671c57..69ca05d 100644 --- a/crates/voelin-ui/src/lib.rs +++ b/crates/voelin-ui/src/lib.rs @@ -16,8 +16,6 @@ mod inbox; mod links; mod members; mod messages; -#[cfg(not(target_os = "android"))] -mod myts; mod popout; mod previews; mod servers; diff --git a/crates/voelin-ui/src/main.rs b/crates/voelin-ui/src/main.rs index ad7545e..7ef7032 100644 --- a/crates/voelin-ui/src/main.rs +++ b/crates/voelin-ui/src/main.rs @@ -13,7 +13,7 @@ use voelin_platform::logs; /// portal's request or session object is gone before it reads the object's /// properties, which is harmless; its errors stay. const FILE_FILTER: &str = "warn,zbus=error,voelin=info,voelin_ui=info,voelin_core=info,voelin_media=info,\ - voelin_stream=info,voelin_audio=info,voelin_store=info,voelin_myts=info,voelin_observer=info,\ + voelin_stream=info,voelin_audio=info,voelin_store=info,voelin_observer=info,\ voelin_query=info,voelin_gateway_proto=info,voelin_platform=info,tsclientlib=info"; fn main() -> Result<()> { diff --git a/crates/voelin-ui/src/myts.rs b/crates/voelin-ui/src/myts.rs deleted file mode 100644 index 81e1e48..0000000 --- a/crates/voelin-ui/src/myts.rs +++ /dev/null @@ -1,1741 +0,0 @@ -//! Desktop account state. Only the UI thread mutates state or persists credentials. -use serde::{Deserialize, Serialize}; -use slint::{ComponentHandle, ModelRc, SharedString, VecModel}; -use std::collections::HashMap; -use std::path::PathBuf; -use std::sync::Arc; -use std::time::Duration; -use voelin_myts::{ - Client, Login, OwnAvatar, Presentation, Profile, ServerIdentity, SessionToken, SignedBadge, -}; -use voelin_store::Secrets; - -use crate::app::{App, Bridge, MytsBadge, MytsForm, later}; - -// One keyring item makes session replacement atomic: a failed write cannot -// combine a new session with another account's renewal material. -const KEY: &str = "myts/session"; - -#[derive(Default, Serialize, Deserialize)] -struct Saved { - session: String, - email: String, - username: String, - #[serde(default)] - uuid: String, - renewal_token: String, - device_id: String, - #[serde(default)] - otp_token: String, - // Private account identity belongs in the same secret-store transaction. - #[serde(default)] - identity: Option, - /// What the account service tells about the account, shown at once on - /// the next start. - #[serde(default)] - profile: SavedProfile, -} - -/// The profile of [`voelin_myts::Profile`] worth keeping between runs. -#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] -#[serde(default)] -struct SavedProfile { - description: String, - /// Unix seconds; 0: not known. - registered: i64, - last_login: i64, - badges: Vec, - /// "Name · region · date" per signed-in device. - devices: Vec, - /// The avatar file shown, as the service names it; the picture is - /// [`AVATAR_FILE`] in the account directory. - avatar: String, -} - -/// The account's avatar picture, in the account directory. -const AVATAR_FILE: &str = "avatar"; -/// What servers are shown of the account ([`SavedPresentation`]), in the -/// account directory: public data, so not in the keyring (whose items are -/// small on some systems). -const PRESENTATION_FILE: &str = "presentation.json"; -/// The badges chosen to show on servers, per account (`{account: [badge -/// id]}`), in the account directory: kept across sign-outs. -const BADGES_FILE: &str = "badges.json"; -/// Servers are shown at most this many badges, as the official client -/// shows them. -const MAX_SHOWN_BADGES: usize = 3; -/// A User Tag's token is asked for again when it holds for less than this. -const USER_TAG_MARGIN: i64 = 3 * 86_400; -/// While signed in, what servers are shown is asked for again this often -/// (certificates and tokens expire; the avatar may change elsewhere). -const PRESENTATION_REFRESH: Duration = Duration::from_secs(86_400); - -/// [`PRESENTATION_FILE`]: whose it is, and what myTeamSpeak handed out for -/// it, as it came (public data: certificates, signatures, links, ids). -#[derive(Clone, Default, PartialEq, Eq, Serialize, Deserialize)] -struct SavedPresentation { - uuid: String, - /// What the last password sign-in brought ([`Presentation`]). - certificate: Vec, - avatar: Vec, - /// What myTeamSpeak's avatar service hands out for the account's myTS - /// ID ([`OwnAvatar`]): no password needed. - #[serde(default)] - service_certificate: Vec, - #[serde(default)] - service_avatar: Vec, - /// The account's badges as signed for its myTS ID (`SignedUserBadge`s). - #[serde(default)] - badges: Vec>, - /// The primary User Tag, and the token that proves it. - #[serde(default)] - user_tag: String, - #[serde(default)] - user_tag_token: Vec, -} - -/// What asking myTeamSpeak again learned; `None`: nothing (an empty or -/// failed answer), and what was known stays. -#[derive(Default)] -struct Fetched { - avatar: Option, - badges: Option>, - user_tag: Option, - /// Checked for the tag before it is taken. - user_tag_token: Option>, -} - -impl SavedPresentation { - fn merge(&mut self, fetched: Fetched) { - if let Some(own) = fetched.avatar { - self.service_certificate = own.certificate; - self.service_avatar = own.avatar; - } - if let Some(badges) = fetched.badges { - self.badges = badges.iter().map(|b| b.raw().to_vec()).collect(); - } - if let Some(tag) = fetched.user_tag { - self.user_tag = tag; - } - if let Some(token) = fetched.user_tag_token { - self.user_tag_token = token; - } - } - - fn signed_badges(&self) -> Vec { - self.badges.iter().filter_map(|raw| SignedBadge::parse(raw)).collect() - } -} - -/// Now, Unix seconds. -fn unix_now() -> i64 { - std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .map_or(0, |d| d.as_secs() as i64) -} - -/// A date (Unix seconds) as the profile shows it; empty when not known. -fn date(seconds: i64) -> String { - chrono::DateTime::from_timestamp(seconds, 0) - .filter(|_| seconds > 0) - .map(|d| d.with_timezone(&chrono::Local).format("%Y-%m-%d").to_string()) - .unwrap_or_default() -} - -impl SavedProfile { - /// Take what the service told; empty fields keep what was known. - fn update(&mut self, profile: &Profile) { - if !profile.description.is_empty() { - self.description = profile.description.clone(); - } - if profile.registered > 0 { - self.registered = profile.registered; - } - if profile.last_login > 0 { - self.last_login = profile.last_login; - } - if !profile.badges.is_empty() { - self.badges = profile.badges.iter().map(|b| b.name.clone()).collect(); - } - if !profile.devices.is_empty() { - self.devices = profile - .devices - .iter() - .map(|d| { - [d.name.as_str(), d.region.as_str(), &date(d.last_login)] - .into_iter() - .filter(|part| !part.is_empty()) - .collect::>() - .join(" · ") - }) - .collect(); - } - } -} - -#[derive(Default)] -pub(crate) struct Account { - /// Where the avatar picture is kept (`/account`); none in tests. - dir: Option, - /// The avatar, decoded. - avatar: slint::Image, - saved: Option, - /// What servers can be shown of the account: from a password sign-in, - /// and from myTeamSpeak with the session alone. - presentation: Option, - /// The ids of the badges chosen to show on servers, in order. - shown_badges: Vec, - signed_in: bool, - busy: bool, - /// The saved session is being checked (not a password sign-in). - checking: bool, - otp_required: bool, - status: i32, - persistence_status: i32, - generation: u64, - started: bool, - prompt: bool, - // Also set after a failed read/delete so the user can retry clearing. - can_forget: bool, - identity_failed: bool, -} - -impl Account { - pub(crate) fn new(dir: PathBuf) -> Self { - Self { dir: Some(dir), ..Default::default() } - } - - fn avatar_path(&self) -> Option { - self.dir.as_ref().map(|dir| dir.join(AVATAR_FILE)) - } - - fn presentation_path(&self) -> Option { - self.dir.as_ref().map(|dir| dir.join(PRESENTATION_FILE)) - } - - fn badges_path(&self) -> Option { - self.dir.as_ref().map(|dir| dir.join(BADGES_FILE)) - } - - /// The kept presentation and badge choice, if they are the saved - /// account's. - fn load_presentation(&mut self) { - let uuid = self.saved.as_ref().map(|s| s.uuid.clone()).unwrap_or_default(); - self.presentation = self - .presentation_path() - .and_then(|path| std::fs::read(path).ok()) - .and_then(|bytes| serde_json::from_slice::(&bytes).ok()) - .filter(|kept| !uuid.is_empty() && kept.uuid == uuid); - self.load_badge_choice(&uuid); - } - - fn save_presentation(&self) { - let (Some(path), Some(kept)) = (self.presentation_path(), self.presentation.as_ref()) - else { - return; - }; - let written = serde_json::to_vec(kept).map_err(std::io::Error::other).and_then(|json| { - path.parent().map_or(Ok(()), std::fs::create_dir_all)?; - std::fs::write(&path, json) - }); - if let Err(error) = written { - tracing::warn!(%error, "could not keep what servers are shown of the account"); - } - } - - /// The kept presentation if it is `uuid`'s, else a new one. - fn presentation_for(&mut self, uuid: &str) -> &mut SavedPresentation { - if self.presentation.as_ref().is_none_or(|kept| kept.uuid != uuid) { - self.presentation = - Some(SavedPresentation { uuid: uuid.to_owned(), ..Default::default() }); - } - self.presentation.as_mut().expect("just set") - } - - /// A sign-in's presentation, kept for the next start. - fn set_presentation(&mut self, uuid: &str, presentation: Presentation) { - let kept = self.presentation_for(uuid); - kept.certificate = presentation.certificate; - kept.avatar = presentation.avatar; - self.save_presentation(); - } - - /// What asking myTeamSpeak again learned for the account `uuid`; what - /// it did not learn stays as known. - fn take_fetched(&mut self, uuid: &str, fetched: Fetched) { - self.presentation_for(uuid).merge(fetched); - self.save_presentation(); - } - - fn forget_presentation(&mut self) { - self.presentation = None; - self.shown_badges.clear(); - if let Some(path) = self.presentation_path() { - let _ = std::fs::remove_file(path); - } - } - - fn badge_choices(&self) -> HashMap> { - self.badges_path() - .and_then(|path| std::fs::read(path).ok()) - .and_then(|bytes| serde_json::from_slice(&bytes).ok()) - .unwrap_or_default() - } - - fn load_badge_choice(&mut self, uuid: &str) { - self.shown_badges = self.badge_choices().remove(uuid).unwrap_or_default(); - } - - /// Show the badge at `index` (of the signed badges) on servers, or not: - /// at most [`MAX_SHOWN_BADGES`], in the order chosen, kept per account. - /// The choice kept is then what the list shows: a chosen badge - /// myTeamSpeak no longer lists is dropped from it. - fn choose_badge(&mut self, index: usize, on: bool) -> bool { - let Some(account) = self.saved.as_ref().map(|s| s.uuid.clone()) else { return false }; - let badges = self.presentation.as_ref().map(SavedPresentation::signed_badges); - let Some(badge) = badges.unwrap_or_default().into_iter().nth(index) else { - return false; - }; - let mut chosen: Vec = self.chosen_badges().into_iter().map(|b| b.uuid).collect(); - let shown = chosen.contains(&badge.uuid); - if on == shown || (on && chosen.len() >= MAX_SHOWN_BADGES) { - return false; - } - if on { - chosen.push(badge.uuid); - } else { - chosen.retain(|uuid| *uuid != badge.uuid); - } - self.shown_badges = chosen; - if let Some(path) = self.badges_path() { - let mut choices = self.badge_choices(); - choices.insert(account, self.shown_badges.clone()); - let written = - serde_json::to_vec(&choices).map_err(std::io::Error::other).and_then(|json| { - path.parent().map_or(Ok(()), std::fs::create_dir_all)?; - std::fs::write(&path, json) - }); - if let Err(error) = written { - tracing::warn!(%error, "could not keep which badges servers are shown"); - } - } - true - } - - /// The chosen badges myTeamSpeak lists, in the order chosen, as it - /// signed them: one it no longer lists takes no place (and no place of - /// the [`MAX_SHOWN_BADGES`]). - fn chosen_badges(&self) -> Vec { - let signed = self.presentation.as_ref().map(SavedPresentation::signed_badges); - let signed = signed.unwrap_or_default(); - self.shown_badges - .iter() - .filter_map(|uuid| signed.iter().find(|b| b.uuid == *uuid).cloned()) - .take(MAX_SHOWN_BADGES) - .collect() - } - - /// What voice servers are shown of the signed-in account at `now` - /// (Unix seconds), checked as a TeamSpeak 6 server and its viewers check - /// it: the newest avatar a certificate at hand verifies, the chosen - /// badges if one certificate verifies them all, the User Tag if its - /// token holds. Each with the certificate that verifies it, since the - /// server shows nothing of what it cannot verify. - fn myts_data(&self, now: i64) -> Option { - self.myts_data_from(&voelin_myts::ROOT_KEY, now) - } - - /// [`Self::myts_data`] with certificates from `root` (tests). - fn myts_data_from(&self, root: &[u8; 32], now: i64) -> Option { - let identity = self.identity()?; - let kept = self.presentation.as_ref()?; - let id = identity.id_bytes(); - // The certificates at hand, and where they came from (for the log). - let sources = ["the sign-in's", "the avatar service's", "the myTS ID's"]; - let certificates = [ - kept.certificate.as_slice(), - kept.service_certificate.as_slice(), - identity.public_signature_certificate(), - ]; - let avatars = [kept.avatar.as_slice(), kept.service_avatar.as_slice()]; - let mut data = tsclientlib::MytsData { myts_id: id.to_vec(), ..Default::default() }; - match voelin_myts::choose_avatar_from(root, &avatars, &certificates, id, now) { - // The newest avatar has no pictures: the account has none now. - Some((avatar, _)) if !voelin_myts::avatar_has_pictures(avatars[avatar]) => { - tracing::info!("servers are shown no avatar: the account has none") - } - Some((avatar, certificate)) => { - tracing::info!( - avatar = ["from the sign-in", "from the avatar service"][avatar], - certificate = sources[certificate], - "servers are shown the account's avatar" - ); - data.avatar = tsclientlib::Signed { - certificate: certificates[certificate].to_vec(), - data: avatars[avatar].to_vec(), - }; - } - None if avatars.iter().all(|a| a.is_empty()) => { - tracing::info!("servers are shown no avatar: myTeamSpeak has not handed one out") - } - None => tracing::info!( - "servers are shown no avatar: no certificate at hand verifies it (expired, or \ - another key)" - ), - } - let badges = self.chosen_badges(); - let badges: Vec<&SignedBadge> = badges.iter().collect(); - if !badges.is_empty() { - match voelin_myts::choose_badges_certificate_from(root, &badges, &certificates, id, now) - { - Some(certificate) => { - data.badge_ids = badges.iter().map(|b| b.uuid.clone()).collect(); - tracing::info!( - badges = ?data.badge_ids, - certificate = sources[certificate], - "servers are shown the chosen badges" - ); - data.badges = tsclientlib::Signed { - certificate: certificates[certificate].to_vec(), - data: voelin_myts::badge_list(badges), - }; - } - None => tracing::info!( - "servers are shown no badges: no certificate at hand verifies all the chosen \ - ones" - ), - } - } - if !kept.user_tag.is_empty() { - if kept.user_tag_token.is_empty() { - tracing::info!("servers are shown no User Tag: myTeamSpeak has not sent its token"); - } else { - let token = &kept.user_tag_token; - match voelin_myts::check_user_tag_from(root, token, &kept.user_tag, id, now) { - Ok(_) => { - tracing::info!(tag = %kept.user_tag, "servers are shown the account's User Tag"); - data.user_tag = Some(tsclientlib::UserTag { - tag: kept.user_tag.clone(), - token: kept.user_tag_token.clone(), - }); - } - Err(error) => tracing::info!(%error, "servers are shown no User Tag"), - } - } - } - Some(data) - } - - /// The kept picture, shown while the session is checked. - fn load_avatar(&mut self) { - let bytes = self.avatar_path().and_then(|path| std::fs::read(path).ok()); - self.avatar = bytes.map(|b| crate::images::picture("myts-avatar", &b)).unwrap_or_default(); - } - - /// A new picture from the service: kept on disk and shown. - fn set_avatar(&mut self, name: String, bytes: &[u8]) { - crate::images::forget_picture("myts-avatar"); - self.avatar = crate::images::picture("myts-avatar", bytes); - if self.avatar.size().width == 0 { - return; - } - if let Some(path) = self.avatar_path() { - let written = path - .parent() - .map_or(Ok(()), std::fs::create_dir_all) - .and_then(|()| std::fs::write(&path, bytes)); - if let Err(error) = written { - tracing::warn!(%error, "could not keep the account's avatar"); - } - } - if let Some(saved) = self.saved.as_mut() { - saved.profile.avatar = name; - } - } - - fn forget_avatar(&mut self) { - self.avatar = slint::Image::default(); - crate::images::forget_picture("myts-avatar"); - if let Some(path) = self.avatar_path() { - let _ = std::fs::remove_file(path); - } - } - - fn load(&mut self, secrets: &dyn Secrets) { - match read_saved(secrets) { - Ok(saved) => { - self.saved = saved; - if self.saved.is_some() { - self.load_avatar(); - } - self.load_presentation(); - self.can_forget = false; - self.status = 0; - self.persistence_status = 0; - self.identity_failed = false; - } - Err(()) => { - self.can_forget = true; - self.persistence_status = 1; - } - } - } - - fn restored(&mut self) { - self.signed_in = true; - self.prompt = false; - self.otp_required = false; - } - - fn device_for(&self, email: &str) -> (String, String) { - self.saved - .as_ref() - .filter(|s| s.email.eq_ignore_ascii_case(email.trim())) - .map(|s| (s.device_id.clone(), s.otp_token.clone())) - .unwrap_or_default() - } - - fn accept(&mut self, secrets: &dyn Secrets, login: Login, email: String) { - self.identity_failed = login.identity.is_err(); - let (renewal_token, device_id, otp_token) = login - .renewal - .map(|renewal| (renewal.token, renewal.device_id, renewal.otp_token)) - .unwrap_or_default(); - // Another account's picture is not this one's. - let same_account = - self.saved.as_ref().is_some_and(|s| !s.uuid.is_empty() && s.uuid == login.uuid); - let mut profile = - if same_account { self.saved.take().unwrap().profile } else { SavedProfile::default() }; - if !same_account { - self.forget_avatar(); - self.forget_presentation(); - self.load_badge_choice(&login.uuid); - } - // A sign-in without it keeps the same account's known one. - if !login.presentation.is_empty() { - self.set_presentation(&login.uuid, login.presentation); - } - profile.update(&login.profile); - let saved = Saved { - profile, - session: login.token.into_inner(), - email, - username: login.username, - uuid: login.uuid, - renewal_token, - device_id, - otp_token, - identity: login.identity.ok(), - }; - self.persistence_status = if save(secrets, &saved) { - 0 - } else { - // Remove an older credential after a replacement failed. Do not - // silently sign back into the previous account on next startup. - let cleared = secrets.delete(KEY).is_ok(); - if cleared { 5 } else { 6 } - }; - self.status = 0; - self.saved = Some(saved); - self.restored(); - } - - fn revocation_failed(&mut self, generation: u64) { - if self.generation == generation && !self.signed_in && !self.busy && !self.can_forget { - self.status = 9; - } - } - /// Store what the account service told (`Client::profile`). - fn take_profile(&mut self, secrets: &dyn Secrets, profile: &Profile) { - let Some(saved) = self.saved.as_mut() else { return }; - if !profile.username.is_empty() { - saved.username = profile.username.clone(); - } - saved.profile.update(profile); - if self.persistence_status == 0 && !save(secrets, saved) { - self.persistence_status = 5; - } - } - - fn form(&self) -> MytsForm { - let identity = self.identity(); - let profile = self.saved.as_ref().map(|s| s.profile.clone()).unwrap_or_default(); - let name = self - .saved - .as_ref() - .map(|s| if s.username.is_empty() { s.email.as_str() } else { s.username.as_str() }) - .unwrap_or_default(); - let strings = |items: Vec| -> ModelRc { - ModelRc::new(VecModel::from( - items.into_iter().map(SharedString::from).collect::>(), - )) - }; - let signed = self.presentation.as_ref().map(SavedPresentation::signed_badges); - let chosen: Vec = self.chosen_badges().into_iter().map(|b| b.uuid).collect(); - let full = chosen.len() >= MAX_SHOWN_BADGES; - let badge_choice = signed - .unwrap_or_default() - .into_iter() - .map(|badge| { - let place = chosen.iter().position(|uuid| *uuid == badge.uuid); - MytsBadge { - name: badge.name.into(), - shown: place.map_or(0, |place| place as i32 + 1), - can_change: place.is_some() || !full, - } - }) - .collect::>(); - MytsForm { - available: true, - prompt: self.prompt, - signed_in: self.signed_in, - // A saved session being checked: its profile shows, not the form. - restoring: !self.signed_in && self.busy && self.checking && self.saved.is_some(), - avatar: self.avatar.clone(), - initials: crate::vm::avatar::initials(name).into(), - description: profile.description.into(), - member_since: date(profile.registered).into(), - last_login: date(profile.last_login).into(), - badges: strings(profile.badges), - badge_choice: ModelRc::new(VecModel::from(badge_choice)), - user_tag: self - .presentation - .as_ref() - .map(|p| p.user_tag.as_str()) - .unwrap_or_default() - .into(), - devices: strings(profile.devices), - email: self.saved.as_ref().map(|s| s.email.as_str()).unwrap_or_default().into(), - username: self.saved.as_ref().map(|s| s.username.as_str()).unwrap_or_default().into(), - uuid: self.saved.as_ref().map(|s| s.uuid.as_str()).unwrap_or_default().into(), - myts_id: identity.map(ServerIdentity::id).unwrap_or_default().into(), - identity_status: if !self.signed_in { - 0 - } else if identity.is_some() { - 1 - } else if self.identity_failed { - 3 - } else { - 2 - }, - status: self.status, - persistence_status: self.persistence_status, - busy: self.busy, - otp_required: self.otp_required, - can_forget: self.can_forget || self.saved.is_some(), - } - } - fn identity(&self) -> Option<&ServerIdentity> { - self.saved.as_ref().filter(|_| self.signed_in).and_then(|s| s.identity.as_ref()) - } - fn begin(&mut self) -> Option { - if self.busy { - return None; - } - self.generation += 1; - self.busy = true; - self.checking = false; - self.status = 0; - Some(self.generation) - } - - fn finish(&mut self, generation: u64) -> bool { - if self.generation != generation { - return false; - } - self.busy = false; - self.checking = false; - true - } - - fn forget(&mut self, secrets: &dyn Secrets) -> bool { - self.generation += 1; - self.busy = false; - self.checking = false; - self.signed_in = false; - self.prompt = true; - self.saved = None; - self.identity_failed = false; - self.otp_required = false; - let cleared = secrets.delete(KEY).is_ok(); - self.persistence_status = if cleared { 0 } else { 8 }; - self.can_forget = !cleared; - self.forget_avatar(); - self.forget_presentation(); - cleared - } -} - -fn login_error_status(error: &voelin_myts::Error) -> i32 { - match error.status_code() { - Some(208) => 3, - Some(209) => 14, - Some(203) => 13, - Some(202) => 16, - Some(103 | 206 | 207) => 15, - _ if matches!(error, voelin_myts::Error::Http(429)) => 17, - _ => 4, - } -} - -// Fixed official routes only. Neither the session nor an email goes in a URL. -fn portal_url(action: i32) -> Option<&'static str> { - match action { - 0 => Some("https://www.myteamspeak.com/register"), - 1 => Some("https://www.myteamspeak.com/forgot-password"), - 2 => Some("https://www.myteamspeak.com/my-account"), - 3 => Some("https://www.myteamspeak.com/resend-activation"), - 4 => Some("https://www.myteamspeak.com/my-account/change-username"), - 5 => Some("https://www.myteamspeak.com/my-account/change-email"), - 6 => Some("https://www.myteamspeak.com/my-account/change-password"), - 7 => Some("https://www.myteamspeak.com/my-account/change-2fa"), - 8 => Some("https://www.myteamspeak.com/my-account/manage-account"), - 9 => Some("https://www.myteamspeak.com/my-account/manage-data"), - _ => None, - } -} - -fn read_saved(secrets: &dyn Secrets) -> Result, ()> { - secrets - .get(KEY) - .map_err(|_| ())? - .map(|value| { - let saved: Saved = serde_json::from_str(&value).map_err(|_| ())?; - SessionToken::new(saved.session.clone()).map_err(|_| ())?; - Ok(saved) - }) - .transpose() -} - -fn save(secrets: &dyn Secrets, saved: &Saved) -> bool { - serde_json::to_string(saved).ok().is_some_and(|value| secrets.set(KEY, &value).is_ok()) -} - -impl App { - fn publish_myts_identity(&self) { - self.engine.send(voelin_core::Command::SetMytsIdentity( - self.myts.identity().cloned().map(Arc::new), - )); - // What servers are shown of it, after the proof. - self.publish_myts_data(); - } - - /// What servers are shown of the account (avatar, badges, User Tag): - /// only what changed goes to them. - fn publish_myts_data(&self) { - let data = self.myts.myts_data(unix_now()); - if data.is_none() && self.myts.identity().is_some() { - tracing::info!( - "servers are shown nothing of the account but its myTS ID until myTeamSpeak \ - answers" - ); - } - self.engine.send(voelin_core::Command::SetMytsData(data.map(Arc::new))); - } - - /// Ask myTeamSpeak, with the session alone, for what servers are shown - /// of the account: its avatar and a certificate (the avatar service's - /// answer for its own myTS ID), its signed badges, its User Tag and the - /// token that proves it. After a password sign-in, a checked saved - /// session, and then daily. An empty or failed answer changes nothing. - fn refresh_myts_presentation(&self) { - let Some(saved) = self.myts.saved.as_ref().filter(|_| self.myts.signed_in) else { - return; - }; - let (Some(identity), Ok(token)) = - (self.myts.identity(), SessionToken::new(saved.session.clone())) - else { - return; - }; - if saved.uuid.is_empty() { - return; - } - let uuid = saved.uuid.clone(); - let id = identity.id_bytes().to_vec(); - let kept_token = self - .myts - .presentation - .as_ref() - .filter(|kept| kept.uuid == uuid) - .map(|kept| kept.user_tag_token.clone()) - .unwrap_or_default(); - let generation = self.myts.generation; - self.runtime.spawn(async move { - let client = match Client::new() { - Ok(client) => client, - Err(error) => return tracing::debug!(%error, "no account client"), - }; - let (avatar, badges, tag) = tokio::join!( - client.own_avatar(&token, &id), - client.signed_badges(&token), - client.user_tag(&token) - ); - let mut fetched = Fetched::default(); - match avatar { - Ok(Some(own)) => { - tracing::info!( - "myTeamSpeak's avatar service sent the account's avatar and certificate" - ); - fetched.avatar = Some(own); - } - Ok(None) => tracing::info!( - "myTeamSpeak's avatar service sent nothing for the account; what was known \ - is kept" - ), - Err(error) => { - tracing::info!(%error, "the account's avatar for servers was not fetched") - } - } - match badges { - Ok(Some(badges)) => { - tracing::info!( - count = badges.len(), - "myTeamSpeak sent the account's signed badges" - ); - fetched.badges = Some(badges); - } - Ok(None) => { - tracing::info!("myTeamSpeak sent no badge list; what was known is kept") - } - Err(error) => { - tracing::info!(%error, "the account's signed badges were not fetched") - } - } - match tag { - Ok(Some(tag)) => { - tracing::info!(%tag, "the account's primary User Tag"); - // The token proves all the account's tags; asked for again - // when it would not prove this one in a few days. - let at = unix_now() + USER_TAG_MARGIN; - if voelin_myts::check_user_tag(&kept_token, &tag, &id, at).is_err() { - match client.user_tag_token(&token).await { - Ok(token) => { - match voelin_myts::check_user_tag(&token, &tag, &id, unix_now()) { - Ok(until) => { - tracing::info!( - valid_until = until, - "myTeamSpeak sent the token for the User Tag" - ); - fetched.user_tag_token = Some(token); - } - Err(error) => tracing::info!( - %error, - "myTeamSpeak sent a token for the User Tag that viewers would not accept" - ), - } - } - Err(error) => { - tracing::info!(%error, "the User Tag's token was not fetched") - } - } - } - fetched.user_tag = Some(tag); - } - Ok(None) => tracing::info!("myTeamSpeak names no User Tag for the account"), - Err(error) => tracing::info!(%error, "the account's User Tag was not fetched"), - } - later(move |app| { - if app.myts.generation != generation || !app.myts.signed_in { - return; - } - if app.myts.saved.as_ref().is_some_and(|s| s.uuid == uuid) { - app.myts.take_fetched(&uuid, fetched); - app.publish_myts_data(); - app.refresh_myts(); - } - }); - tokio::time::sleep(PRESENTATION_REFRESH).await; - later(move |app| { - if app.myts.generation == generation { - app.refresh_myts_presentation(); - } - }); - }); - } - - /// Show a badge on servers, or not (Settings → My Account). - pub(crate) fn myts_badge(&mut self, index: i32, on: bool) { - let changed = usize::try_from(index).is_ok_and(|index| self.myts.choose_badge(index, on)); - if changed { - self.publish_myts_data(); - } - self.refresh_myts(); - } - - pub(crate) fn refresh_myts(&self) { - let Some(ui) = self.ui.upgrade() else { - return; - }; - ui.global::().set_myts(self.myts.form()); - } - - pub(crate) fn start_myts(&mut self) { - if self.myts.started { - return; - } - self.myts.started = true; - if self.demo_ui { - self.refresh_myts(); - return; - } - self.myts.load(self.secrets.as_ref()); - // Signed in before: no login page. The saved session is checked in - // the background, and only one that has expired asks again. Without - // one, the page shows unless "Continue without an account" was - // chosen before. - self.myts.prompt = self.myts.saved.is_none() && !self.settings.skip_account_prompt; - self.myts_retry(); - } - - pub(crate) fn myts_dismiss(&mut self) { - self.myts.prompt = false; - if !self.demo_ui && !self.settings.skip_account_prompt { - self.settings.skip_account_prompt = true; - self.store_settings(); - } - self.refresh_myts(); - } - - /// Ask the account service for the profile and avatar of the signed-in - /// account; what comes back is stored and shown. - fn refresh_myts_profile(&self) { - let Some(token) = - self.myts.saved.as_ref().and_then(|s| SessionToken::new(s.session.clone()).ok()) - else { - return; - }; - let shown = self.myts.saved.as_ref().map(|s| s.profile.avatar.clone()).unwrap_or_default(); - let has_picture = self.myts.avatar.size().width > 0; - let generation = self.myts.generation; - self.runtime.spawn(async move { - let client = match Client::new() { - Ok(client) => client, - Err(error) => return tracing::debug!(%error, "no account client"), - }; - let profile = match client.profile(&token).await { - Ok(profile) => profile, - Err(error) => return tracing::info!(%error, "account profile not refreshed"), - }; - let avatar = profile.avatars.first().cloned(); - later(move |app| { - if app.myts.generation == generation && app.myts.signed_in { - app.myts.take_profile(app.secrets.as_ref(), &profile); - app.refresh_myts(); - } - }); - // The picture only when it changed (or was never fetched). - let Some(name) = avatar.filter(|name| *name != shown || !has_picture) else { return }; - match client.avatar(&name).await { - Ok(bytes) => later(move |app| { - if app.myts.generation == generation && app.myts.signed_in { - app.myts.set_avatar(name, &bytes); - if let Some(saved) = app.myts.saved.as_ref() { - let _ = save(app.secrets.as_ref(), saved); - } - app.refresh_myts(); - } - }), - Err(error) => tracing::info!(%error, "account avatar not fetched"), - } - }); - } - - pub(crate) fn myts_portal(&mut self, action: i32) { - let Some(url) = portal_url(action).filter(|_| !self.myts.busy) else { - return; - }; - let opened = crate::app::open_target(std::ffi::OsStr::new(url)).is_ok(); - self.myts.status = if opened { 11 } else { 10 }; - self.refresh_myts(); - } - - pub(crate) fn myts_retry(&mut self) { - if self.demo_ui || self.myts.busy { - return; - } - if self.myts.saved.is_none() { - self.myts.load(self.secrets.as_ref()); - } - let Some(saved) = self.myts.saved.as_ref() else { - self.refresh_myts(); - return; - }; - let token = SessionToken::new(saved.session.clone()).expect("validated stored token"); - let generation = self.myts.begin().expect("startup is idle"); - self.myts.checking = true; - self.refresh_myts(); - self.runtime.spawn(async move { - // Password login does not provide the separate auth token required - // by loginWithRenewalToken. Expiry requires a fresh password login. - let result = async { Client::new()?.validate_session(&token).await }.await; - later(move |app| { - if !app.myts.finish(generation) { - return; - } - let was_signed_in = app.myts.signed_in; - match result { - Ok(()) => { - app.myts.restored(); - app.refresh_myts_profile(); - app.refresh_myts_presentation(); - } - Err(error) => { - app.myts.otp_required = - error.is_otp_required() || error.status_code() == Some(209); - app.myts.status = 2; - if error.is_invalid_session() { - app.myts.signed_in = false; - app.myts.status = 15; - // Expired: ask to sign in again. - app.myts.prompt = true; - } - } - } - if was_signed_in != app.myts.signed_in { - app.publish_myts_identity(); - } - app.refresh_myts(); - }); - }); - } - - pub(crate) fn myts_login(&mut self, email: String, password: String, otp: String) { - // The sample screens of VOELIN_DEMO_UI sign in nowhere. - if self.demo_ui || email.trim().is_empty() || password.is_empty() || self.myts.signed_in { - return; - } - let (device, otp_renewal) = self.myts.device_for(&email); - let Some(generation) = self.myts.begin() else { - return; - }; - self.refresh_myts(); - self.runtime.spawn(async move { - let result = async { - Client::new()? - .login_with_otp_renewal( - email.trim(), - &password, - (!otp.is_empty()).then_some(otp.as_str()), - &device, - &otp_renewal, - ) - .await - } - .await; - later(move |app| { - if !app.myts.finish(generation) { - app.discard_myts_login(result.ok()); - return; - } - match result { - Ok(login) => { - app.myts.accept(app.secrets.as_ref(), login, email.trim().to_owned()); - app.publish_myts_identity(); - if app.settings.skip_account_prompt { - app.settings.skip_account_prompt = false; - app.store_settings(); - } - app.refresh_myts_profile(); - app.refresh_myts_presentation(); - } - Err(error) => { - app.myts.otp_required = - error.is_otp_required() || error.status_code() == Some(209); - app.myts.status = login_error_status(&error); - } - } - app.refresh_myts(); - }); - }); - } - - // A canceled login can still have created a remote session. Revoke it, - // never publish or save it after a sign-out/replacement. - fn discard_myts_login(&self, login: Option) { - if let Some(login) = login { - let generation = - (!self.myts.busy && !self.myts.signed_in).then_some(self.myts.generation); - self.runtime.spawn(async move { - let result = async { Client::new()?.logout(&login.token).await }.await; - if result.is_err() { - // Static diagnostic: no credential, account, response body or URL. - tracing::warn!("canceled account sign-in session could not be revoked"); - later(move |app| { - if let Some(generation) = generation { - app.myts.revocation_failed(generation); - } - app.refresh_myts(); - }); - } - }); - } - } - - pub(crate) fn myts_logout(&mut self) { - // Nor do they sign out: no session, keyring or engine account to clear. - if self.demo_ui { - return; - } - let token = - self.myts.saved.as_ref().and_then(|s| SessionToken::new(s.session.clone()).ok()); - let cleared = self.myts.forget(self.secrets.as_ref()); - self.publish_myts_identity(); - self.myts.status = if cleared { 7 } else { 0 }; - if let Some(token) = token { - let generation = self.myts.generation; - self.myts.busy = true; - self.runtime.spawn(async move { - let result = async { Client::new()?.logout(&token).await }.await; - later(move |app| { - if !app.myts.finish(generation) { - return; - } - if result.is_err() && cleared { - app.myts.status = 9; - } - app.refresh_myts(); - }); - }); - } - self.refresh_myts(); - } -} - -#[cfg(test)] -mod tests { - use super::*; - use slint::Model; - use voelin_store::MemorySecrets; - - fn login(name: &str) -> Login { - Login { - token: SessionToken::new(format!("{name}-session")).unwrap(), - uuid: format!("{name}-uuid"), - username: name.into(), - identity: Ok(server_identity()), - profile: Profile { - description: format!("{name}'s profile"), - avatars: vec![format!("{name}.png")], - ..Default::default() - }, - renewal: Some(voelin_myts::Renewal { - token: format!("{name}-renewal"), - otp_token: format!("{name}-otp"), - device_id: format!("{name}-device"), - }), - presentation: Presentation { - certificate: format!("{name}-cert").into_bytes(), - avatar: format!("{name}-avatar").into_bytes(), - }, - } - } - - /// What servers are shown of the account is kept for it, told once its - /// session is valid again, and never shown for another account. - #[test] - fn what_servers_are_shown_is_kept_per_account() { - let dir = std::env::temp_dir().join(format!("voelin-presentation-{}", std::process::id())); - let _ = std::fs::remove_dir_all(&dir); - let secrets = MemorySecrets::default(); - let mut account = Account::new(dir.clone()); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert_eq!(account.presentation.as_ref().unwrap().certificate, b"Alice-cert"); - let data = account.myts_data(NOW).unwrap(); - assert_eq!(data.myts_id, [1; 33]); - // Nothing a server would verify: nothing shown. - assert!(data.avatar.is_empty() && data.badges.is_empty() && data.user_tag.is_none()); - let mut restarted = Account::new(dir.clone()); - restarted.load(&secrets); - assert!(restarted.myts_data(NOW).is_none(), "not before the session is checked"); - assert!(restarted.presentation == account.presentation); - restarted.restored(); - assert!(restarted.myts_data(NOW).is_some()); - restarted.forget(&secrets); - assert!(!dir.join(PRESENTATION_FILE).exists()); - let mut bob = login("Bob"); - bob.presentation = Presentation::default(); - restarted.accept(&secrets, bob, "bob@example.test".into()); - assert!(restarted.presentation.is_none()); - // What myTeamSpeak hands out with the session alone is Bob's. - restarted.take_fetched("Bob-uuid", fetched_tag("bob@myteamspeak.com")); - let mut again = Account::new(dir.clone()); - again.load(&secrets); - assert_eq!(again.presentation.as_ref().unwrap().uuid, "Bob-uuid"); - assert_eq!(again.form().user_tag, "bob@myteamspeak.com"); - let _ = std::fs::remove_dir_all(dir); - } - - use voelin_myts::testing::NOW; - - fn fetched_tag(tag: &str) -> Fetched { - Fetched { user_tag: Some(tag.into()), ..Default::default() } - } - - /// A `SignedUserBadge` as myTeamSpeak sends it (protobuf by hand). - fn signed_badge(uuid: &str, name: &str) -> Vec { - let mut badge = vec![0x0a, uuid.len() as u8]; - badge.extend_from_slice(uuid.as_bytes()); - badge.extend_from_slice(&[0x1a, name.len() as u8]); - badge.extend_from_slice(name.as_bytes()); - let mut signed = vec![0x0a, badge.len() as u8]; - signed.extend_from_slice(&badge); - signed.extend_from_slice(&[0x12, 64]); - signed.extend_from_slice(&[7; 64]); - signed - } - - /// An empty or failed answer changes nothing; an answer replaces only - /// what it is about. - #[test] - fn what_myteamspeak_did_not_tell_stays() { - let mut kept = SavedPresentation { - uuid: "a".into(), - certificate: b"login".to_vec(), - avatar: b"login avatar".to_vec(), - service_certificate: b"service".to_vec(), - service_avatar: b"service avatar".to_vec(), - badges: vec![signed_badge("b1", "One")], - user_tag: "alex@myteamspeak.com".into(), - user_tag_token: b"token".to_vec(), - }; - let before = kept.clone(); - kept.merge(Fetched::default()); - assert!(kept == before); - kept.merge(Fetched { - avatar: Some(OwnAvatar { certificate: b"new".to_vec(), avatar: b"newer".to_vec() }), - ..Default::default() - }); - assert_eq!( - (kept.service_certificate.as_slice(), kept.service_avatar.as_slice()), - (&b"new"[..], &b"newer"[..]) - ); - assert_eq!(kept.certificate, b"login", "the sign-in's stays"); - assert_eq!(kept.badges, before.badges); - // A list is the list, even an empty one. - kept.merge(Fetched { badges: Some(Vec::new()), ..Default::default() }); - assert!(kept.badges.is_empty()); - kept.merge(fetched_tag("alex@tschat-1.teamspeak.com")); - assert_eq!(kept.user_tag, "alex@tschat-1.teamspeak.com"); - assert_eq!(kept.user_tag_token, b"token", "the token proves all the tags"); - kept.merge(Fetched { user_tag_token: Some(b"fresh".to_vec()), ..Default::default() }); - assert_eq!(kept.user_tag_token, b"fresh"); - } - - /// Up to three badges, in the order chosen, kept per account (across - /// sign-outs); none chosen at first. - #[test] - fn badges_shown_on_servers_are_chosen_per_account() { - let dir = std::env::temp_dir().join(format!("voelin-badges-{}", std::process::id())); - let _ = std::fs::remove_dir_all(&dir); - let secrets = MemorySecrets::default(); - let mut account = Account::new(dir.clone()); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - let badges = ["One", "Two", "Three", "Four"] - .iter() - .enumerate() - .map(|(i, name)| SignedBadge::parse(&signed_badge(&format!("b{i}"), name)).unwrap()) - .collect(); - account.take_fetched("Alice-uuid", Fetched { badges: Some(badges), ..Default::default() }); - assert!(account.shown_badges.is_empty(), "none chosen at first"); - assert!(account.chosen_badges().is_empty()); - for index in [2, 0, 3] { - assert!(account.choose_badge(index, true)); - } - assert!(!account.choose_badge(1, true), "three at most"); - assert!(!account.choose_badge(0, true), "already shown"); - assert!(!account.choose_badge(9, true)); - let names = |account: &Account| { - account.chosen_badges().into_iter().map(|b| b.name).collect::>() - }; - assert_eq!(names(&account), ["Three", "One", "Four"]); - let form = account.form(); - let choice: Vec<_> = form.badge_choice.iter().map(|b| (b.shown, b.can_change)).collect(); - assert_eq!(choice, [(2, true), (0, false), (1, true), (3, true)]); - assert!(account.choose_badge(0, false)); - assert!(account.choose_badge(1, true)); - assert_eq!(names(&account), ["Three", "Four", "Two"]); - // Kept for the account, also after signing out and in again. - account.forget(&secrets); - assert!(account.shown_badges.is_empty()); - account.accept(&secrets, login("Bob"), "bob@example.test".into()); - assert!(account.shown_badges.is_empty(), "Bob chose none"); - account.forget(&secrets); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert_eq!(account.shown_badges, ["b2", "b3", "b1"]); - let _ = std::fs::remove_dir_all(dir); - } - - /// A chosen badge myTeamSpeak no longer lists takes no place: the others - /// move up, another can be chosen, and the choice kept is then what the - /// list shows. - #[test] - fn a_badge_no_longer_listed_takes_no_place() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - let listed = |names: &[&str]| Fetched { - badges: Some( - names.iter().map(|n| SignedBadge::parse(&signed_badge(n, n)).unwrap()).collect(), - ), - ..Default::default() - }; - account.take_fetched("Alice-uuid", listed(&["b0", "b1", "b2", "b3"])); - for index in [0, 1, 2] { - assert!(account.choose_badge(index, true)); - } - // b1 is gone. - account.take_fetched("Alice-uuid", listed(&["b0", "b2", "b3"])); - let names = |account: &Account| { - account.chosen_badges().into_iter().map(|b| b.name).collect::>() - }; - assert_eq!(names(&account), ["b0", "b2"]); - let choice = |account: &Account| { - account.form().badge_choice.iter().map(|b| (b.shown, b.can_change)).collect::>() - }; - assert_eq!(choice(&account), [(1, true), (2, true), (0, true)]); - assert!(account.choose_badge(2, true), "a place is free"); - assert_eq!(account.shown_badges, ["b0", "b2", "b3"]); - assert_eq!(choice(&account), [(1, true), (2, true), (3, true)]); - // Back again, b1 is not chosen: the choice is what the list showed. - account.take_fetched("Alice-uuid", listed(&["b0", "b1", "b2", "b3"])); - assert_eq!(names(&account), ["b0", "b2", "b3"]); - // A choice kept from before (badges.json) with more than three listed: - // three are shown. - account.shown_badges = ["b3", "b1", "b0", "b2"].map(String::from).to_vec(); - assert_eq!(names(&account), ["b3", "b1", "b0"]); - assert_eq!(choice(&account)[2], (0, false)); - } - - /// Servers are shown what verifies, each part with the certificate that - /// verifies it: here the avatar service's newer avatar with its own - /// certificate, the chosen badges with the sign-in's, the User Tag with - /// its token. (Certificates from a synthetic root: TeamSpeak's verifies - /// none of it.) - #[test] - fn servers_are_shown_what_verifies_with_its_certificate() { - use voelin_myts::testing::Chain; - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - let id = [1; 33]; - let sign_in = Chain::signing(1); - // Valid for an hour only. - let service = Chain::new(2, 6, NOW - 3600, NOW + 3600); - let chat = Chain::new(3, 4, NOW - 3600, NOW + 86_400); - let root = sign_in.root; - let uuids = [ - "a2a2a2a2-0000-4000-8000-000000000001", - "a2a2a2a2-0000-4000-8000-000000000002", - "a2a2a2a2-0000-4000-8000-000000000003", - ]; - let badges: Vec = uuids - .iter() - .zip(["One", "Two", "Three"]) - .map(|(uuid, name)| SignedBadge::parse(&sign_in.badge(&id, uuid, name)).unwrap()) - .collect(); - account.set_presentation( - "Alice-uuid", - Presentation { - certificate: sign_in.certificate.clone(), - avatar: sign_in.avatar(&id, 100), - }, - ); - let tag = "alice@myteamspeak.com"; - let token = chat.user_tag_token(&["alice@tschat-1.teamspeak.com", tag], &id); - account.take_fetched( - "Alice-uuid", - Fetched { - avatar: Some(OwnAvatar { - certificate: service.certificate.clone(), - avatar: service.avatar(&id, 200), - }), - badges: Some(badges), - user_tag: Some(tag.into()), - user_tag_token: Some(token.clone()), - }, - ); - assert!(account.choose_badge(2, true) && account.choose_badge(0, true)); - let data = account.myts_data_from(&root, NOW).unwrap(); - assert_eq!(data.myts_id, id); - assert!( - data.avatar - == tsclientlib::Signed { - certificate: service.certificate.clone(), - data: service.avatar(&id, 200), - } - ); - assert_eq!(data.badges.certificate, sign_in.certificate); - let chosen = account.chosen_badges(); - assert_eq!(data.badges.data, voelin_myts::badge_list(&chosen)); - assert_eq!(data.badge_ids, [uuids[2], uuids[0]]); - assert!(data.user_tag == Some(tsclientlib::UserTag { tag: tag.into(), token })); - // The avatar and the badges with two certificates: two commands. - assert_eq!(data.updates(&tsclientlib::MytsData::default(), false).len(), 2); - // Two hours on, the avatar service's certificate has expired: the - // sign-in's avatar, with the sign-in's certificate, and one command. - let later = account.myts_data_from(&root, NOW + 7200).unwrap(); - assert!( - later.avatar - == tsclientlib::Signed { - certificate: sign_in.certificate.clone(), - data: sign_in.avatar(&id, 100), - } - ); - assert_eq!(later.updates(&tsclientlib::MytsData::default(), false).len(), 1); - // A day on, the User Tag's token no longer holds. - assert!(account.myts_data_from(&root, NOW + 86_400).unwrap().user_tag.is_none()); - // For another myTS ID, nothing verifies. - account.saved.as_mut().unwrap().identity = Some(server_identity_for(2)); - let other = account.myts_data_from(&root, NOW).unwrap(); - assert!(other.avatar.is_empty() && other.badges.is_empty() && other.user_tag.is_none()); - // TeamSpeak's root verifies none of it. - account.saved.as_mut().unwrap().identity = Some(server_identity()); - let data = account.myts_data(NOW).unwrap(); - assert!(data.avatar.is_empty() && data.badges.is_empty() && data.user_tag.is_none()); - } - - fn server_identity() -> ServerIdentity { - server_identity_for(1) - } - - /// An identity with the myTS ID `[id; 33]`. - fn server_identity_for(id: u8) -> ServerIdentity { - let mut private = [0; 32]; - private[0] = 1; - let mut public = [0x66; 32]; - public[0] = 0x58; // Compressed Ed25519 basepoint for scalar one. - ServerIdentity::new(vec![id; 33], 1, public, private, vec![2; 65]).unwrap() - } - - #[test] - fn primary_account_persists_restores_after_validation_and_signout_returns_to_login() { - let secrets = MemorySecrets::default(); - let mut account = Account { prompt: true, ..Default::default() }; - account.load(&secrets); - assert!(account.form().prompt); - assert!(!account.form().signed_in); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert!(!account.form().prompt); - assert!(account.form().signed_in); - assert_eq!(account.form().identity_status, 1); - assert!(account.identity().is_some()); - assert_eq!(account.form().uuid, "Alice-uuid"); - let mut restarted = Account { prompt: true, ..Default::default() }; - restarted.load(&secrets); - assert!(restarted.identity().is_none(), "unvalidated cache cannot authenticate servers"); - assert!(!restarted.form().signed_in, "cached profile is not validated yet"); - let generation = restarted.begin().unwrap(); - assert!(restarted.finish(generation)); - restarted.restored(); - assert!(restarted.identity().is_some()); - assert!(!restarted.form().prompt); - assert_eq!(restarted.form().username, "Alice"); - assert!(restarted.forget(&secrets)); - assert!(restarted.form().prompt); - assert_eq!(restarted.form().username, ""); - assert_eq!(restarted.form().uuid, ""); - assert!(!restarted.form().signed_in); - assert!(restarted.identity().is_none()); - assert_eq!(restarted.form().myts_id, ""); - } - - #[test] - fn switching_primary_account_never_reuses_another_accounts_device_material() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert_eq!( - account.device_for(" ALICE@example.test "), - ("Alice-device".into(), "Alice-otp".into()) - ); - assert_eq!(account.device_for("bob@example.test"), Default::default()); - account.forget(&secrets); - assert_eq!(account.device_for("alice@example.test"), Default::default()); - let mut bob = login("Bob"); - bob.renewal = None; - account.accept(&secrets, bob, "bob@example.test".into()); - let saved = read_saved(&secrets).unwrap().unwrap(); - assert_eq!(saved.uuid, "Bob-uuid"); - assert_eq!(saved.email, "bob@example.test"); - assert!(saved.renewal_token.is_empty()); - assert!(saved.otp_token.is_empty()); - assert!(saved.device_id.is_empty()); - } - - #[test] - fn missing_server_key_keeps_login_but_never_reuses_previous_identity() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert!(account.identity().is_some()); - account.forget(&secrets); - let mut bob = login("Bob"); - bob.identity = Err(voelin_myts::IdentityError::Missing); - account.accept(&secrets, bob, "bob@example.test".into()); - assert!(account.signed_in); - assert!(account.identity().is_none()); - assert_eq!(account.form().identity_status, 3); - assert!(account.form().myts_id.is_empty()); - assert!(read_saved(&secrets).unwrap().unwrap().identity.is_none()); - } - - #[test] - fn corrupted_persisted_private_identity_cannot_be_restored() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - let mut value: serde_json::Value = - serde_json::from_str(&secrets.get(KEY).unwrap().unwrap()).unwrap(); - value["identity"]["private_key"] = serde_json::json!(vec![0u8; 32]); - secrets.set(KEY, &value.to_string()).unwrap(); - assert!(read_saved(&secrets).is_err()); - let mut restored = Account::default(); - restored.load(&secrets); - assert!(restored.identity().is_none()); - assert_eq!(restored.form().persistence_status, 1); - } - - #[test] - fn keyring_retry_and_legacy_bundle_do_not_claim_a_validated_account() { - let secrets = MemorySecrets::default(); - secrets.set(KEY, r#"{"session":"legacy","email":"a@example.test","username":"A","renewal_token":"r","device_id":"d"}"#).unwrap(); - let mut account = Account { prompt: true, ..Default::default() }; - account.load(&Unavailable); - assert_eq!(account.form().persistence_status, 1); - account.load(&secrets); - assert_eq!(account.status, 0); - assert_eq!(account.form().persistence_status, 0); - assert!(!account.can_forget); - assert!(!account.signed_in); - assert!(account.prompt); - assert_eq!(account.form().uuid, ""); - account.restored(); - assert_eq!(account.form().identity_status, 2); - assert!(account.identity().is_none()); - assert_eq!(account.saved.unwrap().otp_token, ""); - } - - #[test] - fn login_survives_keyring_failure_with_visible_session_only_status() { - let mut account = Account { prompt: true, ..Default::default() }; - account.accept(&Unavailable, login("Alice"), "alice@example.test".into()); - assert!(account.signed_in); - assert!(!account.prompt); - assert_eq!(account.form().persistence_status, 6); - assert!(account.form().can_forget); - assert_eq!(account.form().username, "Alice"); - let generation = account.begin().unwrap(); - assert!(account.finish(generation)); - account.restored(); - assert_eq!( - account.form().persistence_status, - 6, - "validation must not hide failed persistence" - ); - account.status = 11; - assert_eq!( - account.form().persistence_status, - 6, - "opening management must retain the warning" - ); - account.forget(&Unavailable); - account.status = 11; - assert_eq!( - account.form().persistence_status, - 8, - "failed deletion must remain visible after browser launch" - ); - account.forget(&MemorySecrets::default()); - assert_eq!(account.form().persistence_status, 0); - } - - #[test] - fn portal_actions_are_fixed_official_https_destinations() { - for action in 0..10 { - let url = portal_url(action).unwrap(); - assert!(url.starts_with("https://www.myteamspeak.com/")); - assert!(!url.contains(['?', '#', '@'])); - } - assert!(portal_url(-1).is_none()); - assert!(portal_url(10).is_none()); - assert_eq!(portal_url(1), Some("https://www.myteamspeak.com/forgot-password")); - assert_eq!(login_error_status(&voelin_myts::Error::Http(429)), 17); - assert_eq!(login_error_status(&voelin_myts::Error::Timeout), 4); - } - - #[test] - fn failed_late_session_revocation_reports_signed_out_without_overwriting_new_login() { - let mut account = Account::default(); - let old = account.begin().unwrap(); - account.forget(&MemorySecrets::default()); - assert!(!account.finish(old)); - let signed_out = account.generation; - account.revocation_failed(signed_out); - assert_eq!(account.status, 9); - let new = account.begin().unwrap(); - account.revocation_failed(signed_out); - account.revocation_failed(new); - assert_eq!(account.status, 0); - assert!(account.busy); - account.finish(new); - account.signed_in = true; - account.revocation_failed(new); - assert_eq!(account.status, 0); - } - - #[test] - fn a_saved_session_being_checked_shows_its_profile_not_the_form() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert_eq!(account.form().description, "Alice's profile"); - let mut restarted = Account { prompt: true, ..Default::default() }; - restarted.load(&secrets); - restarted.begin().unwrap(); - restarted.checking = true; - let form = restarted.form(); - assert!(form.restoring && !form.signed_in); - assert_eq!((form.username.as_str(), form.initials.as_str()), ("Alice", "AL")); - // A password sign-in over an expired saved session shows the form. - restarted.finish(restarted.generation); - restarted.begin().unwrap(); - assert!(!restarted.form().restoring); - } - - #[test] - fn the_service_profile_is_kept_and_another_account_starts_empty() { - let secrets = MemorySecrets::default(); - let mut account = Account::default(); - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - let profile = Profile { - username: "Alice B".into(), - registered: 1_600_000_000, - badges: vec![voelin_myts::Badge { name: "Early".into(), ..Default::default() }], - devices: vec![voelin_myts::Device { - name: "Voelin".into(), - region: "EU".into(), - last_login: 0, - }], - ..Default::default() - }; - account.take_profile(&secrets, &profile); - let saved = read_saved(&secrets).unwrap().unwrap(); - assert_eq!(saved.username, "Alice B"); - assert_eq!(saved.profile.registered, 1_600_000_000); - assert_eq!(saved.profile.badges, ["Early"]); - assert_eq!(saved.profile.devices, ["Voelin · EU"]); - assert_eq!(saved.profile.description, "Alice's profile", "kept: not in this reply"); - let form = account.form(); - assert_eq!(form.member_since, date(1_600_000_000)); - assert_eq!(form.badges.row_count(), 1); - // The same account signing in again keeps it, another one does not. - account.accept(&secrets, login("Alice"), "alice@example.test".into()); - assert_eq!(account.saved.as_ref().unwrap().profile.registered, 1_600_000_000); - account.accept(&secrets, login("Bob"), "bob@example.test".into()); - let bob = &account.saved.as_ref().unwrap().profile; - assert_eq!((bob.registered, bob.description.as_str()), (0, "Bob's profile")); - } - - #[test] - fn form_exposes_signed_out_busy_otp_and_signed_in_states_without_tokens() { - let mut account = Account::default(); - assert!(account.form().available); - assert!(!account.form().signed_in); - assert!(!account.form().can_forget); - let generation = account.begin().unwrap(); - assert!(account.form().busy); - account.finish(generation); - account.otp_required = true; - account.status = 3; - assert!(account.form().otp_required); - assert_eq!(account.form().status, 3); - account.saved = Some(Saved { - session: "secret session".into(), - email: "a@example.test".into(), - username: "Name".into(), - ..Default::default() - }); - account.signed_in = true; - account.otp_required = false; - let form = account.form(); - assert!(form.signed_in); - assert!(form.can_forget); - assert_eq!(form.username, "Name"); - assert_eq!(form.email, "a@example.test"); - assert!(!form.otp_required); - } - - #[test] - fn persistence_roundtrip_and_logout_delete_all_material() { - let secrets = MemorySecrets::default(); - let saved = Saved { - session: "session".into(), - email: "email".into(), - renewal_token: "renewal".into(), - device_id: "device".into(), - username: "name".into(), - otp_token: "otp renewal".into(), - uuid: "account-uuid".into(), - identity: Some(server_identity()), - profile: SavedProfile { description: "Hi".into(), ..Default::default() }, - }; - assert!(save(&secrets, &saved)); - let loaded = read_saved(&secrets).unwrap().unwrap(); - assert_eq!(loaded.session, "session"); - assert_eq!(loaded.renewal_token, "renewal"); - assert_eq!(loaded.email, "email"); - assert_eq!(loaded.identity.unwrap().id(), server_identity().id()); - let loaded = read_saved(&secrets).unwrap().unwrap(); - let mut account = Account { saved: Some(loaded), signed_in: true, ..Default::default() }; - assert!(account.forget(&secrets)); - assert!(read_saved(&secrets).unwrap().is_none()); - assert!(!account.signed_in); - } - - #[test] - fn single_operation_and_logout_prevent_stale_resurrection() { - let mut account = Account::default(); - let generation = account.begin().unwrap(); - assert!(account.begin().is_none()); - account.forget(&MemorySecrets::default()); - assert!(!account.finish(generation)); - let replacement = account.begin().unwrap(); - assert!(!account.finish(generation)); - assert!(account.busy); - assert!(account.finish(replacement)); - } - - struct Unavailable; - impl Secrets for Unavailable { - fn get(&self, _: &str) -> voelin_store::Result> { - Err(voelin_store::Error::Secrets("locked".into())) - } - fn set(&self, _: &str, _: &str) -> voelin_store::Result<()> { - Err(voelin_store::Error::Secrets("locked".into())) - } - fn delete(&self, _: &str) -> voelin_store::Result<()> { - Err(voelin_store::Error::Secrets("locked".into())) - } - } - - #[test] - fn keyring_failure_is_visible_and_logout_still_clears_memory() { - assert!(read_saved(&Unavailable).is_err()); - assert!(!save(&Unavailable, &Saved::default())); - let mut account = - Account { saved: Some(Saved::default()), signed_in: true, ..Default::default() }; - assert!(!account.forget(&Unavailable)); - assert!(account.saved.is_none()); - assert!(!account.signed_in); - assert!(account.can_forget); - } - - #[test] - fn malformed_or_empty_session_is_not_used() { - let secrets = MemorySecrets::default(); - secrets.set(KEY, "broken").unwrap(); - assert!(read_saved(&secrets).is_err()); - assert!(save(&secrets, &Saved::default())); - assert!(read_saved(&secrets).is_err()); - } -} diff --git a/crates/voelin-ui/src/settings.rs b/crates/voelin-ui/src/settings.rs index c177fa7..8d1c2f0 100644 --- a/crates/voelin-ui/src/settings.rs +++ b/crates/voelin-ui/src/settings.rs @@ -284,9 +284,6 @@ pub struct UiSettings { pub share: ShareDefaults, /// Write crash reports to disk (opt-in; never uploaded). pub crash_reports: bool, - /// "Continue without an account" was chosen on the login page: it does - /// not show at start any more (signing in clears it). - pub skip_account_prompt: bool, /// The voice channel we were in last (Home's "Continue where you left /// off"). pub last_voice: Option, @@ -301,7 +298,6 @@ impl Default for UiSettings { portal_restore_token: None, share: ShareDefaults::default(), crash_reports: false, - skip_account_prompt: false, last_voice: None, } } diff --git a/crates/voelin-ui/ui/bridge.slint b/crates/voelin-ui/ui/bridge.slint index f8645c3..4f2bdca 100644 --- a/crates/voelin-ui/ui/bridge.slint +++ b/crates/voelin-ui/ui/bridge.slint @@ -1283,6 +1283,8 @@ export global Bridge { // Settings pages: a section was shown (its data is loaded then). callback settings-section(int); in property account; + // Not set in this build (see `AccountCard`): the default form is signed + // out, unavailable and without the login page. in property myts; in property primary-name: myts.signed-in || myts.restoring ? (myts.username != "" ? myts.username : myts.email) : nickname != "" ? nickname : app-name; callback myts-dismiss(); diff --git a/crates/voelin-ui/ui/screens/account.slint b/crates/voelin-ui/ui/screens/account.slint index c19ecbb..b8ffcc7 100644 --- a/crates/voelin-ui/ui/screens/account.slint +++ b/crates/voelin-ui/ui/screens/account.slint @@ -451,11 +451,16 @@ component SessionActions inherits HorizontalLayout { } // Settings → My Account. +// +// The account sign-in is not part of this build: nothing sets `Bridge.myts`, +// so it keeps its default (signed out, not available, no prompt) and the card +// shows only the note. The rest of this file stays for the account that comes +// back through the gateway. export component AccountCard inherits Card { title: @tr("myTeamSpeak"); icon: Icons.user; - subtitle: Bridge.myts.signed-in ? @tr("Your account") : Bridge.myts.restoring ? @tr("Checking your saved session") : @tr("Sign in to make your account your main profile"); - if !Bridge.myts.available: Note { text: @tr("Account sign-in is available on desktop."); } + subtitle: !Bridge.myts.available ? "" : Bridge.myts.signed-in ? @tr("Your account") : Bridge.myts.restoring ? @tr("Checking your saved session") : @tr("Sign in to make your account your main profile"); + if !Bridge.myts.available: Note { text: @tr("Account sign-in is not available in this build."); } if Bridge.myts.signed-in || Bridge.myts.restoring: AccountProfile { } if Bridge.myts.available && !Bridge.myts.signed-in && !Bridge.myts.restoring: LoginForm { } if AccountText.status(Bridge.myts.status) != "" || AccountText.persistence(Bridge.myts.persistence-status) != "": AccountNotices { } diff --git a/docs/identity.md b/docs/identity.md index 59324b0..bba53c9 100644 --- a/docs/identity.md +++ b/docs/identity.md @@ -10,10 +10,10 @@ private key.** Voelin can import identities from the official clients so that switching does not mean starting over, and export them back so they are never trapped here. -The myTeamSpeak account has a separate signing identity. After password sign-in, -Voelin can authenticate its `myTS ID` on voice servers without replacing the -P-256 identity that owns server permissions. The primary account applies to all -voice connections and is cleared on sign-out. See +The myTeamSpeak account has a separate signing identity, which could +authenticate a `myTS ID` on voice servers without replacing the P-256 identity +that owns server permissions. This build has no account sign-in, so it presents +none; the account returns through the gateway. See [the account protocol notes](research/myteamspeak.md#authenticated-account-identity-on-voice-servers). ## The unique ids @@ -238,14 +238,12 @@ the repository. Every fixture in the tests is generated by and import that. - **The other `ProtobufItems` item types.** Bookmarks, connection profiles and server lists are not imported. Only identities are. -- **myTeamSpeak identity synchronisation.** Desktop My Account supports an - experimental account session, but does not fetch cloud identities or decrypt - account backups. Sign in with the official client once so it writes the - identities to `settings.db`, then import from there. See - [research/myteamspeak.md](research/myteamspeak.md) for the account client's - verification scope, session renewal, and cloud-sync limitations. The signed-in - account is the main app profile; server identities and bookmark nicknames are - independent. +- **myTeamSpeak identity synchronisation.** There is no account sign-in in + this build, so no cloud identities are fetched and no account backups are + decrypted. Sign in with the official client once so it writes the identities + to `settings.db`, then import from there. See + [research/myteamspeak.md](research/myteamspeak.md) for the account protocol + notes; the account returns through the gateway. - **Writing back to the official clients.** Voelin only reads them. Use the `.ini` export and the client's own import. - **Bringing the nickname's history along.** Only the key pair and the diff --git a/docs/research/myteamspeak.md b/docs/research/myteamspeak.md index 7d5f0d3..583368b 100644 --- a/docs/research/myteamspeak.md +++ b/docs/research/myteamspeak.md @@ -1,5 +1,7 @@ # myTeamSpeak +> The implementation (`voelin-myts`) moved to VoelinGateWay; this client has no account sign-in and carries neither the crate nor the `schema-api` snapshot it used (`third_party/schema-api`, which had no licence). The notes below are kept as research, written when the client had the feature, so they describe the removed implementation (`voelin-myts`, the login page, `Bridge.myts`) in the present tense. + ## Desktop account sessions myTeamSpeak is TeamSpeak's account service: it holds the user's identities, @@ -32,7 +34,7 @@ import. See [../identity.md](../identity.md). ### Transport and verification boundary The implementation consumes the message types, session status checks and wire -codec from the local `schema-api` snapshot in `third_party/schema-api`. Its +codec from the `schema-api` snapshot that was vendored in `third_party/schema-api` (removed from this repository). Its generated tonic gRPC clients are not used: the official clients use custom protobuf-over-HTTP with `Content-Type: application/ts3cloud` at `https://clientapi.myteamspeak.com`. @@ -321,9 +323,8 @@ An account change during an automatic transport reconnect cancels that voice session to prevent stale credentials from being sent. Reconnect manually in that case; ordinary connected account changes use the live update command. -The vendored crate has no declared license. Its provenance is recorded in -`third_party/schema-api/VOELIN-PATCH.md`; no license grant is inferred from its -presence. Runtime dependency notices are generated normally. +The vendored crate had no declared license, which is why it was removed from this +repository (its provenance was recorded in `third_party/schema-api/VOELIN-PATCH.md`). ### Official account-management routes diff --git a/docs/research/ui-review.md b/docs/research/ui-review.md index 35ac498..c2bc257 100644 --- a/docs/research/ui-review.md +++ b/docs/research/ui-review.md @@ -226,8 +226,8 @@ is not new in TS6. It is the classic client that TS3 already had. | Several streams of a channel at once, pause, hide your own and inactive streams, auto-focus | shipped | one stream at a time (`viewer-streamer-id`) | Show a grid of the channel's streams on the voice page | | Camera as a quick share | shipped | camera only as a Stream Studio source | Add "Camera" to the Share menu | | Viewer limit, privacy (channel / contacts / private), join requests | shipped (fixed in beta4) | permissions plus accept/deny exist | Add the viewer limit | -| Global chat: DMs and group chats across servers, through myTeamSpeak (Matrix based, optional E2EE), with offline delivery, reply, edit, delete, reactions, pins, search | shipped | DMs need a voice connection to the peer's server | The largest interop item. Voelin already signs in to myTeamSpeak. Research the chat service (extend `research/myteamspeak.md`); it would give real DMs with official TS6 users, and streaming in DMs | -| myTeamSpeak cloud sync: bookmarks, contacts, group chats, badges | shipped | sign-in only (`docs/identity.md:239`) | Sync bookmarks and contacts first | +| Global chat: DMs and group chats across servers, through myTeamSpeak (Matrix based, optional E2EE), with offline delivery, reply, edit, delete, reactions, pins, search | shipped | DMs need a voice connection to the peer's server | The largest interop item. Voelin signed in to myTeamSpeak when this was written; that left the client, and it returns through the gateway. Research the chat service (extend `research/myteamspeak.md`); it would give real DMs with official TS6 users, and streaming in DMs | +| myTeamSpeak cloud sync: bookmarks, contacts, group chats, badges | shipped | sign-in only, since removed (`docs/identity.md`) | Sync bookmarks and contacts first | | Direct calls 1:1 with picture-in-picture | alpha (2026-08-20) | — | Wait; needs the global chat | | Multi-track recording (a track per speaker) | alpha (2026-09-04) | the Studio records streams | Possible later with the Studio's recorder | | Per-application audio for screen sharing | alpha | **already in Voelin** | — | diff --git a/docs/ui.md b/docs/ui.md index eda1a3c..d1334dd 100644 --- a/docs/ui.md +++ b/docs/ui.md @@ -243,7 +243,7 @@ Settings sections (`settings:
`): | Section | Holds | |---|---| -| `account` | The identity in use (nickname, TeamSpeak 3 and 6 unique ids, security level); on desktop, the primary myTeamSpeak profile, login/OTP, session status, sign-out and official browser account-management actions | +| `account` | The identity in use (nickname, TeamSpeak 3 and 6 unique ids, security level), and a note that account sign-in is not available in this build | | `profiles` (also `identities`) | Identities with where they came from: rename, use as default (the store's default, `Store::set_default_identity`), export as a TeamSpeak 3 .ini, delete, raise the security level on every core; the import of the official clients' identities on start (`identity.import_from_teamspeak`) and by hand from their settings and .ini files (key material is never shown); the identity per server | | `appearance` | Theme, text size, the phone layout's width, the image cache | | `voice` | Microphone (device, test, level, noise suppression, echo cancellation, automatic gain), output (device, test sound, volume), streaming permissions, camera (device, preview with the background effect), video settings (resolution, frame rate 15 to 320 fps, codec, hardware acceleration, mirror), stream quality presets (Auto, 720p to 8K) with free bitrate entry (slider up to 60 Mbit/s, empty: automatic) and the upload it takes | @@ -258,27 +258,13 @@ Settings sections (`settings:
`): Settings controls read and write `voelin_core::settings` and apply at once; numbers are typed freely next to the presets. -Desktop startup shows the myTeamSpeak login page (`LoginPage` in -`screens/account.slint`: the artwork and what an account gives beside the -form on wide windows, the form alone on narrow ones; email, password with a -show button, the one-time code when asked, Sign in, password recovery and -registration on the website) only when no session is saved and Continue -without an account was never chosen (`ui.skip_account_prompt`). A saved -session is checked in the background; only an expired one brings the page -back. The signed-in username/email and the account's avatar become the -primary app profile in the desktop user card and mobile You page; they do -not replace server identities or bookmark nicknames. Settings → My Account -shows the profile from the account service (avatar, name, email, -description, member since, previous sign-in, badges with a toggle each to -show up to three of them on servers, in the order picked, signed-in -devices, the User Tag, the account and myTS ids) or the sign-in form, -supports retry/OTP/sign-out, and -opens official browser flows for registration, activation, recovery and -account management. Account and renewal material live only in the keyring; -passwords and one-time codes are cleared after submission. Expired sessions -require fresh sign-in because password login supplies no renewal auth token. -See [research/myteamspeak.md](research/myteamspeak.md) for protocol evidence -and remaining cloud-sync limitations. +There is no account sign-in in this build: no login page at start, and +Settings → My Account shows the identity in use under a note, "Account sign-in +is not available in this build." The myTeamSpeak account (profile, avatar, +badges, User Tag) is meant to return through the gateway; the sign-in +screens (`screens/account.slint`) stay in the Slint code for it, fed no data +(`Bridge.myts` keeps its default: signed out, not available, no prompt). +[research/myteamspeak.md](research/myteamspeak.md) keeps the protocol notes. ## The Stream Studio