summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2019-12-09 15:49:03 +0100
committerDavid Lönnhager <david.l@mullvad.net>2019-12-17 12:30:15 +0100
commit9e11671235a1dbb3460a58767f286033f2b9634e (patch)
tree4de4445b2a5b10c30e7ca84bf06c9e9ca86ff7b6 /mullvad-cli/src
parent5d3f8dbba974f2b94c4baf617a439961be72de2a (diff)
downloadmullvadvpn-9e11671235a1dbb3460a58767f286033f2b9634e.tar.xz
mullvadvpn-9e11671235a1dbb3460a58767f286033f2b9634e.zip
Add CLI interface for configuring automatic wg key rotation
Diffstat (limited to 'mullvad-cli/src')
-rw-r--r--mullvad-cli/src/cmds/tunnel.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs
index 75119ac87d..24949b95e2 100644
--- a/mullvad-cli/src/cmds/tunnel.rs
+++ b/mullvad-cli/src/cmds/tunnel.rs
@@ -56,6 +56,18 @@ 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())
+}
+
+fn create_wireguard_keys_automatic_rotation_subcommand() -> clap::App<'static, 'static> {
+ clap::SubCommand::with_name("automatic-rotation")
+ .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("set").arg(clap::Arg::with_name("interval").required(true)),
+ )
}
@@ -120,8 +132,15 @@ 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(),
+ ("set", Some(matches)) => Self::process_wireguard_automatic_rotation_set(matches),
+ ("unset", _) => Self::process_wireguard_automatic_rotation_unset(),
+ _ => unreachable!("unhandled command"),
+ },
_ => unreachable!("unhandled command"),
},
+
_ => unreachable!("unhandled command"),
}
}
@@ -184,6 +203,34 @@ impl Tunnel {
Ok(())
}
+ fn process_wireguard_automatic_rotation_get() -> Result<()> {
+ let tunnel_options = Self::get_tunnel_options()?;
+ println!(
+ "Automatic rotation interval (hours): {}",
+ tunnel_options
+ .wireguard
+ .automatic_rotation
+ .map(|interval| interval.to_string())
+ .unwrap_or_else(|| "unset".to_owned())
+ );
+ Ok(())
+ }
+
+ fn process_wireguard_automatic_rotation_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");
+ Ok(())
+ }
+
+ fn process_wireguard_automatic_rotation_unset() -> Result<()> {
+ let mut rpc = new_rpc_client()?;
+ rpc.set_wireguard_automatic_rotation(None)?;
+ println!("Wireguard automatic key rotation has been unset");
+ Ok(())
+ }
+
fn handle_ipv6_cmd(matches: &clap::ArgMatches<'_>) -> Result<()> {
if matches.subcommand_matches("get").is_some() {
Self::process_ipv6_get()