summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md2
-rw-r--r--mullvad-cli/src/cmds/account.rs4
-rw-r--r--mullvad-cli/src/cmds/connect.rs2
-rw-r--r--mullvad-cli/src/cmds/disconnect.rs2
-rw-r--r--mullvad-cli/src/cmds/lan.rs4
-rw-r--r--mullvad-cli/src/cmds/relay.rs18
-rw-r--r--mullvad-cli/src/cmds/shutdown.rs2
-rw-r--r--mullvad-cli/src/cmds/status.rs2
-rw-r--r--mullvad-cli/src/cmds/tunnel.rs4
-rw-r--r--mullvad-cli/src/cmds/version.rs2
-rw-r--r--mullvad-daemon/src/rpc_uniqueness_check.rs2
-rw-r--r--mullvad-daemon/tests/common/mod.rs2
-rw-r--r--mullvad-ipc-client/src/lib.rs79
-rw-r--r--talpid-ipc/src/client.rs4
-rw-r--r--talpid-ipc/tests/ipc-client-server.rs8
-rw-r--r--talpid-openvpn-plugin/src/lib.rs2
-rw-r--r--talpid-openvpn-plugin/src/processing.rs2
17 files changed, 84 insertions, 57 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ee33f43f71..9f7e5435be 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -56,6 +56,8 @@ Line wrap the file at 100 chars. Th
- Fix OpenVPN warning about usage of AES-256-CBC cipher.
- Fix "Out of time" screen status icon position.
- Fix log newline characters on Windows.
+- Mullvad CLI can now be used with daemon instance that doesn't have the `--disable-rpc-auth`
+ flag set.
## [2018.1] - 2018-03-01
diff --git a/mullvad-cli/src/cmds/account.rs b/mullvad-cli/src/cmds/account.rs
index 65d7d1f904..5ad7822222 100644
--- a/mullvad-cli/src/cmds/account.rs
+++ b/mullvad-cli/src/cmds/account.rs
@@ -50,7 +50,7 @@ impl Command for Account {
impl Account {
fn set(&self, token: Option<AccountToken>) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.set_account(token.clone())?;
if let Some(token) = token {
println!("Mullvad account \"{}\" set", token);
@@ -61,7 +61,7 @@ impl Account {
}
fn get(&self) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let account_token = rpc.get_account()?;
if let Some(account_token) = account_token {
println!("Mullvad account: {}", account_token);
diff --git a/mullvad-cli/src/cmds/connect.rs b/mullvad-cli/src/cmds/connect.rs
index 50308b2b82..b9da45618d 100644
--- a/mullvad-cli/src/cmds/connect.rs
+++ b/mullvad-cli/src/cmds/connect.rs
@@ -17,7 +17,7 @@ impl Command for Connect {
}
fn run(&self, _matches: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.connect()?;
Ok(())
}
diff --git a/mullvad-cli/src/cmds/disconnect.rs b/mullvad-cli/src/cmds/disconnect.rs
index ee1337a10d..70e5699545 100644
--- a/mullvad-cli/src/cmds/disconnect.rs
+++ b/mullvad-cli/src/cmds/disconnect.rs
@@ -17,7 +17,7 @@ impl Command for Disconnect {
}
fn run(&self, _matches: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.disconnect()?;
Ok(())
}
diff --git a/mullvad-cli/src/cmds/lan.rs b/mullvad-cli/src/cmds/lan.rs
index 84830eae87..7f6b3a0444 100644
--- a/mullvad-cli/src/cmds/lan.rs
+++ b/mullvad-cli/src/cmds/lan.rs
@@ -43,14 +43,14 @@ impl Command for Lan {
impl Lan {
fn set(&self, allow_lan: bool) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.set_allow_lan(allow_lan)?;
println!("Changed local network sharing setting");
Ok(())
}
fn get(&self) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let allow_lan = rpc.get_allow_lan()?;
println!(
"Local network sharing setting: {}",
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 0df0e46b4f..27aaf3d6b4 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -3,12 +3,14 @@ use std::str::FromStr;
use {Command, Result, ResultExt};
use mullvad_ipc_client::DaemonRpcClient;
-use mullvad_types::relay_constraints::{Constraint, LocationConstraint, OpenVpnConstraints,
- RelayConstraintsUpdate, RelaySettingsUpdate,
- TunnelConstraints};
+use mullvad_types::relay_constraints::{
+ Constraint, LocationConstraint, OpenVpnConstraints, RelayConstraintsUpdate,
+ RelaySettingsUpdate, TunnelConstraints,
+};
use mullvad_types::CustomTunnelEndpoint;
-use talpid_types::net::{OpenVpnEndpointData, TransportProtocol, TunnelEndpointData,
- WireguardEndpointData};
+use talpid_types::net::{
+ OpenVpnEndpointData, TransportProtocol, TunnelEndpointData, WireguardEndpointData,
+};
pub struct Relay;
@@ -113,7 +115,7 @@ impl Command for Relay {
impl Relay {
fn update_constraints(&self, update: RelaySettingsUpdate) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.update_relay_settings(update)?;
println!("Relay constraints updated");
Ok(())
@@ -183,7 +185,7 @@ impl Relay {
}
fn get(&self) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let constraints = rpc.get_relay_settings()?;
println!("Current constraints: {:#?}", constraints);
@@ -191,7 +193,7 @@ impl Relay {
}
fn list(&self, _matches: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let mut locations = rpc.get_relay_locations()?;
locations.countries.sort_by(|c1, c2| c1.name.cmp(&c2.name));
for mut country in locations.countries {
diff --git a/mullvad-cli/src/cmds/shutdown.rs b/mullvad-cli/src/cmds/shutdown.rs
index 43bc3342fd..f56ba0a972 100644
--- a/mullvad-cli/src/cmds/shutdown.rs
+++ b/mullvad-cli/src/cmds/shutdown.rs
@@ -15,7 +15,7 @@ impl Command for Shutdown {
}
fn run(&self, _matches: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.shutdown()?;
Ok(())
}
diff --git a/mullvad-cli/src/cmds/status.rs b/mullvad-cli/src/cmds/status.rs
index a869fd5eb6..f6a41f8813 100644
--- a/mullvad-cli/src/cmds/status.rs
+++ b/mullvad-cli/src/cmds/status.rs
@@ -17,7 +17,7 @@ impl Command for Status {
}
fn run(&self, _matches: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let state = rpc.get_state()?;
print!("Tunnel status: ");
match (state.state, state.target_state) {
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs
index c83d6e0b98..b06b7df3ee 100644
--- a/mullvad-cli/src/cmds/tunnel.rs
+++ b/mullvad-cli/src/cmds/tunnel.rs
@@ -71,7 +71,7 @@ impl Tunnel {
Some(mssfix_str.parse()?)
};
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
rpc.set_openvpn_mssfix(mssfix)?;
println!("mssfix parameter updated");
Ok(())
@@ -81,7 +81,7 @@ impl Tunnel {
}
fn get_tunnel_options() -> Result<TunnelOptions> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
Ok(rpc.get_tunnel_options()?)
}
diff --git a/mullvad-cli/src/cmds/version.rs b/mullvad-cli/src/cmds/version.rs
index 468dc35ee9..c3adca3040 100644
--- a/mullvad-cli/src/cmds/version.rs
+++ b/mullvad-cli/src/cmds/version.rs
@@ -16,7 +16,7 @@ impl Command for Version {
}
fn run(&self, _: &clap::ArgMatches) -> Result<()> {
- let rpc = DaemonRpcClient::new()?;
+ let mut rpc = DaemonRpcClient::new()?;
let current_version = rpc.get_current_version()?;
println!("Current version: {}", current_version);
let version_info = rpc.get_version_info()?;
diff --git a/mullvad-daemon/src/rpc_uniqueness_check.rs b/mullvad-daemon/src/rpc_uniqueness_check.rs
index fd889cdddf..96f1e9c15c 100644
--- a/mullvad-daemon/src/rpc_uniqueness_check.rs
+++ b/mullvad-daemon/src/rpc_uniqueness_check.rs
@@ -9,7 +9,7 @@ use mullvad_ipc_client::DaemonRpcClient;
/// other daemon has stopped.
pub fn is_another_instance_running() -> bool {
match DaemonRpcClient::new() {
- Ok(client) => match client.get_state() {
+ Ok(mut client) => match client.get_state() {
Ok(_) => true,
Err(error) => {
let chained_error = error.chain_err(|| {
diff --git a/mullvad-daemon/tests/common/mod.rs b/mullvad-daemon/tests/common/mod.rs
index 84bd84a3ed..5356f4ee1e 100644
--- a/mullvad-daemon/tests/common/mod.rs
+++ b/mullvad-daemon/tests/common/mod.rs
@@ -99,7 +99,7 @@ impl DaemonRunner {
fn request_clean_shutdown(&mut self, _: &mut duct::Handle) -> bool {
use self::mullvad_ipc_client::DaemonRpcClient;
- if let Ok(rpc_client) = DaemonRpcClient::new() {
+ if let Ok(mut rpc_client) = DaemonRpcClient::new() {
rpc_client.shutdown().is_ok()
} else {
false
diff --git a/mullvad-ipc-client/src/lib.rs b/mullvad-ipc-client/src/lib.rs
index 90c14de5d6..0105176fb6 100644
--- a/mullvad-ipc-client/src/lib.rs
+++ b/mullvad-ipc-client/src/lib.rs
@@ -24,6 +24,10 @@ pub use platform_specific::rpc_file_path;
error_chain! {
errors {
+ AuthenticationError {
+ description("Failed to authenticate the connection with the daemon")
+ }
+
EmptyRpcFile(file_path: String) {
description("RPC connection file is empty")
display("RPC connection file \"{}\" is empty", file_path)
@@ -40,6 +44,11 @@ error_chain! {
)
}
+ MissingRpcCredentials(file_path: String) {
+ description("no credentials found in RPC connection file")
+ display("no credentials found in RPC connection file {}", file_path)
+ }
+
ReadRpcFileError(file_path: String) {
description("Failed to read RPC connection information")
display("Failed to read RPC connection information from {}", file_path)
@@ -64,17 +73,24 @@ error_chain! {
static NO_ARGS: [u8; 0] = [];
pub struct DaemonRpcClient {
- address: String,
+ rpc_client: WsIpcClient,
}
impl DaemonRpcClient {
pub fn new() -> Result<Self> {
- let address = Self::read_rpc_file()?;
+ let (address, credentials) = Self::read_rpc_file()?;
+ let rpc_client =
+ WsIpcClient::connect(&address).chain_err(|| ErrorKind::StartRpcClient(address))?;
+ let mut instance = DaemonRpcClient { rpc_client };
+
+ instance
+ .auth(&credentials)
+ .chain_err(|| ErrorKind::AuthenticationError)?;
- Ok(DaemonRpcClient { address })
+ Ok(instance)
}
- fn read_rpc_file() -> Result<String> {
+ fn read_rpc_file() -> Result<(String, String)> {
let file_path = rpc_file_path()?;
let file_path_string = || file_path.display().to_string();
let rpc_file =
@@ -89,89 +105,96 @@ impl DaemonRpcClient {
let reader = BufReader::new(rpc_file);
let mut lines = reader.lines();
- lines
+ let address = lines
.next()
.ok_or_else(|| ErrorKind::EmptyRpcFile(file_path_string()))?
- .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string()))
+ .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string()))?;
+ let credentials = lines
+ .next()
+ .ok_or_else(|| ErrorKind::MissingRpcCredentials(file_path_string()))?
+ .chain_err(|| ErrorKind::ReadRpcFileError(file_path_string()))?;
+
+ Ok((address, credentials))
}
- pub fn connect(&self) -> Result<()> {
+ pub fn auth(&mut self, credentials: &str) -> Result<()> {
+ self.call("auth", &[credentials])
+ }
+
+ pub fn connect(&mut self) -> Result<()> {
self.call("connect", &NO_ARGS)
}
- pub fn disconnect(&self) -> Result<()> {
+ pub fn disconnect(&mut self) -> Result<()> {
self.call("disconnect", &NO_ARGS)
}
- pub fn get_account(&self) -> Result<Option<AccountToken>> {
+ pub fn get_account(&mut self) -> Result<Option<AccountToken>> {
self.call("get_account", &NO_ARGS)
}
- pub fn get_account_data(&self, account: AccountToken) -> Result<AccountData> {
+ pub fn get_account_data(&mut self, account: AccountToken) -> Result<AccountData> {
self.call("get_account_data", &[account])
}
- pub fn get_allow_lan(&self) -> Result<bool> {
+ pub fn get_allow_lan(&mut self) -> Result<bool> {
self.call("get_allow_lan", &NO_ARGS)
}
- pub fn get_current_location(&self) -> Result<GeoIpLocation> {
+ pub fn get_current_location(&mut self) -> Result<GeoIpLocation> {
self.call("get_current_location", &NO_ARGS)
}
- pub fn get_current_version(&self) -> Result<String> {
+ pub fn get_current_version(&mut self) -> Result<String> {
self.call("get_current_version", &NO_ARGS)
}
- pub fn get_relay_locations(&self) -> Result<RelayList> {
+ pub fn get_relay_locations(&mut self) -> Result<RelayList> {
self.call("get_relay_locations", &NO_ARGS)
}
- pub fn get_relay_settings(&self) -> Result<RelaySettings> {
+ pub fn get_relay_settings(&mut self) -> Result<RelaySettings> {
self.call("get_relay_settings", &NO_ARGS)
}
- pub fn get_state(&self) -> Result<DaemonState> {
+ pub fn get_state(&mut self) -> Result<DaemonState> {
self.call("get_state", &NO_ARGS)
}
- pub fn get_tunnel_options(&self) -> Result<TunnelOptions> {
+ pub fn get_tunnel_options(&mut self) -> Result<TunnelOptions> {
self.call("get_tunnel_options", &NO_ARGS)
}
- pub fn get_version_info(&self) -> Result<AppVersionInfo> {
+ pub fn get_version_info(&mut self) -> Result<AppVersionInfo> {
self.call("get_version_info", &NO_ARGS)
}
- pub fn set_account(&self, account: Option<AccountToken>) -> Result<()> {
+ pub fn set_account(&mut self, account: Option<AccountToken>) -> Result<()> {
self.call("set_account", &[account])
}
- pub fn set_allow_lan(&self, allow_lan: bool) -> Result<()> {
+ pub fn set_allow_lan(&mut self, allow_lan: bool) -> Result<()> {
self.call("set_allow_lan", &[allow_lan])
}
- pub fn set_openvpn_mssfix(&self, mssfix: Option<u16>) -> Result<()> {
+ pub fn set_openvpn_mssfix(&mut self, mssfix: Option<u16>) -> Result<()> {
self.call("set_openvpn_mssfix", &[mssfix])
}
- pub fn shutdown(&self) -> Result<()> {
+ pub fn shutdown(&mut self) -> Result<()> {
self.call("shutdown", &NO_ARGS)
}
- pub fn update_relay_settings(&self, update: RelaySettingsUpdate) -> Result<()> {
+ pub fn update_relay_settings(&mut self, update: RelaySettingsUpdate) -> Result<()> {
self.call("update_relay_settings", &[update])
}
- pub fn call<A, O>(&self, method: &str, args: &A) -> Result<O>
+ pub fn call<A, O>(&mut self, method: &str, args: &A) -> Result<O>
where
A: Serialize,
O: for<'de> Deserialize<'de>,
{
- let mut rpc_client = WsIpcClient::connect(self.address.clone())
- .chain_err(|| ErrorKind::StartRpcClient(self.address.clone()))?;
-
- rpc_client
+ self.rpc_client
.call(method, args)
.chain_err(|| ErrorKind::RpcCallError(method.to_owned()))
}
diff --git a/talpid-ipc/src/client.rs b/talpid-ipc/src/client.rs
index 19f981d379..9e76bfe443 100644
--- a/talpid-ipc/src/client.rs
+++ b/talpid-ipc/src/client.rs
@@ -180,8 +180,8 @@ pub struct WsIpcClient {
}
impl WsIpcClient {
- pub fn connect(server_id: ::IpcServerId) -> Result<Self> {
- let url = url::Url::parse(&server_id).chain_err(|| "Unable to parse server_id as url")?;
+ pub fn connect(server_id: &::IpcServerId) -> Result<Self> {
+ let url = url::Url::parse(server_id).chain_err(|| "Unable to parse server_id as url")?;
let active_request = Arc::new(Mutex::new(None));
let sender = Self::open_websocket(url, active_request.clone())?;
diff --git a/talpid-ipc/tests/ipc-client-server.rs b/talpid-ipc/tests/ipc-client-server.rs
index 150c950b96..34b44beb68 100644
--- a/talpid-ipc/tests/ipc-client-server.rs
+++ b/talpid-ipc/tests/ipc-client-server.rs
@@ -36,7 +36,7 @@ fn can_call_rpcs_on_server() {
let (server, rx) = create_server();
let server_id = server.address().to_owned();
- let mut client = create_client(server_id);
+ let mut client = create_client(&server_id);
let _result: () = client.call("foo", &[97]).unwrap();
assert_eq!(Ok(97), rx.recv_timeout(Duration::from_millis(500)));
@@ -51,12 +51,12 @@ fn can_call_rpcs_on_server() {
#[test]
#[should_panic]
fn ipc_client_invalid_url() {
- create_client("INVALID ID".to_owned());
+ create_client(&"INVALID ID".to_owned());
}
#[test]
fn ipc_client_bad_connection() {
- let mut client = create_client("ws://127.0.0.1:9876".to_owned());
+ let mut client = create_client(&"ws://127.0.0.1:9876".to_owned());
let result: Result<(), _> = client.call("invalid_method", &[0]);
assert_matches!(result, Err(_));
}
@@ -71,6 +71,6 @@ fn create_server() -> (talpid_ipc::IpcServer, mpsc::Receiver<i64>) {
(server, rx)
}
-fn create_client(id: talpid_ipc::IpcServerId) -> talpid_ipc::WsIpcClient {
+fn create_client(id: &talpid_ipc::IpcServerId) -> talpid_ipc::WsIpcClient {
talpid_ipc::WsIpcClient::connect(id).unwrap()
}
diff --git a/talpid-openvpn-plugin/src/lib.rs b/talpid-openvpn-plugin/src/lib.rs
index f1c210b4d1..71c332a212 100644
--- a/talpid-openvpn-plugin/src/lib.rs
+++ b/talpid-openvpn-plugin/src/lib.rs
@@ -66,7 +66,7 @@ fn openvpn_open(
let core_server_id = parse_args(&args)?;
info!("Connecting back to talpid core at {}", core_server_id);
- let processor = EventProcessor::new(core_server_id).chain_err(|| ErrorKind::InitHandleFailed)?;
+ let processor = EventProcessor::new(&core_server_id).chain_err(|| ErrorKind::InitHandleFailed)?;
Ok((INTERESTING_EVENTS.to_vec(), processor))
}
diff --git a/talpid-openvpn-plugin/src/processing.rs b/talpid-openvpn-plugin/src/processing.rs
index 5fc2a1312e..a376665888 100644
--- a/talpid-openvpn-plugin/src/processing.rs
+++ b/talpid-openvpn-plugin/src/processing.rs
@@ -18,7 +18,7 @@ pub struct EventProcessor {
}
impl EventProcessor {
- pub fn new(server_id: IpcServerId) -> Result<EventProcessor> {
+ pub fn new(server_id: &IpcServerId) -> Result<EventProcessor> {
trace!("Creating EventProcessor");
let ipc_client =
WsIpcClient::connect(server_id).chain_err(|| "Unable to create IPC client")?;