Release pipeline in the builder menu. Release tab: keys (app-native, PBKDF2 + ChaCha20-Poly1305, passphrase asked twice), Linux/Windows builds (Windows via VM), sign, push. Server no longer watches the manifest: builder uploads seq-named binaries (sha256 checked) and pushes a signed manifest, which sets minimum, kicks outdated clients, announces and prunes old files. Per-CPU builds: x86-64 v1/v3/v4, clients pick the best level they support. Sessions store their release
Browse files at this commite47e0f706635de0ed321747fa031979ebdd12714Parent: debc8fb- feat
- release pipeline in the builder menu. Release tab: keys (app-native, PBKDF2 + ChaCha20-Poly1305, passphrase asked twice), Linux/Windows builds (Windows via VM), sign, push. Server no longer watches the manifest: builder uploads seq-named binaries (sha256 checked) and pushes a signed manifest, which sets minimum, kicks outdated clients, announces and prunes old files. Per-CPU builds: x86-64 v1/v3/v4, clients pick the best level they support. Sessions store their release
- overview shows clients per release. One builder at most (unique index), role moves only via the server CLI. Fix: Ctrl+K panicked on the Danger zone settings entry
44 changed files +1474 -274
- Cargo.lock +1 -0
- crates/client/Cargo.toml +1 -0
- crates/client/lang/en/builder.txt +1 -0
- crates/client/lang/en/builder_log.txt +1 -0
- crates/client/lang/en/builder_overview.txt +2 -0
- crates/client/lang/en/builder_release.txt +28 -0
- crates/client/lang/en/builder_users.txt +1 -4
- crates/client/lang/tr/builder.txt +1 -0
- crates/client/lang/tr/builder_log.txt +1 -0
- crates/client/lang/tr/builder_overview.txt +2 -0
- crates/client/lang/tr/builder_release.txt +28 -0
- crates/client/lang/tr/builder_users.txt +1 -4
- crates/client/src/cpu.rs +25 -0
- crates/client/src/gui.rs +20 -0
- crates/client/src/gui/builder.rs +8 -1
- crates/client/src/gui/builder/log.rs +3 -1
- crates/client/src/gui/builder/overview.rs +27 -0
- crates/client/src/gui/builder/release.rs +500 -0
- crates/client/src/gui/builder/users.rs +12 -66
- crates/client/src/gui/settings_page.rs +9 -3
- crates/client/src/lib.rs +2 -0
- crates/client/src/net/link.rs +37 -0
- crates/client/src/net/mod.rs +10 -0
- crates/client/src/release.rs +371 -0
- crates/client/src/settings.rs +12 -1
- crates/client/src/update.rs +32 -9
- crates/common/src/call.rs +13 -9
- crates/common/src/error.rs +2 -0
- crates/common/src/model.rs +18 -0
- crates/common/src/open.rs +8 -0
- crates/common/src/permission.rs +0 -4
- crates/common/src/update.rs +12 -0
- crates/server/src/call/admin.rs +42 -38
- crates/server/src/call/mod.rs +2 -1
- crates/server/src/db/schema.sql +2 -0
- crates/server/src/db/session.rs +10 -4
- crates/server/src/db/user.rs +10 -0
- crates/server/src/hub.rs +10 -0
- crates/server/src/lib.rs +4 -1
- crates/server/src/network.rs +7 -2
- crates/server/src/update.rs +140 -33
- packaging/keygen.sh +0 -29
- packaging/release-windows.ps1 +18 -10
- packaging/release.sh +40 -54
Cargo.lockmodified+1 -0
| @@ -1301,6 +1301,7 @@ dependencies = [ | |||
| 1301 | "spectrum", | 1301 | "spectrum", |
| 1302 | "sys-locale", | 1302 | "sys-locale", |
| 1303 | "sysinfo 0.40.4", | 1303 | "sysinfo 0.40.4", |
| 1304 | + "thiserror 2.0.21", | ||
| 1304 | "tokio", | 1305 | "tokio", |
| 1305 | "toml 1.2.3+spec-1.1.0", | 1306 | "toml 1.2.3+spec-1.1.0", |
| 1306 | "tracing", | 1307 | "tracing", |
crates/client/Cargo.tomlmodified+1 -0
| @@ -40,6 +40,7 @@ sysinfo = { version = "0.40.4", default-features = false, features = ["system"] | |||
| 40 | flate2 = "1.1.11" | 40 | flate2 = "1.1.11" |
| 41 | emojis = "0.9.1" | 41 | emojis = "0.9.1" |
| 42 | resvg = "0.50.0" | 42 | resvg = "0.50.0" |
| 43 | +thiserror = "2.0.21" | ||
| 43 | 44 | ||
| 44 | [target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies] | 45 | [target.'cfg(any(target_os = "linux", target_os = "windows"))'.dependencies] |
| 45 | nokhwa = { version = "0.10.11", default-features = false, features = ["input-native"] } | 46 | nokhwa = { version = "0.10.11", default-features = false, features = ["input-native"] } |
crates/client/lang/en/builder.txtmodified+1 -0
| @@ -6,6 +6,7 @@ storage = Storage | |||
| 6 | access = Access | 6 | access = Access |
| 7 | reports = Reports | 7 | reports = Reports |
| 8 | server = Server | 8 | server = Server |
| 9 | +release = Release | ||
| 9 | log = Log | 10 | log = Log |
| 10 | ghost = Ghost | 11 | ghost = Ghost |
| 11 | refresh = Refresh | 12 | refresh = Refresh |
crates/client/lang/en/builder_log.txtmodified+1 -0
| @@ -32,6 +32,7 @@ ghost_voice = {actor} listened in {community} as ghost for {seconds}s | |||
| 32 | backup_created = {actor} created backup {name} | 32 | backup_created = {actor} created backup {name} |
| 33 | backup_deleted = {actor} deleted backup {name} | 33 | backup_deleted = {actor} deleted backup {name} |
| 34 | backup_downloaded = {actor} exported backup {name} | 34 | backup_downloaded = {actor} exported backup {name} |
| 35 | +release_pushed = {actor} pushed release #{seq} (min {minimum}) | ||
| 35 | unknown_user = Unknown user | 36 | unknown_user = Unknown user |
| 36 | apply = Apply | 37 | apply = Apply |
| 37 | no_entries = No entries | 38 | no_entries = No entries |
crates/client/lang/en/builder_overview.txtmodified+2 -0
| @@ -5,3 +5,5 @@ in_voice = In voice | |||
| 5 | storage = Storage | 5 | storage = Storage |
| 6 | active_users = Active users | 6 | active_users = Active users |
| 7 | server = Server | 7 | server = Server |
| 8 | +versions = Versions | ||
| 9 | +dev = dev | ||
crates/client/lang/en/builder_release.txtadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +release = Release | ||
| 2 | +live = Live | ||
| 3 | +no_release = No release | ||
| 4 | +pipeline = Pipeline | ||
| 5 | +source = Source | ||
| 6 | +pick = Pick | ||
| 7 | +seq = Seq | ||
| 8 | +minimum = Min | ||
| 9 | +passphrase = Passphrase | ||
| 10 | +keys = Keys | ||
| 11 | +linux = Linux | ||
| 12 | +windows = Windows | ||
| 13 | +sign = Sign | ||
| 14 | +push = Push | ||
| 15 | +binaries = Binaries | ||
| 16 | +signed = Signed | ||
| 17 | +unsigned = Unsigned | ||
| 18 | +none = Nothing built | ||
| 19 | +log = Log | ||
| 20 | +not_source = Not a source folder | ||
| 21 | +live_line = #{seq} · min {minimum} · {version} | ||
| 22 | +keys_made = keys in {dir}; commit keys.rs, move backup.key offline | ||
| 23 | +built = {platform} built #{seq} | ||
| 24 | +signed_done = signed #{seq} | ||
| 25 | +uploaded = uploaded {name} | ||
| 26 | +pushed = live #{seq} | ||
| 27 | +again = Type the passphrase again, then Keys | ||
| 28 | +mismatch = Passphrases differ | ||
crates/client/lang/en/builder_users.txtmodified+1 -4
| @@ -7,13 +7,10 @@ confirm = Confirm | |||
| 7 | revoke = Revoke | 7 | revoke = Revoke |
| 8 | end_session = End this session | 8 | end_session = End this session |
| 9 | unknown_device = unknown device | 9 | unknown_device = unknown device |
| 10 | +dev = dev | ||
| 10 | ip_on = IP: on | 11 | ip_on = IP: on |
| 11 | ip_off = IP: off | 12 | ip_off = IP: off |
| 12 | manage = Manage | 13 | manage = Manage |
| 13 | -remove_builder = Remove builder | ||
| 14 | -make_builder = Make builder | ||
| 15 | -revoke_admin = Revoke admin tools | ||
| 16 | -grant_admin = Grant admin tools | ||
| 17 | unsuspend = Unsuspend | 14 | unsuspend = Unsuspend |
| 18 | suspend = Suspend | 15 | suspend = Suspend |
| 19 | allow_sign_in = Allow sign in again | 16 | allow_sign_in = Allow sign in again |
crates/client/lang/tr/builder.txtmodified+1 -0
| @@ -6,6 +6,7 @@ storage = Depolama | |||
| 6 | access = Erişim | 6 | access = Erişim |
| 7 | reports = Raporlar | 7 | reports = Raporlar |
| 8 | server = Sunucu | 8 | server = Sunucu |
| 9 | +release = Sürüm | ||
| 9 | log = Günlük | 10 | log = Günlük |
| 10 | ghost = Hayalet | 11 | ghost = Hayalet |
| 11 | refresh = Yenile | 12 | refresh = Yenile |
crates/client/lang/tr/builder_log.txtmodified+1 -0
| @@ -32,6 +32,7 @@ ghost_voice = {actor} hayalet olarak dinledi: {community} ({seconds} sn) | |||
| 32 | backup_created = {actor} yedek oluşturdu: {name} | 32 | backup_created = {actor} yedek oluşturdu: {name} |
| 33 | backup_deleted = {actor} yedeği sildi: {name} | 33 | backup_deleted = {actor} yedeği sildi: {name} |
| 34 | backup_downloaded = {actor} yedeği dışa aktardı: {name} | 34 | backup_downloaded = {actor} yedeği dışa aktardı: {name} |
| 35 | +release_pushed = {actor} #{seq} sürümünü yayınladı (en az {minimum}) | ||
| 35 | unknown_user = Bilinmeyen kullanıcı | 36 | unknown_user = Bilinmeyen kullanıcı |
| 36 | apply = Uygula | 37 | apply = Uygula |
| 37 | no_entries = Kayıt yok | 38 | no_entries = Kayıt yok |
crates/client/lang/tr/builder_overview.txtmodified+2 -0
| @@ -5,3 +5,5 @@ in_voice = Seste | |||
| 5 | storage = Depolama | 5 | storage = Depolama |
| 6 | active_users = Aktif kullanıcılar | 6 | active_users = Aktif kullanıcılar |
| 7 | server = Sunucu | 7 | server = Sunucu |
| 8 | +versions = Sürümler | ||
| 9 | +dev = geliştirme | ||
crates/client/lang/tr/builder_release.txtadded+28 -0
| @@ -0,0 +1,28 @@ | |||
| 1 | +release = Sürüm | ||
| 2 | +live = Canlı | ||
| 3 | +no_release = Sürüm yok | ||
| 4 | +pipeline = Hat | ||
| 5 | +source = Kaynak | ||
| 6 | +pick = Seç | ||
| 7 | +seq = Sıra | ||
| 8 | +minimum = Min | ||
| 9 | +passphrase = Parola | ||
| 10 | +keys = Anahtar | ||
| 11 | +linux = Linux | ||
| 12 | +windows = Windows | ||
| 13 | +sign = İmzala | ||
| 14 | +push = Gönder | ||
| 15 | +binaries = İkililer | ||
| 16 | +signed = İmzalı | ||
| 17 | +unsigned = İmzasız | ||
| 18 | +none = Derlenmedi | ||
| 19 | +log = Günlük | ||
| 20 | +not_source = Kaynak klasörü değil | ||
| 21 | +live_line = #{seq} · min {minimum} · {version} | ||
| 22 | +keys_made = {dir} içinde anahtarlar; keys.rs'i commit et, backup.key'i çevrimdışına taşı | ||
| 23 | +built = {platform} derlendi #{seq} | ||
| 24 | +signed_done = #{seq} imzalandı | ||
| 25 | +uploaded = {name} yüklendi | ||
| 26 | +pushed = canlı #{seq} | ||
| 27 | +again = Parolayı tekrar yazıp Anahtar'a bas | ||
| 28 | +mismatch = Parolalar farklı | ||
crates/client/lang/tr/builder_users.txtmodified+1 -4
| @@ -7,13 +7,10 @@ confirm = Onayla | |||
| 7 | revoke = İptal et | 7 | revoke = İptal et |
| 8 | end_session = Bu oturumu sonlandır | 8 | end_session = Bu oturumu sonlandır |
| 9 | unknown_device = bilinmeyen cihaz | 9 | unknown_device = bilinmeyen cihaz |
| 10 | +dev = geliştirme | ||
| 10 | ip_on = IP: açık | 11 | ip_on = IP: açık |
| 11 | ip_off = IP: kapalı | 12 | ip_off = IP: kapalı |
| 12 | manage = Yönet | 13 | manage = Yönet |
| 13 | -remove_builder = Kurucu yetkisini al | ||
| 14 | -make_builder = Kurucu yap | ||
| 15 | -revoke_admin = Yönetici araçlarını al | ||
| 16 | -grant_admin = Yönetici araçlarını ver | ||
| 17 | unsuspend = Askıyı kaldır | 14 | unsuspend = Askıyı kaldır |
| 18 | suspend = Askıya al | 15 | suspend = Askıya al |
| 19 | allow_sign_in = Yeniden girişe izin ver | 16 | allow_sign_in = Yeniden girişe izin ver |
crates/client/src/cpu.rsadded+25 -0
| @@ -0,0 +1,25 @@ | |||
| 1 | +#[cfg(target_arch = "x86_64")] | ||
| 2 | +pub fn levels() -> impl Iterator<Item = &'static str> { | ||
| 3 | + let v3 = std::arch::is_x86_feature_detected!("avx2") | ||
| 4 | + && std::arch::is_x86_feature_detected!("bmi1") | ||
| 5 | + && std::arch::is_x86_feature_detected!("bmi2") | ||
| 6 | + && std::arch::is_x86_feature_detected!("fma") | ||
| 7 | + && std::arch::is_x86_feature_detected!("lzcnt") | ||
| 8 | + && std::arch::is_x86_feature_detected!("movbe") | ||
| 9 | + && std::arch::is_x86_feature_detected!("f16c"); | ||
| 10 | + let v4 = v3 | ||
| 11 | + && std::arch::is_x86_feature_detected!("avx512f") | ||
| 12 | + && std::arch::is_x86_feature_detected!("avx512bw") | ||
| 13 | + && std::arch::is_x86_feature_detected!("avx512cd") | ||
| 14 | + && std::arch::is_x86_feature_detected!("avx512dq") | ||
| 15 | + && std::arch::is_x86_feature_detected!("avx512vl"); | ||
| 16 | + [("v4", v4), ("v3", v3), ("v1", true)] | ||
| 17 | + .into_iter() | ||
| 18 | + .filter(|(_, supported)| *supported) | ||
| 19 | + .map(|(level, _)| level) | ||
| 20 | +} | ||
| 21 | + | ||
| 22 | +#[cfg(not(target_arch = "x86_64"))] | ||
| 23 | +pub fn levels() -> impl Iterator<Item = &'static str> { | ||
| 24 | + std::iter::empty() | ||
| 25 | +} | ||
crates/client/src/gui.rsmodified+20 -0
| @@ -603,6 +603,14 @@ pub struct Yumush { | |||
| 603 | deferred: Vec<NetworkEvent>, | 603 | deferred: Vec<NetworkEvent>, |
| 604 | backups: Vec<BackupInfo>, | 604 | backups: Vec<BackupInfo>, |
| 605 | pending_backup_delete: Option<String>, | 605 | pending_backup_delete: Option<String>, |
| 606 | + release: Option<common::model::Release>, | ||
| 607 | + release_seq: Entity<InputState>, | ||
| 608 | + release_minimum: Entity<InputState>, | ||
| 609 | + release_passphrase: Entity<InputState>, | ||
| 610 | + release_log: Vec<String>, | ||
| 611 | + release_busy: bool, | ||
| 612 | + pending_release_push: Option<()>, | ||
| 613 | + release_first_passphrase: Option<String>, | ||
| 606 | share_apps: Vec<crate::share::audio::AudioApp>, | 614 | share_apps: Vec<crate::share::audio::AudioApp>, |
| 607 | share_apps_seen: std::cell::Cell<Instant>, | 615 | share_apps_seen: std::cell::Cell<Instant>, |
| 608 | share_apps_task: Option<gpui_kit::Task<()>>, | 616 | share_apps_task: Option<gpui_kit::Task<()>>, |
| @@ -661,6 +669,10 @@ impl Yumush { | |||
| 661 | 669 | ||
| 662 | let server = network.server(); | 670 | let server = network.server(); |
| 663 | let account_filter = new_input(w().auth.find_account, window, cx); | 671 | let account_filter = new_input(w().auth.find_account, window, cx); |
| 672 | + let release_seq = new_input(w().builder_release.seq, window, cx); | ||
| 673 | + let release_minimum = new_input(w().builder_release.minimum, window, cx); | ||
| 674 | + let release_passphrase = new_input(w().builder_release.passphrase, window, cx); | ||
| 675 | + release_passphrase.update(cx, |input, cx| input.set_masked(true, window, cx)); | ||
| 664 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { | 676 | cx.subscribe(&account_filter, |_, _, event: &InputEvent, cx| { |
| 665 | if matches!(event, InputEvent::Change) { | 677 | if matches!(event, InputEvent::Change) { |
| 666 | cx.notify(); | 678 | cx.notify(); |
| @@ -685,6 +697,14 @@ impl Yumush { | |||
| 685 | deferred: Vec::new(), | 697 | deferred: Vec::new(), |
| 686 | backups: Vec::new(), | 698 | backups: Vec::new(), |
| 687 | pending_backup_delete: None, | 699 | pending_backup_delete: None, |
| 700 | + release: None, | ||
| 701 | + release_seq, | ||
| 702 | + release_minimum, | ||
| 703 | + release_passphrase, | ||
| 704 | + release_log: Vec::new(), | ||
| 705 | + release_busy: false, | ||
| 706 | + pending_release_push: None, | ||
| 707 | + release_first_passphrase: None, | ||
| 688 | share_apps: Vec::new(), | 708 | share_apps: Vec::new(), |
| 689 | share_apps_seen: std::cell::Cell::new(Instant::now()), | 709 | share_apps_seen: std::cell::Cell::new(Instant::now()), |
| 690 | share_apps_task: None, | 710 | share_apps_task: None, |
crates/client/src/gui/builder.rsmodified+8 -1
| @@ -4,6 +4,7 @@ mod communities; | |||
| 4 | mod log; | 4 | mod log; |
| 5 | mod messages; | 5 | mod messages; |
| 6 | mod overview; | 6 | mod overview; |
| 7 | +mod release; | ||
| 7 | mod reports; | 8 | mod reports; |
| 8 | mod server; | 9 | mod server; |
| 9 | mod storage; | 10 | mod storage; |
| @@ -53,11 +54,12 @@ pub(super) enum BuilderTab { | |||
| 53 | Access, | 54 | Access, |
| 54 | Reports, | 55 | Reports, |
| 55 | Server, | 56 | Server, |
| 57 | + Release, | ||
| 56 | Log, | 58 | Log, |
| 57 | } | 59 | } |
| 58 | 60 | ||
| 59 | impl BuilderTab { | 61 | impl BuilderTab { |
| 60 | - pub(super) const ALL: [Self; 10] = [ | 62 | + pub(super) const ALL: [Self; 11] = [ |
| 61 | Self::Overview, | 63 | Self::Overview, |
| 62 | Self::Users, | 64 | Self::Users, |
| 63 | Self::Communities, | 65 | Self::Communities, |
| @@ -67,6 +69,7 @@ impl BuilderTab { | |||
| 67 | Self::Access, | 69 | Self::Access, |
| 68 | Self::Reports, | 70 | Self::Reports, |
| 69 | Self::Server, | 71 | Self::Server, |
| 72 | + Self::Release, | ||
| 70 | Self::Log, | 73 | Self::Log, |
| 71 | ]; | 74 | ]; |
| 72 | 75 | ||
| @@ -81,6 +84,7 @@ impl BuilderTab { | |||
| 81 | Self::Access => "access", | 84 | Self::Access => "access", |
| 82 | Self::Reports => "reports", | 85 | Self::Reports => "reports", |
| 83 | Self::Server => "server", | 86 | Self::Server => "server", |
| 87 | + Self::Release => "release", | ||
| 84 | Self::Log => "log", | 88 | Self::Log => "log", |
| 85 | } | 89 | } |
| 86 | } | 90 | } |
| @@ -97,6 +101,7 @@ impl BuilderTab { | |||
| 97 | Self::Access => w.access, | 101 | Self::Access => w.access, |
| 98 | Self::Reports => w.reports, | 102 | Self::Reports => w.reports, |
| 99 | Self::Server => w.server, | 103 | Self::Server => w.server, |
| 104 | + Self::Release => w.release, | ||
| 100 | Self::Log => w.log, | 105 | Self::Log => w.log, |
| 101 | } | 106 | } |
| 102 | } | 107 | } |
| @@ -131,6 +136,7 @@ impl Yumush { | |||
| 131 | BuilderTab::Access => self.access_body(entity, palette), | 136 | BuilderTab::Access => self.access_body(entity, palette), |
| 132 | BuilderTab::Reports => self.reports_body(entity, palette), | 137 | BuilderTab::Reports => self.reports_body(entity, palette), |
| 133 | BuilderTab::Server => self.server_body(entity, palette), | 138 | BuilderTab::Server => self.server_body(entity, palette), |
| 139 | + BuilderTab::Release => self.release_body(entity, palette, cx), | ||
| 134 | BuilderTab::Log => self.log_body(entity, palette), | 140 | BuilderTab::Log => self.log_body(entity, palette), |
| 135 | }; | 141 | }; |
| 136 | let mut sections = vec![ | 142 | let mut sections = vec![ |
| @@ -282,6 +288,7 @@ impl Yumush { | |||
| 282 | BuilderTab::Access => self.load_access(window, cx), | 288 | BuilderTab::Access => self.load_access(window, cx), |
| 283 | BuilderTab::Reports => self.load_reports(window, cx), | 289 | BuilderTab::Reports => self.load_reports(window, cx), |
| 284 | BuilderTab::Server => {} | 290 | BuilderTab::Server => {} |
| 291 | + BuilderTab::Release => self.load_release(window, cx), | ||
| 285 | BuilderTab::Log => { | 292 | BuilderTab::Log => { |
| 286 | self.load_users(window, cx); | 293 | self.load_users(window, cx); |
| 287 | self.load_builder_logs(window, cx); | 294 | self.load_builder_logs(window, cx); |
crates/client/src/gui/builder/log.rsmodified+3 -1
| @@ -75,6 +75,7 @@ fn builder_log_text(entry: &AdminLogEntry) -> String { | |||
| 75 | AdminAction::BackupCreated { name } => words.backup_created(actor, name), | 75 | AdminAction::BackupCreated { name } => words.backup_created(actor, name), |
| 76 | AdminAction::BackupDeleted { name } => words.backup_deleted(actor, name), | 76 | AdminAction::BackupDeleted { name } => words.backup_deleted(actor, name), |
| 77 | AdminAction::BackupDownloaded { name } => words.backup_downloaded(actor, name), | 77 | AdminAction::BackupDownloaded { name } => words.backup_downloaded(actor, name), |
| 78 | + AdminAction::ReleasePushed { seq, minimum } => words.release_pushed(actor, minimum, seq), | ||
| 78 | } | 79 | } |
| 79 | } | 80 | } |
| 80 | 81 | ||
| @@ -166,7 +167,8 @@ fn action_icon(action: &AdminAction) -> IconName { | |||
| 166 | | AdminAction::GhostVoice { .. } => IconName::Eye, | 167 | | AdminAction::GhostVoice { .. } => IconName::Eye, |
| 167 | AdminAction::BackupCreated { .. } | 168 | AdminAction::BackupCreated { .. } |
| 168 | | AdminAction::BackupDeleted { .. } | 169 | | AdminAction::BackupDeleted { .. } |
| 169 | - | AdminAction::BackupDownloaded { .. } => IconName::HardDrive, | 170 | + | AdminAction::BackupDownloaded { .. } |
| 171 | + | AdminAction::ReleasePushed { .. } => IconName::HardDrive, | ||
| 170 | } | 172 | } |
| 171 | } | 173 | } |
| 172 | 174 | ||
crates/client/src/gui/builder/overview.rsmodified+27 -0
| @@ -223,6 +223,33 @@ impl Yumush { | |||
| 223 | palette, | 223 | palette, |
| 224 | )), | 224 | )), |
| 225 | ); | 225 | ); |
| 226 | + if !overview.releases.is_empty() { | ||
| 227 | + rows.push( | ||
| 228 | + card(palette) | ||
| 229 | + .child(card_header( | ||
| 230 | + w().builder_overview.versions, | ||
| 231 | + Vec::new(), | ||
| 232 | + palette, | ||
| 233 | + )) | ||
| 234 | + .child( | ||
| 235 | + div() | ||
| 236 | + .pt(px(space::SM)) | ||
| 237 | + .flex() | ||
| 238 | + .flex_wrap() | ||
| 239 | + .gap(px(space::MD)) | ||
| 240 | + .children(overview.releases.iter().map(|count| { | ||
| 241 | + let label = count.release.map_or_else( | ||
| 242 | + || w().builder_overview.dev.to_string(), | ||
| 243 | + |release| format!("#{release}"), | ||
| 244 | + ); | ||
| 245 | + div() | ||
| 246 | + .text_size(text(text::LABEL)) | ||
| 247 | + .text_color(palette.text) | ||
| 248 | + .child(format!("{label} · {}", count.clients)) | ||
| 249 | + })), | ||
| 250 | + ), | ||
| 251 | + ); | ||
| 252 | + } | ||
| 226 | if let Some(stats) = &self.chat.server_stats { | 253 | if let Some(stats) = &self.chat.server_stats { |
| 227 | rows.push( | 254 | rows.push( |
| 228 | card(palette) | 255 | card(palette) |
crates/client/src/gui/builder/release.rsadded+500 -0
| @@ -0,0 +1,500 @@ | |||
| 1 | +use std::{fmt::Display, fs, path::PathBuf}; | ||
| 2 | + | ||
| 3 | +use common::{ | ||
| 4 | + call::{GetRelease, PushRelease}, | ||
| 5 | + model::Release, | ||
| 6 | +}; | ||
| 7 | +use gpui_kit::{ | ||
| 8 | + AnyElement, App, AsyncWindowContext, Context, Div, Entity, IntoElement, ParentElement, | ||
| 9 | + PathPromptOptions, Styled, WeakEntity, Window, | ||
| 10 | + component::{WindowExt, notification::Notification}, | ||
| 11 | + div, | ||
| 12 | + prelude::FluentBuilder as _, | ||
| 13 | +}; | ||
| 14 | + | ||
| 15 | +use crate::gui::glyph::Fill as _; | ||
| 16 | + | ||
| 17 | +use super::ui::{confirmed, field_row, list_card, list_row, toolbar}; | ||
| 18 | +use crate::{ | ||
| 19 | + gui::{ | ||
| 20 | + MONO_FONT, Palette, Yumush, entity_action, notify_error, | ||
| 21 | + parts::{self, Press}, | ||
| 22 | + storage, | ||
| 23 | + style::text, | ||
| 24 | + text, | ||
| 25 | + widget::field, | ||
| 26 | + }, | ||
| 27 | + lang::w, | ||
| 28 | + net::NetworkHandle, | ||
| 29 | + release::{self, Platform, ReleaseError}, | ||
| 30 | + settings, | ||
| 31 | +}; | ||
| 32 | + | ||
| 33 | +const LOG_LINES: usize = 300; | ||
| 34 | +const LOG_VIEW: usize = 40; | ||
| 35 | + | ||
| 36 | +fn text_of(input: &Entity<gpui_kit::component::input::InputState>, cx: &App) -> String { | ||
| 37 | + input.read(cx).text().to_string() | ||
| 38 | +} | ||
| 39 | + | ||
| 40 | +fn set_text( | ||
| 41 | + input: &Entity<gpui_kit::component::input::InputState>, | ||
| 42 | + value: &str, | ||
| 43 | + window: &mut Window, | ||
| 44 | + cx: &mut App, | ||
| 45 | +) { | ||
| 46 | + input.update(cx, |input, cx| input.fill(value, window, cx)); | ||
| 47 | +} | ||
| 48 | + | ||
| 49 | +fn platform_label(platform: Platform) -> &'static str { | ||
| 50 | + let words = &w().builder_release; | ||
| 51 | + match platform { | ||
| 52 | + Platform::Linux => words.linux, | ||
| 53 | + Platform::Windows => words.windows, | ||
| 54 | + } | ||
| 55 | +} | ||
| 56 | + | ||
| 57 | +fn text_row(label: String, value: Option<String>, palette: Palette) -> Div { | ||
| 58 | + list_row() | ||
| 59 | + .child( | ||
| 60 | + div() | ||
| 61 | + .flex_1() | ||
| 62 | + .min_w_0() | ||
| 63 | + .truncate() | ||
| 64 | + .text_size(text(text::LABEL)) | ||
| 65 | + .text_color(palette.text) | ||
| 66 | + .child(label), | ||
| 67 | + ) | ||
| 68 | + .children(value.map(|value| { | ||
| 69 | + div() | ||
| 70 | + .flex_shrink_0() | ||
| 71 | + .text_size(text(text::CAPTION)) | ||
| 72 | + .text_color(palette.muted) | ||
| 73 | + .child(value) | ||
| 74 | + })) | ||
| 75 | +} | ||
| 76 | + | ||
| 77 | +fn release_button( | ||
| 78 | + id: String, | ||
| 79 | + label: &'static str, | ||
| 80 | + enabled: bool, | ||
| 81 | + palette: Palette, | ||
| 82 | + entity: &Entity<Yumush>, | ||
| 83 | + run: impl Fn(&mut Yumush, &mut Window, &mut Context<Yumush>) + 'static, | ||
| 84 | +) -> AnyElement { | ||
| 85 | + parts::button( | ||
| 86 | + id, | ||
| 87 | + label, | ||
| 88 | + Press::Plain, | ||
| 89 | + palette.tokens, | ||
| 90 | + entity_action(entity, move |yumush, window, cx| { | ||
| 91 | + if enabled { | ||
| 92 | + run(yumush, window, cx) | ||
| 93 | + } | ||
| 94 | + }), | ||
| 95 | + ) | ||
| 96 | + .when(!enabled, |this| this.opacity(0.4)) | ||
| 97 | + .into_any_element() | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +async fn push_release( | ||
| 101 | + network: &NetworkHandle, | ||
| 102 | + this: &WeakEntity<Yumush>, | ||
| 103 | + cx: &mut AsyncWindowContext, | ||
| 104 | + files: Vec<(String, PathBuf)>, | ||
| 105 | + signed: Vec<u8>, | ||
| 106 | +) -> Result<Release, String> { | ||
| 107 | + for (name, path) in files { | ||
| 108 | + let line = w().builder_release.uploaded(&name); | ||
| 109 | + let _ = this.update(cx, |yumush, cx| yumush.release_line(line, cx)); | ||
| 110 | + network | ||
| 111 | + .publish(name, path) | ||
| 112 | + .await | ||
| 113 | + .map_err(|error| error.to_string())?; | ||
| 114 | + } | ||
| 115 | + network | ||
| 116 | + .call(PushRelease { manifest: signed }) | ||
| 117 | + .await | ||
| 118 | + .map_err(|error| error.to_string()) | ||
| 119 | +} | ||
| 120 | + | ||
| 121 | +impl Yumush { | ||
| 122 | + fn release_source(&self) -> Option<PathBuf> { | ||
| 123 | + self.settings | ||
| 124 | + .release_source | ||
| 125 | + .clone() | ||
| 126 | + .filter(|path| release::is_source(path)) | ||
| 127 | + } | ||
| 128 | + | ||
| 129 | + fn release_seq_value(&self, cx: &App) -> Option<u64> { | ||
| 130 | + text_of(&self.release_seq, cx) | ||
| 131 | + .trim() | ||
| 132 | + .parse() | ||
| 133 | + .ok() | ||
| 134 | + .filter(|seq| *seq > 0) | ||
| 135 | + } | ||
| 136 | + | ||
| 137 | + fn release_minimum_value(&self, cx: &App) -> Option<u64> { | ||
| 138 | + text_of(&self.release_minimum, cx) | ||
| 139 | + .trim() | ||
| 140 | + .parse() | ||
| 141 | + .ok() | ||
| 142 | + .filter(|minimum| *minimum > 0) | ||
| 143 | + } | ||
| 144 | + | ||
| 145 | + fn release_line(&mut self, line: String, cx: &mut Context<Self>) { | ||
| 146 | + self.release_log.push(line); | ||
| 147 | + let extra = self.release_log.len().saturating_sub(LOG_LINES); | ||
| 148 | + self.release_log.drain(..extra); | ||
| 149 | + cx.notify(); | ||
| 150 | + } | ||
| 151 | + | ||
| 152 | + fn release_fail(&mut self, error: impl Display, window: &mut Window, cx: &mut Context<Self>) { | ||
| 153 | + let message = error.to_string(); | ||
| 154 | + self.release_line(message.clone(), cx); | ||
| 155 | + window.push_notification(Notification::error(message), cx); | ||
| 156 | + } | ||
| 157 | + | ||
| 158 | + fn run_release<T: Send + 'static>( | ||
| 159 | + &mut self, | ||
| 160 | + window: &mut Window, | ||
| 161 | + cx: &mut Context<Self>, | ||
| 162 | + work: impl FnOnce(&dyn Fn(String)) -> Result<T, ReleaseError> + Send + 'static, | ||
| 163 | + done: impl FnOnce(&mut Self, &mut Window, &mut Context<Self>, Result<T, ReleaseError>) + 'static, | ||
| 164 | + ) { | ||
| 165 | + self.release_busy = true; | ||
| 166 | + let (lines, mut received) = tokio::sync::mpsc::unbounded_channel::<String>(); | ||
| 167 | + let (outcome, reply) = tokio::sync::oneshot::channel(); | ||
| 168 | + std::thread::spawn(move || { | ||
| 169 | + let emit = |line: String| { | ||
| 170 | + let _ = lines.send(line); | ||
| 171 | + }; | ||
| 172 | + let _ = outcome.send(work(&emit)); | ||
| 173 | + }); | ||
| 174 | + | ||
| 175 | + cx.spawn_in(window, async move |this, cx| { | ||
| 176 | + while let Some(line) = received.recv().await { | ||
| 177 | + let _ = this.update(cx, |yumush, cx| yumush.release_line(line, cx)); | ||
| 178 | + } | ||
| 179 | + let result = reply.await; | ||
| 180 | + let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 181 | + yumush.release_busy = false; | ||
| 182 | + match result { | ||
| 183 | + Ok(result) => done(yumush, window, cx, result), | ||
| 184 | + Err(_) => yumush.release_fail(ReleaseError::Build, window, cx), | ||
| 185 | + } | ||
| 186 | + cx.notify(); | ||
| 187 | + }); | ||
| 188 | + }) | ||
| 189 | + .detach(); | ||
| 190 | + } | ||
| 191 | + | ||
| 192 | + pub(super) fn load_release(&self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 193 | + if !self.is_builder() { | ||
| 194 | + return; | ||
| 195 | + } | ||
| 196 | + let network = self.network.clone(); | ||
| 197 | + | ||
| 198 | + cx.spawn_in(window, async move |this, cx| { | ||
| 199 | + let live = match network.call(GetRelease).await { | ||
| 200 | + Ok(live) => live, | ||
| 201 | + Err(error) => { | ||
| 202 | + notify_error(&this, cx, error); | ||
| 203 | + return; | ||
| 204 | + } | ||
| 205 | + }; | ||
| 206 | + let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 207 | + yumush.apply_release(live, window, cx) | ||
| 208 | + }); | ||
| 209 | + }) | ||
| 210 | + .detach(); | ||
| 211 | + } | ||
| 212 | + | ||
| 213 | + fn apply_release( | ||
| 214 | + &mut self, | ||
| 215 | + live: Option<Release>, | ||
| 216 | + window: &mut Window, | ||
| 217 | + cx: &mut Context<Self>, | ||
| 218 | + ) { | ||
| 219 | + let live_seq = live.as_ref().map(|release| release.seq); | ||
| 220 | + let minimum = live.as_ref().map_or(1, |release| release.minimum); | ||
| 221 | + self.release = live; | ||
| 222 | + if let Some(source) = self.release_source() { | ||
| 223 | + let seq = release::next_seq(&source, live_seq); | ||
| 224 | + set_text(&self.release_seq, &seq.to_string(), window, cx); | ||
| 225 | + set_text(&self.release_minimum, &minimum.to_string(), window, cx); | ||
| 226 | + } | ||
| 227 | + cx.notify(); | ||
| 228 | + } | ||
| 229 | + | ||
| 230 | + fn pick_release_source(&self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 231 | + let picked = cx.prompt_for_paths(PathPromptOptions { | ||
| 232 | + files: false, | ||
| 233 | + directories: true, | ||
| 234 | + multiple: false, | ||
| 235 | + prompt: None, | ||
| 236 | + }); | ||
| 237 | + | ||
| 238 | + cx.spawn_in(window, async move |this, cx| { | ||
| 239 | + let Ok(Ok(Some(paths))) = picked.await else { | ||
| 240 | + return; | ||
| 241 | + }; | ||
| 242 | + let Some(path) = paths.into_iter().next() else { | ||
| 243 | + return; | ||
| 244 | + }; | ||
| 245 | + let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 246 | + if !release::is_source(&path) { | ||
| 247 | + window | ||
| 248 | + .push_notification(Notification::error(w().builder_release.not_source), cx); | ||
| 249 | + return; | ||
| 250 | + } | ||
| 251 | + yumush.settings.release_source = Some(path); | ||
| 252 | + settings::save(&yumush.settings); | ||
| 253 | + yumush.load_release(window, cx); | ||
| 254 | + }); | ||
| 255 | + }) | ||
| 256 | + .detach(); | ||
| 257 | + } | ||
| 258 | + | ||
| 259 | + fn release_keys(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 260 | + let Some(source) = self.release_source() else { | ||
| 261 | + return; | ||
| 262 | + }; | ||
| 263 | + let passphrase = text_of(&self.release_passphrase, cx); | ||
| 264 | + set_text(&self.release_passphrase, "", window, cx); | ||
| 265 | + let Some(first) = self.release_first_passphrase.take() else { | ||
| 266 | + self.release_first_passphrase = Some(passphrase); | ||
| 267 | + self.release_line(w().builder_release.again.to_string(), cx); | ||
| 268 | + return; | ||
| 269 | + }; | ||
| 270 | + if first != passphrase { | ||
| 271 | + self.release_fail(w().builder_release.mismatch, window, cx); | ||
| 272 | + return; | ||
| 273 | + } | ||
| 274 | + self.run_release( | ||
| 275 | + window, | ||
| 276 | + cx, | ||
| 277 | + move |_| release::keygen(&source, &passphrase), | ||
| 278 | + |yumush, window, cx, result| match result { | ||
| 279 | + Ok(dir) => { | ||
| 280 | + let line = w().builder_release.keys_made(dir.display()); | ||
| 281 | + yumush.release_line(line, cx); | ||
| 282 | + } | ||
| 283 | + Err(error) => yumush.release_fail(error, window, cx), | ||
| 284 | + }, | ||
| 285 | + ); | ||
| 286 | + } | ||
| 287 | + | ||
| 288 | + fn release_build(&mut self, platform: Platform, window: &mut Window, cx: &mut Context<Self>) { | ||
| 289 | + let (Some(source), Some(seq)) = (self.release_source(), self.release_seq_value(cx)) else { | ||
| 290 | + return; | ||
| 291 | + }; | ||
| 292 | + self.run_release( | ||
| 293 | + window, | ||
| 294 | + cx, | ||
| 295 | + move |emit| release::build(&source, platform, seq, emit), | ||
| 296 | + move |yumush, window, cx, result| match result { | ||
| 297 | + Ok(()) => { | ||
| 298 | + let line = w().builder_release.built(platform_label(platform), seq); | ||
| 299 | + yumush.release_line(line, cx); | ||
| 300 | + } | ||
| 301 | + Err(error) => yumush.release_fail(error, window, cx), | ||
| 302 | + }, | ||
| 303 | + ); | ||
| 304 | + } | ||
| 305 | + | ||
| 306 | + fn release_sign(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 307 | + let (Some(source), Some(seq), Some(minimum)) = ( | ||
| 308 | + self.release_source(), | ||
| 309 | + self.release_seq_value(cx), | ||
| 310 | + self.release_minimum_value(cx), | ||
| 311 | + ) else { | ||
| 312 | + return; | ||
| 313 | + }; | ||
| 314 | + let passphrase = text_of(&self.release_passphrase, cx); | ||
| 315 | + set_text(&self.release_passphrase, "", window, cx); | ||
| 316 | + self.run_release( | ||
| 317 | + window, | ||
| 318 | + cx, | ||
| 319 | + move |_| release::sign(&source, seq, minimum, &passphrase), | ||
| 320 | + move |yumush, window, cx, result| match result { | ||
| 321 | + Ok(_) => { | ||
| 322 | + let line = w().builder_release.signed_done(seq); | ||
| 323 | + yumush.release_line(line, cx); | ||
| 324 | + } | ||
| 325 | + Err(error) => yumush.release_fail(error, window, cx), | ||
| 326 | + }, | ||
| 327 | + ); | ||
| 328 | + } | ||
| 329 | + | ||
| 330 | + fn release_push(&mut self, window: &mut Window, cx: &mut Context<Self>) { | ||
| 331 | + let (Some(source), Some(seq)) = (self.release_source(), self.release_seq_value(cx)) else { | ||
| 332 | + return; | ||
| 333 | + }; | ||
| 334 | + let Some(signed) = release::signed(&source, seq) else { | ||
| 335 | + return; | ||
| 336 | + }; | ||
| 337 | + let Some(files) = release::uploads(&signed, &source) else { | ||
| 338 | + return; | ||
| 339 | + }; | ||
| 340 | + if !confirmed(&mut self.pending_release_push, ()) { | ||
| 341 | + cx.notify(); | ||
| 342 | + return; | ||
| 343 | + } | ||
| 344 | + self.release_busy = true; | ||
| 345 | + let network = self.network.clone(); | ||
| 346 | + | ||
| 347 | + cx.spawn_in(window, async move |this, cx| { | ||
| 348 | + let outcome = push_release(&network, &this, cx, files, signed).await; | ||
| 349 | + let _ = this.update_in(cx, |yumush, window, cx| { | ||
| 350 | + yumush.release_busy = false; | ||
| 351 | + match outcome { | ||
| 352 | + Ok(release) => { | ||
| 353 | + let line = w().builder_release.pushed(release.seq); | ||
| 354 | + yumush.release_line(line, cx); | ||
| 355 | + yumush.load_release(window, cx); | ||
| 356 | + } | ||
| 357 | + Err(error) => yumush.release_fail(error, window, cx), | ||
| 358 | + } | ||
| 359 | + }); | ||
| 360 | + }) | ||
| 361 | + .detach(); | ||
| 362 | + } | ||
| 363 | + | ||
| 364 | + pub(super) fn release_body( | ||
| 365 | + &self, | ||
| 366 | + entity: &Entity<Self>, | ||
| 367 | + palette: Palette, | ||
| 368 | + cx: &App, | ||
| 369 | + ) -> Vec<AnyElement> { | ||
| 370 | + let words = &w().builder_release; | ||
| 371 | + let source = self.release_source(); | ||
| 372 | + let seq = self.release_seq_value(cx); | ||
| 373 | + let minimum = self.release_minimum_value(cx); | ||
| 374 | + let ready = source.is_some() && !self.release_busy; | ||
| 375 | + let build_ready = ready && seq.is_some(); | ||
| 376 | + let sign_ready = build_ready && minimum.is_some(); | ||
| 377 | + let signed = match (&source, seq) { | ||
| 378 | + (Some(source), Some(seq)) => release::signed(source, seq), | ||
| 379 | + _ => None, | ||
| 380 | + }; | ||
| 381 | + let push_ready = ready && signed.is_some(); | ||
| 382 | + | ||
| 383 | + let live_rows: Vec<Div> = match &self.release { | ||
| 384 | + Some(live) => vec![text_row( | ||
| 385 | + words.live_line(live.minimum, live.seq, &live.version), | ||
| 386 | + None, | ||
| 387 | + palette, | ||
| 388 | + )], | ||
| 389 | + None => Vec::new(), | ||
| 390 | + }; | ||
| 391 | + | ||
| 392 | + let mut buttons = Vec::new(); | ||
| 393 | + if source | ||
| 394 | + .as_ref() | ||
| 395 | + .is_some_and(|source| release::trusted(source).is_empty()) | ||
| 396 | + { | ||
| 397 | + buttons.push(release_button( | ||
| 398 | + "release_keys".to_string(), | ||
| 399 | + words.keys, | ||
| 400 | + ready, | ||
| 401 | + palette, | ||
| 402 | + entity, | ||
| 403 | + |yumush, window, cx| yumush.release_keys(window, cx), | ||
| 404 | + )); | ||
| 405 | + } | ||
| 406 | + for platform in Platform::ALL { | ||
| 407 | + buttons.push(release_button( | ||
| 408 | + format!("release_build_{platform:?}"), | ||
| 409 | + platform_label(platform), | ||
| 410 | + build_ready, | ||
| 411 | + palette, | ||
| 412 | + entity, | ||
| 413 | + move |yumush, window, cx| yumush.release_build(platform, window, cx), | ||
| 414 | + )); | ||
| 415 | + } | ||
| 416 | + buttons.push(release_button( | ||
| 417 | + "release_sign".to_string(), | ||
| 418 | + words.sign, | ||
| 419 | + sign_ready, | ||
| 420 | + palette, | ||
| 421 | + entity, | ||
| 422 | + |yumush, window, cx| yumush.release_sign(window, cx), | ||
| 423 | + )); | ||
| 424 | + let push_label = if self.pending_release_push.is_some() { | ||
| 425 | + w().builder_ui.confirm | ||
| 426 | + } else { | ||
| 427 | + words.push | ||
| 428 | + }; | ||
| 429 | + buttons.push(release_button( | ||
| 430 | + "release_push".to_string(), | ||
| 431 | + push_label, | ||
| 432 | + push_ready, | ||
| 433 | + palette, | ||
| 434 | + entity, | ||
| 435 | + |yumush, window, cx| yumush.release_push(window, cx), | ||
| 436 | + )); | ||
| 437 | + | ||
| 438 | + let hint = source.as_ref().map(|path| path.display().to_string()); | ||
| 439 | + let pick = parts::button( | ||
| 440 | + "release_pick", | ||
| 441 | + words.pick, | ||
| 442 | + Press::Plain, | ||
| 443 | + palette.tokens, | ||
| 444 | + entity_action(entity, |yumush, window, cx| { | ||
| 445 | + yumush.pick_release_source(window, cx) | ||
| 446 | + }), | ||
| 447 | + ) | ||
| 448 | + .into_any_element(); | ||
| 449 | + let pipeline_rows: Vec<Div> = vec![ | ||
| 450 | + field_row(words.source, hint.as_deref(), pick, palette), | ||
| 451 | + field_row(words.seq, None, field(palette, &self.release_seq), palette), | ||
| 452 | + field_row( | ||
| 453 | + words.minimum, | ||
| 454 | + None, | ||
| 455 | + field(palette, &self.release_minimum), | ||
| 456 | + palette, | ||
| 457 | + ), | ||
| 458 | + field_row( | ||
| 459 | + words.passphrase, | ||
| 460 | + None, | ||
| 461 | + field(palette, &self.release_passphrase), | ||
| 462 | + palette, | ||
| 463 | + ), | ||
| 464 | + list_row().child(toolbar(buttons)), | ||
| 465 | + ]; | ||
| 466 | + | ||
| 467 | + let mut binary_rows = vec![text_row( | ||
| 468 | + if signed.is_some() { | ||
| 469 | + words.signed.to_string() | ||
| 470 | + } else { | ||
| 471 | + words.unsigned.to_string() | ||
| 472 | + }, | ||
| 473 | + None, | ||
| 474 | + palette, | ||
| 475 | + )]; | ||
| 476 | + if let (Some(source), Some(seq)) = (&source, seq) { | ||
| 477 | + binary_rows.extend( | ||
| 478 | + release::binaries(source, seq) | ||
| 479 | + .into_iter() | ||
| 480 | + .map(|(name, path)| { | ||
| 481 | + let size = fs::metadata(&path).map_or(0, |meta| meta.len()); | ||
| 482 | + text_row(name, Some(storage(size)), palette) | ||
| 483 | + }), | ||
| 484 | + ); | ||
| 485 | + } | ||
| 486 | + | ||
| 487 | + let start = self.release_log.len().saturating_sub(LOG_VIEW); | ||
| 488 | + let log_rows: Vec<Div> = self.release_log[start..] | ||
| 489 | + .iter() | ||
| 490 | + .map(|line| text_row(line.clone(), None, palette).font_family(MONO_FONT)) | ||
| 491 | + .collect(); | ||
| 492 | + | ||
| 493 | + vec![ | ||
| 494 | + list_card(Some(words.live), live_rows, words.no_release, palette).into_any_element(), | ||
| 495 | + list_card(Some(words.pipeline), pipeline_rows, "", palette).into_any_element(), | ||
| 496 | + list_card(Some(words.binaries), binary_rows, words.none, palette).into_any_element(), | ||
| 497 | + list_card(Some(words.log), log_rows, "", palette).into_any_element(), | ||
| 498 | + ] | ||
| 499 | + } | ||
| 500 | +} | ||
crates/client/src/gui/builder/users.rsmodified+12 -66
| @@ -4,8 +4,7 @@ use std::future::Future; | |||
| 4 | use common::{ | 4 | use common::{ |
| 5 | call::{ | 5 | call::{ |
| 6 | BanUser, ClearProfile, CreateUser, DeleteUser, FollowStats, ListSessions, PurgeUser, | 6 | BanUser, ClearProfile, CreateUser, DeleteUser, FollowStats, ListSessions, PurgeUser, |
| 7 | - RenameUser, ResetPassword, RevokeSession, RevokeSessions, SetRole, SuspendUser, | 7 | + RenameUser, ResetPassword, RevokeSession, RevokeSessions, SuspendUser, TimeoutUser, |
| 8 | - TimeoutUser, | ||
| 9 | }, | 8 | }, |
| 10 | model::{Account, BanScope, Role, SessionInfo, User}, | 9 | model::{Account, BanScope, Role, SessionInfo, User}, |
| 11 | permission, | 10 | permission, |
| @@ -86,40 +85,6 @@ impl Yumush { | |||
| 86 | .detach(); | 85 | .detach(); |
| 87 | } | 86 | } |
| 88 | 87 | ||
| 89 | - pub(super) fn set_builder_role( | ||
| 90 | - &mut self, | ||
| 91 | - user_id: Id, | ||
| 92 | - role: Role, | ||
| 93 | - window: &mut Window, | ||
| 94 | - cx: &mut Context<Self>, | ||
| 95 | - ) { | ||
| 96 | - let network = self.network.clone(); | ||
| 97 | - | ||
| 98 | - cx.spawn_in(window, async move |this, cx| { | ||
| 99 | - match network.call(SetRole { user_id, role }).await { | ||
| 100 | - Ok(user) => { | ||
| 101 | - let _ = this.update(cx, |yumush, cx| { | ||
| 102 | - yumush.replace_builder_user(user); | ||
| 103 | - cx.notify(); | ||
| 104 | - }); | ||
| 105 | - } | ||
| 106 | - Err(error) => notify_error(&this, cx, error), | ||
| 107 | - } | ||
| 108 | - }) | ||
| 109 | - .detach(); | ||
| 110 | - } | ||
| 111 | - | ||
| 112 | - fn replace_builder_user(&mut self, user: User) { | ||
| 113 | - let index = self | ||
| 114 | - .chat | ||
| 115 | - .builder_users | ||
| 116 | - .iter() | ||
| 117 | - .position(|existing| existing.user.id == user.id); | ||
| 118 | - if let Some(index) = index { | ||
| 119 | - self.chat.builder_users[index].user = user; | ||
| 120 | - } | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | pub(super) fn delete_builder_user( | 88 | pub(super) fn delete_builder_user( |
| 124 | &mut self, | 89 | &mut self, |
| 125 | user_id: Id, | 90 | user_id: Id, |
| @@ -692,6 +657,16 @@ impl Yumush { | |||
| 692 | .truncate() | 657 | .truncate() |
| 693 | .child(device.to_string()), | 658 | .child(device.to_string()), |
| 694 | ) | 659 | ) |
| 660 | + .child( | ||
| 661 | + div() | ||
| 662 | + .flex_shrink_0() | ||
| 663 | + .text_size(text(text::CAPTION)) | ||
| 664 | + .text_color(palette.muted) | ||
| 665 | + .child(session.release.map_or_else( | ||
| 666 | + || w().builder_users.dev.to_string(), | ||
| 667 | + |release| format!("#{release}"), | ||
| 668 | + )), | ||
| 669 | + ) | ||
| 695 | .child( | 670 | .child( |
| 696 | div() | 671 | div() |
| 697 | .flex_shrink_0() | 672 | .flex_shrink_0() |
| @@ -786,11 +761,9 @@ impl Yumush { | |||
| 786 | ) -> Div { | 761 | ) -> Div { |
| 787 | let user = &account.user; | 762 | let user = &account.user; |
| 788 | let is_self = user.id == me.id; | 763 | let is_self = user.id == me.id; |
| 789 | - let builder = user.role == Role::Builder; | ||
| 790 | let manage = permission::can_manage_user(me.role, is_self, user.role); | 764 | let manage = permission::can_manage_user(me.role, is_self, user.role); |
| 791 | - let can_role = permission::can_set_role(me.role, is_self); | ||
| 792 | let can_delete = !is_self && permission::can_delete_user(me.role, is_self, user.role); | 765 | let can_delete = !is_self && permission::can_delete_user(me.role, is_self, user.role); |
| 793 | - let has_actions = manage || can_role || can_delete; | 766 | + let has_actions = manage || can_delete; |
| 794 | let suspended = account.suspended; | 767 | let suspended = account.suspended; |
| 795 | let timed_out = account | 768 | let timed_out = account |
| 796 | .suspended_until | 769 | .suspended_until |
| @@ -804,7 +777,6 @@ impl Yumush { | |||
| 804 | let expanded = expanded_sessions.is_some(); | 777 | let expanded = expanded_sessions.is_some(); |
| 805 | let pending_delete = self.chat.pending_builder_delete == Some(user.id); | 778 | let pending_delete = self.chat.pending_builder_delete == Some(user.id); |
| 806 | let pending_purge = self.chat.pending_builder_purge == Some(user.id); | 779 | let pending_purge = self.chat.pending_builder_purge == Some(user.id); |
| 807 | - let role_id = user.id; | ||
| 808 | let delete_id = user.id; | 780 | let delete_id = user.id; |
| 809 | let suspend_id = user.id; | 781 | let suspend_id = user.id; |
| 810 | let sessions_id = user.id; | 782 | let sessions_id = user.id; |
| @@ -817,33 +789,8 @@ impl Yumush { | |||
| 817 | let purge_id = user.id; | 789 | let purge_id = user.id; |
| 818 | let joined = millis_time(user.created_at, crate::lang::w().common.date); | 790 | let joined = millis_time(user.created_at, crate::lang::w().common.date); |
| 819 | let seen = seen_text(account.last_seen); | 791 | let seen = seen_text(account.last_seen); |
| 820 | - let next_role = if builder { Role::User } else { Role::Builder }; | ||
| 821 | 792 | ||
| 822 | let tone = palette.text; | 793 | let tone = palette.text; |
| 823 | - let role_button = action_button( | ||
| 824 | - format!("role_{}_{builder}", user.id), | ||
| 825 | - if builder { | ||
| 826 | - IconName::ShieldOff | ||
| 827 | - } else { | ||
| 828 | - IconName::Shield | ||
| 829 | - }, | ||
| 830 | - if builder { | ||
| 831 | - w().builder_users.remove_builder | ||
| 832 | - } else { | ||
| 833 | - w().builder_users.make_builder | ||
| 834 | - }, | ||
| 835 | - if builder { | ||
| 836 | - w().builder_users.revoke_admin | ||
| 837 | - } else { | ||
| 838 | - w().builder_users.grant_admin | ||
| 839 | - }, | ||
| 840 | - tone, | ||
| 841 | - palette, | ||
| 842 | - entity_action(entity, move |yumush, window, cx| { | ||
| 843 | - yumush.set_builder_role(role_id, next_role, window, cx) | ||
| 844 | - }), | ||
| 845 | - ); | ||
| 846 | - | ||
| 847 | let suspend_button = action_button( | 794 | let suspend_button = action_button( |
| 848 | format!("suspend_user_{}_{suspended}", user.id), | 795 | format!("suspend_user_{}_{suspended}", user.id), |
| 849 | IconName::CirclePause, | 796 | IconName::CirclePause, |
| @@ -1093,7 +1040,6 @@ impl Yumush { | |||
| 1093 | let account_actions = [ | 1040 | let account_actions = [ |
| 1094 | manage.then(|| rename_button.into_any_element()), | 1041 | manage.then(|| rename_button.into_any_element()), |
| 1095 | manage.then(|| password_button.into_any_element()), | 1042 | manage.then(|| password_button.into_any_element()), |
| 1096 | - can_role.then(|| role_button.into_any_element()), | ||
| 1097 | Some(stats_button.into_any_element()), | 1043 | Some(stats_button.into_any_element()), |
| 1098 | ]; | 1044 | ]; |
| 1099 | let moderation_actions = [ | 1045 | let moderation_actions = [ |
crates/client/src/gui/settings_page.rsmodified+9 -3
| @@ -29,9 +29,15 @@ use crate::{ | |||
| 29 | share::encode::capabilities, | 29 | share::encode::capabilities, |
| 30 | }; | 30 | }; |
| 31 | 31 | ||
| 32 | -pub(super) const SETTINGS_IDS: [&str; 4] = ["profile", "voice", "camera_share", "appearance"]; | 32 | +pub(super) const SETTINGS_IDS: [&str; 5] = [ |
| 33 | - | 33 | + "profile", |
| 34 | -pub(super) fn settings_titles() -> [&'static str; 5] { | 34 | + "voice", |
| 35 | + "camera_share", | ||
| 36 | + "appearance", | ||
| 37 | + "danger_zone", | ||
| 38 | +]; | ||
| 39 | + | ||
| 40 | +pub(super) fn settings_titles() -> [&'static str; SETTINGS_IDS.len()] { | ||
| 35 | let w = &w().settings_page; | 41 | let w = &w().settings_page; |
| 36 | [ | 42 | [ |
| 37 | w.profile, | 43 | w.profile, |
crates/client/src/lib.rsmodified+2 -0
| @@ -6,6 +6,7 @@ use tracing::warn; | |||
| 6 | pub mod accounts; | 6 | pub mod accounts; |
| 7 | pub mod autostart; | 7 | pub mod autostart; |
| 8 | pub mod avatar; | 8 | pub mod avatar; |
| 9 | +pub mod cpu; | ||
| 9 | pub mod embed; | 10 | pub mod embed; |
| 10 | pub mod emoji; | 11 | pub mod emoji; |
| 11 | pub mod gui; | 12 | pub mod gui; |
| @@ -15,6 +16,7 @@ pub mod logo; | |||
| 15 | pub mod marks; | 16 | pub mod marks; |
| 16 | pub mod media; | 17 | pub mod media; |
| 17 | pub mod net; | 18 | pub mod net; |
| 19 | +pub mod release; | ||
| 18 | pub mod settings; | 20 | pub mod settings; |
| 19 | pub mod share; | 21 | pub mod share; |
| 20 | pub mod tray; | 22 | pub mod tray; |
crates/client/src/net/link.rsmodified+37 -0
| @@ -335,6 +335,38 @@ pub(super) async fn upload( | |||
| 335 | } | 335 | } |
| 336 | } | 336 | } |
| 337 | 337 | ||
| 338 | +pub(super) async fn publish( | ||
| 339 | + connection: &quinn::Connection, | ||
| 340 | + name: String, | ||
| 341 | + path: &Path, | ||
| 342 | +) -> Result<(), Fail> { | ||
| 343 | + let bytes = tokio::fs::read(path).await?; | ||
| 344 | + let sha256 = ring::digest::digest(&ring::digest::SHA256, &bytes) | ||
| 345 | + .as_ref() | ||
| 346 | + .try_into() | ||
| 347 | + .map_err(|_| Fail::Protocol)?; | ||
| 348 | + let header = common::open::Publish { | ||
| 349 | + name, | ||
| 350 | + size: bytes.len() as u64, | ||
| 351 | + sha256, | ||
| 352 | + }; | ||
| 353 | + let (send_stream, mut receive_stream) = connection.open_bi().await?; | ||
| 354 | + let mut send_stream = Sending::new(send_stream); | ||
| 355 | + frame::write(&mut send_stream, &Open::Publish(header), UP_MAX).await?; | ||
| 356 | + let write = async move { | ||
| 357 | + send_stream.get().write_all(&bytes).await?; | ||
| 358 | + Ok::<_, Fail>(send_stream.finish()?) | ||
| 359 | + }; | ||
| 360 | + let read = frame::read::<Result<(), Error>>(&mut receive_stream, DOWN_MAX); | ||
| 361 | + let (sent, reply) = tokio::join!(write, read); | ||
| 362 | + | ||
| 363 | + match (sent, reply) { | ||
| 364 | + (_, Ok(reply)) => Ok(reply?), | ||
| 365 | + (Err(error), _) => Err(error), | ||
| 366 | + (_, Err(error)) => Err(error.into()), | ||
| 367 | + } | ||
| 368 | +} | ||
| 369 | + | ||
| 338 | pub(super) async fn backup_download( | 370 | pub(super) async fn backup_download( |
| 339 | connection: &quinn::Connection, | 371 | connection: &quinn::Connection, |
| 340 | name: &str, | 372 | name: &str, |
| @@ -525,6 +557,11 @@ async fn actor( | |||
| 525 | 557 | ||
| 526 | answer(reply, async move { fetches.memory(&connection, blob).await }); | 558 | answer(reply, async move { fetches.memory(&connection, blob).await }); |
| 527 | } | 559 | } |
| 560 | + Some(Command::Publish { name, path, reply }) => { | ||
| 561 | + let connection = connection.clone(); | ||
| 562 | + | ||
| 563 | + answer(reply, async move { publish(&connection, name, &path).await }); | ||
| 564 | + } | ||
| 528 | Some(Command::BackupDownload { name, path, reply }) => { | 565 | Some(Command::BackupDownload { name, path, reply }) => { |
| 529 | let connection = connection.clone(); | 566 | let connection = connection.clone(); |
| 530 | let fetches = shared.fetches.clone(); | 567 | let fetches = shared.fetches.clone(); |
crates/client/src/net/mod.rsmodified+10 -0
| @@ -80,6 +80,11 @@ enum Command { | |||
| 80 | path: PathBuf, | 80 | path: PathBuf, |
| 81 | reply: oneshot::Sender<Result<(), Fail>>, | 81 | reply: oneshot::Sender<Result<(), Fail>>, |
| 82 | }, | 82 | }, |
| 83 | + Publish { | ||
| 84 | + name: String, | ||
| 85 | + path: PathBuf, | ||
| 86 | + reply: oneshot::Sender<Result<(), Fail>>, | ||
| 87 | + }, | ||
| 83 | } | 88 | } |
| 84 | 89 | ||
| 85 | #[derive(Clone)] | 90 | #[derive(Clone)] |
| @@ -218,6 +223,11 @@ impl NetworkHandle { | |||
| 218 | self.ask(|reply| Command::Download { blob, reply }).await | 223 | self.ask(|reply| Command::Download { blob, reply }).await |
| 219 | } | 224 | } |
| 220 | 225 | ||
| 226 | + pub async fn publish(&self, name: String, path: PathBuf) -> Result<(), Fail> { | ||
| 227 | + self.ask(|reply| Command::Publish { name, path, reply }) | ||
| 228 | + .await | ||
| 229 | + } | ||
| 230 | + | ||
| 221 | pub async fn download_backup(&self, name: &str, path: PathBuf) -> Result<(), Fail> { | 231 | pub async fn download_backup(&self, name: &str, path: PathBuf) -> Result<(), Fail> { |
| 222 | self.ask(|reply| Command::BackupDownload { | 232 | self.ask(|reply| Command::BackupDownload { |
| 223 | name: name.to_string(), | 233 | name: name.to_string(), |
crates/client/src/release.rsadded+371 -0
| @@ -0,0 +1,371 @@ | |||
| 1 | +use std::{ | ||
| 2 | + fs, | ||
| 3 | + io::{BufRead, BufReader}, | ||
| 4 | + num::NonZeroU32, | ||
| 5 | + path::{Path, PathBuf}, | ||
| 6 | + process::{Command, Stdio}, | ||
| 7 | +}; | ||
| 8 | + | ||
| 9 | +use common::update::{self as wire, MAGIC}; | ||
| 10 | +use ring::{ | ||
| 11 | + aead::{Aad, CHACHA20_POLY1305, LessSafeKey, Nonce, UnboundKey}, | ||
| 12 | + digest, pbkdf2, | ||
| 13 | + rand::{SecureRandom, SystemRandom}, | ||
| 14 | + signature::{self, Ed25519KeyPair, KeyPair}, | ||
| 15 | +}; | ||
| 16 | + | ||
| 17 | +const KEY_MAGIC: &[u8] = b"yumush-key 1\n"; | ||
| 18 | +const SALT: usize = 16; | ||
| 19 | +const NONCE: usize = 12; | ||
| 20 | +const SEED: usize = 32; | ||
| 21 | +const KEY_FILE: usize = KEY_MAGIC.len() + SALT + NONCE + SEED + 16; | ||
| 22 | +const ITERATIONS: NonZeroU32 = NonZeroU32::new(2_000_000).unwrap(); | ||
| 23 | +pub const KEY_NAMES: [&str; 2] = ["primary", "backup"]; | ||
| 24 | +const KEYS_RS: &str = "crates/client/src/update/keys.rs"; | ||
| 25 | + | ||
| 26 | +#[derive(Debug, thiserror::Error)] | ||
| 27 | +pub enum ReleaseError { | ||
| 28 | + #[error("not a yumush source folder")] | ||
| 29 | + Source, | ||
| 30 | + #[error("keys.rs already holds keys")] | ||
| 31 | + KeysExist, | ||
| 32 | + #[error("no signing keys")] | ||
| 33 | + NoKeys, | ||
| 34 | + #[error("wrong passphrase or damaged key")] | ||
| 35 | + Passphrase, | ||
| 36 | + #[error("passphrase is too short")] | ||
| 37 | + Short, | ||
| 38 | + #[error("key does not match keys.rs")] | ||
| 39 | + Untrusted, | ||
| 40 | + #[error("minimum must be 1..={0}")] | ||
| 41 | + Minimum(u64), | ||
| 42 | + #[error("{0} is not seq {1}")] | ||
| 43 | + Seq(String, u64), | ||
| 44 | + #[error("no binaries in dist/{0}")] | ||
| 45 | + Empty(u64), | ||
| 46 | + #[error("build failed")] | ||
| 47 | + Build, | ||
| 48 | + #[error("signing failed")] | ||
| 49 | + Sign, | ||
| 50 | + #[error(transparent)] | ||
| 51 | + Io(#[from] std::io::Error), | ||
| 52 | +} | ||
| 53 | + | ||
| 54 | +pub fn is_source(source: &Path) -> bool { | ||
| 55 | + source.join("packaging/release.sh").is_file() && source.join(KEYS_RS).is_file() | ||
| 56 | +} | ||
| 57 | + | ||
| 58 | +fn checked(source: &Path) -> Result<(), ReleaseError> { | ||
| 59 | + if is_source(source) { | ||
| 60 | + Ok(()) | ||
| 61 | + } else { | ||
| 62 | + Err(ReleaseError::Source) | ||
| 63 | + } | ||
| 64 | +} | ||
| 65 | + | ||
| 66 | +pub fn signing_dir() -> PathBuf { | ||
| 67 | + std::env::var_os("YUMUSH_SIGNING_DIR") | ||
| 68 | + .map(PathBuf::from) | ||
| 69 | + .or_else(|| dirs::data_dir().map(|dir| dir.join("yumush-signing"))) | ||
| 70 | + .unwrap_or_else(|| PathBuf::from("yumush-signing")) | ||
| 71 | +} | ||
| 72 | + | ||
| 73 | +pub fn trusted(source: &Path) -> Vec<[u8; 32]> { | ||
| 74 | + let text = fs::read_to_string(source.join(KEYS_RS)).unwrap_or_default(); | ||
| 75 | + text.split('[') | ||
| 76 | + .filter_map(|chunk| { | ||
| 77 | + let bytes: Vec<u8> = chunk | ||
| 78 | + .split(|c: char| c == ',' || c == ']' || c.is_whitespace()) | ||
| 79 | + .filter_map(|part| part.strip_prefix("0x")) | ||
| 80 | + .filter_map(|hex| u8::from_str_radix(hex, 16).ok()) | ||
| 81 | + .collect(); | ||
| 82 | + bytes.try_into().ok() | ||
| 83 | + }) | ||
| 84 | + .collect() | ||
| 85 | +} | ||
| 86 | + | ||
| 87 | +fn derive(passphrase: &str, salt: &[u8]) -> Result<LessSafeKey, ReleaseError> { | ||
| 88 | + let mut key = [0u8; 32]; | ||
| 89 | + pbkdf2::derive( | ||
| 90 | + pbkdf2::PBKDF2_HMAC_SHA256, | ||
| 91 | + ITERATIONS, | ||
| 92 | + salt, | ||
| 93 | + passphrase.as_bytes(), | ||
| 94 | + &mut key, | ||
| 95 | + ); | ||
| 96 | + let unbound = UnboundKey::new(&CHACHA20_POLY1305, &key).map_err(|_| ReleaseError::Sign)?; | ||
| 97 | + Ok(LessSafeKey::new(unbound)) | ||
| 98 | +} | ||
| 99 | + | ||
| 100 | +fn seal(seed: &[u8; SEED], passphrase: &str) -> Result<Vec<u8>, ReleaseError> { | ||
| 101 | + let random = SystemRandom::new(); | ||
| 102 | + let mut salt = [0u8; SALT]; | ||
| 103 | + let mut nonce = [0u8; NONCE]; | ||
| 104 | + random.fill(&mut salt).map_err(|_| ReleaseError::Sign)?; | ||
| 105 | + random.fill(&mut nonce).map_err(|_| ReleaseError::Sign)?; | ||
| 106 | + let mut sealed = seed.to_vec(); | ||
| 107 | + derive(passphrase, &salt)? | ||
| 108 | + .seal_in_place_append_tag( | ||
| 109 | + Nonce::assume_unique_for_key(nonce), | ||
| 110 | + Aad::from(KEY_MAGIC), | ||
| 111 | + &mut sealed, | ||
| 112 | + ) | ||
| 113 | + .map_err(|_| ReleaseError::Sign)?; | ||
| 114 | + Ok([KEY_MAGIC, &salt, &nonce, &sealed].concat()) | ||
| 115 | +} | ||
| 116 | + | ||
| 117 | +fn open(file: &[u8], passphrase: &str) -> Result<Ed25519KeyPair, ReleaseError> { | ||
| 118 | + if file.len() != KEY_FILE || !file.starts_with(KEY_MAGIC) { | ||
| 119 | + return Err(ReleaseError::Passphrase); | ||
| 120 | + } | ||
| 121 | + let (salt, rest) = file[KEY_MAGIC.len()..].split_at(SALT); | ||
| 122 | + let (nonce, sealed) = rest.split_at(NONCE); | ||
| 123 | + let nonce = Nonce::try_assume_unique_for_key(nonce).map_err(|_| ReleaseError::Passphrase)?; | ||
| 124 | + let mut sealed = sealed.to_vec(); | ||
| 125 | + let seed = derive(passphrase, salt)? | ||
| 126 | + .open_in_place(nonce, Aad::from(KEY_MAGIC), &mut sealed) | ||
| 127 | + .map_err(|_| ReleaseError::Passphrase)?; | ||
| 128 | + Ed25519KeyPair::from_seed_unchecked(seed).map_err(|_| ReleaseError::Passphrase) | ||
| 129 | +} | ||
| 130 | + | ||
| 131 | +fn put_private(path: &Path, bytes: &[u8]) -> std::io::Result<()> { | ||
| 132 | + let mut options = fs::OpenOptions::new(); | ||
| 133 | + options.write(true).create_new(true); | ||
| 134 | + #[cfg(unix)] | ||
| 135 | + std::os::unix::fs::OpenOptionsExt::mode(&mut options, 0o600); | ||
| 136 | + let mut file = options.open(path)?; | ||
| 137 | + std::io::Write::write_all(&mut file, bytes)?; | ||
| 138 | + file.sync_all() | ||
| 139 | +} | ||
| 140 | + | ||
| 141 | +pub fn keygen(source: &Path, passphrase: &str) -> Result<PathBuf, ReleaseError> { | ||
| 142 | + checked(source)?; | ||
| 143 | + if !trusted(source).is_empty() { | ||
| 144 | + return Err(ReleaseError::KeysExist); | ||
| 145 | + } | ||
| 146 | + if passphrase.chars().count() < 12 { | ||
| 147 | + return Err(ReleaseError::Short); | ||
| 148 | + } | ||
| 149 | + let directory = signing_dir(); | ||
| 150 | + fs::create_dir_all(&directory)?; | ||
| 151 | + let mut lines = String::from("pub const KEYS: &[[u8; 32]] = &[\n"); | ||
| 152 | + for name in KEY_NAMES { | ||
| 153 | + let mut seed = [0u8; SEED]; | ||
| 154 | + SystemRandom::new() | ||
| 155 | + .fill(&mut seed) | ||
| 156 | + .map_err(|_| ReleaseError::Sign)?; | ||
| 157 | + let pair = Ed25519KeyPair::from_seed_unchecked(&seed).map_err(|_| ReleaseError::Sign)?; | ||
| 158 | + let sealed = seal(&seed, passphrase)?; | ||
| 159 | + put_private(&directory.join(format!("{name}.key")), &sealed)?; | ||
| 160 | + let bytes: Vec<String> = pair | ||
| 161 | + .public_key() | ||
| 162 | + .as_ref() | ||
| 163 | + .iter() | ||
| 164 | + .map(|byte| format!("0x{byte:02x}")) | ||
| 165 | + .collect(); | ||
| 166 | + lines.push_str(&format!(" [{}],\n", bytes.join(", "))); | ||
| 167 | + } | ||
| 168 | + lines.push_str("];\n"); | ||
| 169 | + let out = source.join(KEYS_RS); | ||
| 170 | + let part = out.with_extension("rs.part"); | ||
| 171 | + fs::write(&part, lines)?; | ||
| 172 | + fs::rename(part, out)?; | ||
| 173 | + Ok(directory) | ||
| 174 | +} | ||
| 175 | + | ||
| 176 | +pub fn dist(source: &Path, seq: u64) -> PathBuf { | ||
| 177 | + source.join("dist").join(seq.to_string()) | ||
| 178 | +} | ||
| 179 | + | ||
| 180 | +pub fn next_seq(source: &Path, live: Option<u64>) -> u64 { | ||
| 181 | + let built = fs::read_dir(source.join("dist")) | ||
| 182 | + .into_iter() | ||
| 183 | + .flatten() | ||
| 184 | + .flatten() | ||
| 185 | + .filter_map(|entry| entry.file_name().to_str()?.parse::<u64>().ok()) | ||
| 186 | + .max(); | ||
| 187 | + built.max(live).unwrap_or(0) + 1 | ||
| 188 | +} | ||
| 189 | + | ||
| 190 | +#[derive(Debug, Clone, Copy, PartialEq, Eq)] | ||
| 191 | +pub enum Platform { | ||
| 192 | + Linux, | ||
| 193 | + Windows, | ||
| 194 | +} | ||
| 195 | + | ||
| 196 | +impl Platform { | ||
| 197 | + pub const ALL: [Self; 2] = [Self::Linux, Self::Windows]; | ||
| 198 | + | ||
| 199 | + fn arg(self) -> &'static str { | ||
| 200 | + match self { | ||
| 201 | + Self::Linux => "linux", | ||
| 202 | + Self::Windows => "windows", | ||
| 203 | + } | ||
| 204 | + } | ||
| 205 | +} | ||
| 206 | + | ||
| 207 | +pub fn build( | ||
| 208 | + source: &Path, | ||
| 209 | + platform: Platform, | ||
| 210 | + seq: u64, | ||
| 211 | + mut line: impl FnMut(String), | ||
| 212 | +) -> Result<(), ReleaseError> { | ||
| 213 | + checked(source)?; | ||
| 214 | + let mut child = Command::new("bash") | ||
| 215 | + .arg(source.join("packaging/release.sh")) | ||
| 216 | + .arg(platform.arg()) | ||
| 217 | + .arg(seq.to_string()) | ||
| 218 | + .current_dir(source) | ||
| 219 | + .stdin(Stdio::null()) | ||
| 220 | + .stdout(Stdio::piped()) | ||
| 221 | + .stderr(Stdio::piped()) | ||
| 222 | + .spawn()?; | ||
| 223 | + let stderr = child.stderr.take().ok_or(ReleaseError::Build)?; | ||
| 224 | + let (sender, receiver) = std::sync::mpsc::channel(); | ||
| 225 | + let errors = sender.clone(); | ||
| 226 | + let reader = std::thread::spawn(move || { | ||
| 227 | + for text in BufReader::new(stderr).lines().map_while(Result::ok) { | ||
| 228 | + let _ = errors.send(text); | ||
| 229 | + } | ||
| 230 | + }); | ||
| 231 | + let stdout = child.stdout.take().ok_or(ReleaseError::Build)?; | ||
| 232 | + std::thread::spawn(move || { | ||
| 233 | + for text in BufReader::new(stdout).lines().map_while(Result::ok) { | ||
| 234 | + let _ = sender.send(text); | ||
| 235 | + } | ||
| 236 | + }); | ||
| 237 | + for text in receiver { | ||
| 238 | + line(text); | ||
| 239 | + } | ||
| 240 | + let _ = reader.join(); | ||
| 241 | + if child.wait()?.success() { | ||
| 242 | + Ok(()) | ||
| 243 | + } else { | ||
| 244 | + Err(ReleaseError::Build) | ||
| 245 | + } | ||
| 246 | +} | ||
| 247 | + | ||
| 248 | +pub fn binaries(source: &Path, seq: u64) -> Vec<(String, PathBuf)> { | ||
| 249 | + let mut found: Vec<(String, PathBuf)> = fs::read_dir(dist(source, seq)) | ||
| 250 | + .into_iter() | ||
| 251 | + .flatten() | ||
| 252 | + .flatten() | ||
| 253 | + .filter_map(|entry| { | ||
| 254 | + let name = entry.file_name().to_str()?.to_string(); | ||
| 255 | + let target = name.split_once('-').is_some_and(|(arch, os)| { | ||
| 256 | + !arch.is_empty() && !os.is_empty() && !os.contains(['-', '.']) | ||
| 257 | + }); | ||
| 258 | + (target && wire::valid_name(&name)).then(|| (name, entry.path())) | ||
| 259 | + }) | ||
| 260 | + .collect(); | ||
| 261 | + found.sort(); | ||
| 262 | + found | ||
| 263 | +} | ||
| 264 | + | ||
| 265 | +fn version(source: &Path) -> Result<String, ReleaseError> { | ||
| 266 | + let manifest = fs::read_to_string(source.join("crates/client/Cargo.toml"))?; | ||
| 267 | + manifest | ||
| 268 | + .lines() | ||
| 269 | + .find_map(|line| { | ||
| 270 | + let value = line.strip_prefix("version")?.trim().strip_prefix('=')?; | ||
| 271 | + Some(value.trim().trim_matches('"').to_string()) | ||
| 272 | + }) | ||
| 273 | + .filter(|version| !version.is_empty()) | ||
| 274 | + .ok_or(ReleaseError::Source) | ||
| 275 | +} | ||
| 276 | + | ||
| 277 | +pub fn sign( | ||
| 278 | + source: &Path, | ||
| 279 | + seq: u64, | ||
| 280 | + minimum: u64, | ||
| 281 | + passphrase: &str, | ||
| 282 | +) -> Result<Vec<u8>, ReleaseError> { | ||
| 283 | + checked(source)?; | ||
| 284 | + if !(1..=seq).contains(&minimum) { | ||
| 285 | + return Err(ReleaseError::Minimum(seq)); | ||
| 286 | + } | ||
| 287 | + let files = binaries(source, seq); | ||
| 288 | + if files.is_empty() { | ||
| 289 | + return Err(ReleaseError::Empty(seq)); | ||
| 290 | + } | ||
| 291 | + let mut body = format!( | ||
| 292 | + "{MAGIC}\nseq {seq}\nminimum {minimum}\nversion {}\n", | ||
| 293 | + version(source)? | ||
| 294 | + ); | ||
| 295 | + for (name, path) in &files { | ||
| 296 | + let built = | ||
| 297 | + fs::read_to_string(path.with_file_name(format!("{name}.seq"))).unwrap_or_default(); | ||
| 298 | + if built.trim().parse::<u64>().ok() != Some(seq) { | ||
| 299 | + return Err(ReleaseError::Seq(name.clone(), seq)); | ||
| 300 | + } | ||
| 301 | + let bytes = fs::read(path)?; | ||
| 302 | + let hash: String = digest::digest(&digest::SHA256, &bytes) | ||
| 303 | + .as_ref() | ||
| 304 | + .iter() | ||
| 305 | + .map(|byte| format!("{byte:02x}")) | ||
| 306 | + .collect(); | ||
| 307 | + body.push_str(&format!("{name} {} {hash}\n", bytes.len())); | ||
| 308 | + } | ||
| 309 | + if wire::parse(body.as_bytes()).is_none() { | ||
| 310 | + return Err(ReleaseError::Sign); | ||
| 311 | + } | ||
| 312 | + let keys = trusted(source); | ||
| 313 | + if keys.is_empty() { | ||
| 314 | + return Err(ReleaseError::NoKeys); | ||
| 315 | + } | ||
| 316 | + let file = fs::read(signing_dir().join(format!("{}.key", KEY_NAMES[0]))) | ||
| 317 | + .map_err(|_| ReleaseError::NoKeys)?; | ||
| 318 | + let pair = open(&file, passphrase)?; | ||
| 319 | + if !keys.iter().any(|key| key == pair.public_key().as_ref()) { | ||
| 320 | + return Err(ReleaseError::Untrusted); | ||
| 321 | + } | ||
| 322 | + let sig = pair.sign(body.as_bytes()); | ||
| 323 | + let signed = [sig.as_ref(), body.as_bytes()].concat(); | ||
| 324 | + let (sig, checked_body) = wire::split(&signed).ok_or(ReleaseError::Sign)?; | ||
| 325 | + signature::UnparsedPublicKey::new(&signature::ED25519, pair.public_key().as_ref()) | ||
| 326 | + .verify(checked_body, sig) | ||
| 327 | + .map_err(|_| ReleaseError::Sign)?; | ||
| 328 | + let out = dist(source, seq).join(wire::MANIFEST); | ||
| 329 | + fs::write(&out, &signed)?; | ||
| 330 | + Ok(signed) | ||
| 331 | +} | ||
| 332 | + | ||
| 333 | +pub fn signed(source: &Path, seq: u64) -> Option<Vec<u8>> { | ||
| 334 | + fs::read(dist(source, seq).join(wire::MANIFEST)).ok() | ||
| 335 | +} | ||
| 336 | + | ||
| 337 | +pub fn uploads(signed: &[u8], source: &Path) -> Option<Vec<(String, PathBuf)>> { | ||
| 338 | + let (_, body) = wire::split(signed)?; | ||
| 339 | + let manifest = wire::parse(body)?; | ||
| 340 | + let directory = dist(source, manifest.seq); | ||
| 341 | + Some( | ||
| 342 | + manifest | ||
| 343 | + .files | ||
| 344 | + .iter() | ||
| 345 | + .map(|file| { | ||
| 346 | + ( | ||
| 347 | + wire::file_name(&file.name, manifest.seq), | ||
| 348 | + directory.join(&file.name), | ||
| 349 | + ) | ||
| 350 | + }) | ||
| 351 | + .collect(), | ||
| 352 | + ) | ||
| 353 | +} | ||
| 354 | + | ||
| 355 | +#[cfg(test)] | ||
| 356 | +mod tests { | ||
| 357 | + use super::*; | ||
| 358 | + | ||
| 359 | + #[test] | ||
| 360 | + fn key_round_trip() { | ||
| 361 | + let seed = [7u8; SEED]; | ||
| 362 | + let sealed = seal(&seed, "correct horse battery").unwrap(); | ||
| 363 | + let pair = open(&sealed, "correct horse battery").unwrap(); | ||
| 364 | + let expected = Ed25519KeyPair::from_seed_unchecked(&seed).unwrap(); | ||
| 365 | + assert_eq!(pair.public_key().as_ref(), expected.public_key().as_ref()); | ||
| 366 | + assert!(open(&sealed, "wrong horse battery").is_err()); | ||
| 367 | + let mut tampered = sealed.clone(); | ||
| 368 | + tampered[KEY_MAGIC.len()] ^= 1; | ||
| 369 | + assert!(open(&tampered, "correct horse battery").is_err()); | ||
| 370 | + } | ||
| 371 | +} | ||
crates/client/src/settings.rsmodified+12 -1
| @@ -1,4 +1,4 @@ | |||
| 1 | -use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive}; | 1 | +use std::{collections::BTreeMap, fmt::Display, ops::RangeInclusive, path::PathBuf}; |
| 2 | 2 | ||
| 3 | use common::{ | 3 | use common::{ |
| 4 | config::Config, | 4 | config::Config, |
| @@ -224,6 +224,7 @@ pub struct Settings { | |||
| 224 | pub clock_seconds: bool, | 224 | pub clock_seconds: bool, |
| 225 | pub jump_usage: BTreeMap<String, u32>, | 225 | pub jump_usage: BTreeMap<String, u32>, |
| 226 | pub last_chats: BTreeMap<Id, Id>, | 226 | pub last_chats: BTreeMap<Id, Id>, |
| 227 | + pub release_source: Option<PathBuf>, | ||
| 227 | } | 228 | } |
| 228 | 229 | ||
| 229 | impl Settings { | 230 | impl Settings { |
| @@ -253,6 +254,7 @@ impl Default for Settings { | |||
| 253 | clock_seconds: false, | 254 | clock_seconds: false, |
| 254 | jump_usage: BTreeMap::new(), | 255 | jump_usage: BTreeMap::new(), |
| 255 | last_chats: BTreeMap::new(), | 256 | last_chats: BTreeMap::new(), |
| 257 | + release_source: None, | ||
| 256 | } | 258 | } |
| 257 | } | 259 | } |
| 258 | } | 260 | } |
| @@ -388,6 +390,7 @@ pub fn load() -> Settings { | |||
| 388 | .collect() | 390 | .collect() |
| 389 | }) | 391 | }) |
| 390 | .unwrap_or_default(), | 392 | .unwrap_or_default(), |
| 393 | + release_source: text("release.source").map(PathBuf::from), | ||
| 391 | } | 394 | } |
| 392 | } | 395 | } |
| 393 | 396 | ||
| @@ -478,6 +481,14 @@ pub fn save(settings: &Settings) { | |||
| 478 | .collect::<Vec<_>>() | 481 | .collect::<Vec<_>>() |
| 479 | .join(","), | 482 | .join(","), |
| 480 | ), | 483 | ), |
| 484 | + line( | ||
| 485 | + "release.source", | ||
| 486 | + settings | ||
| 487 | + .release_source | ||
| 488 | + .as_ref() | ||
| 489 | + .map(|path| path.display().to_string()) | ||
| 490 | + .unwrap_or_default(), | ||
| 491 | + ), | ||
| 481 | ] | 492 | ] |
| 482 | .concat(); | 493 | .concat(); |
| 483 | 494 | ||
crates/client/src/update.rsmodified+32 -9
| @@ -92,6 +92,7 @@ enum Outcome { | |||
| 92 | 92 | ||
| 93 | #[derive(Debug, PartialEq)] | 93 | #[derive(Debug, PartialEq)] |
| 94 | struct Release { | 94 | struct Release { |
| 95 | + name: String, | ||
| 95 | seq: u64, | 96 | seq: u64, |
| 96 | minimum: u64, | 97 | minimum: u64, |
| 97 | version: String, | 98 | version: String, |
| @@ -150,8 +151,16 @@ fn mode() -> Result<(u64, &'static Path), Off> { | |||
| 150 | Ok((seq, exe)) | 151 | Ok((seq, exe)) |
| 151 | } | 152 | } |
| 152 | 153 | ||
| 153 | -fn target() -> String { | 154 | +fn targets() -> Vec<String> { |
| 154 | - format!("{}-{}", std::env::consts::ARCH, std::env::consts::OS) | 155 | + let os = std::env::consts::OS; |
| 156 | + let levels: Vec<&str> = crate::cpu::levels().collect(); | ||
| 157 | + if levels.is_empty() { | ||
| 158 | + return vec![format!("{}-{os}", std::env::consts::ARCH)]; | ||
| 159 | + } | ||
| 160 | + levels | ||
| 161 | + .into_iter() | ||
| 162 | + .map(|level| format!("{}_{level}-{os}", std::env::consts::ARCH)) | ||
| 163 | + .collect() | ||
| 155 | } | 164 | } |
| 156 | 165 | ||
| 157 | fn sibling(exe: &Path, tag: &str) -> PathBuf { | 166 | fn sibling(exe: &Path, tag: &str) -> PathBuf { |
| @@ -437,7 +446,7 @@ async fn fetch_release( | |||
| 437 | exe: &Path, | 446 | exe: &Path, |
| 438 | ) -> Result<Outcome, Fail> { | 447 | ) -> Result<Outcome, Fail> { |
| 439 | let manifest = fetch(connection, MANIFEST, MANIFEST_MAX).await?; | 448 | let manifest = fetch(connection, MANIFEST, MANIFEST_MAX).await?; |
| 440 | - let release = verify(&manifest, &target(), keys::KEYS).map_err(Fail::Reject)?; | 449 | + let release = verify(&manifest, &targets(), keys::KEYS).map_err(Fail::Reject)?; |
| 441 | let required = running < release.minimum || OUTDATED.load(Ordering::Relaxed); | 450 | let required = running < release.minimum || OUTDATED.load(Ordering::Relaxed); |
| 442 | if release.seq <= installed { | 451 | if release.seq <= installed { |
| 443 | return Ok(if required && installed > running { | 452 | return Ok(if required && installed > running { |
| @@ -451,7 +460,12 @@ async fn fetch_release( | |||
| 451 | } | 460 | } |
| 452 | let file = open_new(exe)?; | 461 | let file = open_new(exe)?; |
| 453 | info!("update: downloading {} ({})", release.version, release.seq); | 462 | info!("update: downloading {} ({})", release.version, release.seq); |
| 454 | - let bytes = fetch(connection, &target(), release.size).await; | 463 | + let bytes = fetch( |
| 464 | + connection, | ||
| 465 | + &wire::file_name(&release.name, release.seq), | ||
| 466 | + release.size, | ||
| 467 | + ) | ||
| 468 | + .await; | ||
| 455 | let bytes = bytes.inspect_err(|_| { | 469 | let bytes = bytes.inspect_err(|_| { |
| 456 | let _ = fs::remove_file(sibling(exe, "new")); | 470 | let _ = fs::remove_file(sibling(exe, "new")); |
| 457 | })?; | 471 | })?; |
| @@ -469,7 +483,7 @@ async fn fetch_release( | |||
| 469 | }) | 483 | }) |
| 470 | } | 484 | } |
| 471 | 485 | ||
| 472 | -fn verify(signed: &[u8], target: &str, keys: &[[u8; 32]]) -> Result<Release, Reject> { | 486 | +fn verify(signed: &[u8], targets: &[String], keys: &[[u8; 32]]) -> Result<Release, Reject> { |
| 473 | let (sig, body) = wire::split(signed).ok_or(Reject::Short)?; | 487 | let (sig, body) = wire::split(signed).ok_or(Reject::Short)?; |
| 474 | let signed_by_us = keys.iter().any(|key| { | 488 | let signed_by_us = keys.iter().any(|key| { |
| 475 | signature::UnparsedPublicKey::new(&signature::ED25519, key) | 489 | signature::UnparsedPublicKey::new(&signature::ED25519, key) |
| @@ -480,8 +494,12 @@ fn verify(signed: &[u8], target: &str, keys: &[[u8; 32]]) -> Result<Release, Rej | |||
| 480 | return Err(Reject::Signature); | 494 | return Err(Reject::Signature); |
| 481 | } | 495 | } |
| 482 | let manifest = wire::parse(body).ok_or(Reject::Format)?; | 496 | let manifest = wire::parse(body).ok_or(Reject::Format)?; |
| 483 | - let file = manifest.file(target).ok_or(Reject::Target)?; | 497 | + let file = targets |
| 498 | + .iter() | ||
| 499 | + .find_map(|target| manifest.file(target)) | ||
| 500 | + .ok_or(Reject::Target)?; | ||
| 484 | Ok(Release { | 501 | Ok(Release { |
| 502 | + name: file.name.clone(), | ||
| 485 | seq: manifest.seq, | 503 | seq: manifest.seq, |
| 486 | minimum: manifest.minimum, | 504 | minimum: manifest.minimum, |
| 487 | version: manifest.version.clone(), | 505 | version: manifest.version.clone(), |
| @@ -604,9 +622,14 @@ mod tests { | |||
| 604 | fn verifies() { | 622 | fn verifies() { |
| 605 | let (key, public) = pair(); | 623 | let (key, public) = pair(); |
| 606 | let body = format!( | 624 | let body = format!( |
| 607 | - "{MAGIC}\nseq 7\nminimum 3\nversion 0.2.0\nx86_64-linux 10 {HASH}\nx86_64-windows 20 {HASH}\n" | 625 | + "{MAGIC}\nseq 7\nminimum 3\nversion 0.2.0\nx86_64_v3-linux 10 {HASH}\nx86_64_v4-linux 20 {HASH}\n" |
| 608 | ); | 626 | ); |
| 609 | - let release = verify(&signed(&key, &body), "x86_64-windows", &[public]).unwrap(); | 627 | + let wanted = ["x86_64_v4-linux".to_string(), "x86_64_v3-linux".to_string()]; |
| 628 | + let release = verify(&signed(&key, &body), &wanted, &[public]).unwrap(); | ||
| 629 | + assert_eq!(release.name, "x86_64_v4-linux"); | ||
| 630 | + let release = verify(&signed(&key, &body), &wanted[1..], &[public]).unwrap(); | ||
| 631 | + assert_eq!(release.name, "x86_64_v3-linux"); | ||
| 632 | + let release = verify(&signed(&key, &body), &wanted, &[public]).unwrap(); | ||
| 610 | assert_eq!( | 633 | assert_eq!( |
| 611 | ( | 634 | ( |
| 612 | release.seq, | 635 | release.seq, |
| @@ -640,7 +663,7 @@ mod tests { | |||
| 640 | signed(&key, &good.replace("minimum 7\n", "")), | 663 | signed(&key, &good.replace("minimum 7\n", "")), |
| 641 | ]; | 664 | ]; |
| 642 | for case in cases { | 665 | for case in cases { |
| 643 | - assert!(verify(&case, "x86_64-linux", &[public]).is_err()); | 666 | + assert!(verify(&case, &["x86_64-linux".to_string()], &[public]).is_err()); |
| 644 | } | 667 | } |
| 645 | } | 668 | } |
| 646 | } | 669 | } |
crates/common/src/call.rsmodified+13 -9
| @@ -7,8 +7,9 @@ use crate::{ | |||
| 7 | model::{ | 7 | model::{ |
| 8 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, | 8 | Account, AdminActionKind, AdminLogEntry, AttachmentInfo, BackupInfo, Ban, BanScope, |
| 9 | Community, CommunitySummary, CommunityUsage, DayStat, Edit, Friends, Id, Invitation, | 9 | Community, CommunitySummary, CommunityUsage, DayStat, Edit, Friends, Id, Invitation, |
| 10 | - InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Report, | 10 | + InviteCode, LogEntry, Member, Message, MessageHit, Overview, Presence, Rank, Release, |
| 11 | - ReportStatus, Role, ServerBan, ServerSettings, SessionInfo, Unread, Usage, User, VoiceRoom, | 11 | + Report, ReportStatus, ServerBan, ServerSettings, SessionInfo, Unread, Usage, User, |
| 12 | + VoiceRoom, | ||
| 12 | }, | 13 | }, |
| 13 | share::{Codec, Kind, Quality, Share, Source}, | 14 | share::{Codec, Kind, Quality, Share, Source}, |
| 14 | stats::Stats, | 15 | stats::Stats, |
| @@ -468,12 +469,6 @@ pub struct WatchCommunity { | |||
| 468 | #[derive(Debug, Clone, Encode, Decode)] | 469 | #[derive(Debug, Clone, Encode, Decode)] |
| 469 | pub struct ListUsers; | 470 | pub struct ListUsers; |
| 470 | 471 | ||
| 471 | -#[derive(Debug, Clone, Encode, Decode)] | ||
| 472 | -pub struct SetRole { | ||
| 473 | - pub user_id: Id, | ||
| 474 | - pub role: Role, | ||
| 475 | -} | ||
| 476 | - | ||
| 477 | #[derive(Debug, Clone, Encode, Decode)] | 472 | #[derive(Debug, Clone, Encode, Decode)] |
| 478 | pub struct ListUserFriends { | 473 | pub struct ListUserFriends { |
| 479 | pub user_id: Id, | 474 | pub user_id: Id, |
| @@ -630,6 +625,14 @@ pub struct CreateBackup; | |||
| 630 | #[derive(Debug, Clone, Encode, Decode)] | 625 | #[derive(Debug, Clone, Encode, Decode)] |
| 631 | pub struct ListBackups; | 626 | pub struct ListBackups; |
| 632 | 627 | ||
| 628 | +#[derive(Debug, Clone, Encode, Decode)] | ||
| 629 | +pub struct GetRelease; | ||
| 630 | + | ||
| 631 | +#[derive(Debug, Clone, Encode, Decode)] | ||
| 632 | +pub struct PushRelease { | ||
| 633 | + pub manifest: Vec<u8>, | ||
| 634 | +} | ||
| 635 | + | ||
| 633 | #[derive(Debug, Clone, Encode, Decode)] | 636 | #[derive(Debug, Clone, Encode, Decode)] |
| 634 | pub struct FollowStats { | 637 | pub struct FollowStats { |
| 635 | pub user_id: Option<Id>, | 638 | pub user_id: Option<Id>, |
| @@ -738,7 +741,6 @@ calls! { | |||
| 738 | DeleteUser: User -> (); | 741 | DeleteUser: User -> (); |
| 739 | WatchCommunity: User -> (); | 742 | WatchCommunity: User -> (); |
| 740 | ListUsers: Builder -> Vec<Account>; | 743 | ListUsers: Builder -> Vec<Account>; |
| 741 | - SetRole: User -> User; | ||
| 742 | ListAdminLogs: Builder -> Vec<AdminLogEntry>; | 744 | ListAdminLogs: Builder -> Vec<AdminLogEntry>; |
| 743 | ListUserFriends: Builder -> Vec<User>; | 745 | ListUserFriends: Builder -> Vec<User>; |
| 744 | GetOverview: Builder -> Overview; | 746 | GetOverview: Builder -> Overview; |
| @@ -770,6 +772,8 @@ calls! { | |||
| 770 | CreateBackup: Builder -> BackupInfo; | 772 | CreateBackup: Builder -> BackupInfo; |
| 771 | ListBackups: Builder -> Vec<BackupInfo>; | 773 | ListBackups: Builder -> Vec<BackupInfo>; |
| 772 | DeleteBackup: Builder -> (); | 774 | DeleteBackup: Builder -> (); |
| 775 | + GetRelease: Builder -> Option<Release>; | ||
| 776 | + PushRelease: Builder -> Release; | ||
| 773 | FollowStats: Builder -> Option<Stats>; | 777 | FollowStats: Builder -> Option<Stats>; |
| 774 | PushStats: User -> (); | 778 | PushStats: User -> (); |
| 775 | GetServerStats: Builder -> Stats; | 779 | GetServerStats: Builder -> Stats; |
crates/common/src/error.rsmodified+2 -0
| @@ -145,6 +145,8 @@ pub enum Error { | |||
| 145 | RateLimited { retry_after_seconds: u64 }, | 145 | RateLimited { retry_after_seconds: u64 }, |
| 146 | #[error("{field} {}", .problem.describe(.field))] | 146 | #[error("{field} {}", .problem.describe(.field))] |
| 147 | Invalid { field: Field, problem: Problem }, | 147 | Invalid { field: Field, problem: Problem }, |
| 148 | + #[error("release: {0}")] | ||
| 149 | + Release(String), | ||
| 148 | #[error("server error")] | 150 | #[error("server error")] |
| 149 | Server, | 151 | Server, |
| 150 | } | 152 | } |
crates/common/src/model.rsmodified+18 -0
| @@ -114,6 +114,7 @@ pub struct Account { | |||
| 114 | pub struct SessionInfo { | 114 | pub struct SessionInfo { |
| 115 | pub id: Id, | 115 | pub id: Id, |
| 116 | pub device: String, | 116 | pub device: String, |
| 117 | + pub release: Option<u64>, | ||
| 117 | pub last_seen: Option<u64>, | 118 | pub last_seen: Option<u64>, |
| 118 | } | 119 | } |
| 119 | 120 | ||
| @@ -265,6 +266,7 @@ pub enum AdminAction { | |||
| 265 | BackupCreated { name: String }, | 266 | BackupCreated { name: String }, |
| 266 | BackupDeleted { name: String }, | 267 | BackupDeleted { name: String }, |
| 267 | BackupDownloaded { name: String }, | 268 | BackupDownloaded { name: String }, |
| 269 | + ReleasePushed { seq: u64, minimum: u64 }, | ||
| 268 | Community(LogAction), | 270 | Community(LogAction), |
| 269 | } | 271 | } |
| 270 | 272 | ||
| @@ -302,6 +304,7 @@ string_enum! { | |||
| 302 | BackupCreated => "backup_created", | 304 | BackupCreated => "backup_created", |
| 303 | BackupDeleted => "backup_deleted", | 305 | BackupDeleted => "backup_deleted", |
| 304 | BackupDownloaded => "backup_downloaded", | 306 | BackupDownloaded => "backup_downloaded", |
| 307 | + ReleasePushed => "release_pushed", | ||
| 305 | Community => "community", | 308 | Community => "community", |
| 306 | } | 309 | } |
| 307 | } | 310 | } |
| @@ -340,6 +343,7 @@ impl AdminAction { | |||
| 340 | AdminAction::BackupCreated { .. } => AdminActionKind::BackupCreated, | 343 | AdminAction::BackupCreated { .. } => AdminActionKind::BackupCreated, |
| 341 | AdminAction::BackupDeleted { .. } => AdminActionKind::BackupDeleted, | 344 | AdminAction::BackupDeleted { .. } => AdminActionKind::BackupDeleted, |
| 342 | AdminAction::BackupDownloaded { .. } => AdminActionKind::BackupDownloaded, | 345 | AdminAction::BackupDownloaded { .. } => AdminActionKind::BackupDownloaded, |
| 346 | + AdminAction::ReleasePushed { .. } => AdminActionKind::ReleasePushed, | ||
| 343 | AdminAction::Community(_) => AdminActionKind::Community, | 347 | AdminAction::Community(_) => AdminActionKind::Community, |
| 344 | } | 348 | } |
| 345 | } | 349 | } |
| @@ -425,6 +429,13 @@ pub struct AttachmentInfo { | |||
| 425 | pub community: String, | 429 | pub community: String, |
| 426 | } | 430 | } |
| 427 | 431 | ||
| 432 | +#[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | ||
| 433 | +pub struct Release { | ||
| 434 | + pub seq: u64, | ||
| 435 | + pub minimum: u64, | ||
| 436 | + pub version: String, | ||
| 437 | +} | ||
| 438 | + | ||
| 428 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 439 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
| 429 | pub struct BackupInfo { | 440 | pub struct BackupInfo { |
| 430 | pub name: String, | 441 | pub name: String, |
| @@ -478,6 +489,13 @@ pub struct Overview { | |||
| 478 | pub online: u64, | 489 | pub online: u64, |
| 479 | pub voice: u64, | 490 | pub voice: u64, |
| 480 | pub storage_bytes: u64, | 491 | pub storage_bytes: u64, |
| 492 | + pub releases: Vec<ReleaseCount>, | ||
| 493 | +} | ||
| 494 | + | ||
| 495 | +#[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] | ||
| 496 | +pub struct ReleaseCount { | ||
| 497 | + pub release: Option<u64>, | ||
| 498 | + pub clients: u64, | ||
| 481 | } | 499 | } |
| 482 | 500 | ||
| 483 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] | 501 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Encode, Decode)] |
crates/common/src/open.rsmodified+8 -0
| @@ -7,6 +7,14 @@ pub enum Open { | |||
| 7 | Call(Box<Request>), | 7 | Call(Box<Request>), |
| 8 | Upload(Upload), | 8 | Upload(Upload), |
| 9 | Fetch(Blob), | 9 | Fetch(Blob), |
| 10 | + Publish(Publish), | ||
| 11 | +} | ||
| 12 | + | ||
| 13 | +#[derive(Debug, Clone, Encode, Decode)] | ||
| 14 | +pub struct Publish { | ||
| 15 | + pub name: String, | ||
| 16 | + pub size: u64, | ||
| 17 | + pub sha256: [u8; 32], | ||
| 10 | } | 18 | } |
| 11 | 19 | ||
| 12 | #[derive(Debug, Clone, Encode, Decode)] | 20 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/permission.rsmodified+0 -4
| @@ -89,10 +89,6 @@ pub fn can_leave(actor: Option<Rank>) -> bool { | |||
| 89 | actor.is_some() && actor != Some(Rank::Owner) | 89 | actor.is_some() && actor != Some(Rank::Owner) |
| 90 | } | 90 | } |
| 91 | 91 | ||
| 92 | -pub fn can_set_role(actor: Role, is_self: bool) -> bool { | ||
| 93 | - is_builder(actor) && !is_self | ||
| 94 | -} | ||
| 95 | - | ||
| 96 | pub fn can_delete_user(actor: Role, is_self: bool, target: Role) -> bool { | 92 | pub fn can_delete_user(actor: Role, is_self: bool, target: Role) -> bool { |
| 97 | is_self || can_manage_user(actor, false, target) | 93 | is_self || can_manage_user(actor, false, target) |
| 98 | } | 94 | } |
crates/common/src/update.rsmodified+12 -0
| @@ -100,7 +100,19 @@ pub struct File { | |||
| 100 | pub sha256: [u8; 32], | 100 | pub sha256: [u8; 32], |
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | +pub fn file_name(target: &str, seq: u64) -> String { | ||
| 104 | + format!("{target}-{seq}") | ||
| 105 | +} | ||
| 106 | + | ||
| 103 | impl Manifest { | 107 | impl Manifest { |
| 108 | + pub fn release(&self) -> crate::model::Release { | ||
| 109 | + crate::model::Release { | ||
| 110 | + seq: self.seq, | ||
| 111 | + minimum: self.minimum, | ||
| 112 | + version: self.version.clone(), | ||
| 113 | + } | ||
| 114 | + } | ||
| 115 | + | ||
| 104 | pub fn file(&self, name: &str) -> Option<&File> { | 116 | pub fn file(&self, name: &str) -> Option<&File> { |
| 105 | self.files.iter().find(|file| file.name == name) | 117 | self.files.iter().find(|file| file.name == name) |
| 106 | } | 118 | } |
crates/server/src/call/admin.rsmodified+42 -38
| @@ -1,19 +1,19 @@ | |||
| 1 | use common::{ | 1 | use common::{ |
| 2 | call::{ | 2 | call::{ |
| 3 | BanUser, ClearProfile, CreateBackup, CreateInviteCode, CreateUser, DeleteAttachment, | 3 | BanUser, ClearProfile, CreateBackup, CreateInviteCode, CreateUser, DeleteAttachment, |
| 4 | - DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetStorageUsage, | 4 | + DeleteBackup, DeleteInviteCode, DeleteUser, GetDailyStats, GetOverview, GetRelease, |
| 5 | - ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, ListInviteCodes, | 5 | + GetStorageUsage, ListAdminLogs, ListAllCommunities, ListAttachments, ListBackups, |
| 6 | - ListServerBans, ListUsers, Logout, PurgeUser, RemoveServerBan, RenameUser, ResetPassword, | 6 | + ListInviteCodes, ListServerBans, ListUsers, Logout, PurgeUser, PushRelease, |
| 7 | - RevokeSessions, SearchCommunity, SearchMessages, SetCommunityVoice, SetGhost, SetRole, | 7 | + RemoveServerBan, RenameUser, ResetPassword, RevokeSessions, SearchCommunity, |
| 8 | - StorageUsage, SuspendUser, TimeoutUser, TransferOwnership, UpdateServerSettings, | 8 | + SearchMessages, SetCommunityVoice, SetGhost, StorageUsage, SuspendUser, TimeoutUser, |
| 9 | - WatchCommunity, | 9 | + TransferOwnership, UpdateServerSettings, WatchCommunity, |
| 10 | }, | 10 | }, |
| 11 | error::Error, | 11 | error::Error, |
| 12 | event::Event, | 12 | event::Event, |
| 13 | model::{ | 13 | model::{ |
| 14 | Account, AdminAction, AdminLogEntry, AttachmentInfo, BackupInfo, BanScope, Community, | 14 | Account, AdminAction, AdminLogEntry, AttachmentInfo, BackupInfo, BanScope, Community, |
| 15 | - CommunitySummary, DayStat, InviteCode, LogAction, MessageHit, Overview, Rank, ServerBan, | 15 | + CommunitySummary, DayStat, InviteCode, LogAction, MessageHit, Overview, Rank, Release, |
| 16 | - ServerBanKind, ServerSettings, User, | 16 | + ReleaseCount, ServerBan, ServerBanKind, ServerSettings, User, |
| 17 | }, | 17 | }, |
| 18 | permission, | 18 | permission, |
| 19 | time::{self, MINUTE_MILLIS}, | 19 | time::{self, MINUTE_MILLIS}, |
| @@ -34,7 +34,7 @@ use crate::{ | |||
| 34 | request::{ | 34 | request::{ |
| 35 | allowed, call_ended, delete_community, ensure_editable, is_outsider, leave_room_voice, | 35 | allowed, call_ended, delete_community, ensure_editable, is_outsider, leave_room_voice, |
| 36 | leave_user_voice, managed, message_event, messages_deleted, record_ghost_voice, | 36 | leave_user_voice, managed, message_event, messages_deleted, record_ghost_voice, |
| 37 | - shares_ended, voice_joined, voice_muted, | 37 | + shares_ended, voice_joined, |
| 38 | }, | 38 | }, |
| 39 | }; | 39 | }; |
| 40 | 40 | ||
| @@ -190,6 +190,17 @@ impl Handle for GetOverview { | |||
| 190 | online: cx.sh.services.hub.online() as u64, | 190 | online: cx.sh.services.hub.online() as u64, |
| 191 | voice: cx.sh.services.rooms.count() as u64, | 191 | voice: cx.sh.services.rooms.count() as u64, |
| 192 | storage_bytes, | 192 | storage_bytes, |
| 193 | + releases: cx | ||
| 194 | + .sh | ||
| 195 | + .services | ||
| 196 | + .hub | ||
| 197 | + .releases() | ||
| 198 | + .into_iter() | ||
| 199 | + .map(|(release, clients)| ReleaseCount { | ||
| 200 | + release: (release != u64::MAX).then_some(release), | ||
| 201 | + clients, | ||
| 202 | + }) | ||
| 203 | + .collect(), | ||
| 193 | }) | 204 | }) |
| 194 | } | 205 | } |
| 195 | } | 206 | } |
| @@ -270,35 +281,6 @@ impl Handle for ClearProfile { | |||
| 270 | } | 281 | } |
| 271 | } | 282 | } |
| 272 | 283 | ||
| 273 | -impl Handle for SetRole { | ||
| 274 | - async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<User, ServerError> { | ||
| 275 | - let me = me.user()?; | ||
| 276 | - let Self { user_id, role } = self; | ||
| 277 | - ensure(permission::can_set_role(me.role, me.id == user_id))?; | ||
| 278 | - let user = user::set_role_by_id(user_id, role, cx.db).await?; | ||
| 279 | - log::record_admin( | ||
| 280 | - Some(me.id), | ||
| 281 | - Some(user_id), | ||
| 282 | - None, | ||
| 283 | - &AdminAction::RoleChanged { role }, | ||
| 284 | - cx.db, | ||
| 285 | - ) | ||
| 286 | - .await?; | ||
| 287 | - user_updated(&user, cx); | ||
| 288 | - if permission::is_builder(role) { | ||
| 289 | - if let Some(community_id) = cx.sh.services.rooms.set_muted(user_id, false) { | ||
| 290 | - cx.out | ||
| 291 | - .push(voice_muted(Some(community_id), user_id, false, cx.db).await?); | ||
| 292 | - } | ||
| 293 | - } else { | ||
| 294 | - user::set_ghost(user_id, false, cx.db).await?; | ||
| 295 | - cx.sh.services.hub.kick_user(user_id, Close::Revoked); | ||
| 296 | - } | ||
| 297 | - | ||
| 298 | - Ok(user) | ||
| 299 | - } | ||
| 300 | -} | ||
| 301 | - | ||
| 302 | impl Handle for DeleteUser { | 284 | impl Handle for DeleteUser { |
| 303 | async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { | 285 | async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<(), ServerError> { |
| 304 | let me = me.user()?; | 286 | let me = me.user()?; |
| @@ -660,6 +642,28 @@ impl Handle for CreateBackup { | |||
| 660 | } | 642 | } |
| 661 | } | 643 | } |
| 662 | 644 | ||
| 645 | +impl Handle for GetRelease { | ||
| 646 | + async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Option<Release>, ServerError> { | ||
| 647 | + Ok(crate::update::live(&cx.sh.updates) | ||
| 648 | + .await | ||
| 649 | + .map(|manifest| manifest.release())) | ||
| 650 | + } | ||
| 651 | +} | ||
| 652 | + | ||
| 653 | +impl Handle for PushRelease { | ||
| 654 | + async fn handle(self, me: Me, cx: &mut Cx<'_>) -> Result<Release, ServerError> { | ||
| 655 | + let me = me.user()?; | ||
| 656 | + let release = crate::update::push(&self.manifest, cx.sh).await?; | ||
| 657 | + let action = AdminAction::ReleasePushed { | ||
| 658 | + seq: release.seq, | ||
| 659 | + minimum: release.minimum, | ||
| 660 | + }; | ||
| 661 | + log::record_admin(Some(me.id), None, None, &action, cx.db).await?; | ||
| 662 | + | ||
| 663 | + Ok(release) | ||
| 664 | + } | ||
| 665 | +} | ||
| 666 | + | ||
| 663 | impl Handle for ListBackups { | 667 | impl Handle for ListBackups { |
| 664 | async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Vec<BackupInfo>, ServerError> { | 668 | async fn handle(self, _: Me, cx: &mut Cx<'_>) -> Result<Vec<BackupInfo>, ServerError> { |
| 665 | backup::list(&cx.sh.backups) | 669 | backup::list(&cx.sh.backups) |
crates/server/src/call/mod.rsmodified+2 -1
| @@ -184,7 +184,6 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | |||
| 184 | Request::DeleteUser(call) => serve(call, cx).await, | 184 | Request::DeleteUser(call) => serve(call, cx).await, |
| 185 | Request::WatchCommunity(call) => serve(call, cx).await, | 185 | Request::WatchCommunity(call) => serve(call, cx).await, |
| 186 | Request::ListUsers(call) => serve(call, cx).await, | 186 | Request::ListUsers(call) => serve(call, cx).await, |
| 187 | - Request::SetRole(call) => serve(call, cx).await, | ||
| 188 | Request::ListAdminLogs(call) => serve(call, cx).await, | 187 | Request::ListAdminLogs(call) => serve(call, cx).await, |
| 189 | Request::ListUserFriends(call) => serve(call, cx).await, | 188 | Request::ListUserFriends(call) => serve(call, cx).await, |
| 190 | Request::GetOverview(call) => serve(call, cx).await, | 189 | Request::GetOverview(call) => serve(call, cx).await, |
| @@ -215,6 +214,8 @@ pub(crate) async fn dispatch(request: Request, cx: &mut Cx<'_>) -> Vec<u8> { | |||
| 215 | Request::SetGhost(call) => serve(call, cx).await, | 214 | Request::SetGhost(call) => serve(call, cx).await, |
| 216 | Request::CreateBackup(call) => serve(call, cx).await, | 215 | Request::CreateBackup(call) => serve(call, cx).await, |
| 217 | Request::ListBackups(call) => serve(call, cx).await, | 216 | Request::ListBackups(call) => serve(call, cx).await, |
| 217 | + Request::GetRelease(call) => serve(call, cx).await, | ||
| 218 | + Request::PushRelease(call) => serve(call, cx).await, | ||
| 218 | Request::DeleteBackup(call) => serve(call, cx).await, | 219 | Request::DeleteBackup(call) => serve(call, cx).await, |
| 219 | Request::FollowStats(call) => serve(call, cx).await, | 220 | Request::FollowStats(call) => serve(call, cx).await, |
| 220 | Request::PushStats(call) => serve(call, cx).await, | 221 | Request::PushStats(call) => serve(call, cx).await, |
crates/server/src/db/schema.sqlmodified+2 -0
| @@ -14,12 +14,14 @@ CREATE TABLE user ( | |||
| 14 | last_seen INTEGER, | 14 | last_seen INTEGER, |
| 15 | created_at INTEGER NOT NULL | 15 | created_at INTEGER NOT NULL |
| 16 | ) STRICT; | 16 | ) STRICT; |
| 17 | +CREATE UNIQUE INDEX one_builder ON user (role) WHERE role = 'builder'; | ||
| 17 | 18 | ||
| 18 | CREATE TABLE session ( | 19 | CREATE TABLE session ( |
| 19 | id INTEGER PRIMARY KEY AUTOINCREMENT, | 20 | id INTEGER PRIMARY KEY AUTOINCREMENT, |
| 20 | token_hash BLOB NOT NULL UNIQUE, | 21 | token_hash BLOB NOT NULL UNIQUE, |
| 21 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, | 22 | user_id INTEGER NOT NULL REFERENCES user (id) ON DELETE CASCADE, |
| 22 | device TEXT NOT NULL DEFAULT '', | 23 | device TEXT NOT NULL DEFAULT '', |
| 24 | + release INTEGER, | ||
| 23 | last_seen INTEGER | 25 | last_seen INTEGER |
| 24 | ) STRICT; | 26 | ) STRICT; |
| 25 | CREATE INDEX session_user ON session (user_id); | 27 | CREATE INDEX session_user ON session (user_id); |
crates/server/src/db/session.rsmodified+10 -4
| @@ -60,11 +60,16 @@ pub async fn seen(session_id: Id, db: &Connection) -> Result<(), ServerError> { | |||
| 60 | Ok(()) | 60 | Ok(()) |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | -pub async fn set_device(session_id: Id, device: &str, db: &Connection) -> Result<(), ServerError> { | 63 | +pub async fn set_device( |
| 64 | + session_id: Id, | ||
| 65 | + device: &str, | ||
| 66 | + release: Option<u64>, | ||
| 67 | + db: &Connection, | ||
| 68 | +) -> Result<(), ServerError> { | ||
| 64 | run( | 69 | run( |
| 65 | db, | 70 | db, |
| 66 | - "UPDATE session SET device = ?2 WHERE id = ?1", | 71 | + "UPDATE session SET device = ?2, release = ?3 WHERE id = ?1", |
| 67 | - (session_id, device), | 72 | + (session_id, device, release.map(|release| release as i64)), |
| 68 | ) | 73 | ) |
| 69 | .await?; | 74 | .await?; |
| 70 | 75 | ||
| @@ -74,12 +79,13 @@ pub async fn set_device(session_id: Id, device: &str, db: &Connection) -> Result | |||
| 74 | pub async fn list(user_id: Id, db: &Connection) -> Result<Vec<SessionInfo>, ServerError> { | 79 | pub async fn list(user_id: Id, db: &Connection) -> Result<Vec<SessionInfo>, ServerError> { |
| 75 | all( | 80 | all( |
| 76 | db, | 81 | db, |
| 77 | - "SELECT id, device, last_seen FROM session WHERE user_id = ?1 ORDER BY last_seen DESC", | 82 | + "SELECT id, device, release, last_seen FROM session WHERE user_id = ?1 ORDER BY last_seen DESC", |
| 78 | (user_id,), | 83 | (user_id,), |
| 79 | |r| { | 84 | |r| { |
| 80 | Ok(SessionInfo { | 85 | Ok(SessionInfo { |
| 81 | id: r.get()?, | 86 | id: r.get()?, |
| 82 | device: r.get()?, | 87 | device: r.get()?, |
| 88 | + release: r.get::<Option<i64>>()?.map(|release| release as u64), | ||
| 83 | last_seen: r.get()?, | 89 | last_seen: r.get()?, |
| 84 | }) | 90 | }) |
| 85 | }, | 91 | }, |
crates/server/src/db/user.rsmodified+10 -0
| @@ -168,6 +168,16 @@ pub async fn last_ip(id: Id, db: &Connection) -> Result<Option<String>, ServerEr | |||
| 168 | .await | 168 | .await |
| 169 | } | 169 | } |
| 170 | 170 | ||
| 171 | +pub async fn make_builder(id: Id, db: &Connection) -> Result<User, ServerError> { | ||
| 172 | + run( | ||
| 173 | + db, | ||
| 174 | + "UPDATE user SET role = ?2 WHERE role = ?1 AND id != ?3", | ||
| 175 | + (Role::Builder.as_str(), Role::User.as_str(), id), | ||
| 176 | + ) | ||
| 177 | + .await?; | ||
| 178 | + set_role_by_id(id, Role::Builder, db).await | ||
| 179 | +} | ||
| 180 | + | ||
| 171 | pub async fn builder_ids(db: &Connection) -> Result<Vec<Id>, ServerError> { | 181 | pub async fn builder_ids(db: &Connection) -> Result<Vec<Id>, ServerError> { |
| 172 | all( | 182 | all( |
| 173 | db, | 183 | db, |
crates/server/src/hub.rsmodified+10 -0
| @@ -194,6 +194,16 @@ impl Hub { | |||
| 194 | } | 194 | } |
| 195 | } | 195 | } |
| 196 | 196 | ||
| 197 | + pub fn releases(&self) -> std::collections::BTreeMap<u64, u64> { | ||
| 198 | + let mut counts = std::collections::BTreeMap::new(); | ||
| 199 | + for client in self.0.lock().unwrap().values() { | ||
| 200 | + *counts | ||
| 201 | + .entry(client.release.load(Ordering::Relaxed)) | ||
| 202 | + .or_default() += 1; | ||
| 203 | + } | ||
| 204 | + counts | ||
| 205 | + } | ||
| 206 | + | ||
| 197 | pub fn kick_outdated(&self, minimum: u64) { | 207 | pub fn kick_outdated(&self, minimum: u64) { |
| 198 | let targets: Vec<Arc<Client>> = self | 208 | let targets: Vec<Arc<Client>> = self |
| 199 | .0 | 209 | .0 |
crates/server/src/lib.rsmodified+4 -1
| @@ -96,7 +96,10 @@ pub async fn set_role(username: &str, role: Role) -> Result<(), ServerError> { | |||
| 96 | let user = db::user::by_username(username, db) | 96 | let user = db::user::by_username(username, db) |
| 97 | .await? | 97 | .await? |
| 98 | .ok_or(CommonError::NotFound)?; | 98 | .ok_or(CommonError::NotFound)?; |
| 99 | - db::user::set_role_by_id(user.id, role, db).await?; | 99 | + match role { |
| 100 | + Role::Builder => db::user::make_builder(user.id, db).await?, | ||
| 101 | + role => db::user::set_role_by_id(user.id, role, db).await?, | ||
| 102 | + }; | ||
| 100 | 103 | ||
| 101 | Ok(()) | 104 | Ok(()) |
| 102 | }) | 105 | }) |
crates/server/src/network.rsmodified+7 -2
| @@ -84,7 +84,7 @@ pub async fn serve( | |||
| 84 | shared.services.machine.watch(shared.directory.clone()); | 84 | shared.services.machine.watch(shared.directory.clone()); |
| 85 | 85 | ||
| 86 | tokio::spawn(retention::collect(shared.clone())); | 86 | tokio::spawn(retention::collect(shared.clone())); |
| 87 | - tokio::spawn(crate::update::watch(shared.clone())); | 87 | + crate::update::load(&shared).await; |
| 88 | 88 | ||
| 89 | while let Some(incoming) = endpoint.accept().await { | 89 | while let Some(incoming) = endpoint.accept().await { |
| 90 | tokio::spawn(handle_connection(incoming, shared.clone())); | 90 | tokio::spawn(handle_connection(incoming, shared.clone())); |
| @@ -278,7 +278,7 @@ async fn admit( | |||
| 278 | db::user::set_last_ip(user.id, &ip, db).await?; | 278 | db::user::set_last_ip(user.id, &ip, db).await?; |
| 279 | let device = async { | 279 | let device = async { |
| 280 | validate_device(&hello.device)?; | 280 | validate_device(&hello.device)?; |
| 281 | - db::session::set_device(session_id, &hello.device, db).await | 281 | + db::session::set_device(session_id, &hello.device, hello.release, db).await |
| 282 | } | 282 | } |
| 283 | .await; | 283 | .await; |
| 284 | if let Err(error) = device { | 284 | if let Err(error) = device { |
| @@ -342,6 +342,11 @@ async fn route( | |||
| 342 | ) | 342 | ) |
| 343 | .await | 343 | .await |
| 344 | } | 344 | } |
| 345 | + Open::Publish(publish) => { | ||
| 346 | + let user = signed_user(&client, &shared).await?; | ||
| 347 | + crate::update::publish(user.as_ref(), publish, receive_stream, send_stream, &shared) | ||
| 348 | + .await | ||
| 349 | + } | ||
| 345 | Open::Fetch(blob) => { | 350 | Open::Fetch(blob) => { |
| 346 | let user = signed_user(&client, &shared).await?; | 351 | let user = signed_user(&client, &shared).await?; |
| 347 | files::fetch( | 352 | files::fetch( |
crates/server/src/update.rsmodified+140 -33
| @@ -6,19 +6,35 @@ use std::{ | |||
| 6 | time::Duration, | 6 | time::Duration, |
| 7 | }; | 7 | }; |
| 8 | 8 | ||
| 9 | -use common::update::{self, FILE_MAX, MANIFEST, MANIFEST_MAX}; | 9 | +use common::{ |
| 10 | + error::Error, | ||
| 11 | + frame::{self, DOWN_MAX, Sending}, | ||
| 12 | + model::{Release, User}, | ||
| 13 | + open::Publish, | ||
| 14 | + permission, | ||
| 15 | + update::{self, FILE_MAX, MANIFEST, MANIFEST_MAX, Manifest}, | ||
| 16 | +}; | ||
| 10 | use quinn::{Connection, RecvStream, SendStream}; | 17 | use quinn::{Connection, RecvStream, SendStream}; |
| 11 | -use tokio::{io::AsyncReadExt, sync::Semaphore, time::timeout}; | 18 | +use sha2::{Digest, Sha256}; |
| 19 | +use std::sync::atomic::Ordering; | ||
| 20 | +use tokio::{ | ||
| 21 | + io::{AsyncReadExt, AsyncWriteExt}, | ||
| 22 | + sync::Semaphore, | ||
| 23 | + time::timeout, | ||
| 24 | +}; | ||
| 12 | use tracing::warn; | 25 | use tracing::warn; |
| 13 | 26 | ||
| 14 | -use crate::{error::ServerError, network::Shared}; | 27 | +use crate::{ |
| 28 | + error::{ServerError, ensure}, | ||
| 29 | + network::Shared, | ||
| 30 | +}; | ||
| 15 | 31 | ||
| 16 | const STREAMS: usize = 4; | 32 | const STREAMS: usize = 4; |
| 17 | const ACCEPT_DEADLINE: Duration = Duration::from_secs(30); | 33 | const ACCEPT_DEADLINE: Duration = Duration::from_secs(30); |
| 18 | const ASK_DEADLINE: Duration = Duration::from_secs(5); | 34 | const ASK_DEADLINE: Duration = Duration::from_secs(5); |
| 19 | const TRANSFER_DEADLINE: Duration = Duration::from_secs(15 * 60); | 35 | const TRANSFER_DEADLINE: Duration = Duration::from_secs(15 * 60); |
| 20 | const STALL_DEADLINE: Duration = Duration::from_secs(30); | 36 | const STALL_DEADLINE: Duration = Duration::from_secs(30); |
| 21 | -const WATCH_EVERY: Duration = Duration::from_secs(5); | 37 | +static TURN: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(()); |
| 22 | const CHUNK: usize = 64 << 10; | 38 | const CHUNK: usize = 64 << 10; |
| 23 | static PERMITS: Semaphore = Semaphore::const_new(16); | 39 | static PERMITS: Semaphore = Semaphore::const_new(16); |
| 24 | const PER_PEER: u8 = 4; | 40 | const PER_PEER: u8 = 4; |
| @@ -119,42 +135,133 @@ async fn transfer( | |||
| 119 | Ok(()) | 135 | Ok(()) |
| 120 | } | 136 | } |
| 121 | 137 | ||
| 122 | -pub(crate) async fn watch(shared: Shared) { | 138 | +pub(crate) async fn live(directory: &Path) -> Option<Manifest> { |
| 123 | - let path = shared.updates.join(MANIFEST); | 139 | + let signed = tokio::fs::read(directory.join(MANIFEST)).await.ok()?; |
| 124 | - let mut seen = None; | 140 | + let (_, body) = update::split(&signed)?; |
| 125 | - let mut seq = None; | 141 | + update::parse(body) |
| 126 | - let mut interval = tokio::time::interval(WATCH_EVERY); | 142 | +} |
| 127 | - loop { | 143 | + |
| 128 | - interval.tick().await; | 144 | +pub(crate) async fn load(shared: &Shared) { |
| 129 | - let stamp = tokio::fs::metadata(&path) | 145 | + if let Some(manifest) = live(&shared.updates).await { |
| 130 | - .await | ||
| 131 | - .ok() | ||
| 132 | - .map(|metadata| (metadata.modified().ok(), metadata.len())); | ||
| 133 | - if stamp == seen { | ||
| 134 | - continue; | ||
| 135 | - } | ||
| 136 | - seen = stamp; | ||
| 137 | - let manifest = tokio::fs::read(&path).await.ok().and_then(|signed| { | ||
| 138 | - let (_, body) = update::split(&signed)?; | ||
| 139 | - update::parse(body) | ||
| 140 | - }); | ||
| 141 | - let Some(manifest) = manifest else { | ||
| 142 | - continue; | ||
| 143 | - }; | ||
| 144 | shared | 146 | shared |
| 145 | .services | 147 | .services |
| 146 | .minimum | 148 | .minimum |
| 147 | - .store(manifest.minimum, std::sync::atomic::Ordering::Relaxed); | 149 | + .store(manifest.minimum, Ordering::Relaxed); |
| 148 | - shared.services.hub.kick_outdated(manifest.minimum); | 150 | + } |
| 149 | - if seq | 151 | +} |
| 150 | - .replace(manifest.seq) | 152 | + |
| 151 | - .is_some_and(|old| old != manifest.seq) | 153 | +fn rejected(problem: impl std::fmt::Display) -> ServerError { |
| 152 | - { | 154 | + Error::Release(problem.to_string()).into() |
| 153 | - announce(&shared); | 155 | +} |
| 156 | + | ||
| 157 | +pub(crate) async fn push(signed: &[u8], shared: &Shared) -> Result<Release, ServerError> { | ||
| 158 | + let _turn = TURN.lock().await; | ||
| 159 | + let directory = &shared.updates; | ||
| 160 | + let manifest = update::split(signed) | ||
| 161 | + .and_then(|(_, body)| update::parse(body)) | ||
| 162 | + .ok_or_else(|| rejected("bad manifest"))?; | ||
| 163 | + if let Some(current) = live(directory).await | ||
| 164 | + && manifest.seq <= current.seq | ||
| 165 | + { | ||
| 166 | + return Err(rejected(format!( | ||
| 167 | + "{} is not above live {}", | ||
| 168 | + manifest.seq, current.seq | ||
| 169 | + ))); | ||
| 170 | + } | ||
| 171 | + let mut keep = vec![MANIFEST.to_string()]; | ||
| 172 | + for file in &manifest.files { | ||
| 173 | + let name = update::file_name(&file.name, manifest.seq); | ||
| 174 | + let size = tokio::fs::metadata(directory.join(&name)) | ||
| 175 | + .await | ||
| 176 | + .map(|metadata| metadata.len()) | ||
| 177 | + .ok(); | ||
| 178 | + if size != Some(file.size) { | ||
| 179 | + return Err(rejected(format!("{name} not uploaded"))); | ||
| 180 | + } | ||
| 181 | + keep.push(name); | ||
| 182 | + } | ||
| 183 | + let part = directory.join("manifest.part"); | ||
| 184 | + tokio::fs::write(&part, signed).await?; | ||
| 185 | + tokio::fs::File::open(&part).await?.sync_all().await?; | ||
| 186 | + tokio::fs::rename(&part, directory.join(MANIFEST)).await?; | ||
| 187 | + let mut entries = tokio::fs::read_dir(directory).await?; | ||
| 188 | + while let Some(entry) = entries.next_entry().await? { | ||
| 189 | + let name = entry.file_name().to_string_lossy().into_owned(); | ||
| 190 | + if !keep.contains(&name) && !name.ends_with(".part") { | ||
| 191 | + let _ = tokio::fs::remove_file(entry.path()).await; | ||
| 154 | } | 192 | } |
| 155 | } | 193 | } |
| 194 | + | ||
| 195 | + let services = &shared.services; | ||
| 196 | + services.minimum.store(manifest.minimum, Ordering::Relaxed); | ||
| 197 | + services.hub.kick_outdated(manifest.minimum); | ||
| 198 | + announce(shared); | ||
| 199 | + | ||
| 200 | + Ok(manifest.release()) | ||
| 201 | +} | ||
| 202 | + | ||
| 203 | +pub(crate) async fn publish( | ||
| 204 | + user: Option<&User>, | ||
| 205 | + header: Publish, | ||
| 206 | + mut receive: RecvStream, | ||
| 207 | + mut send: Sending, | ||
| 208 | + shared: &Shared, | ||
| 209 | +) -> Result<(), ServerError> { | ||
| 210 | + let stored = store(user, &header, &mut receive, &shared.updates).await; | ||
| 211 | + let rejected = stored.is_err(); | ||
| 212 | + let reply = stored.map_err(Error::from); | ||
| 213 | + frame::write(&mut send, &reply, DOWN_MAX).await?; | ||
| 214 | + send.finish()?; | ||
| 215 | + if rejected { | ||
| 216 | + let _ = receive.stop(0u32.into()); | ||
| 217 | + } | ||
| 218 | + | ||
| 219 | + Ok(()) | ||
| 156 | } | 220 | } |
| 157 | 221 | ||
| 222 | +async fn store( | ||
| 223 | + user: Option<&User>, | ||
| 224 | + header: &Publish, | ||
| 225 | + receive: &mut RecvStream, | ||
| 226 | + directory: &Path, | ||
| 227 | +) -> Result<(), ServerError> { | ||
| 228 | + let user = user.ok_or(Error::Unauthenticated)?; | ||
| 229 | + ensure(permission::is_builder(user.role))?; | ||
| 230 | + let name = &header.name; | ||
| 231 | + if !update::valid_name(name) || name == MANIFEST || !(1..=FILE_MAX).contains(&header.size) { | ||
| 232 | + return Err(rejected("bad file")); | ||
| 233 | + } | ||
| 234 | + let part = directory.join(format!("{name}.part")); | ||
| 235 | + let written = async { | ||
| 236 | + let mut file = tokio::fs::File::create(&part).await?; | ||
| 237 | + let mut hash = Sha256::new(); | ||
| 238 | + let mut remaining = header.size; | ||
| 239 | + let mut chunk = vec![0u8; CHUNK]; | ||
| 240 | + while remaining > 0 { | ||
| 241 | + let want = remaining.min(CHUNK as u64) as usize; | ||
| 242 | + let read = timeout(STALL_DEADLINE, receive.read(&mut chunk[..want])) | ||
| 243 | + .await? | ||
| 244 | + .map_err(|error| ServerError::Internal(error.to_string()))? | ||
| 245 | + .ok_or_else(|| rejected("short upload"))?; | ||
| 246 | + hash.update(&chunk[..read]); | ||
| 247 | + file.write_all(&chunk[..read]).await?; | ||
| 248 | + remaining -= read as u64; | ||
| 249 | + } | ||
| 250 | + if hash.finalize().as_slice() != header.sha256 { | ||
| 251 | + return Err(rejected("hash mismatch")); | ||
| 252 | + } | ||
| 253 | + file.sync_all().await?; | ||
| 254 | + tokio::fs::rename(&part, directory.join(name)).await?; | ||
| 255 | + | ||
| 256 | + Ok(()) | ||
| 257 | + } | ||
| 258 | + .await; | ||
| 259 | + if written.is_err() { | ||
| 260 | + let _ = tokio::fs::remove_file(&part).await; | ||
| 261 | + } | ||
| 262 | + | ||
| 263 | + written | ||
| 264 | +} | ||
| 158 | fn announce(shared: &Shared) { | 265 | fn announce(shared: &Shared) { |
| 159 | let down = common::event::Down::Event(Box::new(common::event::Event::Release)); | 266 | let down = common::event::Down::Event(Box::new(common::event::Event::Release)); |
| 160 | match common::frame::encode(&down, common::frame::DOWN_MAX) { | 267 | match common::frame::encode(&down, common::frame::DOWN_MAX) { |
packaging/keygen.shdeleted+0 -29
| @@ -1,29 +0,0 @@ | |||
| 1 | -#!/usr/bin/env bash | ||
| 2 | -set -euo pipefail | ||
| 3 | -ROOT="$(cd "$(dirname "$0")/.." && pwd)" | ||
| 4 | -KEYS="${YUMUSH_SIGNING_DIR:-$HOME/.local/share/yumush-signing}" | ||
| 5 | -OUT="$ROOT/crates/client/src/update/keys.rs" | ||
| 6 | -umask 077 | ||
| 7 | -mkdir -p "$KEYS" | ||
| 8 | -if grep -q 0x "$OUT"; then | ||
| 9 | - echo "$OUT already holds keys; rotating them is a release of its own" >&2 | ||
| 10 | - exit 1 | ||
| 11 | -fi | ||
| 12 | -for name in primary backup; do | ||
| 13 | - [[ -e "$KEYS/$name.pem" ]] && continue | ||
| 14 | - echo "passphrase for $name key:" | ||
| 15 | - openssl genpkey -algorithm ed25519 | openssl pkcs8 -topk8 -v2 aes-256-cbc -iter 2000000 -out "$KEYS/$name.pem.part" | ||
| 16 | - mv "$KEYS/$name.pem.part" "$KEYS/$name.pem" | ||
| 17 | -done | ||
| 18 | -{ | ||
| 19 | - echo "pub const KEYS: &[[u8; 32]] = &[" | ||
| 20 | - for name in primary backup; do | ||
| 21 | - echo "unlock $name key to export its public half:" >&2 | ||
| 22 | - bytes=$(openssl pkey -in "$KEYS/$name.pem" -pubout -outform DER | tail -c 32 | od -An -v -tx1 | tr -s ' \n' ' ' | sed 's/^ //; s/ $//; s/\([0-9a-f][0-9a-f]\)/0x\1,/g; s/,$//') | ||
| 23 | - echo " [$bytes]," | ||
| 24 | - done | ||
| 25 | - echo "];" | ||
| 26 | -} > "$OUT.tmp" | ||
| 27 | -mv "$OUT.tmp" "$OUT" | ||
| 28 | -echo "keys in $KEYS, public keys in $OUT" | ||
| 29 | -echo "copy $KEYS/backup.pem to offline storage, then delete it from this machine" | ||
packaging/release-windows.ps1modified+18 -10
| @@ -1,14 +1,22 @@ | |||
| 1 | -param([Parameter(Mandatory)][ValidatePattern('^[1-9][0-9]{0,17}$')][string]$Seq) | 1 | +param( |
| 2 | + [Parameter(Mandatory)][ValidatePattern('^[1-9][0-9]{0,17}$')][string]$Seq, | ||
| 3 | + [Parameter(Mandatory)][string]$Levels | ||
| 4 | +) | ||
| 2 | $ErrorActionPreference = 'Stop' | 5 | $ErrorActionPreference = 'Stop' |
| 3 | Set-Location (Split-Path $PSScriptRoot) | 6 | Set-Location (Split-Path $PSScriptRoot) |
| 4 | -if (git status --porcelain) { throw 'working tree is dirty' } | 7 | +$env:Path += ";$env:USERPROFILE\.cargo\bin" |
| 5 | -$env:RUSTFLAGS = '-C target-feature=+crt-static -C target-cpu=x86-64-v3 -C link-arg=/OPT:REF -C link-arg=/OPT:ICF' | ||
| 6 | $env:YUMUSH_RELEASE_SEQ = $Seq | 8 | $env:YUMUSH_RELEASE_SEQ = $Seq |
| 7 | -cargo build --release --locked -p client | ||
| 8 | -if ($LASTEXITCODE -ne 0) { throw 'build failed' } | ||
| 9 | -$out = (& .\target\release\client.exe --selftest | Out-String).Trim() | ||
| 10 | -if ($out -ne $Seq) { throw "selftest printed '$out'" } | ||
| 11 | New-Item -ItemType Directory -Force "dist\$Seq" | Out-Null | 9 | New-Item -ItemType Directory -Force "dist\$Seq" | Out-Null |
| 12 | -Copy-Item .\target\release\client.exe "dist\$Seq\x86_64-windows" | 10 | +foreach ($level in $Levels.Split(' ')) { |
| 13 | -Set-Content -NoNewline "dist\$Seq\x86_64-windows.seq" $out | 11 | + $name = "x86_64_$level-windows" |
| 14 | -Write-Output "copy dist\$Seq\x86_64-windows and x86_64-windows.seq into dist/$Seq on the signing machine" | 12 | + $cpu = if ($level -eq 'v1') { 'x86-64' } else { "x86-64-$level" } |
| 13 | + $env:RUSTFLAGS = "-C target-feature=+crt-static -C target-cpu=$cpu -C link-arg=/OPT:REF -C link-arg=/OPT:ICF" | ||
| 14 | + $env:CARGO_TARGET_DIR = "..\target-release-$level" | ||
| 15 | + cargo build --release --locked -p client | ||
| 16 | + if ($LASTEXITCODE -ne 0) { throw 'build failed' } | ||
| 17 | + $exe = "..\target-release-$level\release\client.exe" | ||
| 18 | + try { $out = (& $exe --selftest | Out-String).Trim() } catch { $out = $Seq; Write-Output "$name cannot run on this CPU, selftest skipped" } | ||
| 19 | + if ($out -ne $Seq) { throw "$name selftest printed '$out'" } | ||
| 20 | + Copy-Item $exe "dist\$Seq\$name" | ||
| 21 | + Set-Content -NoNewline "dist\$Seq\$name.seq" $Seq | ||
| 22 | +} | ||
packaging/release.shmodified+40 -54
| @@ -1,67 +1,53 @@ | |||
| 1 | #!/usr/bin/env bash | 1 | #!/usr/bin/env bash |
| 2 | set -euo pipefail | 2 | set -euo pipefail |
| 3 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" | 3 | ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 4 | -KEYS="${YUMUSH_SIGNING_DIR:-$HOME/.local/share/yumush-signing}" | 4 | +LEVELS="v1 v3 v4" |
| 5 | cd "$ROOT" | 5 | cd "$ROOT" |
| 6 | -usage() { | 6 | +usage() { echo "usage: $0 linux|windows <seq>" >&2; exit 1; } |
| 7 | - echo "usage: $0 build <seq> | sign <seq> <minimum> (minimum = oldest seq still allowed; = seq forces everyone up)" >&2 | 7 | +[[ $# -eq 2 && "$2" =~ ^[1-9][0-9]{0,17}$ ]] || usage |
| 8 | - exit 1 | ||
| 9 | -} | ||
| 10 | -[[ $# -ge 2 && "$2" =~ ^[1-9][0-9]{0,17}$ ]] || usage | ||
| 11 | SEQ="$2" | 8 | SEQ="$2" |
| 12 | DIST="$ROOT/dist/$SEQ" | 9 | DIST="$ROOT/dist/$SEQ" |
| 10 | +[[ -z "$(git status --porcelain)" ]] || { echo "working tree is dirty" >&2; exit 1; } | ||
| 11 | +grep -q 0x crates/client/src/update/keys.rs || { echo "no signing keys in keys.rs" >&2; exit 1; } | ||
| 12 | +for done in "$ROOT"/dist/*/; do | ||
| 13 | + [[ -d "$done" && "$(basename "$done")" != "$SEQ" ]] || continue | ||
| 14 | + (( $(basename "$done") < SEQ )) || { echo "seq $SEQ is not above $(basename "$done")" >&2; exit 1; } | ||
| 15 | +done | ||
| 16 | +mkdir -p "$DIST" | ||
| 13 | 17 | ||
| 14 | case "$1" in | 18 | case "$1" in |
| 15 | -build) | 19 | +linux) |
| 16 | - [[ -z "$(git status --porcelain)" ]] || { echo "working tree is dirty" >&2; exit 1; } | 20 | + for level in $LEVELS; do |
| 17 | - for done in "$ROOT"/dist/*/; do | 21 | + name="$(uname -m)_$level-linux" |
| 18 | - [[ -d "$done" ]] || continue | 22 | + cpu="x86-64-$level"; [[ $level == v1 ]] && cpu="x86-64" |
| 19 | - (( $(basename "$done") < SEQ )) || { echo "seq $SEQ is not above $(basename "$done")" >&2; exit 1; } | 23 | + RUSTFLAGS="-C target-cpu=$cpu -C link-arg=-Wl,--gc-sections -C link-arg=-Wl,-O2" \ |
| 24 | + CARGO_TARGET_DIR="target/release-$level" YUMUSH_RELEASE_SEQ="$SEQ" \ | ||
| 25 | + cargo build --release --locked -p client | ||
| 26 | + cp "target/release-$level/release/client" "$DIST/$name" | ||
| 27 | + if built=$("$DIST/$name" --selftest); then | ||
| 28 | + [[ "$built" == "$SEQ" ]] || { echo "$name selftest printed '$built'" >&2; exit 1; } | ||
| 29 | + else | ||
| 30 | + echo "$name cannot run on this CPU, selftest skipped" | ||
| 31 | + fi | ||
| 32 | + printf '%s' "$SEQ" > "$DIST/$name.seq" | ||
| 33 | + echo "built $name" | ||
| 20 | done | 34 | done |
| 21 | - TARGET="$(uname -m)-linux" | ||
| 22 | - RUSTFLAGS="-C target-cpu=x86-64-v3 -C link-arg=-Wl,--gc-sections -C link-arg=-Wl,-O2" \ | ||
| 23 | - YUMUSH_RELEASE_SEQ="$SEQ" cargo build --release --locked -p client | ||
| 24 | - mkdir -p "$DIST" | ||
| 25 | - cp target/release/client "$DIST/$TARGET" | ||
| 26 | - [[ "$("$DIST/$TARGET" --selftest)" == "$SEQ" ]] || { echo "selftest failed" >&2; exit 1; } | ||
| 27 | - echo "$DIST/$TARGET" | ||
| 28 | ;; | 35 | ;; |
| 29 | -sign) | 36 | +windows) |
| 30 | - [[ $# -ge 3 && "$3" =~ ^[1-9][0-9]{0,17}$ ]] && (( $3 <= SEQ )) || usage | 37 | + ssh_win() { ssh -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o ConnectTimeout=10 -o LogLevel=ERROR -p 2222 yumush@127.0.0.1 "$@"; } |
| 31 | - MINIMUM="$3" | 38 | + scp_win() { scp -q -i ~/vm/yumush-win/id_ed25519 -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null -o LogLevel=ERROR -P 2222 "$@"; } |
| 32 | - KEY="$KEYS/${YUMUSH_SIGNING_KEY:-primary}.pem" | 39 | + TAR="$(mktemp --suffix=.tgz)" |
| 33 | - VERSION=$(cargo pkgid -p client | sed 's/.*[#@]//') | 40 | + trap 'rm -f "$TAR"' EXIT |
| 34 | - BODY="$DIST/manifest.body" | 41 | + git ls-files | tar czf "$TAR" -T - |
| 35 | - { | 42 | + ssh_win 'Remove-Item -Recurse -Force release -ErrorAction SilentlyContinue; New-Item -ItemType Directory release | Out-Null' |
| 36 | - printf 'yumush-update 1\nseq %s\nminimum %s\nversion %s\n' "$SEQ" "$MINIMUM" "$VERSION" | 43 | + scp_win "$TAR" yumush@127.0.0.1:release.tgz |
| 37 | - for file in "$DIST"/*; do | 44 | + ssh_win "tar xmzf release.tgz -C release; powershell -NoProfile -ExecutionPolicy Bypass -File release\\packaging\\release-windows.ps1 -Seq $SEQ -Levels '$LEVELS'" |
| 38 | - name=$(basename "$file") | 45 | + for level in $LEVELS; do |
| 39 | - [[ "$name" =~ ^[a-z0-9_]+-[a-z0-9_]+$ ]] || continue | 46 | + name="x86_64_$level-windows" |
| 40 | - if [[ "$name" == "$(uname -m)-linux" ]]; then | 47 | + scp_win "yumush@127.0.0.1:release/dist/$SEQ/$name" "yumush@127.0.0.1:release/dist/$SEQ/$name.seq" "$DIST/" |
| 41 | - built=$("$file" --selftest) | 48 | + [[ "$(cat "$DIST/$name.seq")" == "$SEQ" ]] || { echo "$name seq mismatch" >&2; exit 1; } |
| 42 | - else | 49 | + echo "built $name" |
| 43 | - built=$(cat "$file.seq") | 50 | + done |
| 44 | - fi | ||
| 45 | - [[ "$built" == "$SEQ" ]] || { echo "$name was built as seq '$built', not $SEQ" >&2; exit 1; } | ||
| 46 | - printf '%s %s %s\n' "$name" "$(stat -c %s "$file")" "$(sha256sum "$file" | cut -d' ' -f1)" | ||
| 47 | - done | ||
| 48 | - } > "$BODY" | ||
| 49 | - grep -q ' ' <(tail -n +5 "$BODY") || { echo "no binaries in $DIST" >&2; exit 1; } | ||
| 50 | - cat "$BODY" | ||
| 51 | - SIG=$(mktemp) | ||
| 52 | - PUBLIC=$(mktemp) | ||
| 53 | - trap 'rm -f "$SIG" "$PUBLIC"' EXIT | ||
| 54 | - openssl pkeyutl -sign -rawin -inkey "$KEY" -in "$BODY" -out "$SIG" | ||
| 55 | - [[ $(stat -c %s "$SIG") == 64 ]] || { echo "bad signature size" >&2; exit 1; } | ||
| 56 | - TRUSTED=0 | ||
| 57 | - while read -r hex; do | ||
| 58 | - { printf '302a300506032b6570032100'; printf '%s' "$hex"; } | xxd -r -p > "$PUBLIC" | ||
| 59 | - openssl pkeyutl -verify -rawin -pubin -keyform DER -inkey "$PUBLIC" -in "$BODY" -sigfile "$SIG" >/dev/null 2>&1 && TRUSTED=1 | ||
| 60 | - done < <(grep -o '\[0x[^]]*\]' crates/client/src/update/keys.rs | tr -d '[], ' | sed 's/0x//g') | ||
| 61 | - [[ $TRUSTED == 1 ]] || { echo "signature does not match any key in keys.rs" >&2; exit 1; } | ||
| 62 | - cat "$SIG" "$BODY" > "$DIST/manifest" | ||
| 63 | - rm "$BODY" | ||
| 64 | - echo "upload the binaries in $DIST to the server's updates/ directory first, then manifest last" | ||
| 65 | ;; | 51 | ;; |
| 66 | *) usage ;; | 52 | *) usage ;; |
| 67 | esac | 53 | esac |