summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2019-12-17 10:06:27 +0100
committerDavid Lönnhager <david.l@mullvad.net>2019-12-17 12:30:16 +0100
commit964d5211746a3e2841e6a86c22d1c5bd757707bb (patch)
tree70f42303da155de47edbf1689cf2b8958eeea671
parentbe990b4373d75dde1352d0812e2c418855c82e40 (diff)
downloadmullvadvpn-964d5211746a3e2841e6a86c22d1c5bd757707bb.tar.xz
mullvadvpn-964d5211746a3e2841e6a86c22d1c5bd757707bb.zip
Improve key rotation CLI
-rw-r--r--mullvad-cli/src/cmds/tunnel.rs34
-rw-r--r--mullvad-daemon/src/lib.rs10
-rw-r--r--mullvad-daemon/src/management_interface.rs12
-rw-r--r--mullvad-ipc-client/src/lib.rs7
-rw-r--r--mullvad-types/src/settings/mod.rs2
5 files changed, 31 insertions, 34 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs
index c1e1e174e1..2d0da4bf32 100644
--- a/mullvad-cli/src/cmds/tunnel.rs
+++ b/mullvad-cli/src/cmds/tunnel.rs
@@ -56,15 +56,15 @@ fn create_wireguard_keys_subcommand() -> clap::App<'static, 'static> {
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(clap::SubCommand::with_name("check"))
.subcommand(clap::SubCommand::with_name("generate"))
- .subcommand(create_wireguard_keys_automatic_rotation_subcommand())
+ .subcommand(create_wireguard_keys_rotation_interval_subcommand())
}
-fn create_wireguard_keys_automatic_rotation_subcommand() -> clap::App<'static, 'static> {
- clap::SubCommand::with_name("automatic-rotation")
+fn create_wireguard_keys_rotation_interval_subcommand() -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name("rotation-interval")
.about("Manage automatic key rotation (specified in hours; 0 = disabled)")
.setting(clap::AppSettings::SubcommandRequiredElseHelp)
.subcommand(clap::SubCommand::with_name("get"))
- .subcommand(clap::SubCommand::with_name("unset"))
+ .subcommand(clap::SubCommand::with_name("reset").about("Use the default rotation interval"))
.subcommand(
clap::SubCommand::with_name("set").arg(clap::Arg::with_name("interval").required(true)),
)
@@ -132,12 +132,12 @@ impl Tunnel {
("key", Some(matches)) => match matches.subcommand() {
("check", _) => Self::process_wireguard_key_check(),
("generate", _) => Self::process_wireguard_key_generate(),
- ("automatic-rotation", Some(matches)) => match matches.subcommand() {
- ("get", _) => Self::process_wireguard_automatic_rotation_get(),
+ ("rotation-interval", Some(matches)) => match matches.subcommand() {
+ ("get", _) => Self::process_wireguard_rotation_interval_get(),
("set", Some(matches)) => {
- Self::process_wireguard_automatic_rotation_set(matches)
+ Self::process_wireguard_rotation_interval_set(matches)
}
- ("unset", _) => Self::process_wireguard_automatic_rotation_unset(),
+ ("reset", _) => Self::process_wireguard_rotation_interval_reset(),
_ => unreachable!("unhandled command"),
},
_ => unreachable!("unhandled command"),
@@ -205,32 +205,32 @@ impl Tunnel {
Ok(())
}
- fn process_wireguard_automatic_rotation_get() -> Result<()> {
+ fn process_wireguard_rotation_interval_get() -> Result<()> {
let tunnel_options = Self::get_tunnel_options()?;
println!(
- "Automatic rotation interval (hours): {}",
+ "Rotation interval: {} hour(s)",
tunnel_options
.wireguard
.automatic_rotation
.map(|interval| interval.to_string())
- .unwrap_or_else(|| "unset".to_owned())
+ .unwrap_or_else(|| "default".to_owned())
);
Ok(())
}
- fn process_wireguard_automatic_rotation_set(matches: &clap::ArgMatches<'_>) -> Result<()> {
+ fn process_wireguard_rotation_interval_set(matches: &clap::ArgMatches<'_>) -> Result<()> {
let rotate_interval =
value_t!(matches.value_of("interval"), u32).unwrap_or_else(|e| e.exit());
let mut rpc = new_rpc_client()?;
- rpc.set_wireguard_automatic_rotation(Some(rotate_interval))?;
- println!("Wireguard automatic key rotation has been updated");
+ rpc.set_wireguard_rotation_interval(Some(rotate_interval))?;
+ println!("Set key rotation interval: {} hour(s)", rotate_interval);
Ok(())
}
- fn process_wireguard_automatic_rotation_unset() -> Result<()> {
+ fn process_wireguard_rotation_interval_reset() -> Result<()> {
let mut rpc = new_rpc_client()?;
- rpc.set_wireguard_automatic_rotation(None)?;
- println!("Wireguard automatic key rotation has been unset");
+ rpc.set_wireguard_rotation_interval(None)?;
+ println!("Set key rotation interval: default");
Ok(())
}
diff --git a/mullvad-daemon/src/lib.rs b/mullvad-daemon/src/lib.rs
index c05e668a2a..4d01e802f5 100644
--- a/mullvad-daemon/src/lib.rs
+++ b/mullvad-daemon/src/lib.rs
@@ -836,8 +836,8 @@ where
SetBridgeState(tx, bridge_state) => self.on_set_bridge_state(tx, bridge_state),
SetEnableIpv6(tx, enable_ipv6) => self.on_set_enable_ipv6(tx, enable_ipv6),
SetWireguardMtu(tx, mtu) => self.on_set_wireguard_mtu(tx, mtu),
- SetWireguardAutomaticRotation(tx, interval) => {
- self.on_set_wireguard_automatic_rotation(tx, interval)
+ SetWireguardRotationInterval(tx, interval) => {
+ self.on_set_wireguard_rotation_interval(tx, interval)
}
GetSettings(tx) => self.on_get_settings(tx),
GenerateWireguardKey(tx) => self.on_generate_wireguard_key(tx),
@@ -1369,15 +1369,15 @@ where
}
}
- fn on_set_wireguard_automatic_rotation(
+ fn on_set_wireguard_rotation_interval(
&mut self,
tx: oneshot::Sender<()>,
interval: Option<u32>,
) {
- let save_result = self.settings.set_wireguard_automatic_rotation(interval);
+ let save_result = self.settings.set_wireguard_rotation_interval(interval);
match save_result {
Ok(settings_changed) => {
- Self::oneshot_send(tx, (), "set_wireguard_automatic_rotation response");
+ Self::oneshot_send(tx, (), "set_wireguard_rotation_interval response");
if settings_changed {
let account_token = self.settings.get_account_token();
diff --git a/mullvad-daemon/src/management_interface.rs b/mullvad-daemon/src/management_interface.rs
index feb1adb8e3..0e4547b42d 100644
--- a/mullvad-daemon/src/management_interface.rs
+++ b/mullvad-daemon/src/management_interface.rs
@@ -143,8 +143,8 @@ build_rpc_trait! {
fn set_wireguard_mtu(&self, Self::Metadata, Option<u16>) -> BoxFuture<(), Error>;
/// Set automatic key rotation interval for wireguard tunnels
- #[rpc(meta, name = "set_wireguard_automatic_rotation")]
- fn set_wireguard_automatic_rotation(&self, Self::Metadata, Option<u32>) -> BoxFuture<(), Error>;
+ #[rpc(meta, name = "set_wireguard_rotation_interval")]
+ fn set_wireguard_rotation_interval(&self, Self::Metadata, Option<u32>) -> BoxFuture<(), Error>;
/// Returns the current daemon settings
#[rpc(meta, name = "get_settings")]
@@ -244,7 +244,7 @@ pub enum ManagementCommand {
/// Set MTU for wireguard tunnels
SetWireguardMtu(OneshotSender<()>, Option<u16>),
/// Set automatic key rotation interval for wireguard tunnels
- SetWireguardAutomaticRotation(OneshotSender<()>, Option<u32>),
+ SetWireguardRotationInterval(OneshotSender<()>, Option<u32>),
/// Get the daemon settings
GetSettings(OneshotSender<Settings>),
/// Generate new wireguard key
@@ -702,15 +702,15 @@ impl<T: From<ManagementCommand> + 'static + Send> ManagementInterfaceApi
}
/// Set automatic key rotation interval for wireguard tunnels
- fn set_wireguard_automatic_rotation(
+ fn set_wireguard_rotation_interval(
&self,
_: Self::Metadata,
interval: Option<u32>,
) -> BoxFuture<(), Error> {
- log::debug!("set_wireguard_automatic_rotation({:?})", interval);
+ log::debug!("set_wireguard_rotation_interval({:?})", interval);
let (tx, rx) = sync::oneshot::channel();
let future = self
- .send_command_to_daemon(ManagementCommand::SetWireguardAutomaticRotation(
+ .send_command_to_daemon(ManagementCommand::SetWireguardRotationInterval(
tx, interval,
))
.and_then(|_| rx.map_err(|_| Error::internal_error()));
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs
index 2e08eada83..ed55bc15d7 100644
--- a/mullvad-ipc-client/src/lib.rs
+++ b/mullvad-ipc-client/src/lib.rs
@@ -199,11 +199,8 @@ impl DaemonRpcClient {
self.call("set_wireguard_mtu", &[mtu])
}
- pub fn set_wireguard_automatic_rotation(
- &mut self,
- automatic_rotation: Option<u32>,
- ) -> Result<()> {
- self.call("set_wireguard_automatic_rotation", &[automatic_rotation])
+ pub fn set_wireguard_rotation_interval(&mut self, interval: Option<u32>) -> Result<()> {
+ self.call("set_wireguard_rotation_interval", &[interval])
}
pub fn set_openvpn_mssfix(&mut self, mssfix: Option<u16>) -> Result<()> {
diff --git a/mullvad-types/src/settings/mod.rs b/mullvad-types/src/settings/mod.rs
index 893dbee849..89b0fa2ad7 100644
--- a/mullvad-types/src/settings/mod.rs
+++ b/mullvad-types/src/settings/mod.rs
@@ -284,7 +284,7 @@ impl Settings {
}
}
- pub fn set_wireguard_automatic_rotation(
+ pub fn set_wireguard_rotation_interval(
&mut self,
automatic_rotation: Option<u32>,
) -> Result<bool> {