summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/leap/soledad/__init__.py16
-rw-r--r--src/leap/soledad/backends/sqlcipher.py21
2 files changed, 22 insertions, 15 deletions
diff --git a/src/leap/soledad/__init__.py b/src/leap/soledad/__init__.py
index 6c313f77..26e982ba 100644
--- a/src/leap/soledad/__init__.py
+++ b/src/leap/soledad/__init__.py
@@ -13,10 +13,10 @@ import util
class Soledad(object):
# paths
- PREFIX = os.environ['HOME'] + '/.config/leap/soledad'
- SECRET_PATH = PREFIX + '/secret.gpg'
- GNUPG_HOME = PREFIX + '/gnupg'
- U1DB_PATH = PREFIX + '/soledad.u1db'
+ PREFIX = os.environ['HOME'] + '/.config/leap/soledad'
+ SECRET_PATH = PREFIX + '/secret.gpg'
+ GNUPG_HOME = PREFIX + '/gnupg'
+ LOCAL_DB_PATH = PREFIX + '/soledad.u1db'
# other configs
SECRET_LENGTH = 50
@@ -28,7 +28,7 @@ class Soledad(object):
if not gpghome:
gpghome = self.GNUPG_HOME
self._gpg = util.GPGWrapper(gpghome=gpghome)
- # loaa/generate OpenPGP keypair
+ # load/generate OpenPGP keypair
if not self._has_openpgp_keypair():
self._gen_openpgp_keypair()
self._load_openpgp_keypair()
@@ -39,7 +39,7 @@ class Soledad(object):
# instantiate u1db
# TODO: verify if secret for sqlcipher should be the same as the one
# for symmetric encryption.
- self._db = sqlcipher.open(self.U1DB_PATH, True, self._secret)
+ self._db = sqlcipher.open(self.LOCAL_DB_PATH, True, self._secret)
#-------------------------------------------------------------------------
# Management of secret for symmetric encryption
@@ -112,6 +112,7 @@ class Soledad(object):
"""
Publish OpenPGP public key to a keyserver.
"""
+ # TODO: this has to talk to LEAP's Nickserver.
pass
#-------------------------------------------------------------------------
@@ -199,6 +200,7 @@ class Soledad(object):
Synchronize the local encrypted database with LEAP server.
"""
# TODO: create authentication scheme for sync with server.
- return self._db.sync(url, creds=None, autocreate=True)
+ return self._db.sync(url, creds=None, autocreate=True, soledad=self)
__all__ = ['util']
+
diff --git a/src/leap/soledad/backends/sqlcipher.py b/src/leap/soledad/backends/sqlcipher.py
index f7dc6c0b..3d03449e 100644
--- a/src/leap/soledad/backends/sqlcipher.py
+++ b/src/leap/soledad/backends/sqlcipher.py
@@ -20,14 +20,17 @@ import os
from sqlite3 import dbapi2, DatabaseError
import time
-from u1db.backends.sqlite_backend import SQLitePartialExpandDatabase
+from u1db.backends.sqlite_backend import (
+ SQLiteDatabase,
+ SQLitePartialExpandDatabase,
+)
from u1db import (
Document,
errors,
)
-def open(path, password, create, document_factory=None):
+def open(path, password, create=True, document_factory=None):
"""Open a database at the given location.
Will raise u1db.errors.DatabaseDoesNotExist if create=False and the
@@ -127,13 +130,15 @@ class SQLCipherDatabase(SQLitePartialExpandDatabase):
document_factory=document_factory)
- @staticmethod
- def register_implementation(klass):
- """Register that we implement an SQLCipherDatabase.
-
- The attribute _index_storage_value will be used as the lookup key.
+ def sync(self, url, creds=None, autocreate=True, soledad=None):
+ """
+ Synchronize encrypted documents with remote replica exposed at url.
"""
- SQLCipherDatabase._sqlite_registry[klass._index_storage_value] = klass
+ from u1db.sync import Synchronizer
+ from leap.soledad.backends.leap_backend import LeapSyncTarget
+ return Synchronizer(self, LeapSyncTarget(url, creds=creds),
+ soledad=self._soledad).sync(
+ autocreate=autocreate)
SQLiteDatabase.register_implementation(SQLCipherDatabase)