diff options
| author | Emīls <emils@mullvad.net> | 2020-07-02 22:49:29 +0100 |
|---|---|---|
| committer | Emīls <emils@mullvad.net> | 2020-07-03 15:11:25 +0100 |
| commit | 48240f36657799c46e7db16edbc47771e9d44403 (patch) | |
| tree | 256be74d1c7dca145b34fb856f1c045c58b2fe3b | |
| parent | e9d8f92059650d717e8871176ead70ef49092a9d (diff) | |
| download | mullvadvpn-48240f36657799c46e7db16edbc47771e9d44403.tar.xz mullvadvpn-48240f36657799c46e7db16edbc47771e9d44403.zip | |
Add RPC to clear account history
| -rw-r--r-- | mullvad-cli/src/cmds/account.rs | 17 | ||||
| -rw-r--r-- | mullvad-daemon/src/lib.rs | 16 | ||||
| -rw-r--r-- | mullvad-daemon/src/management_interface.rs | 13 | ||||
| -rw-r--r-- | mullvad-ipc-client/src/lib.rs | 4 |
4 files changed, 48 insertions, 2 deletions
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs index 3baac8d192..e35699605c 100644 --- a/mullvad-cli/src/cmds/account.rs +++ b/mullvad-cli/src/cmds/account.rs @@ -31,6 +31,10 @@ impl Command for Account { .about("Removes the account number from the settings"), ) .subcommand( + clap::SubCommand::with_name("clear-history") + .about("Clear account history, along with removing all associated keys"), + ) + .subcommand( clap::SubCommand::with_name("create") .about("Creates a new account and sets it as the active one"), ) @@ -49,10 +53,12 @@ impl Command for Account { if let Some(set_matches) = matches.subcommand_matches("set") { let token = value_t_or_exit!(set_matches.value_of("token"), String); self.set(Some(token)) - } else if let Some(_matches) = matches.subcommand_matches("unset") { - self.set(None) } else if let Some(_matches) = matches.subcommand_matches("get") { self.get() + } else if let Some(_matches) = matches.subcommand_matches("unset") { + self.set(None) + } else if let Some(_matches) = matches.subcommand_matches("clear-history") { + self.clear_history() } else if let Some(_matches) = matches.subcommand_matches("create") { self.create() } else if let Some(matches) = matches.subcommand_matches("redeem") { @@ -138,4 +144,11 @@ impl Account { _ => 0, } } + + fn clear_history(&self) -> Result<()> { + let mut rpc = new_rpc_client()?; + rpc.clear_account_history()?; + println!("Removed account history and all associated keys"); + Ok(()) + } } diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs index 0c12acf1f5..f1cb483f9a 100644 --- a/mullvad-daemon/src/lib.rs +++ b/mullvad-daemon/src/lib.rs @@ -172,6 +172,8 @@ pub enum DaemonCommand { GetAccountHistory(oneshot::Sender<Vec<AccountToken>>), /// Request account history RemoveAccountFromHistory(oneshot::Sender<()>, AccountToken), + /// Clear account history + ClearAccountHistory(oneshot::Sender<()>), /// Get the list of countries and cities where there are relays. GetRelayLocations(oneshot::Sender<RelayList>), /// Trigger an asynchronous relay list update. This returns before the relay list is actually @@ -988,6 +990,7 @@ where RemoveAccountFromHistory(tx, account_token) => { self.on_remove_account_from_history(tx, account_token) } + ClearAccountHistory(tx) => self.on_clear_account_history(tx), UpdateRelaySettings(tx, update) => self.on_update_relay_settings(tx, update), SetAllowLan(tx, allow_lan) => self.on_set_allow_lan(tx, allow_lan), SetShowBetaReleases(tx, enabled) => self.on_set_show_beta_releases(tx, enabled), @@ -1328,6 +1331,19 @@ where } } + fn on_clear_account_history(&mut self, tx: oneshot::Sender<()>) { + match self.account_history.clear() { + Ok(_) => { + self.set_target_state(TargetState::Unsecured); + Self::oneshot_send(tx, (), "clear_account_history response"); + } + Err(err) => log::error!( + "{}", + err.display_chain_with_msg("Failed to clear account history") + ), + } + } + fn on_get_version_info(&mut self, tx: oneshot::Sender<AppVersionInfo>) { Self::oneshot_send( tx, diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs index 75ea62168c..d593f0aa9d 100644 --- a/mullvad-daemon/src/management_interface.rs +++ b/mullvad-daemon/src/management_interface.rs @@ -126,6 +126,10 @@ build_rpc_trait! { #[rpc(meta, name = "remove_account_from_history")] fn remove_account_from_history(&self, Self::Metadata, AccountToken) -> BoxFuture<(), Error>; + /// Removes all accounts from history, removing any associated keys in the process + #[rpc(meta, name = "clear_account_history")] + fn clear_account_history(&self, Self::Metadata) -> BoxFuture<(), Error>; + /// Sets openvpn's mssfix parameter #[rpc(meta, name = "set_openvpn_mssfix")] fn set_openvpn_mssfix(&self, Self::Metadata, Option<u16>) -> BoxFuture<(), Error>; @@ -602,6 +606,15 @@ impl ManagementInterfaceApi for ManagementInterface { Box::new(future) } + fn clear_account_history(&self, _: Self::Metadata) -> BoxFuture<(), Error> { + log::debug!("clear_account_history"); + let (tx, rx) = sync::oneshot::channel(); + let future = self + .send_command_to_daemon(DaemonCommand::ClearAccountHistory(tx)) + .and_then(|_| rx.map_err(|_| Error::internal_error())); + Box::new(future) + } + fn set_openvpn_mssfix(&self, _: Self::Metadata, mssfix: Option<u16>) -> BoxFuture<(), Error> { log::debug!("set_openvpn_mssfix({:?})", mssfix); let (tx, rx) = sync::oneshot::channel(); diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs index 93817c7328..f1bae521b8 100644 --- a/mullvad-ipc-client/src/lib.rs +++ b/mullvad-ipc-client/src/lib.rs @@ -195,6 +195,10 @@ impl DaemonRpcClient { self.call("set_account", &[account]) } + pub fn clear_account_history(&mut self) -> Result<()> { + self.call("clear_account_history", &NO_ARGS) + } + pub fn set_enable_ipv6(&mut self, enabled: bool) -> Result<()> { self.call("set_enable_ipv6", &[enabled]) } |
