summaryrefslogtreecommitdiff
path: root/src/leap/services
diff options
context:
space:
mode:
authorKali Kaneko <kali@leap.se>2013-08-09 18:18:00 +0200
committerKali Kaneko <kali@leap.se>2013-08-09 18:18:00 +0200
commite3758f91f58d3a17032860bb17e1643c331c3b0f (patch)
tree7fb9d8e5a675a093443a4224b0fd70c26d437b0c /src/leap/services
parent275109e17f53c2fceb21d6f87626762800f53e22 (diff)
parentb942468aac94be2bf4bb9bc1849391e72c366697 (diff)
Merge remote-tracking branch 'chiiph/feature/relnotes' into develop
Diffstat (limited to 'src/leap/services')
-rw-r--r--src/leap/services/eip/eipconfig.py20
-rw-r--r--src/leap/services/eip/vpnlaunchers.py33
-rw-r--r--src/leap/services/eip/vpnprocess.py27
-rw-r--r--src/leap/services/mail/imap.py42
-rw-r--r--src/leap/services/mail/smtpbootstrapper.py8
-rw-r--r--src/leap/services/mail/smtpconfig.py10
-rw-r--r--src/leap/services/mail/smtpspec.py21
-rw-r--r--src/leap/services/soledad/soledadbootstrapper.py50
-rw-r--r--src/leap/services/soledad/soledadconfig.py10
-rw-r--r--src/leap/services/soledad/soledadspec.py21
-rw-r--r--src/leap/services/tx.py2
11 files changed, 190 insertions, 54 deletions
diff --git a/src/leap/services/eip/eipconfig.py b/src/leap/services/eip/eipconfig.py
index 2f2f6e7c..d69e1fd8 100644
--- a/src/leap/services/eip/eipconfig.py
+++ b/src/leap/services/eip/eipconfig.py
@@ -138,25 +138,13 @@ class EIPConfig(BaseConfig):
BaseConfig.__init__(self)
self._api_version = None
- def _get_spec(self):
+ def _get_schema(self):
"""
- Returns the spec object for the specific configuration
- """
- leap_assert(self._api_version is not None,
- "You should set the API version.")
-
- return get_schema(self._api_version)
+ Returns the schema corresponding to the version given.
- def set_api_version(self, version):
+ :rtype: dict or None if the version is not supported.
"""
- Sets the supported api version.
-
- :param api_version: the version of the api supported by the provider.
- :type api_version: str
- """
- self._api_version = version
- leap_assert(get_schema(self._api_version) is not None,
- "Version %s is not supported." % (version, ))
+ return get_schema(self._api_version)
def get_clusters(self):
# TODO: create an abstraction for clusters
diff --git a/src/leap/services/eip/vpnlaunchers.py b/src/leap/services/eip/vpnlaunchers.py
index 526f1ba4..17950a25 100644
--- a/src/leap/services/eip/vpnlaunchers.py
+++ b/src/leap/services/eip/vpnlaunchers.py
@@ -352,7 +352,7 @@ class LinuxVPNLauncher(VPNLauncher):
return None
def get_vpn_command(self, eipconfig=None, providerconfig=None,
- socket_host=None, socket_port="unix"):
+ socket_host=None, socket_port="unix", openvpn_verb=1):
"""
Returns the platform dependant vpn launching command. It will
look for openvpn in the regular paths and algo in
@@ -375,6 +375,9 @@ class LinuxVPNLauncher(VPNLauncher):
socket, or port otherwise
:type socket_port: str
+ :param openvpn_verb: openvpn verbosity wanted
+ :type openvpn_verb: int
+
:return: A VPN command ready to be launched
:rtype: list
"""
@@ -404,7 +407,8 @@ class LinuxVPNLauncher(VPNLauncher):
args.append(openvpn)
openvpn = first(pkexec)
- # TODO: handle verbosity
+ if openvpn_verb is not None:
+ args += ['--verb', '%d' % (openvpn_verb,)]
gateway_selector = VPNGatewaySelector(eipconfig)
gateways = gateway_selector.get_gateways()
@@ -516,9 +520,9 @@ class DarwinVPNLauncher(VPNLauncher):
COCOASUDO = "cocoasudo"
# XXX need the good old magic translate for these strings
# (look for magic in 0.2.0 release)
- SUDO_MSG = ("LEAP needs administrative privileges to run "
+ SUDO_MSG = ("Bitmask needs administrative privileges to run "
"Encrypted Internet.")
- INSTALL_MSG = ("\"LEAP needs administrative privileges to install "
+ INSTALL_MSG = ("\"Bitmask needs administrative privileges to install "
"missing scripts and fix permissions.\"")
INSTALL_PATH = os.path.realpath(os.getcwd() + "/../../")
@@ -604,7 +608,7 @@ class DarwinVPNLauncher(VPNLauncher):
return self.COCOASUDO, args
def get_vpn_command(self, eipconfig=None, providerconfig=None,
- socket_host=None, socket_port="unix"):
+ socket_host=None, socket_port="unix", openvpn_verb=1):
"""
Returns the platform dependant vpn launching command
@@ -623,6 +627,9 @@ class DarwinVPNLauncher(VPNLauncher):
socket, or port otherwise
:type socket_port: str
+ :param openvpn_verb: openvpn verbosity wanted
+ :type openvpn_verb: int
+
:return: A VPN command ready to be launched
:rtype: list
"""
@@ -651,7 +658,8 @@ class DarwinVPNLauncher(VPNLauncher):
openvpn = first(openvpn_possibilities)
args = [openvpn]
- # TODO: handle verbosity
+ if openvpn_verb is not None:
+ args += ['--verb', '%d' % (openvpn_verb,)]
gateway_selector = VPNGatewaySelector(eipconfig)
gateways = gateway_selector.get_gateways()
@@ -768,9 +776,10 @@ class WindowsVPNLauncher(VPNLauncher):
OPENVPN_BIN = 'openvpn_leap.exe'
# XXX UPDOWN_FILES ... we do not have updown files defined yet!
+ # (and maybe we won't)
def get_vpn_command(self, eipconfig=None, providerconfig=None,
- socket_host=None, socket_port="9876"):
+ socket_host=None, socket_port="9876", openvpn_verb=1):
"""
Returns the platform dependant vpn launching command. It will
look for openvpn in the regular paths and algo in
@@ -780,14 +789,20 @@ class WindowsVPNLauncher(VPNLauncher):
: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
+ :param openvpn_verb: the openvpn verbosity wanted
+ :type openvpn_verb: int
+
:return: A VPN command ready to be launched
:rtype: list
"""
@@ -810,8 +825,8 @@ class WindowsVPNLauncher(VPNLauncher):
openvpn = first(openvpn_possibilities)
args = []
-
- # TODO: handle verbosity
+ if openvpn_verb is not None:
+ args += ['--verb', '%d' % (openvpn_verb,)]
gateway_selector = VPNGatewaySelector(eipconfig)
gateways = gateway_selector.get_gateways()
diff --git a/src/leap/services/eip/vpnprocess.py b/src/leap/services/eip/vpnprocess.py
index c4bdb30c..5b07a3cf 100644
--- a/src/leap/services/eip/vpnprocess.py
+++ b/src/leap/services/eip/vpnprocess.py
@@ -80,7 +80,9 @@ class VPN(object):
TERMINATE_MAXTRIES = 10
TERMINATE_WAIT = 1 # secs
- def __init__(self):
+ OPENVPN_VERB = "openvpn_verb"
+
+ def __init__(self, **kwargs):
"""
Instantiate empty attributes and get a copy
of a QObject containing the QSignals that we will pass along
@@ -92,6 +94,8 @@ class VPN(object):
self._reactor = reactor
self._qtsigs = VPNSignals()
+ self._openvpn_verb = kwargs.get(self.OPENVPN_VERB, None)
+
@property
def qtsigs(self):
return self._qtsigs
@@ -108,9 +112,12 @@ class VPN(object):
"""
self._stop_pollers()
kwargs['qtsigs'] = self.qtsigs
+ kwargs['openvpn_verb'] = self._openvpn_verb
# start the main vpn subprocess
vpnproc = VPNProcess(*args, **kwargs)
+ #qtsigs=self.qtsigs,
+ #openvpn_verb=self._openvpn_verb)
if vpnproc.get_openvpn_process():
logger.info("Another vpn process is running. Will try to stop it.")
@@ -566,7 +573,12 @@ class VPNManager(object):
# we should check that cmdline BEGINS
# with openvpn or with our wrapper
# (pkexec / osascript / whatever)
- if "openvpn" in ' '.join(p.cmdline):
+
+ # This needs more work, see #3268, but for the moment
+ # we need to be able to filter out arguments in the form
+ # --openvpn-foo, since otherwise we are shooting ourselves
+ # in the feet.
+ if any(map(lambda s: s.startswith("openvpn"), p.cmdline)):
openvpn_process = p
break
except psutil.error.AccessDenied:
@@ -645,7 +657,7 @@ class VPNProcess(protocol.ProcessProtocol, VPNManager):
"""
def __init__(self, eipconfig, providerconfig, socket_host, socket_port,
- qtsigs):
+ qtsigs, openvpn_verb):
"""
:param eipconfig: eip configuration object
:type eipconfig: EIPConfig
@@ -663,6 +675,10 @@ class VPNProcess(protocol.ProcessProtocol, VPNManager):
:param qtsigs: a QObject containing the Qt signals used to notify the
UI.
:type qtsigs: QObject
+
+ :param openvpn_verb: the desired level of verbosity in the
+ openvpn invocation
+ :type openvpn_verb: int
"""
VPNManager.__init__(self, qtsigs=qtsigs)
leap_assert_type(eipconfig, EIPConfig)
@@ -682,6 +698,8 @@ class VPNProcess(protocol.ProcessProtocol, VPNManager):
self._last_status = None
self._alive = False
+ self._openvpn_verb = openvpn_verb
+
# processProtocol methods
def connectionMade(self):
@@ -757,7 +775,8 @@ class VPNProcess(protocol.ProcessProtocol, VPNManager):
eipconfig=self._eipconfig,
providerconfig=self._providerconfig,
socket_host=self._socket_host,
- socket_port=self._socket_port)
+ socket_port=self._socket_port,
+ openvpn_verb=self._openvpn_verb)
return map(str, cmd)
# shutdown
diff --git a/src/leap/services/mail/imap.py b/src/leap/services/mail/imap.py
new file mode 100644
index 00000000..4dceb2ad
--- /dev/null
+++ b/src/leap/services/mail/imap.py
@@ -0,0 +1,42 @@
+# -*- coding: utf-8 -*-
+# imap.py
+# Copyright (C) 2013 LEAP
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+"""
+Initialization of imap service
+"""
+import logging
+import sys
+
+from leap.mail.imap.service import imap
+from twisted.python import log
+
+logger = logging.getLogger(__name__)
+
+
+def start_imap_service(*args, **kwargs):
+ """
+ Initializes and run imap service.
+
+ :returns: twisted.internet.task.LoopingCall instance
+ """
+ logger.debug('Launching imap service')
+
+ # Uncomment the next two lines to get a separate debugging log
+ # TODO handle this by a separate flag.
+ #log.startLogging(open('/tmp/leap-imap.log', 'w'))
+ #log.startLogging(sys.stdout)
+
+ return imap.run_service(*args, **kwargs)
diff --git a/src/leap/services/mail/smtpbootstrapper.py b/src/leap/services/mail/smtpbootstrapper.py
index e8af5349..48040035 100644
--- a/src/leap/services/mail/smtpbootstrapper.py
+++ b/src/leap/services/mail/smtpbootstrapper.py
@@ -72,10 +72,12 @@ class SMTPBootstrapper(AbstractBootstrapper):
if self._download_if_needed and mtime:
headers['if-modified-since'] = mtime
+ api_version = self._provider_config.get_api_version()
+
# there is some confusion with this uri,
config_uri = "%s/%s/config/smtp-service.json" % (
- self._provider_config.get_api_uri(),
- self._provider_config.get_api_version())
+ self._provider_config.get_api_uri(), api_version)
+
logger.debug('Downloading SMTP config from: %s' % config_uri)
srp_auth = SRPAuth(self._provider_config)
@@ -91,6 +93,8 @@ class SMTPBootstrapper(AbstractBootstrapper):
cookies=cookies)
res.raise_for_status()
+ self._smtp_config.set_api_version(api_version)
+
# Not modified
if res.status_code == 304:
logger.debug("SMTP definition has not been modified")
diff --git a/src/leap/services/mail/smtpconfig.py b/src/leap/services/mail/smtpconfig.py
index 30371005..ea0f9c37 100644
--- a/src/leap/services/mail/smtpconfig.py
+++ b/src/leap/services/mail/smtpconfig.py
@@ -21,7 +21,7 @@ SMTP configuration
import logging
from leap.common.config.baseconfig import BaseConfig
-from leap.services.mail.smtpspec import smtp_config_spec
+from leap.services.mail.smtpspec import get_schema
logger = logging.getLogger(__name__)
@@ -34,11 +34,13 @@ class SMTPConfig(BaseConfig):
def __init__(self):
BaseConfig.__init__(self)
- def _get_spec(self):
+ def _get_schema(self):
"""
- Returns the spec object for the specific configuration
+ Returns the schema corresponding to the version given.
+
+ :rtype: dict or None if the version is not supported.
"""
- return smtp_config_spec
+ return get_schema(self._api_version)
def get_hosts(self):
return self._safe_get_value("hosts")
diff --git a/src/leap/services/mail/smtpspec.py b/src/leap/services/mail/smtpspec.py
index 270dfb76..ff9d1bf8 100644
--- a/src/leap/services/mail/smtpspec.py
+++ b/src/leap/services/mail/smtpspec.py
@@ -15,7 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-smtp_config_spec = {
+# Schemas dict
+# To add a schema for a version you should follow the form:
+# { '1': schema_v1, '2': schema_v2, ... etc }
+# so for instance, to add the '2' version, you should do:
+# smtp_config_spec['2'] = schema_v2
+smtp_config_spec = {}
+
+smtp_config_spec['1'] = {
'description': 'sample smtp service config',
'type': 'object',
'properties': {
@@ -49,3 +56,15 @@ smtp_config_spec = {
}
}
}
+
+
+def get_schema(version):
+ """
+ Returns the schema corresponding to the version given.
+
+ :param version: the version of the schema to get.
+ :type version: str
+ :rtype: dict or None if the version is not supported.
+ """
+ schema = smtp_config_spec.get(version, None)
+ return schema
diff --git a/src/leap/services/soledad/soledadbootstrapper.py b/src/leap/services/soledad/soledadbootstrapper.py
index ac3243c1..c67bc004 100644
--- a/src/leap/services/soledad/soledadbootstrapper.py
+++ b/src/leap/services/soledad/soledadbootstrapper.py
@@ -23,6 +23,7 @@ import logging
import os
from PySide import QtCore
+from u1db import errors as u1db_errors
from leap.common.check import leap_assert, leap_assert_type
from leap.common.files import get_mtime
@@ -103,15 +104,18 @@ class SoledadBootstrapper(AbstractBootstrapper):
# TODO: If selected server fails, retry with another host
# (issue #3309)
- self._soledad = Soledad(uuid,
- self._password.encode("utf-8"),
- secrets_path=secrets_path,
- local_db_path=local_db_path,
- server_url=server_url,
- cert_file=cert_file,
- auth_token=srp_auth.get_token())
-
- self._soledad.sync()
+ try:
+ self._soledad = Soledad(
+ uuid,
+ self._password.encode("utf-8"),
+ secrets_path=secrets_path,
+ local_db_path=local_db_path,
+ server_url=server_url,
+ cert_file=cert_file,
+ auth_token=srp_auth.get_token())
+ self._soledad.sync()
+ except u1db_errors.Unauthorized:
+ logger.error("Error while initializing soledad.")
else:
raise Exception("No soledad server found")
@@ -139,10 +143,12 @@ class SoledadBootstrapper(AbstractBootstrapper):
if self._download_if_needed and mtime:
headers['if-modified-since'] = mtime
+ api_version = self._provider_config.get_api_version()
+
# there is some confusion with this uri,
config_uri = "%s/%s/config/soledad-service.json" % (
self._provider_config.get_api_uri(),
- self._provider_config.get_api_version())
+ api_version)
logger.debug('Downloading soledad config from: %s' % config_uri)
srp_auth = SRPAuth(self._provider_config)
@@ -158,6 +164,8 @@ class SoledadBootstrapper(AbstractBootstrapper):
cookies=cookies)
res.raise_for_status()
+ self._soledad_config.set_api_version(api_version)
+
# Not modified
if res.status_code == 304:
logger.debug("Soledad definition has not been modified")
@@ -190,6 +198,14 @@ class SoledadBootstrapper(AbstractBootstrapper):
logger.debug("Retrieving key for %s" % (address,))
srp_auth = SRPAuth(self._provider_config)
+
+ # TODO: Fix for Windows
+ gpgbin = "/usr/bin/gpg"
+
+ if self._standalone:
+ gpgbin = os.path.join(self._provider_config.get_path_prefix(),
+ "..", "apps", "mail", "gpg")
+
self._keymanager = KeyManager(
address,
"https://nicknym.%s:6425" % (self._provider_config.get_domain(),),
@@ -199,7 +215,8 @@ class SoledadBootstrapper(AbstractBootstrapper):
ca_cert_path=self._provider_config.get_ca_cert_path(),
api_uri=self._provider_config.get_api_uri(),
api_version=self._provider_config.get_api_version(),
- uid=srp_auth.get_uid())
+ uid=srp_auth.get_uid(),
+ gpgbinary=gpgbin)
try:
self._keymanager.get_key(address, openpgp.OpenPGPKey,
private=True, fetch_remote=False)
@@ -213,7 +230,8 @@ class SoledadBootstrapper(AbstractBootstrapper):
provider_config,
user,
password,
- download_if_needed=False):
+ download_if_needed=False,
+ standalone=False):
"""
Starts the checks needed for a new soledad setup
@@ -223,6 +241,13 @@ class SoledadBootstrapper(AbstractBootstrapper):
:type user: str
:param password: User's password
:type password: str
+ :param download_if_needed: If True, it will only download
+ files if the have changed since the
+ time it was previously downloaded.
+ :type download_if_needed: bool
+ :param standalone: If True, it'll look for paths inside the
+ bundle (like for gpg)
+ :type standalone: bool
"""
leap_assert_type(provider_config, ProviderConfig)
@@ -230,6 +255,7 @@ class SoledadBootstrapper(AbstractBootstrapper):
self._download_if_needed = download_if_needed
self._user = user
self._password = password
+ self._standalone = standalone
cb_chain = [
(self._download_config, self.download_config),
diff --git a/src/leap/services/soledad/soledadconfig.py b/src/leap/services/soledad/soledadconfig.py
index 80a82d11..a2367692 100644
--- a/src/leap/services/soledad/soledadconfig.py
+++ b/src/leap/services/soledad/soledadconfig.py
@@ -21,7 +21,7 @@ Soledad configuration
import logging
from leap.common.config.baseconfig import BaseConfig
-from leap.services.soledad.soledadspec import soledad_config_spec
+from leap.services.soledad.soledadspec import get_schema
logger = logging.getLogger(__name__)
@@ -34,11 +34,13 @@ class SoledadConfig(BaseConfig):
def __init__(self):
BaseConfig.__init__(self)
- def _get_spec(self):
+ def _get_schema(self):
"""
- Returns the spec object for the specific configuration
+ Returns the schema corresponding to the version given.
+
+ :rtype: dict or None if the version is not supported.
"""
- return soledad_config_spec
+ return get_schema(self._api_version)
def get_hosts(self):
return self._safe_get_value("hosts")
diff --git a/src/leap/services/soledad/soledadspec.py b/src/leap/services/soledad/soledadspec.py
index 8233d6a0..111175dd 100644
--- a/src/leap/services/soledad/soledadspec.py
+++ b/src/leap/services/soledad/soledadspec.py
@@ -15,7 +15,14 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
-soledad_config_spec = {
+# Schemas dict
+# To add a schema for a version you should follow the form:
+# { '1': schema_v1, '2': schema_v2, ... etc }
+# so for instance, to add the '2' version, you should do:
+# soledad_config_spec['2'] = schema_v2
+soledad_config_spec = {}
+
+soledad_config_spec['1'] = {
'description': 'sample soledad service config',
'type': 'object',
'properties': {
@@ -55,3 +62,15 @@ soledad_config_spec = {
}
}
}
+
+
+def get_schema(version):
+ """
+ Returns the schema corresponding to the version given.
+
+ :param version: the version of the schema to get.
+ :type version: str
+ :rtype: dict or None if the version is not supported.
+ """
+ schema = soledad_config_spec.get(version, None)
+ return schema
diff --git a/src/leap/services/tx.py b/src/leap/services/tx.py
index ef08fcc6..7da1cb01 100644
--- a/src/leap/services/tx.py
+++ b/src/leap/services/tx.py
@@ -40,7 +40,7 @@ def leap_services():
register them.
"""
logger.debug('starting leap services')
- application = Application("LEAP Client Local Services")
+ application = Application("Bitmask Local Services")
#lc = LoopingCall(task)
#lc.start(5)
return application