Commit c668cff4dd
Unsigned
Layout: unified · split
src/server.rs +44 −19
| @@ -242,9 +242,19 @@ pub enum ServerError { | |||
| 242 | enum DeviceTrust { | 242 | enum DeviceTrust { |
| 243 | Verified, | 243 | Verified, |
| 244 | Unverified, | 244 | Unverified, |
| 245 | MissingKeys, | ||
| 245 | Unsupported, | 246 | Unsupported, |
| 246 | } | 247 | } |
| 247 | 248 | ||
| 249 | fn device_trust_label(device_trust: DeviceTrust) -> &'static str { | ||
| 250 | match device_trust { | ||
| 251 | DeviceTrust::Verified => "Trusted", | ||
| 252 | DeviceTrust::Unverified => "Not trusted", | ||
| 253 | DeviceTrust::MissingKeys => "No uploaded keys", | ||
| 254 | DeviceTrust::Unsupported => "No encryption support", | ||
| 255 | } | ||
| 256 | } | ||
| 257 | |||
| 248 | #[derive(Clone, Debug, PartialEq)] | 258 | #[derive(Clone, Debug, PartialEq)] |
| 249 | pub struct ServerSettings { | 259 | pub struct ServerSettings { |
| 250 | pub homeserver: Option<Url>, | 260 | pub homeserver: Option<Url>, |
| @@ -2484,19 +2494,14 @@ impl InnerServer { | |||
| 2484 | 2494 | ||
| 2485 | let own_device = own_device_id == Some(&device_info.device_id); | 2495 | let own_device = own_device_id == Some(&device_info.device_id); |
| 2486 | 2496 | ||
| 2487 | let device_trust = if own_device { | 2497 | let device_trust = match (own_device, device.as_ref()) { |
| 2488 | DeviceTrust::Verified | 2498 | (true, Some(_)) => DeviceTrust::Verified, |
| 2489 | } else { | 2499 | (true, None) => DeviceTrust::MissingKeys, |
| 2490 | device | 2500 | (false, Some(device)) if device.is_verified() => { |
| 2491 | .as_ref() | 2501 | DeviceTrust::Verified |
| 2492 | .map(|d| { | 2502 | } |
| 2493 | if d.is_verified() { | 2503 | (false, Some(_)) => DeviceTrust::Unverified, |
| 2494 | DeviceTrust::Verified | 2504 | (false, None) => DeviceTrust::Unsupported, |
| 2495 | } else { | ||
| 2496 | DeviceTrust::Unverified | ||
| 2497 | } | ||
| 2498 | }) | ||
| 2499 | .unwrap_or(DeviceTrust::Unsupported) | ||
| 2500 | }; | 2505 | }; |
| 2501 | 2506 | ||
| 2502 | let info = Self::format_device( | 2507 | let info = Self::format_device( |
| @@ -2620,22 +2625,33 @@ impl InnerServer { | |||
| 2620 | let verified = match device_trust { | 2625 | let verified = match device_trust { |
| 2621 | DeviceTrust::Verified => { | 2626 | DeviceTrust::Verified => { |
| 2622 | format!( | 2627 | format!( |
| 2623 | "{}Trusted{}", | 2628 | "{}{}{}", |
| 2624 | Weechat::color("green"), | 2629 | Weechat::color("green"), |
| 2630 | device_trust_label(device_trust), | ||
| 2625 | Weechat::color("reset") | 2631 | Weechat::color("reset") |
| 2626 | ) | 2632 | ) |
| 2627 | } | 2633 | } |
| 2628 | DeviceTrust::Unverified => { | 2634 | DeviceTrust::Unverified => { |
| 2629 | format!( | 2635 | format!( |
| 2630 | "{}Not trusted{}", | 2636 | "{}{}{}", |
| 2631 | Weechat::color("red"), | 2637 | Weechat::color("red"), |
| 2638 | device_trust_label(device_trust), | ||
| 2639 | Weechat::color("reset") | ||
| 2640 | ) | ||
| 2641 | } | ||
| 2642 | DeviceTrust::MissingKeys => { | ||
| 2643 | format!( | ||
| 2644 | "{}{}{}", | ||
| 2645 | Weechat::color("yellow"), | ||
| 2646 | device_trust_label(device_trust), | ||
| 2632 | Weechat::color("reset") | 2647 | Weechat::color("reset") |
| 2633 | ) | 2648 | ) |
| 2634 | } | 2649 | } |
| 2635 | DeviceTrust::Unsupported => { | 2650 | DeviceTrust::Unsupported => { |
| 2636 | format!( | 2651 | format!( |
| 2637 | "{}No encryption support{}", | 2652 | "{}{}{}", |
| 2638 | Weechat::color("darkgray"), | 2653 | Weechat::color("darkgray"), |
| 2654 | device_trust_label(device_trust), | ||
| 2639 | Weechat::color("reset") | 2655 | Weechat::color("reset") |
| 2640 | ) | 2656 | ) |
| 2641 | } | 2657 | } |
| @@ -3052,9 +3068,10 @@ impl InnerServer { | |||
| 3052 | #[cfg(test)] | 3068 | #[cfg(test)] |
| 3053 | mod tests { | 3069 | mod tests { |
| 3054 | use super::{ | 3070 | use super::{ |
| 3055 | create_room_request, missing_alias_action, room_id_join_servers, | 3071 | create_room_request, device_trust_label, missing_alias_action, |
| 3056 | room_key_withheld_message, secure_set_token_command, | 3072 | room_id_join_servers, room_key_withheld_message, |
| 3057 | with_entered_runtime_until_drop, InnerServer, MissingAliasAction, | 3073 | secure_set_token_command, with_entered_runtime_until_drop, DeviceTrust, |
| 3074 | InnerServer, MissingAliasAction, | ||
| 3058 | }; | 3075 | }; |
| 3059 | use matrix_sdk::ruma::{ | 3076 | use matrix_sdk::ruma::{ |
| 3060 | events::room_key::withheld::{ | 3077 | events::room_key::withheld::{ |
| @@ -3088,6 +3105,14 @@ mod tests { | |||
| 3088 | } | 3105 | } |
| 3089 | } | 3106 | } |
| 3090 | 3107 | ||
| 3108 | #[test] | ||
| 3109 | fn labels_server_listed_devices_without_uploaded_keys() { | ||
| 3110 | assert_eq!( | ||
| 3111 | device_trust_label(DeviceTrust::MissingKeys), | ||
| 3112 | "No uploaded keys" | ||
| 3113 | ); | ||
| 3114 | } | ||
| 3115 | |||
| 3091 | #[test] | 3116 | #[test] |
| 3092 | fn secure_token_command_does_not_store_literal_quotes() { | 3117 | fn secure_token_command_does_not_store_literal_quotes() { |
| 3093 | assert_eq!( | 3118 | assert_eq!( |