summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorLinus Färnstrand <linus@mullvad.net>2017-07-06 22:36:20 +0200
committerLinus Färnstrand <linus@mullvad.net>2017-07-06 22:36:20 +0200
commit82a5ddf1bd3e697ae165af991ea0a3e2476f7bc8 (patch)
tree33aafd509f1ada9c3a458028e519983a7bac42db
parent87e32c106b5dbe285b340dfc334ca1b64cd5f8c0 (diff)
parent6e221e8b7a8778faaf735d5dc2012875e2b7d41f (diff)
downloadmullvadvpn-82a5ddf1bd3e697ae165af991ea0a3e2476f7bc8.tar.xz
mullvadvpn-82a5ddf1bd3e697ae165af991ea0a3e2476f7bc8.zip
Merge branch 'add-ca-directive-to-openvpn'
-rw-r--r--talpid_core/src/process/openvpn.rs13
-rw-r--r--talpid_core/src/tunnel/mod.rs10
2 files changed, 20 insertions, 3 deletions
diff --git a/talpid_core/src/process/openvpn.rs b/talpid_core/src/process/openvpn.rs
index 09e845b640..ea66ef894c 100644
--- a/talpid_core/src/process/openvpn.rs
+++ b/talpid_core/src/process/openvpn.rs
@@ -36,6 +36,7 @@ pub struct OpenVpnCommand {
config: Option<PathBuf>,
remote: Option<net::Endpoint>,
user_pass_path: Option<PathBuf>,
+ ca: Option<PathBuf>,
plugin: Option<(PathBuf, Vec<String>)>,
}
@@ -48,6 +49,7 @@ impl OpenVpnCommand {
config: None,
remote: None,
user_pass_path: None,
+ ca: None,
plugin: None,
}
}
@@ -71,6 +73,12 @@ impl OpenVpnCommand {
self
}
+ /// Sets the path to the CA certificate file.
+ pub fn ca<P: AsRef<Path>>(&mut self, path: P) -> &mut Self {
+ self.ca = Some(path.as_ref().to_path_buf());
+ self
+ }
+
/// Sets a plugin and its arguments that OpenVPN will be started with.
pub fn plugin<P: AsRef<Path>>(&mut self, path: P, args: Vec<String>) -> &mut Self {
self.plugin = Some((path.as_ref().to_path_buf(), args));
@@ -95,6 +103,11 @@ impl OpenVpnCommand {
args.extend(self.remote_arguments().iter().map(OsString::from));
args.extend(self.authentication_arguments());
+ if let Some(ref ca) = self.ca {
+ args.push(OsString::from("--ca"));
+ args.push(OsString::from(ca.as_os_str()));
+ }
+
if let Some((ref path, ref plugin_args)) = self.plugin {
args.push(OsString::from("--plugin"));
args.push(OsString::from(path));
diff --git a/talpid_core/src/tunnel/mod.rs b/talpid_core/src/tunnel/mod.rs
index a3cf019da7..b05f1283f3 100644
--- a/talpid_core/src/tunnel/mod.rs
+++ b/talpid_core/src/tunnel/mod.rs
@@ -85,7 +85,10 @@ impl TunnelMonitor {
fn create_openvpn_cmd(remote: net::Endpoint, user_pass_file: &Path) -> OpenVpnCommand {
let mut cmd = OpenVpnCommand::new("openvpn");
- cmd.config(get_config_path()).remote(remote).user_pass(user_pass_file);
+ if let Some(config) = get_config_path() {
+ cmd.config(config);
+ }
+ cmd.remote(remote).user_pass(user_pass_file).ca("ca.crt");
cmd
}
@@ -162,6 +165,7 @@ fn get_plugin_path() -> Result<PathBuf> {
// TODO(linus): Temporary implementation for getting hold of a config location.
// Manually place a working config here or change this string in order to test
-fn get_config_path() -> &'static str {
- "./openvpn.conf"
+fn get_config_path() -> Option<&'static Path> {
+ let path = Path::new("./openvpn.conf");
+ if path.exists() { Some(path) } else { None }
}