diff options
author | drebs <drebs@leap.se> | 2013-01-20 16:29:53 -0200 |
---|---|---|
committer | drebs <drebs@leap.se> | 2013-01-20 16:29:53 -0200 |
commit | eae9fd4b5d93845fc708abb722714ebf9d003418 (patch) | |
tree | 9f1bd621c2f832a470d27eaab71fbd8629862e51 /src | |
parent | c1e460cc15523a0138dde1ece9d584554d99c04b (diff) |
SQLCipher backend syncs using a LeapSyncTarget.
Diffstat (limited to 'src')
-rw-r--r-- | src/leap/soledad/__init__.py | 16 | ||||
-rw-r--r-- | src/leap/soledad/backends/sqlcipher.py | 21 |
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) |