summaryrefslogtreecommitdiff
path: root/src/leap
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap')
-rw-r--r--src/leap/config/prefixers.py22
-rw-r--r--src/leap/gui/wizard.py4
-rw-r--r--src/leap/services/eip/vpn.py11
-rw-r--r--src/leap/services/eip/vpnlaunchers.py118
4 files changed, 153 insertions, 2 deletions
diff --git a/src/leap/config/prefixers.py b/src/leap/config/prefixers.py
index 557a77ac..5a9b2112 100644
--- a/src/leap/config/prefixers.py
+++ b/src/leap/config/prefixers.py
@@ -77,6 +77,28 @@ class LinuxPrefixer(Prefixer):
return os.path.join(os.getcwd(), "config")
+class DarwinPrefixer(Prefixer):
+ """
+ Config prefixer for the Darwin platform
+ """
+
+ def get_path_prefix(self, standalone=False):
+ """
+ Returns the platform dependant path prefixer.
+ This method expects an env variable named LEAP_CLIENT_PATH if
+ standalone is used.
+
+ @param standalone: if True it will return the prefix for a
+ standalone application. Otherwise, it will return the system
+ default for configuration storage.
+ @type standalone: bool
+ """
+ config_dir = BaseDirectory.xdg_config_home
+ if not standalone:
+ return config_dir
+ return os.getenv("LEAP_CLIENT_PATH", config_dir)
+
+
if __name__ == "__main__":
try:
abs_prefixer = Prefixer()
diff --git a/src/leap/gui/wizard.py b/src/leap/gui/wizard.py
index 4e811fb9..dee3b230 100644
--- a/src/leap/gui/wizard.py
+++ b/src/leap/gui/wizard.py
@@ -435,10 +435,10 @@ class Wizard(QtGui.QWizard):
"""
if state == QtCore.Qt.Checked:
self._selected_services = \
- self._selected_services.union({service})
+ self._selected_services.union(set([service]))
else:
self._selected_services = \
- self._selected_services.difference({service})
+ self._selected_services.difference(set([service]))
def _populate_services(self):
"""
diff --git a/src/leap/services/eip/vpn.py b/src/leap/services/eip/vpn.py
index 4ac7f8a2..9d838609 100644
--- a/src/leap/services/eip/vpn.py
+++ b/src/leap/services/eip/vpn.py
@@ -166,6 +166,7 @@ class VPN(QtCore.QThread):
self._subp.setProcessEnvironment(env)
self._subp.finished.connect(self.process_finished)
+ self._subp.finished.connect(self._dump_exitinfo)
self._subp.start(command[:1][0], command[1:])
logger.debug("Waiting for started...")
self._subp.waitForStarted()
@@ -181,6 +182,16 @@ class VPN(QtCore.QThread):
logger.warning("Something went wrong while starting OpenVPN: %r" %
(e,))
+ def _dump_exitinfo(self):
+ """
+ SLOT
+ TRIGGER: self._subp.finished
+
+ Prints debug info when quitting the process
+ """
+ logger.debug("stdout: %s", self._subp.readAllStandardOutput())
+ logger.debug("stderr: %s", self._subp.readAllStandardError())
+
def _get_openvpn_process(self):
"""
Looks for openvpn instances running
diff --git a/src/leap/services/eip/vpnlaunchers.py b/src/leap/services/eip/vpnlaunchers.py
index e6502813..78db0176 100644
--- a/src/leap/services/eip/vpnlaunchers.py
+++ b/src/leap/services/eip/vpnlaunchers.py
@@ -214,6 +214,8 @@ class LinuxVPNLauncher(VPNLauncher):
]
openvpn_configuration = eipconfig.get_openvpn_configuration()
+
+ # FIXME: sanitize this! --
for key, value in openvpn_configuration.items():
args += ['--%s' % (key,), value]
@@ -270,6 +272,122 @@ class LinuxVPNLauncher(VPNLauncher):
providerconfig.get_path_prefix(),
"..", "lib")}
+class DarwinVPNLauncher(VPNLauncher):
+ """
+ VPN launcher for the Darwin Platform
+ """
+
+ OSASCRIPT_BIN = '/usr/bin/osascript'
+ OSX_ASADMIN = "do shell script \"%s\" with administrator privileges"
+ OPENVPN_BIN = 'openvpn.leap'
+ INSTALL_PATH = "/Applications/LEAPClient.app/"
+ # OPENVPN_BIN = "/%s/Contents/Resources/openvpn.leap" % (
+ # self.INSTALL_PATH,)
+ UP_SCRIPT = "/%s/client.up.sh" % (INSTALL_PATH,)
+ DOWN_SCRIPT = "/%s/client.down.sh" % (INSTALL_PATH,)
+
+ # TODO: Add
+ # OPENVPN_DOWN_ROOT = "/usr/lib/openvpn/openvpn-down-root.so"
+
+ def get_vpn_command(self, eipconfig=None, providerconfig=None,
+ socket_host=None, socket_port="unix"):
+ """
+ Returns the platform dependant vpn launching command
+
+ Might raise VPNException.
+
+ @param eipconfig: eip configuration object
+ @type eipconfig: EIPConfig
+ @param providerconfig: provider specific configuration
+ @type providerconfig: ProviderConfig
+ @param socket_host: either socket path (unix) or socket IP
+ @type socket_host: str
+ @param socket_port: either string "unix" if it's a unix
+ socket, or port otherwise
+ @type socket_port: str
+
+ @return: A VPN command ready to be launched
+ @rtype: list
+ """
+ leap_assert(eipconfig, "We need an eip config")
+ leap_assert_type(eipconfig, EIPConfig)
+ leap_assert(providerconfig, "We need a provider config")
+ leap_assert_type(providerconfig, ProviderConfig)
+ leap_assert(socket_host, "We need a socket host!")
+ leap_assert(socket_port, "We need a socket port!")
+
+ openvpn_possibilities = which(self.OPENVPN_BIN)
+ if len(openvpn_possibilities) == 0:
+ raise OpenVPNNotFoundException()
+
+ openvpn = openvpn_possibilities[0]
+ args = [openvpn]
+
+ # TODO: handle verbosity
+
+ gateway_ip = str(eipconfig.get_gateway_ip(0))
+ logger.debug("Using gateway ip %s" % (gateway_ip,))
+
+ args += [
+ '--client',
+ '--dev', 'tun',
+ '--persist-tun',
+ '--persist-key',
+ '--remote', gateway_ip, '1194', 'udp',
+ '--tls-client',
+ '--remote-cert-tls',
+ 'server'
+ ]
+
+ # FIXME: sanitize this! --
+
+ openvpn_configuration = eipconfig.get_openvpn_configuration()
+ for key, value in openvpn_configuration.items():
+ args += ['--%s' % (key,), value]
+
+ args += [
+ '--user', getpass.getuser(),
+ '--group', grp.getgrgid(os.getgroups()[-1]).gr_name
+ ]
+
+ if socket_port == "unix":
+ args += [
+ '--management-client-user', getpass.getuser()
+ ]
+
+ args += [
+ '--management-signal',
+ '--management', socket_host, socket_port,
+ '--script-security', '2'
+ ]
+
+ if _has_updown_scripts(self.UP_SCRIPT):
+ args += [
+ '--up', self.UP_SCRIPT,
+ ]
+ if _has_updown_scripts(self.DOWN_SCRIPT):
+ args += [
+ '--down', self.DOWN_SCRIPT,
+ # FIXME add down-plugin
+ # '--plugin', self.OPENVPN_DOWN_ROOT,
+ # '\'script_type=down %s\'' % self.DOWN_SCRIPT
+ ]
+
+ args += [
+ '--cert', eipconfig.get_client_cert_path(providerconfig),
+ '--key', eipconfig.get_client_cert_path(providerconfig),
+ '--ca', providerconfig.get_ca_cert_path()
+ ]
+
+ command = self.OSASCRIPT_BIN
+ cmd_args = ["-e", self.OSX_ASADMIN % (' '.join(args),)]
+
+ logger.debug("Running VPN with command:")
+ logger.debug("%s %s" % (command, " ".join(cmd_args)))
+
+ return [command] + cmd_args
+
+
if __name__ == "__main__":
logger = logging.getLogger(name='leap')
logger.setLevel(logging.DEBUG)