summaryrefslogtreecommitdiff
path: root/src/leap/services/soledad
diff options
context:
space:
mode:
Diffstat (limited to 'src/leap/services/soledad')
-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
3 files changed, 64 insertions, 17 deletions
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