diff options
| -rw-r--r-- | talpid-openvpn-plugin/src/lib.rs | 25 | ||||
| -rw-r--r-- | talpid-openvpn-plugin/src/processing.rs | 21 |
2 files changed, 36 insertions, 10 deletions
diff --git a/talpid-openvpn-plugin/src/lib.rs b/talpid-openvpn-plugin/src/lib.rs index 71c332a212..9c6c690339 100644 --- a/talpid-openvpn-plugin/src/lib.rs +++ b/talpid-openvpn-plugin/src/lib.rs @@ -57,6 +57,11 @@ openvpn_plugin!( ::EventProcessor ); +pub struct Arguments { + server_id: talpid_ipc::IpcServerId, + credentials: String, +} + fn openvpn_open( args: Vec<CString>, _env: HashMap<CString, CString>, @@ -64,22 +69,30 @@ fn openvpn_open( env_logger::init(); debug!("Initializing plugin"); - 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 arguments = parse_args(&args)?; + info!("Connecting back to talpid core at {}", arguments.server_id); + let processor = EventProcessor::new(&arguments).chain_err(|| ErrorKind::InitHandleFailed)?; Ok((INTERESTING_EVENTS.to_vec(), processor)) } -fn parse_args(args: &[CString]) -> Result<talpid_ipc::IpcServerId> { +fn parse_args(args: &[CString]) -> Result<Arguments> { let mut args_iter = openvpn_plugin::ffi::parse::string_array_utf8(args) .chain_err(|| ErrorKind::ParseArgsFailed)? .into_iter(); + let _plugin_path = args_iter.next(); - let core_server_id: talpid_ipc::IpcServerId = args_iter + let server_id: talpid_ipc::IpcServerId = args_iter .next() .ok_or_else(|| ErrorKind::Msg("No core server id given as first argument".to_owned()))?; - Ok(core_server_id) + let credentials = args_iter + .next() + .ok_or_else(|| ErrorKind::Msg("No IPC credentials given as second argument".to_owned()))?; + + Ok(Arguments { + server_id, + credentials, + }) } diff --git a/talpid-openvpn-plugin/src/processing.rs b/talpid-openvpn-plugin/src/processing.rs index a376665888..cadaf80647 100644 --- a/talpid-openvpn-plugin/src/processing.rs +++ b/talpid-openvpn-plugin/src/processing.rs @@ -1,10 +1,15 @@ use openvpn_plugin; use std::collections::HashMap; use std::sync::Mutex; -use talpid_ipc::{IpcServerId, WsIpcClient}; +use talpid_ipc::WsIpcClient; + +use super::Arguments; error_chain! { errors { + AuthDenied { + description("Authentication failed with Talpid Core IPC server") + } IpcSendingError { description("Failed while sending an event over the IPC channel") } @@ -18,10 +23,18 @@ pub struct EventProcessor { } impl EventProcessor { - pub fn new(server_id: &IpcServerId) -> Result<EventProcessor> { + pub fn new(arguments: &Arguments) -> Result<EventProcessor> { trace!("Creating EventProcessor"); - let ipc_client = - WsIpcClient::connect(server_id).chain_err(|| "Unable to create IPC client")?; + let mut ipc_client = + WsIpcClient::connect(&arguments.server_id).chain_err(|| "Unable to create IPC client")?; + + trace!("Authenticating EventProcessor"); + match ipc_client.call("authenticate", &[&arguments.credentials]) { + Ok(true) => trace!("Credentials accepted"), + Ok(false) => bail!(ErrorKind::AuthDenied), + Err(error) => bail!(Error::with_chain(error, ErrorKind::AuthDenied)), + } + Ok(EventProcessor { ipc_client: Mutex::new(ipc_client), }) |
