summaryrefslogtreecommitdiff
path: root/src/leap/eip
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/eip')
-rw-r--r--src/leap/eip/conductor.py21
-rw-r--r--src/leap/eip/config.py56
2 files changed, 73 insertions, 4 deletions
diff --git a/src/leap/eip/conductor.py b/src/leap/eip/conductor.py
index 243f1fde..3f40f068 100644
--- a/src/leap/eip/conductor.py
+++ b/src/leap/eip/conductor.py
@@ -5,15 +5,16 @@ from __future__ import (division, unicode_literals, print_function)
#import threading
from functools import partial
import logging
-import os
from leap.util.coroutines import spawn_and_watch_process
-
+# XXX import eip.config as eipconfig
from leap.eip.config import (get_config, build_ovpn_command,
check_or_create_default_vpnconf,
+ check_vpn_keys,
EIPNoPkexecAvailable,
- EIPNoPolkitAuthAgentAvailable)
+ EIPNoPolkitAuthAgentAvailable,
+ EIPInitBadKeyFilePermError)
from leap.eip.vpnwatcher import EIPConnectionStatus, status_watcher
from leap.eip.vpnmanager import OpenVPNManager, ConnectionRefusedError
@@ -21,6 +22,7 @@ logger = logging.getLogger(name=__name__)
# TODO Move exceptions to their own module
+# eip.exceptions
class EIPNoCommandError(Exception):
pass
@@ -98,11 +100,14 @@ to be triggered for each one of them.
self.missing_pkexec = False
self.missing_auth_agent = False
+ self.bad_keyfile_perms = False
+
self.command = None
self.args = None
self.autostart = True
self._get_or_create_config()
+ self._check_vpn_keys()
def _set_autostart(self):
config = self.config
@@ -170,6 +175,16 @@ to be triggered for each one of them.
self._set_ovpn_command()
self._check_ovpn_config()
+ def _check_vpn_keys(self):
+ """
+ checks for correct permissions on vpn keys
+ """
+ try:
+ check_vpn_keys(self.config)
+ except EIPInitBadKeyFilePermError:
+ logger.error('error while checking vpn keys')
+ self.bad_keyfile_perms = True
+
def _launch_openvpn(self):
"""
invocation of openvpn binaries in a subprocess.
diff --git a/src/leap/eip/config.py b/src/leap/eip/config.py
index 9af6f57a..91c3953b 100644
--- a/src/leap/eip/config.py
+++ b/src/leap/eip/config.py
@@ -4,13 +4,17 @@ import logging
import os
import platform
-from leap.util.fileutil import which, mkdir_p
+from leap.util.fileutil import (which, mkdir_p,
+ check_and_fix_urw_only)
from leap.baseapp.permcheck import (is_pkexec_in_system,
is_auth_agent_running)
logger = logging.getLogger(name=__name__)
logger.setLevel('DEBUG')
+# XXX move exceptions to
+# from leap.eip import exceptions as eip_exceptions
+
class EIPNoPkexecAvailable(Exception):
pass
@@ -20,6 +24,14 @@ class EIPNoPolkitAuthAgentAvailable(Exception):
pass
+class EIPInitNoKeyFileError(Exception):
+ pass
+
+
+class EIPInitBadKeyFilePermError(Exception):
+ pass
+
+
OPENVPN_CONFIG_TEMPLATE = """#Autogenerated by eip-client wizard
remote {VPN_REMOTE_HOST} {VPN_REMOTE_PORT}
@@ -345,3 +357,45 @@ def get_config(config_file=None):
config.readfp(config_file)
return config
+
+
+def check_vpn_keys(config):
+ """
+ performs an existance and permission check
+ over the openvpn keys file.
+ Currently we're expecting a single file
+ per provider, containing the CA cert,
+ the provider key, and our client certificate
+ """
+
+ keyopt = ('provider', 'keyfile')
+
+ # XXX at some point,
+ # should separate between CA, provider cert
+ # and our certificate.
+ # make changes in the default provider template
+ # accordingly.
+
+ # get vpn keys
+ if config.has_option(*keyopt):
+ keyfile = config.get(*keyopt)
+ else:
+ keyfile = get_config_file(
+ 'openvpn.keys',
+ folder=get_default_provider_path())
+ logger.debug('keyfile = %s', keyfile)
+
+ # if no keys, raise error.
+ # should be catched by the ui and signal user.
+
+ if not os.path.isfile(keyfile):
+ logger.error('key file %s not found. aborting.',
+ keyfile)
+ raise EIPInitNoKeyFileError
+
+ # check proper permission on keys
+ # bad perms? try to fix them
+ try:
+ check_and_fix_urw_only(keyfile)
+ except OSError:
+ raise EIPInitBadKeyFilePermError