summaryrefslogtreecommitdiff
path: root/src/leap/bitmask/vpn/process.py
diff options
context:
space:
mode:
authorKali Kaneko (leap communications) <kali@leap.se>2017-06-01 02:28:48 +0200
committerKali Kaneko (leap communications) <kali@leap.se>2017-06-01 02:42:17 +0200
commitd82a57fdcf44a78127733b8db4cc434363ef607f (patch)
tree9b8eef75113e90dccfb323b05a68b43e0db1ba2c /src/leap/bitmask/vpn/process.py
parent5388eb01e016a7d109dc53c464df94b412300e0c (diff)
[feat] darwin helper command
Diffstat (limited to 'src/leap/bitmask/vpn/process.py')
-rw-r--r--src/leap/bitmask/vpn/process.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/leap/bitmask/vpn/process.py b/src/leap/bitmask/vpn/process.py
index e136e5b..429b7b7 100644
--- a/src/leap/bitmask/vpn/process.py
+++ b/src/leap/bitmask/vpn/process.py
@@ -32,6 +32,8 @@ from leap.bitmask.vpn.utils import get_vpn_launcher
from leap.bitmask.vpn import _status
from leap.bitmask.vpn import _management
+from leap.bitmask.vpn.launchers import darwin
+
# OpenVPN verbosity level - from flags.py
OPENVPN_VERBOSITY = 1
@@ -229,3 +231,43 @@ class VPNProcess(protocol.ProcessProtocol, _management.VPNManagement):
self.transport.signalProcess('KILL')
except internet_error.ProcessExitedAlready:
self.log.debug('Process Exited Already')
+
+
+class VPNCanary(VPNProcess):
+
+ """
+ Special form of the VPNProcess, for Darwin Launcher (windows might use same
+ strategy).
+
+ This is a Canary Process that does not run openvpn itself, but it's
+ notified by the privileged process when the process dies.
+
+ This is a workaround to allow the state machine to be notified when openvpn
+ process is spawned by the privileged helper.
+ """
+ def setupHelper(self):
+ self.helper = darwin.HelperCommand()
+
+ def connectionMade(self):
+ VPNProcess.connectionMade(self)
+ reactor.callLater(2, self.registerPID)
+
+ def registerPID(self):
+ cmd = 'openvpn_set_watcher %s' % self.pid
+ self.helper.send(cmd)
+
+ def killProcess(self):
+ cmd = 'openvpn_force_stop'
+ self.helper.send(cmd)
+
+ def getVPNCommand(self):
+ return VPNProcess.getCommand(self)
+
+ def getCommand(self):
+ canary = '''import sys, signal, time
+def receive_signal(signum, stack):
+ sys.exit()
+signal.signal(signal.SIGTERM, receive_signal)
+while True:
+ time.sleep(60)'''
+ return ['python', '-c', '%s' % canary]