diff --git a/Cargo.lock b/Cargo.lock index 8094e97..eb691b7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1585,7 +1585,6 @@ dependencies = [ "keyring", "oauth2", "open", - "parking_lot 0.13.0", "rand 0.10.4", "reqwest", "rfd", @@ -2536,15 +2535,6 @@ dependencies = [ "scopeguard", ] -[[package]] -name = "lock_api" -version = "0.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65d91b22da179613dcf4d6ec8349563f52a363f6849e03b00dd0a185ec4a59af" -dependencies = [ - "scopeguard", -] - [[package]] name = "log" version = "0.4.35" @@ -3313,7 +3303,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7d17b78036a60663b797adeaee46f5c9dfebb86948d1255007a1d6be0271ff99" dependencies = [ "instant", - "lock_api 0.4.14", + "lock_api", "parking_lot_core 0.8.6", ] @@ -3323,20 +3313,10 @@ version = "0.12.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" dependencies = [ - "lock_api 0.4.14", + "lock_api", "parking_lot_core 0.9.12", ] -[[package]] -name = "parking_lot" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a9cf937ca4e1d0b7578784559063422fc39ae7c5a00f02471f2614d5486fd226" -dependencies = [ - "lock_api 0.5.0", - "parking_lot_core 0.10.0", -] - [[package]] name = "parking_lot_core" version = "0.8.6" @@ -3364,18 +3344,6 @@ dependencies = [ "windows-link", ] -[[package]] -name = "parking_lot_core" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9cfff060068cc18aa7815010fcaf80c68c7fb9e85fc7f5c0f9bf142c21d19826" -dependencies = [ - "libc", - "redox_syscall 0.9.5", - "smallvec", - "windows-link", -] - [[package]] name = "password-hash" version = "0.6.1" diff --git a/Cargo.toml b/Cargo.toml index cb48db4..fd62a10 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,7 +40,6 @@ tracing-appender = "0.2.5" argon2 = { version = "0.6.0", default-features = false, features = ["alloc"] } thiserror = "2.0.21" zeroize = { version = "1.9.2", features = ["derive"] } -parking_lot = "0.13.0" oauth2 = { version = "5.0.0", default-features = false } webbrowser = "1.2.7" diff --git a/README.md b/README.md index 23c1065..9da15a2 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,9 @@ panel-based window inspired by GitKraken. > work out of the box. OAuth sign-in needs the client ID of an OAuth app you register > yourself, because no build embeds one yet. The git operations are covered by tests on > local repositories; SSH sign-in, proxies and OAuth are covered by unit tests of their -> logic, not by tests against live servers. The interface has no language setting yet: most -> of it is in English, the Preferences window in French. It is being moved from egui to iced -> and the shared Colony UI kit, which brings English and French locales. +> logic, not by tests against live servers. The interface is built on iced and has no +> language setting yet: most of it is in French, with some labels still in English. It is +> meant to move to the shared Colony UI kit, which brings English and French locales. ## Why GitSpace @@ -42,17 +42,19 @@ panel-based window inspired by GitKraken. - Clone from GitHub, GitLab or any Git URL over HTTPS or SSH, and reopen recent repositories. - Repository overview with fetch, pull (fast-forward), push, open in the file manager and open a terminal, plus optional auto-fetch on an interval. -- Stage and unstage files with their diffs, restore a file from another branch, and create, - apply and drop stashes. +- Stage and unstage files with their diffs, commit, restore a file from another branch, and + create, apply and drop stashes. - History with commit diffs, filtered by branch. -- Branches: create, rename, delete, check out and track, merge or rebase into the current - branch, compare with it, pin favourites, and archive a branch as a tag. +- Branches: create, rename, delete, check out and track, merge a branch into the current one + or rebase the current one onto it, compare with it, pin favourites, and archive a branch as + a tag. Delete, merge and rebase ask for confirmation, and checkout refuses to overwrite + uncommitted changes. - Sign in to GitHub with a one-time code entered on github.com (OAuth device flow), to GitLab through OAuth in the browser (PKCE), or to GitHub, GitLab and self-hosted hosts with a personal access token. - Network preferences: HTTP and HTTPS proxies, transfer timeout, preferring HTTPS and allowing SSH. -- Four Catppuccin themes, adjustable control sizes and a reduced-motion setting. +- Four Catppuccin themes. - Structured logs with daily rotation (`GITSPACE_LOG` sets the filter). ## Installation diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Bold.ttf deleted file mode 100644 index 41365a8..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-BoldItalic.ttf deleted file mode 100644 index ede5867..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBold.ttf deleted file mode 100644 index 7430b4f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBoldItalic.ttf deleted file mode 100644 index 53020b9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLight.ttf deleted file mode 100644 index cc99cdf..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLightItalic.ttf deleted file mode 100644 index 10bcdaa..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Italic.ttf deleted file mode 100644 index d3857d6..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Light.ttf deleted file mode 100644 index 56d5f65..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-LightItalic.ttf deleted file mode 100644 index bcb382c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Medium.ttf deleted file mode 100644 index ee8c06c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-MediumItalic.ttf deleted file mode 100644 index f836007..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Regular.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Regular.ttf deleted file mode 100644 index 8e9ac86..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Regular.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBold.ttf deleted file mode 100644 index 8c33920..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBoldItalic.ttf deleted file mode 100644 index dcd0a9a..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Thin.ttf deleted file mode 100644 index 5a288f4..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ThinItalic.ttf deleted file mode 100644 index 8410608..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFont-ThinItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Bold.ttf deleted file mode 100644 index 2515d7b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-BoldItalic.ttf deleted file mode 100644 index 1ed2ee9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBold.ttf deleted file mode 100644 index fbac445..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBoldItalic.ttf deleted file mode 100644 index 37ef9fe..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLight.ttf deleted file mode 100644 index ff486a9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLightItalic.ttf deleted file mode 100644 index 4b18f9f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Italic.ttf deleted file mode 100644 index c9156a0..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Light.ttf deleted file mode 100644 index 3ccfbd5..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-LightItalic.ttf deleted file mode 100644 index ec1af2b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Medium.ttf deleted file mode 100644 index c44d7fe..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-MediumItalic.ttf deleted file mode 100644 index 8c3d9ae..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Regular.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Regular.ttf deleted file mode 100644 index bde439e..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Regular.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBold.ttf deleted file mode 100644 index 7e65ea9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBoldItalic.ttf deleted file mode 100644 index b83d3a0..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Thin.ttf deleted file mode 100644 index 9a65eff..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ThinItalic.ttf deleted file mode 100644 index fd2853d..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontMono-ThinItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Bold.ttf deleted file mode 100644 index 953eefc..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-BoldItalic.ttf deleted file mode 100644 index 26f77ff..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBold.ttf deleted file mode 100644 index 2de09ec..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBoldItalic.ttf deleted file mode 100644 index 876ab42..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLight.ttf deleted file mode 100644 index da2ab8f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLightItalic.ttf deleted file mode 100644 index b812b7d..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Italic.ttf deleted file mode 100644 index d64e92f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Light.ttf deleted file mode 100644 index eecc759..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-LightItalic.ttf deleted file mode 100644 index cee40b6..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Medium.ttf deleted file mode 100644 index 7dc9cd8..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-MediumItalic.ttf deleted file mode 100644 index 337396e..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Regular.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Regular.ttf deleted file mode 100644 index c661453..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Regular.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBold.ttf deleted file mode 100644 index dd4f78d..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBoldItalic.ttf deleted file mode 100644 index e0fb5e9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Thin.ttf deleted file mode 100644 index 4423c1c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ThinItalic.ttf deleted file mode 100644 index 5c7e784..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNLNerdFontPropo-ThinItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Bold.ttf deleted file mode 100644 index de2d3b3..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-BoldItalic.ttf deleted file mode 100644 index 35bf0cb..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBold.ttf deleted file mode 100644 index 0917928..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBoldItalic.ttf deleted file mode 100644 index eaec97c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLight.ttf deleted file mode 100644 index 5bc7d30..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLightItalic.ttf deleted file mode 100644 index 75f3496..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Italic.ttf deleted file mode 100644 index d867a9c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Light.ttf deleted file mode 100644 index 55e0842..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-LightItalic.ttf deleted file mode 100644 index 3eb731d..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf deleted file mode 100644 index 79a4b1f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-MediumItalic.ttf deleted file mode 100644 index 3c3a637..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBold.ttf deleted file mode 100644 index c95fbbc..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBoldItalic.ttf deleted file mode 100644 index ad38aaf..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Thin.ttf deleted file mode 100644 index 1ec349b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ThinItalic.ttf deleted file mode 100644 index efc4ae0..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFont-ThinItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Bold.ttf deleted file mode 100644 index a03c26b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-BoldItalic.ttf deleted file mode 100644 index 2b3c9eb..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBold.ttf deleted file mode 100644 index 5649d15..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBoldItalic.ttf deleted file mode 100644 index ef84f9c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLight.ttf deleted file mode 100644 index 6a01f36..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLightItalic.ttf deleted file mode 100644 index e72d48b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Italic.ttf deleted file mode 100644 index a715148..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Light.ttf deleted file mode 100644 index 7e76224..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-LightItalic.ttf deleted file mode 100644 index d065630..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Medium.ttf deleted file mode 100644 index 254a920..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-MediumItalic.ttf deleted file mode 100644 index f002d98..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Regular.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Regular.ttf deleted file mode 100644 index f693474..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Regular.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBold.ttf deleted file mode 100644 index 3959e9f..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBoldItalic.ttf deleted file mode 100644 index 5e1a548..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Thin.ttf deleted file mode 100644 index 12994fe..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ThinItalic.ttf deleted file mode 100644 index 164114c..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontMono-ThinItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Bold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Bold.ttf deleted file mode 100644 index a39883a..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Bold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-BoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-BoldItalic.ttf deleted file mode 100644 index cad2d51..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-BoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBold.ttf deleted file mode 100644 index b75d53e..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBoldItalic.ttf deleted file mode 100644 index 1c5b0ef..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLight.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLight.ttf deleted file mode 100644 index 7b9b79b..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLight.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLightItalic.ttf deleted file mode 100644 index bf291f0..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ExtraLightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Italic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Italic.ttf deleted file mode 100644 index e4eea34..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Italic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Light.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Light.ttf deleted file mode 100644 index 5e026db..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Light.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-LightItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-LightItalic.ttf deleted file mode 100644 index 24004a1..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-LightItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Medium.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Medium.ttf deleted file mode 100644 index ff3ddac..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Medium.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-MediumItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-MediumItalic.ttf deleted file mode 100644 index 706b2d0..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-MediumItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Regular.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Regular.ttf deleted file mode 100644 index 8011ada..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Regular.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBold.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBold.ttf deleted file mode 100644 index 243dc09..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBold.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBoldItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBoldItalic.ttf deleted file mode 100644 index e36cfcf..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-SemiBoldItalic.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Thin.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Thin.ttf deleted file mode 100644 index f563ce9..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-Thin.ttf and /dev/null differ diff --git a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ThinItalic.ttf b/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ThinItalic.ttf deleted file mode 100644 index 52065a7..0000000 Binary files a/assets/JetBrainsMonoNerdFont/JetBrainsMonoNerdFontPropo-ThinItalic.ttf and /dev/null differ diff --git a/docs/README.md b/docs/README.md index 271b37a..f26036f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -22,6 +22,6 @@ Sorted by who is reading, not by subject. | | | |---|---| | [project/gitkraken-layout.md](project/gitkraken-layout.md) | the window layout, tabs and shortcuts, and what GitKraken has that GitSpace leaves out | -| [project/ui-stack.md](project/ui-stack.md) | why the interface is egui today and why it is moving to iced | +| [project/ui-stack.md](project/ui-stack.md) | why the interface moved from egui to iced, and where it goes next | Security policy: [../SECURITY.md](../SECURITY.md). diff --git a/docs/guide/configuration.md b/docs/guide/configuration.md index a2484cd..d6faf9a 100644 --- a/docs/guide/configuration.md +++ b/docs/guide/configuration.md @@ -34,7 +34,9 @@ GitSpace never saves over a file it could not read: GitSpace started or `GITSPACE_TOKEN_MASTER_PASSWORD` changed or is no longer set: saving or removing a token fails with an error and the file is left as it is. Unlock the keyring or set the same master password, then restart GitSpace. If the key is gone for good, move - `tokens.enc` aside to start over. + `tokens.enc` aside to start over. Tokens saved while the keyring was locked are encrypted + with `token-local-key.bin`; the next start with the keyring unlocked reads them with that + key and saves them again under the keyring key. - **`token-hosts.json` cannot be read**: the host list is left as it is and the error is logged. @@ -76,5 +78,4 @@ count set in Preferences are deleted at startup. Logs never contain a token. |---|---| | `GITSPACE_LOG` | the log filter, in [`tracing` `EnvFilter`](https://docs.rs/tracing-subscriber/latest/tracing_subscriber/filter/struct.EnvFilter.html) syntax. The default is `gitspace=info,info`; `GITSPACE_LOG=gitspace=debug` shows GitSpace's own debug messages | | `GITSPACE_TOKEN_MASTER_PASSWORD` | only used when the system keyring is unavailable: a password mixed (Argon2id, salt in `token-salt.bin`) into `token-local-key.bin`, the key that then encrypts `tokens.enc`. In that case it must be set to the same value every time GitSpace starts, or saved tokens cannot be decrypted. It is ignored while the keyring holds the key | -| `GITSPACE_PROFILE_UI` | when set, logs how long each part of the interface takes to draw, for profiling | | `GITSPACE_GITHUB_CLIENT_ID`, `GITSPACE_GITLAB_CLIENT_ID` | read when GitSpace is **built**, not when it runs: the OAuth client IDs compiled into the binary, used instead of any ID entered in **Configure OAuth Apps** on the Auth tab. Without them, OAuth sign-in needs a client ID entered there: a GitHub OAuth app with "Enable Device Flow" ticked, or a GitLab application with "Confidential" unticked and the redirect URI `http://127.0.0.1:9876/callback` | diff --git a/docs/internals/architecture.md b/docs/internals/architecture.md index a8d150d..40a2b52 100644 --- a/docs/internals/architecture.md +++ b/docs/internals/architecture.md @@ -1,13 +1,13 @@ # Architecture GitSpace is one binary crate, `gitspace`, with no workspace and no build script. `src/main.rs` -answers `--version`, starts logging and hands the window to eframe; everything else lives in +answers `--version`, starts logging and hands the window to iced; everything else lives in five modules. ``` src/ -├── main.rs entry point: --version, logging, eframe::run_native -├── ui/ the egui application: shell, tabs, panels, theme, motion +├── main.rs entry point: --version, logging, iced::application +├── ui/ the iced application: shell, tabs, panels, theme ├── git/ repository operations on top of git2, plus the git CLI for three of them ├── auth/ tokens: validation, OAuth, keyring and encrypted-file storage ├── config.rs config.json: preferences, network and logging options, atomic writes @@ -21,40 +21,45 @@ token as a plain argument from the UI. ## `ui`: the application -`ui/app.rs` holds `GitSpaceApp`, the `eframe::App`. Each frame it handles keyboard shortcuts, -draws the shell from `ui/layout.rs` (header, left rail, tab strip, see -[gitkraken-layout.md](../project/gitkraken-layout.md)) and the active tab, applies changes the -panels report through `take_*` methods, and runs auto-fetch when it is due. +`ui/app.rs` holds `GitSpaceApp`, the iced application state. Its `update` routes each +message to the panel it belongs to, applies changes the panels report through `take_*` +methods, and reloads the other panels when one of them changes the repository (commit, +checkout, merge, rebase). Its `view` draws the shell from `ui/layout.rs` (header, left rail, +tab strip, see [gitkraken-layout.md](../project/gitkraken-layout.md)) and the active tab. Its +subscriptions are the Ctrl+1 to Ctrl+7 tab shortcuts, the auto-fetch timer and the toast +timer. One file per tab: `clone.rs` (search and clone), `recent.rs` (the Open tab), `repo_overview.rs`, `stage.rs`, `history.rs`, `branches.rs`, `auth.rs`, and `preferences.rs` for the full-window -Preferences. `settings.rs` is an older settings panel that the tab strip no longer shows. -Shared pieces: `theme.rs` (the Catppuccin palettes), `animation.rs` (motion tokens and reduced -motion), `menu.rs` (menu items and their hover animation), `fonts.rs` (the bundled JetBrains -Mono Nerd Font), `notifications.rs` (toasts) and `perf.rs` (frame timings, logged when -`GITSPACE_PROFILE_UI` is set). `dev_gallery.rs` is a widget gallery shown in debug builds only. +Preferences. Shared pieces: `theme.rs` (the Catppuccin palettes), `menu.rs` (menu items), +`fonts.rs` (the bundled JetBrains Mono Nerd Font, Regular only), `context.rs` (the open +repository) and `notifications.rs` (toasts). -Network work that can take a while (clone, repository search, token checks, OAuth, auto-fetch) -runs on a thread behind a `poll_promise::Promise` that the frame polls. Fetch, pull and push -from Repo Overview still run on the UI thread. +Every git, keyring and network call runs in an iced `Task`, on tokio's blocking pool, and +returns its result as a message. Results carry the repository path they were computed for, +and a panel drops a result for a repository that is no longer open. `view` functions only +read state. ## `git`: repository operations Thin functions over [git2](https://docs.rs/git2) (libgit2, vendored OpenSSL), one file per -area: `clone.rs`, `remote.rs` (fetch, pull as fast-forward only, push, prune), `branch.rs`, -`log.rs`, `diff.rs`, `status.rs`, `stash.rs`, `compare.rs` and `discovery.rs` (repository root, -worktrees, submodules). +area: `clone.rs`, `remote.rs` (fetch, pull as a fast-forward of the checked-out branch only, +push of the checked-out branch to its upstream), `branch.rs`, `commit.rs`, `log.rs`, +`diff.rs`, `status.rs`, `stash.rs`, `compare.rs` and `merge.rs`. Checkout, pull and stash +apply use libgit2's safe checkout, which fails instead of overwriting a modified file. `transport.rs` is shared by every network operation: it checks the URL against the network preferences (HTTPS preferred, SSH allowed), picks the proxy, applies the idle timeout, and -answers libgit2's credential callback. HTTPS remotes get the saved token, plain HTTP never -does, and SSH tries ssh-agent then the default key files, each method once. +answers libgit2's credential callback. Only `https://` remotes get the saved token. Any URL +with a colon before its first slash (`ssh://`, `git+ssh://`, `host:path`) counts as SSH, which +tries ssh-agent then the default key files, each method once. Three operations shell out to the `git` command instead of libgit2, which is why `git` must -be on `PATH` at runtime: merge and rebase (`merge.rs`, with a timeout) and restoring a file -from another branch (`branch.rs`). +be on `PATH` at runtime: merge and rebase (`merge.rs`, with a timeout, reading git's output +while it runs) and restoring a file from another branch (`branch.rs`). -`repo_cache.rs` is a cache of open repositories that nothing calls yet. +`repo_cache.rs` keeps a few open `Repository` handles per thread for the read-only +functions; `merge.rs` re-reads the index before it lists conflicts. ## `auth`: tokens @@ -64,8 +69,12 @@ it, and `TokenStorage`, which keeps it. Tokens go to the operating system keyrin With the encrypted fallback on, they are also written to `tokens.enc` (ChaCha20-Poly1305, fresh nonce per write) under a key that lives in the keyring, or in `token-local-key.bin` when the keyring is unavailable, optionally mixed with `GITSPACE_TOKEN_MASTER_PASSWORD` -through Argon2id. A file that exists but cannot be decrypted is never overwritten. -Host names are normalised to `https://`; a plain `http://` host is refused before any request. +through Argon2id. If the keyring key cannot decrypt the file, the local key is tried and the +file is written again under the keyring key. A file that exists but cannot be decrypted is +never overwritten, and secret files are created owner-only (0600) on Unix. Tokens are saved +under the lowercase host name without scheme or port, the form lookups use; a plain `http://` +host is refused before any request. Signing out removes the token from the keyring and from +`tokens.enc`. `auth/oauth.rs` runs the two OAuth sign-ins, both through its own reqwest client with redirects turned off: @@ -79,7 +88,8 @@ redirects turned off: - **GitLab** uses the authorization code flow with PKCE: `OAuthFlow` opens the browser and listens for the callback on `127.0.0.1` port 9876, the redirect URI registered with the GitLab application. If that port is in use, sign-in stops with an error before the browser - opens. + opens. A request without the expected `state` gets a 400 and the listener keeps waiting. + An expired GitLab token is refreshed with its refresh token when it is next needed. The client IDs come from `GITSPACE_GITHUB_CLIENT_ID` and `GITSPACE_GITLAB_CLIENT_ID` at build time (`ui/auth.rs`), and otherwise from the IDs entered under Configure OAuth Apps. @@ -87,7 +97,7 @@ time (`ui/auth.rs`), and otherwise from the IDs entered under Configure OAuth Ap ## `config`, `logging`, `error` `config.rs` loads and saves `config.json`. An unknown value falls back to its default -without discarding the rest, an unparseable file is backed up before defaults are used, and +without discarding the rest, out-of-range numbers are clamped when read, an unparseable file is backed up before defaults are used, and every write goes through `write_atomic` (temporary file, sync, rename). Where the files live is in [configuration](../guide/configuration.md). @@ -114,7 +124,7 @@ Today these only log a warning at startup; nothing else reads them. ## Tests Unit tests sit next to the code, in a `#[cfg(test)] mod tests` block, or in `git/tests.rs` -and `ui/tests.rs` for the larger suites. The git tests build throwaway repositories with +for the larger git suite. The git tests build throwaway repositories with `tempfile`. CI runs the built binary with `--version`, as the release smoke test does. ## Release chain diff --git a/docs/project/gitkraken-layout.md b/docs/project/gitkraken-layout.md index d80edd9..e6bc4b9 100644 --- a/docs/project/gitkraken-layout.md +++ b/docs/project/gitkraken-layout.md @@ -21,11 +21,10 @@ This page describes the shell as it is built today, in `src/ui/layout.rs` and ``` - **Header.** Pinned to the top. Clicking the GitSpace name opens Preferences, which - replaces the whole window until it is closed (General, Appearance, Accessibility and - GitSpace categories). -- **Left rail.** A resizable side panel, 220 px wide by default, in three groups: - - *Workspaces*: Recent, Favorites and Local Repos open the Open tab; Remote Repos opens - Clone. + replaces the whole window until it is closed (General, Appearance and GitSpace + categories). +- **Left rail.** A side panel, 220 px wide, in three groups: + - *Workspaces*: Recent opens the Open tab; Remote Repos opens Clone. - *Actions*: Clone, Open, New Branch (the Branches tab) and Sync (the Stage tab). - *Context*: the active repository with its path, and buttons to open it in the file manager or copy its path. "No repository selected" until one is open. @@ -35,24 +34,19 @@ This page describes the shell as it is built today, in `src/ui/layout.rs` and ## Tabs In their default order: Clone, Open, Repo Overview, Stage, History, Branches and Auth. -Debug builds add a Dev Gallery tab at the end, a gallery of the menus, buttons and inputs -with their animations, for development. - **Click** a tab to show it. The active tab is underlined in the theme's accent colour. -- **Ctrl+1 to Ctrl+8** (Cmd on macOS) jump to the tab in that position of the current order. -- **Drag** a tab over another to swap them; the dragged tab becomes active. The new order - lasts until GitSpace is closed. +- **Ctrl+1 to Ctrl+7** (Cmd on macOS) jump to the tab in that position. ## What it leaves out GitKraken has more than this, and so did earlier notes for GitSpace. None of the following -exists, and none of it is planned for the egui shell: +exists, and none of it is planned yet: - a right-hand context rail; - context menus on tabs, or tabs that detach into their own window; -- a commit graph with one lane per branch: History draws a single line, with merge commits - marked; +- a commit graph: History is a plain list of commits; - telemetry of any kind, including on navigation (see [Privacy](../../README.md#privacy)). -The interface is being moved to iced and the shared Colony UI kit (see +The interface runs on iced and is meant to move to the shared Colony UI kit (see [ui-stack.md](ui-stack.md)); this page changes with that move. diff --git a/docs/project/ui-stack.md b/docs/project/ui-stack.md index 924e151..e5d7cd3 100644 --- a/docs/project/ui-stack.md +++ b/docs/project/ui-stack.md @@ -1,38 +1,32 @@ # The UI stack -## Today: egui 0.27 through eframe +## Today: iced 0.13 -GitSpace draws its window with [egui](https://github.com/emilk/egui) 0.27, run by eframe with -the OpenGL (glow) renderer. Panels are immediate-mode: every frame, `GitSpaceApp::update` -in `src/ui/app.rs` lays out the header, the left rail and the active tab again from the -application state. Clone, repository search, token checks, OAuth sign-in and auto-fetch run -on a background thread behind a `poll_promise::Promise`, so the window keeps drawing while -they wait on the network. Fetch, pull and push started from Repo Overview do not yet: they -run on the UI thread, and the window stops responding until they finish. +GitSpace draws its window with [iced](https://iced.rs) 0.13 on the wgpu renderer, with tokio +as its runtime. The application follows iced's model: `GitSpaceApp` in `src/ui/app.rs` holds +the state, `update` handles one message at a time, and `view` builds the header, the left +rail and the active tab from that state. Each panel in `src/ui/` has its own `Message` enum, +`update` and `view`. -The look is GitSpace's own: four Catppuccin palettes in `src/ui/theme.rs`, motion tokens and -the reduced-motion switch in `src/ui/animation.rs`, the bundled JetBrains Mono Nerd Font in -`src/ui/fonts.rs`, and hand-drawn menu items in `src/ui/menu.rs`. +Git, keyring and network work never runs in `update` or `view`. It goes to an iced `Task` on +tokio's blocking pool and comes back as a message, so the window keeps drawing during a clone, +a search, a fetch, a merge or a keyring prompt. -## Why egui was chosen +The look is GitSpace's own: four Catppuccin palettes in `src/ui/theme.rs`, the bundled +JetBrains Mono Nerd Font (Regular) in `src/ui/fonts.rs`, and menu items in `src/ui/menu.rs`. -Two options were on the table when GitSpace started: +## Before: egui -- **Tauri with a web frontend**: the whole web ecosystem and mature UI kits, at the cost of a - Rust backend plus a web view at runtime, a two-language build and a larger memory footprint - for a simple shell. -- **A native Rust GUI (egui)**: one language end to end, a small binary with no web view, and - typed colours for theming, at the cost of fewer ready-made widgets and less polish out of - the box. +The first versions used [egui](https://github.com/emilk/egui) 0.27 through eframe. egui was +chosen over Tauri with a web frontend to keep one language end to end and a small binary +with no web view. It was replaced because the other Project Colony programs share a design +system built on iced, and because the immediate-mode panels ran their git calls inside the +frame. -egui won, to keep the project in Rust and the runtime small while the workspace UI was being -prototyped. +## Where it is going: colony-ui -## Where it is going: iced and colony-ui - -The other Project Colony programs share one design system, +The shared design system, [colony-ui](https://github.com/Project-Colony/Project-Colony-Resources/tree/main/crates/colony-ui), -built on [iced](https://iced.rs) 0.14. It brings the shared typography, themes, motion, -preferences page, English and French locales and the per-user paths, none of which egui -GitSpace can reuse. GitSpace is being ported to it. `rust-version` is 1.100, above the 1.88 -floor of iced 0.14. Until that port lands, the egui shell described here is what runs. +is built on iced 0.14. It brings the shared typography, themes, preferences page, English and +French locales and per-user paths. Moving GitSpace onto it means upgrading from iced 0.13 to +0.14 first. `rust-version` is 1.100, above the 1.88 floor of iced 0.14. diff --git a/src/auth/mod.rs b/src/auth/mod.rs index c981ac9..31fb7a6 100644 --- a/src/auth/mod.rs +++ b/src/auth/mod.rs @@ -3,9 +3,7 @@ pub mod oauth; use std::collections::{HashMap, HashSet}; use std::fs; use std::io::ErrorKind; -#[cfg(unix)] -use std::os::unix::fs::PermissionsExt; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::sync::OnceLock; use std::time::Duration; @@ -21,7 +19,7 @@ use tracing::{error, info, warn}; use url::Url; use zeroize::{Zeroize, ZeroizeOnDrop}; -use crate::config::write_atomic; +use crate::config::write_private; pub use oauth::{DeviceFlow, OAuthFlow, OAuthProvider, OAuthResult, OAuthToken}; @@ -76,8 +74,42 @@ impl AuthManager { } } + /// Returns the token saved for `host`. An expired OAuth token with a refresh token is + /// refreshed first, which blocks on one HTTP request; if that fails, the saved access + /// token is returned and the host will reject it. pub fn resolve_for_host(&self, host: &str) -> Option { - self.storage.get_token(host).ok().flatten() + let key = storage_key(host); + if self + .get_oauth_token(&key) + .is_some_and(|oauth| oauth.is_expired() && oauth.refresh_token.is_some()) + { + // One refresh at a time: a provider that rotates refresh tokens refuses the second + // use of the same one. The token is read again once the lock is held. + static REFRESH: std::sync::Mutex<()> = std::sync::Mutex::new(()); + let _guard = REFRESH.lock().unwrap_or_else(|err| err.into_inner()); + if let Some(oauth) = self.get_oauth_token(&key) { + if oauth.is_expired() && oauth.refresh_token.is_some() { + if let Some(token) = self.refresh_oauth_token(&oauth) { + return Some(token); + } + } + } + } + self.storage.get_token(&key).ok().flatten() + } + + /// Refreshes an expired OAuth token, saves the new one and returns its access token. + fn refresh_oauth_token(&self, token: &OAuthToken) -> Option { + let refreshed = token + .refresh() + .inspect_err(|err| { + warn!(target: "gitspace::auth", host = %token.host, error = %err, "failed to refresh the OAuth token"); + }) + .ok()?; + if let Err(err) = self.store_oauth_token(&refreshed) { + warn!(target: "gitspace::auth", host = %token.host, error = %err, "failed to save the refreshed OAuth token"); + } + Some(refreshed.access_token) } pub fn resolve_for_url(&self, url: &str) -> Option { @@ -89,13 +121,15 @@ impl AuthManager { }) } - #[allow(dead_code)] - pub fn set_token(&self, host: &str, token: &str) -> Result<(), String> { - self.storage.set_token(host, token) - } - + /// Removes the token saved for `host`, normalized like a lookup. An entry that an older + /// release saved under the host as typed is removed too. pub fn clear_token(&self, host: &str) -> Result<(), String> { - self.storage.clear_token(host) + let key = storage_key(host); + let result = self.storage.clear_token(&key); + if key != host { + self.storage.clear_token(host)?; + } + result } pub fn known_hosts(&self) -> Vec { @@ -129,21 +163,24 @@ impl AuthManager { return Err("Token contains invalid characters".to_string()); } - let normalized_host = normalize_host(host)?; + let origin = normalize_host(host)?; let client = get_http_client(); - if normalized_host.contains("github") { - validate_github(client, &normalized_host, token).await - } else if normalized_host.contains("gitlab") { - validate_gitlab(client, &normalized_host, token).await - } else { - Ok(()) + match token_check(&origin) { + Some(TokenCheck::GitHub(url)) => validate_github(client, &url, trimmed).await, + Some(TokenCheck::GitLab(url)) => validate_gitlab(client, &url, trimmed).await, + None => Ok(()), } } pub async fn validate_and_store(&self, host: &str, token: &str) -> Result<(), String> { self.validate_token(host, token).await?; - self.storage.set_token(host, token) + let key = storage_key(host); + // Saved under the key `resolve_for_url` looks up, not the host as typed. + self.storage.set_token(&key, token.trim())?; + // The token typed by the user replaces an OAuth sign-in, whose refresh would + // otherwise overwrite it. + self.storage.clear_token(&format!("oauth:{key}")) } pub fn set_encrypted_fallback(&mut self, allowed: bool) { @@ -153,10 +190,11 @@ impl AuthManager { /// Stores an OAuth token for a host. pub fn store_oauth_token(&self, token: &OAuthToken) -> Result<(), String> { // Store the access token using the existing mechanism - self.storage.set_token(&token.host, &token.access_token)?; + let host = storage_key(&token.host); + self.storage.set_token(&host, &token.access_token)?; // Store the full OAuth token (with refresh token) as JSON in a separate entry - let oauth_key = format!("oauth:{}", token.host); + let oauth_key = format!("oauth:{host}"); let oauth_json = serde_json::to_string(token) .map_err(|e| format!("Failed to serialize OAuth token: {}", e))?; self.storage.set_token(&oauth_key, &oauth_json)?; @@ -174,7 +212,7 @@ impl AuthManager { /// Retrieves the OAuth token for a host, if one exists. pub fn get_oauth_token(&self, host: &str) -> Option { - let oauth_key = format!("oauth:{}", host); + let oauth_key = format!("oauth:{}", storage_key(host)); let oauth_json = self.storage.get_token(&oauth_key).ok()??; serde_json::from_str(&oauth_json).ok() } @@ -197,9 +235,11 @@ impl AuthManager { /// Clears OAuth token for a host. pub fn clear_oauth_token(&self, host: &str) -> Result<(), String> { - let oauth_key = format!("oauth:{}", host); - let _ = self.storage.clear_token(&oauth_key); - self.storage.clear_token(host) + let oauth_key = format!("oauth:{}", storage_key(host)); + let oauth_result = self.storage.clear_token(&oauth_key); + // The access token goes even when the refresh token could not be removed. + self.clear_token(host)?; + oauth_result } } @@ -207,6 +247,9 @@ impl AuthManager { #[derive(Clone)] pub struct TokenStorage { key: SecureKey, + /// The local key file, when `key` comes from the keyring: `tokens.enc` may have been + /// written with the local key while the keyring was locked. + local_key_path: Option, path: PathBuf, host_path: PathBuf, allow_encrypted_fallback: bool, @@ -241,23 +284,18 @@ struct EncryptedTokenFile { impl TokenStorage { pub fn new(allow_encrypted_fallback: bool) -> Self { - let key = load_or_create_keyring_key() - .map_err(|err| { + let (key, local_key_path) = match load_or_create_keyring_key() { + Ok(key) => (key, Some(config_dir().join(TOKEN_LOCAL_KEY_FILE))), + Err(err) => { warn!(target: "gitspace::auth", error = %err, "failed to access keyring encryption key"); - }) - .unwrap_or_else(|_| load_or_create_local_key()); - let path = dirs::config_dir() - .unwrap_or_else(|| PathBuf::from(".")) - .join(SERVICE_NAME) - .join(TOKEN_FILE_NAME); - let host_path = dirs::config_dir() - .unwrap_or_else(|| PathBuf::from(".")) - .join(SERVICE_NAME) - .join(HOST_FILE_NAME); + (load_or_create_local_key(), None) + } + }; Self { key: SecureKey(key), - path, - host_path, + local_key_path, + path: config_dir().join(TOKEN_FILE_NAME), + host_path: config_dir().join(HOST_FILE_NAME), allow_encrypted_fallback, } } @@ -312,26 +350,39 @@ impl TokenStorage { } } + /// Removes the token from the keyring and from `tokens.enc`, then the host from the host + /// list. The host stays listed when the keyring entry could not be removed, since the token + /// would still be used. pub fn clear_token(&self, host: &str) -> Result<(), String> { - if let Err(err) = self.remove_from_keyring(host) { - warn!(target: "gitspace::auth", error = %err, "failed to clear token from native keyring"); + let keyring_result = self.remove_from_keyring(host); + if let Err(err) = &keyring_result { + error!(target: "gitspace::auth", error = %err, host, "failed to clear token from native keyring"); } - let mut result = if self.allow_encrypted_fallback { - let mut map = self.read_fallback_for_update()?; - map.tokens.remove(host); + let file_result = self.scrub_fallback(host); + keyring_result?; + file_result?; + self.remove_host(host).inspect_err(|err| { + warn!(target: "gitspace::auth", error = %err, "failed to update saved host list"); + }) + } + + /// Removes `host` from `tokens.enc` whether or not the encrypted fallback is on, so a token + /// saved while it was on does not come back when it is turned on again. + fn scrub_fallback(&self, host: &str) -> Result<(), String> { + let mut map = match self.read_fallback_for_update() { + Ok(map) => map, + // With the fallback off the file is not in use, so a key mismatch is not an error. + Err(err) if !self.allow_encrypted_fallback => { + warn!(target: "gitspace::auth", error = %err, "could not remove the token from the encrypted file"); + return Ok(()); + } + Err(err) => return Err(err), + }; + if map.tokens.remove(host).is_some() { self.write_fallback(&map) } else { Ok(()) - }; - - if let Err(err) = self.remove_host(host) { - warn!(target: "gitspace::auth", error = %err, "failed to update saved host list"); - if result.is_ok() { - result = Err(err); - } } - - result } pub fn known_hosts(&self) -> Vec { @@ -377,6 +428,12 @@ impl TokenStorage { match entry.delete_credential() { Ok(()) => Ok(()), Err(keyring::Error::NoEntry) => Ok(()), + // No keyring service at all: nothing can have been saved there. A locked keyring + // (NoStorageAccess) is still an error, since the token may be in it. + Err(keyring::Error::PlatformFailure(err)) => { + warn!(target: "gitspace::auth", error = %err, host, "native keyring unavailable; nothing to remove there"); + Ok(()) + } Err(err) => Err(format!("Failed to remove keyring entry: {err}")), } } @@ -391,7 +448,7 @@ impl TokenStorage { let blob = encrypt_tokens(map, &self.key.0)?; let serialized = serde_json::to_string_pretty(&blob) .map_err(|err| format!("Failed to serialize credentials: {err}"))?; - write_atomic(&self.path, serialized.as_bytes()) + write_private(&self.path, serialized.as_bytes()) .map_err(|err| format!("Failed to write credentials: {err}")) } @@ -417,7 +474,28 @@ impl TokenStorage { }; let blob: EncryptedTokenFile = serde_json::from_str(&data) .map_err(|err| format!("Failed to parse credential file: {err}"))?; - decrypt_tokens(&blob, &self.key.0) + let err = match decrypt_tokens(&blob, &self.key.0) { + Ok(map) => return Ok(map), + Err(err) => err, + }; + + // Written with the local key while the keyring was locked: decrypt it with that key + // and save it again under the keyring key. + let Some(mut local_key) = self.local_key_path.as_deref().and_then(read_local_key) else { + return Err(err); + }; + let result = decrypt_tokens(&blob, &local_key); + local_key.zeroize(); + let map = result.map_err(|_| err)?; + match self.write_fallback(&map) { + Ok(()) => { + info!(target: "gitspace::auth", "re-encrypted saved tokens with the keyring key") + } + Err(err) => { + warn!(target: "gitspace::auth", error = %err, "failed to re-encrypt saved tokens with the keyring key") + } + } + Ok(map) } fn record_host(&self, host: &str) -> Result<(), String> { @@ -452,7 +530,7 @@ impl TokenStorage { fn write_host_index(&self, index: &HostIndex) -> Result<(), String> { let serialized = serde_json::to_string_pretty(index) .map_err(|err| format!("Failed to serialize host index: {err}"))?; - write_atomic(&self.host_path, serialized.as_bytes()) + write_private(&self.host_path, serialized.as_bytes()) .map_err(|err| format!("Failed to write host index: {err}")) } @@ -498,57 +576,47 @@ fn decrypt_tokens(blob: &EncryptedTokenFile, key: &[u8; 32]) -> Result [u8; 32] { - let key_path = dirs::config_dir() +/// The settings folder that holds the token files. +fn config_dir() -> PathBuf { + dirs::config_dir() .unwrap_or_else(|| PathBuf::from(".")) .join(SERVICE_NAME) - .join(TOKEN_LOCAL_KEY_FILE); +} - // Try to load existing key - let mut stored_key = match fs::read(&key_path) { - Ok(bytes) if bytes.len() == 32 => { - let mut key = [0u8; 32]; - key.copy_from_slice(&bytes); - key - } - Ok(_) => { - warn!(target: "gitspace::auth", "invalid local key file size, regenerating"); - generate_and_store_key(&key_path) - } - Err(err) if err.kind() == ErrorKind::NotFound => { - info!(target: "gitspace::auth", "generating new local encryption key"); - generate_and_store_key(&key_path) - } - Err(err) => { - // Replacing a key file that exists but cannot be read would make the tokens - // encrypted with it unrecoverable. Use a key for this session only: the saved - // tokens then fail to decrypt and are left untouched. - error!(target: "gitspace::auth", error = %err, "failed to read local key file"); - Generate::generate() - } - }; +/// Loads or creates the local encryption key, used when the keyring cannot hold the key. +/// +/// The key is 32 random bytes in `token-local-key.bin`, owner-only on Unix. When +/// `GITSPACE_TOKEN_MASTER_PASSWORD` is set, a key derived from it is XORed in for defense in +/// depth. The master password therefore only applies while the keyring is unavailable; a key +/// kept in the keyring is used as it is. +fn load_or_create_local_key() -> [u8; 32] { + let dir = config_dir(); + let mut key = load_or_create_secret(&dir.join(TOKEN_LOCAL_KEY_FILE)); + mix_master_password(&mut key, &dir); + key +} - // If master password is set, derive additional key material for defense in depth - if let Ok(master_password) = std::env::var(MASTER_PASSWORD_ENV) { - let salt: [u8; 16] = load_or_create_secret(TOKEN_SALT_FILE); - let mut derived = [0u8; 32]; - if derive_master_key(master_password.as_bytes(), &salt, &mut derived) { - // XOR the derived key with the stored key for defense in depth - for (a, b) in stored_key.iter_mut().zip(derived.iter()) { - *a ^= b; - } +/// Reads the local key without creating it, mixed with the master password like +/// [`load_or_create_local_key`]. +fn read_local_key(path: &Path) -> Option<[u8; 32]> { + let mut key: [u8; 32] = fs::read(path).ok()?.try_into().ok()?; + mix_master_password(&mut key, path.parent().unwrap_or(Path::new("."))); + Some(key) +} + +/// XORs the key derived from `GITSPACE_TOKEN_MASTER_PASSWORD`, if set, into `key`. +fn mix_master_password(key: &mut [u8; 32], dir: &Path) { + let Ok(master_password) = std::env::var(MASTER_PASSWORD_ENV) else { + return; + }; + let salt: [u8; 16] = load_or_create_secret(&dir.join(TOKEN_SALT_FILE)); + let mut derived = [0u8; 32]; + if derive_master_key(master_password.as_bytes(), &salt, &mut derived) { + for (a, b) in key.iter_mut().zip(derived.iter()) { + *a ^= b; } - // Zero the derived key - derived.zeroize(); } - - stored_key + derived.zeroize(); } /// Derives the key mixed into the local key when a master password is set, into `out`, which @@ -562,34 +630,6 @@ fn derive_master_key(password: &[u8], salt: &[u8], out: &mut [u8; 32]) -> bool { argon2.hash_password_into(password, salt, out).is_ok() } -/// Generates a cryptographically secure random key and stores it with restricted permissions. -fn generate_and_store_key(path: &PathBuf) -> [u8; 32] { - let key: [u8; 32] = Generate::generate(); - - if let Some(parent) = path.parent() { - if let Err(err) = fs::create_dir_all(parent) { - error!(target: "gitspace::auth", error = %err, "failed to create key directory"); - return key; - } - } - - // Write key file - if let Err(err) = fs::write(path, key) { - error!(target: "gitspace::auth", error = %err, "failed to write local key file"); - return key; - } - - // Set restrictive permissions (owner read/write only) - #[cfg(unix)] - { - if let Err(err) = fs::set_permissions(path, fs::Permissions::from_mode(0o600)) { - warn!(target: "gitspace::auth", error = %err, "failed to set key file permissions"); - } - } - - key -} - fn load_or_create_keyring_key() -> Result<[u8; 32], String> { let entry = Entry::new(SERVICE_NAME, TOKEN_KEYRING_ENTRY) .map_err(|err| format!("Failed to access keyring: {err}"))?; @@ -617,35 +657,39 @@ fn load_or_create_keyring_key() -> Result<[u8; 32], String> { } } -fn load_or_create_secret(name: &str) -> [u8; N] { - let path = dirs::config_dir() - .unwrap_or_else(|| PathBuf::from(".")) - .join(SERVICE_NAME) - .join(name); - - let secret: [u8; N] = Generate::generate(); - match fs::read(&path).map(<[u8; N]>::try_from) { - Ok(Ok(saved)) => return saved, - Err(err) if err.kind() != ErrorKind::NotFound => { - // Same as the local key: never replace a secret that exists but cannot be read. - warn!(target: "gitspace::auth", error = %err, path = %path.display(), "unable to read derived-key secret; using one for this session only"); +/// Reads the `N`-byte secret in `path`, or creates the file, owner-only on Unix, when it does +/// not exist. +/// +/// A file that exists but cannot be read or has the wrong size is never replaced: the tokens +/// encrypted with it would become unrecoverable. A secret for this session only is used +/// instead, so those tokens fail to decrypt and are left untouched. +fn load_or_create_secret(path: &Path) -> [u8; N] { + match fs::read(path) { + Ok(bytes) => match <[u8; N]>::try_from(bytes.as_slice()) { + Ok(saved) => return saved, + Err(_) => error!( + target: "gitspace::auth", + path = %path.display(), + size = bytes.len(), + expected = N, + "secret file has the wrong size; using a secret for this session only and leaving the file as it is" + ), + }, + Err(err) if err.kind() == ErrorKind::NotFound => { + let secret: [u8; N] = Generate::generate(); + if let Err(err) = write_private(path, &secret) { + error!(target: "gitspace::auth", error = %err, path = %path.display(), "failed to save a new secret file; it is used for this session only"); + } return secret; } - _ => {} - } - if let Some(parent) = path.parent() { - let _ = fs::create_dir_all(parent); - } - if let Err(err) = fs::write(&path, secret) { - warn!(target: "gitspace::auth", error = %err, path = %path.display(), "unable to persist derived-key secret"); - } else { - // Set restrictive permissions (owner read/write only) - #[cfg(unix)] - { - let _ = fs::set_permissions(&path, fs::Permissions::from_mode(0o600)); - } + Err(err) => error!( + target: "gitspace::auth", + error = %err, + path = %path.display(), + "failed to read secret file; using a secret for this session only" + ), } - secret + Generate::generate() } /// Turns a user-entered host into the `https://host[:port]` base URL that tokens are sent to. @@ -669,16 +713,32 @@ fn normalize_host(host: &str) -> Result { Ok(parsed.origin().ascii_serialization()) } -async fn validate_github(client: &Client, host: &str, token: &str) -> Result<(), String> { - let api_base = if host.contains("api.github.com") { - host.to_string() - } else if host.contains("github.com") { - "https://api.github.com".to_string() +/// The API that checks a token for `origin` (from [`normalize_host`]), with its `/user` URL. +#[derive(Debug, PartialEq, Eq)] +enum TokenCheck { + GitHub(String), + GitLab(String), +} + +/// Picks the API from the exact host name: a substring test would send the token of +/// `github.company.com` to `api.github.com`. +fn token_check(origin: &str) -> Option { + let host = Url::parse(origin).ok()?.host_str()?.to_ascii_lowercase(); + if host == "github.com" || host == "api.github.com" { + Some(TokenCheck::GitHub( + "https://api.github.com/user".to_string(), + )) + } else if host.starts_with("github.") { + // GitHub Enterprise Server serves its REST API under /api/v3. + Some(TokenCheck::GitHub(format!("{origin}/api/v3/user"))) + } else if host == "gitlab.com" || host.starts_with("gitlab.") { + Some(TokenCheck::GitLab(format!("{origin}/api/v4/user"))) } else { - format!("{}/api/v3", host) - }; - let url = format!("{}/user", api_base.trim_end_matches('/')); + None + } +} +async fn validate_github(client: &Client, url: &str, token: &str) -> Result<(), String> { let response = client .get(url) .header(USER_AGENT, HeaderValue::from_static("gitspace")) @@ -694,8 +754,7 @@ async fn validate_github(client: &Client, host: &str, token: &str) -> Result<(), } } -async fn validate_gitlab(client: &Client, host: &str, token: &str) -> Result<(), String> { - let url = format!("{}/api/v4/user", host.trim_end_matches('/')); +async fn validate_gitlab(client: &Client, url: &str, token: &str) -> Result<(), String> { let mut headers = HeaderMap::new(); headers.insert(USER_AGENT, HeaderValue::from_static("gitspace")); headers.insert( @@ -717,26 +776,31 @@ async fn validate_gitlab(client: &Client, host: &str, token: &str) -> Result<(), } } +/// Returns the lowercase host name of a URL, `host:port`, scp-like `user@host:path` or bare +/// host. pub fn extract_host(target: &str) -> Option { - if let Ok(url) = Url::parse(target) { - return url.host_str().map(|h| h.to_string()); - } - - if let Some((host, _)) = target.split_once("://") { - return Some(host.to_string()); - } - - if let Some((user_host, _)) = target.split_once(':') { - if let Some((_, host)) = user_host.split_once('@') { - return Some(host.to_string()); + let target = target.trim(); + let host = match Url::parse(target) { + // `gitlab.example.com:8443` parses as a URL with scheme `gitlab.example.com` and no + // host, so only a URL with a host is taken. + Ok(url) if url.host_str().is_some() => url.host_str().unwrap_or_default().to_string(), + _ => { + let rest = target.split_once("://").map_or(target, |(_, rest)| rest); + let authority = rest.split('/').next().unwrap_or_default(); + let authority = authority + .rsplit_once('@') + .map_or(authority, |(_, host)| host); + authority.split(':').next().unwrap_or_default().to_string() } - } + }; + let host = host.to_ascii_lowercase(); + (!host.is_empty()).then_some(host) +} - target - .split('/') - .next() - .filter(|segment| !segment.is_empty()) - .map(|h| h.to_string()) +/// The key a host's token is saved under: the host name [`extract_host`] finds, so a token +/// typed for `https://GitLab.example.com:8443/` is found again for any remote on that host. +fn storage_key(host: &str) -> String { + extract_host(host).unwrap_or_else(|| host.trim().to_ascii_lowercase()) } #[cfg(test)] @@ -798,6 +862,7 @@ mod tests { fn storage_in(dir: &std::path::Path) -> TokenStorage { TokenStorage { key: SecureKey(Generate::generate()), + local_key_path: Some(dir.join(TOKEN_LOCAL_KEY_FILE)), path: dir.join(TOKEN_FILE_NAME), host_path: dir.join(HOST_FILE_NAME), allow_encrypted_fallback: true, @@ -830,6 +895,102 @@ mod tests { assert_eq!(tokens["gitlab.com"], "second-token"); } + #[test] + fn sign_out_scrubs_the_token_file_with_the_fallback_off() { + let dir = tempfile::tempdir().expect("tempdir"); + let mut storage = storage_in(dir.path()); + storage + .persist_fallback("gitlab.com", "old-token") + .expect("save"); + storage + .persist_fallback("github.com", "kept-token") + .expect("save"); + + storage.set_allow_encrypted_fallback(false); + storage.scrub_fallback("gitlab.com").expect("scrub"); + let tokens = storage.read_fallback().expect("decrypt").tokens; + assert!(!tokens.contains_key("gitlab.com")); + assert_eq!(tokens["github.com"], "kept-token"); + + // A file this key cannot decrypt is not in use while the fallback is off. + let before = fs::read(&storage.path).expect("read tokens"); + let mut other_key = storage_in(dir.path()); + other_key.set_allow_encrypted_fallback(false); + other_key.scrub_fallback("github.com").expect("ignored"); + other_key.set_allow_encrypted_fallback(true); + assert!(other_key.scrub_fallback("github.com").is_err()); + assert_eq!(fs::read(&storage.path).expect("read tokens"), before); + } + + #[test] + fn wrong_size_secret_is_never_overwritten() { + let dir = tempfile::tempdir().expect("tempdir"); + let path = dir.path().join("gitspace").join(TOKEN_LOCAL_KEY_FILE); + + let created: [u8; 32] = load_or_create_secret(&path); + assert_eq!(load_or_create_secret::<32>(&path), created); + #[cfg(unix)] + { + use std::os::unix::fs::PermissionsExt; + let mode = fs::metadata(&path).expect("metadata").permissions().mode(); + assert_eq!(mode & 0o777, 0o600); + } + + // A truncated write: a session key is used and the file stays as it is. + fs::write(&path, &created[..10]).expect("truncate"); + let session: [u8; 32] = load_or_create_secret(&path); + assert_ne!(session, created); + assert_eq!(fs::read(&path).expect("read"), &created[..10]); + } + + #[cfg(unix)] + #[test] + fn token_files_are_owner_only() { + use std::os::unix::fs::PermissionsExt; + let dir = tempfile::tempdir().expect("tempdir"); + let storage = storage_in(dir.path()); + storage + .persist_fallback("github.com", "token") + .expect("save"); + // A file left 0644 by an older release is made owner-only on the next write. + fs::set_permissions(&storage.path, fs::Permissions::from_mode(0o644)).expect("chmod"); + storage + .persist_fallback("gitlab.com", "token") + .expect("save"); + storage.record_host("github.com").expect("record"); + for path in [&storage.path, &storage.host_path] { + let mode = fs::metadata(path).expect("metadata").permissions().mode(); + assert_eq!(mode & 0o777, 0o600, "{}", path.display()); + } + } + + #[test] + fn tokens_saved_with_the_local_key_open_once_the_keyring_is_back() { + let dir = tempfile::tempdir().expect("tempdir"); + // First run, keyring locked: the local key encrypts the file. + let local_key: [u8; 32] = load_or_create_secret(&dir.path().join(TOKEN_LOCAL_KEY_FILE)); + let locked = TokenStorage { + key: SecureKey(local_key), + local_key_path: None, + ..storage_in(dir.path()) + }; + locked + .persist_fallback("github.com", "token") + .expect("save"); + + // Next run, keyring unlocked: another key, the local one as a fallback. + let unlocked = storage_in(dir.path()); + assert_eq!( + unlocked.read_fallback().expect("decrypt").tokens["github.com"], + "token" + ); + // The file is now encrypted with the keyring key. + let blob: EncryptedTokenFile = + serde_json::from_slice(&fs::read(&unlocked.path).expect("read")).expect("parse"); + assert!(decrypt_tokens(&blob, &unlocked.key.0).is_ok()); + assert!(decrypt_tokens(&blob, &local_key).is_err()); + } + #[test] fn missing_token_file_starts_empty() { let dir = tempfile::tempdir().expect("tempdir"); @@ -871,6 +1032,67 @@ mod tests { assert!(normalize_host("ssh://gitlab.example.com").is_err()); } + #[test] + fn token_check_matches_the_exact_host() { + let check = |host: &str| token_check(&normalize_host(host).unwrap()); + let github = |url: &str| Some(TokenCheck::GitHub(url.to_string())); + let gitlab = |url: &str| Some(TokenCheck::GitLab(url.to_string())); + + assert_eq!(check("github.com"), github("https://api.github.com/user")); + assert_eq!( + check("API.GitHub.com"), + github("https://api.github.com/user") + ); + // An Enterprise host containing "github.com" keeps its token on its own server. + assert_eq!( + check("github.company.com"), + github("https://github.company.com/api/v3/user") + ); + assert_eq!( + check("https://github.example.org:8443/org"), + github("https://github.example.org:8443/api/v3/user") + ); + assert_eq!( + check("gitlab.com"), + gitlab("https://gitlab.com/api/v4/user") + ); + assert_eq!( + check("gitlab.example.com"), + gitlab("https://gitlab.example.com/api/v4/user") + ); + assert_eq!(check("notgithub.com"), None); + assert_eq!(check("mygitlab.example.com"), None); + assert_eq!(check("git.example.com"), None); + } + + #[test] + fn manual_hosts_are_saved_under_the_key_a_remote_looks_up() { + let remote = extract_host("https://gitlab.example.com/group/repo.git"); + assert_eq!(remote.as_deref(), Some("gitlab.example.com")); + for typed in [ + "gitlab.example.com", + "GitLab.example.com", + "gitlab.example.com:8443", + " gitlab.example.com/group ", + "https://gitlab.example.com", + "https://GitLab.Example.com:8443/", + ] { + assert_eq!(Some(storage_key(typed)), remote, "{typed}"); + } + for remote in [ + "ssh://git@GitLab.example.com:22/group/repo.git", + "git@gitlab.example.com:group/repo.git", + ] { + assert_eq!( + extract_host(remote).as_deref(), + Some("gitlab.example.com"), + "{remote}" + ); + } + assert_eq!(extract_host(""), None); + assert_eq!(extract_host("file:///home/me/repo"), None); + } + #[tokio::test] async fn plain_http_host_is_refused_before_any_request() { let dir = tempfile::tempdir().expect("tempdir"); diff --git a/src/auth/oauth.rs b/src/auth/oauth.rs index bd9878d..db0d128 100644 --- a/src/auth/oauth.rs +++ b/src/auth/oauth.rs @@ -15,7 +15,7 @@ use oauth2::basic::{BasicClient, BasicTokenResponse}; use oauth2::{ AuthUrl, AuthorizationCode, ClientId, CsrfToken, DeviceAuthorizationUrl, DeviceCodeErrorResponse, DeviceCodeErrorResponseType, EndpointNotSet, EndpointSet, HttpRequest, - HttpResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, Scope, + HttpResponse, PkceCodeChallenge, PkceCodeVerifier, RedirectUrl, RefreshToken, Scope, StandardDeviceAuthorizationResponse, TokenResponse, TokenUrl, }; use reqwest::blocking::Client; @@ -42,6 +42,10 @@ const SLOW_DOWN_STEP: Duration = Duration::from_secs(5); /// Longest wait between polls while the token endpoint cannot be reached. const MAX_POLL_BACKOFF: Duration = Duration::from_secs(60); +/// Answer to a request on the callback port that is not this sign-in's redirect. +const BAD_REQUEST: &str = + "HTTP/1.1 400 Bad Request\r\nContent-Length: 0\r\nConnection: close\r\n\r\n"; + const CODE_EXPIRED: &str = "The code expired before it was approved. Start the sign-in again."; /// OAuth provider configuration. @@ -108,27 +112,63 @@ pub struct OAuthToken { pub expires_at: Option, pub provider: String, pub host: String, + /// Client ID and token endpoint the refresh token is exchanged with. Missing from tokens + /// saved by older releases, which then cannot be refreshed. + #[serde(default, skip_serializing_if = "Option::is_none")] + pub client_id: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + pub token_url: Option, } impl OAuthToken { /// Creates a new OAuth token from a token response. pub fn from_response(response: &BasicTokenResponse, provider: &OAuthProvider) -> Self { - let expires_at = response.expires_in().map(|duration| { - let now = chrono::Utc::now().timestamp(); - now + duration.as_secs() as i64 - }); - Self { access_token: response.access_token().secret().to_string(), refresh_token: response.refresh_token().map(|t| t.secret().to_string()), - expires_at, + expires_at: expires_at(response), provider: provider.name.clone(), host: provider.host.clone(), + client_id: Some(provider.client_id.clone()), + token_url: Some(provider.token_url.clone()), } } + /// Exchanges the refresh token for a new access token. Blocks on one HTTP request. + /// + /// A response without a new refresh token keeps the current one. + pub fn refresh(&self) -> Result { + let refresh_token = self + .refresh_token + .as_ref() + .ok_or("The OAuth token has no refresh token")?; + let (Some(client_id), Some(token_url)) = (&self.client_id, &self.token_url) else { + return Err(format!( + "The {} token was saved without its client ID; sign in again", + self.provider + )); + }; + let client = BasicClient::new(ClientId::new(client_id.clone())).set_token_uri( + TokenUrl::new(token_url.clone()).map_err(|e| format!("Invalid token URL: {e}"))?, + ); + let http_client = http_client()?; + let response = client + .exchange_refresh_token(&RefreshToken::new(refresh_token.clone())) + .request(&|request| send(&http_client, request)) + .map_err(|e| format!("Token refresh failed: {e}"))?; + + Ok(Self { + access_token: response.access_token().secret().to_string(), + refresh_token: response + .refresh_token() + .map(|t| t.secret().to_string()) + .or_else(|| self.refresh_token.clone()), + expires_at: expires_at(&response), + ..self.clone() + }) + } + /// Checks if the token is expired or about to expire (within 5 minutes). - #[allow(dead_code)] // token refresh is not wired yet pub fn is_expired(&self) -> bool { if let Some(expires_at) = self.expires_at { let now = chrono::Utc::now().timestamp(); @@ -140,6 +180,13 @@ impl OAuthToken { } } +/// Unix time at which the access token of `response` expires, if it says. +fn expires_at(response: &BasicTokenResponse) -> Option { + response + .expires_in() + .map(|duration| chrono::Utc::now().timestamp() + duration.as_secs() as i64) +} + /// Result of an OAuth flow. #[derive(Debug, Clone)] pub enum OAuthResult { @@ -270,22 +317,26 @@ impl OAuthFlow { // Try to accept connection match listener.accept() { Ok((mut stream, _)) => { - let mut buffer = [0; 4096]; + // On macOS and Windows the accepted socket inherits non-blocking mode from + // the listener, and read() would fail with WouldBlock. + stream.set_nonblocking(false).ok(); stream.set_read_timeout(Some(Duration::from_secs(5))).ok(); - - if let Ok(size) = stream.read(&mut buffer) { - let request = String::from_utf8_lossy(&buffer[..size]); - - // Parse the callback - if let Some(result) = parse_callback(&request, &expected_state) { - // Send response to browser + let mut buffer = [0; 4096]; + let Ok(size) = stream.read(&mut buffer) else { + continue; + }; + let request = String::from_utf8_lossy(&buffer[..size]); + match parse_callback(&request, &expected_state) { + Callback::Ignored => { + let _ = stream.write_all(BAD_REQUEST.as_bytes()); + } + Callback::Answer(result) => { let response = match &result { Ok(_) => create_success_response(&self.provider.name), Err(err) => create_error_response(err), }; let _ = stream.write_all(response.as_bytes()); let _ = stream.flush(); - return result; } } @@ -560,46 +611,72 @@ fn send(client: &Client, request: HttpRequest) -> Result Option> { - // Parse GET request - let first_line = request.lines().next()?; - if !first_line.starts_with("GET /callback") { - return None; - } - - // Extract query parameters - let path = first_line.split_whitespace().nth(1)?; - let query_start = path.find('?')?; - let query = &path[query_start + 1..]; +/// What a request on the callback port is. +#[derive(Debug, PartialEq)] +enum Callback { + /// Not this sign-in's redirect: another path, or a missing or wrong state. It gets a 400 + /// answer and the wait goes on. + Ignored, + /// The provider's redirect, with the authorization code or the error it reports. + Answer(Result), +} - let params: HashMap<_, _> = query - .split('&') - .filter_map(|param| { - let mut parts = param.splitn(2, '='); - Some((parts.next()?, parts.next().unwrap_or(""))) - }) +/// Reads one request on the callback port. +/// +/// The state is checked before anything else: any web page can send a request to the loopback +/// port, so only one that carries the state of this sign-in may end it. +fn parse_callback(request: &str, expected_state: &str) -> Callback { + let Some(query) = request + .lines() + .next() + .and_then(|line| line.strip_prefix("GET /callback?")) + .and_then(|rest| rest.split_whitespace().next()) + else { + return Callback::Ignored; + }; + let params: HashMap = url::form_urlencoded::parse(query.as_bytes()) + .into_owned() .collect(); - // Check for error - if let Some(error) = params.get("error") { - let description = params.get("error_description").unwrap_or(&"Unknown error"); - return Some(Err(format!("{}: {}", error, description))); + match params.get("state") { + Some(state) if !expected_state.is_empty() && state == expected_state => {} + _ => { + warn!( + target: "gitspace::auth::oauth", + "Ignoring an OAuth callback without the expected state" + ); + return Callback::Ignored; + } } - // Verify state (CSRF protection) - let state = params.get("state").unwrap_or(&""); - if *state != expected_state { - warn!( - target: "gitspace::auth::oauth", - "CSRF state mismatch in OAuth callback" - ); - return Some(Err("Security error: state mismatch".to_string())); + if let Some(error) = params.get("error") { + let description = params + .get("error_description") + .map_or("Unknown error", String::as_str); + return Callback::Answer(Err(format!("{error}: {description}"))); } + match params.get("code") { + Some(code) => Callback::Answer(Ok(code.clone())), + None => Callback::Answer(Err( + "The sign-in callback has no authorization code".to_string() + )), + } +} - // Extract authorization code - let code = params.get("code")?; - Some(Ok((*code).to_string())) +/// Escapes `text` for an HTML page. +fn escape_html(text: &str) -> String { + let mut escaped = String::with_capacity(text.len()); + for c in text.chars() { + match c { + '&' => escaped.push_str("&"), + '<' => escaped.push_str("<"), + '>' => escaped.push_str(">"), + '"' => escaped.push_str("""), + '\'' => escaped.push_str("'"), + _ => escaped.push(c), + } + } + escaped } /// Creates an HTML success response for the browser. @@ -669,7 +746,7 @@ fn create_error_response(error: &str) -> String { "#, - error + escape_html(error) ); format!( @@ -802,7 +879,7 @@ mod tests { fn parse_callback_extracts_code() { let request = "GET /callback?code=abc123&state=xyz HTTP/1.1\r\nHost: localhost\r\n\r\n"; let result = parse_callback(request, "xyz"); - assert_eq!(result, Some(Ok("abc123".to_string()))); + assert_eq!(result, Callback::Answer(Ok("abc123".to_string()))); } #[test] @@ -810,14 +887,42 @@ mod tests { let request = "GET /callback?error=access_denied&error_description=User+denied&state=xyz HTTP/1.1\r\n"; let result = parse_callback(request, "xyz"); - assert!(matches!(result, Some(Err(_)))); + assert_eq!( + result, + Callback::Answer(Err("access_denied: User denied".to_string())) + ); + } + + #[test] + fn parse_callback_ignores_requests_without_the_state() { + for request in [ + "GET /callback?code=abc123&state=wrong HTTP/1.1\r\n", + "GET /callback?code=abc123 HTTP/1.1\r\n", + // A stray page cannot end the sign-in with an error either. + "GET /callback?error=access_denied HTTP/1.1\r\n", + "GET /callback?error=access_denied&state=wrong HTTP/1.1\r\n", + "GET /favicon.ico HTTP/1.1\r\n", + "GET /callback HTTP/1.1\r\n", + "", + ] { + assert_eq!( + parse_callback(request, "expected"), + Callback::Ignored, + "{request}" + ); + } + // No expected state means no request can match. + let request = "GET /callback?code=abc123&state= HTTP/1.1\r\n"; + assert_eq!(parse_callback(request, ""), Callback::Ignored); } #[test] - fn parse_callback_rejects_wrong_state() { - let request = "GET /callback?code=abc123&state=wrong HTTP/1.1\r\n"; - let result = parse_callback(request, "expected"); - assert!(matches!(result, Some(Err(_)))); + fn error_page_escapes_the_provider_error() { + let page = create_error_response(" & \"more\""); + assert!(!page.contains("