Esempio n. 1
0
    def _init_u1db_sqlcipher_backend(self):
        """
        Initialize the U1DB SQLCipher database for local storage.

        Instantiates a modified twisted adbapi that will maintain a threadpool
        with a u1db-sqclipher connection for each thread, and will return
        deferreds for each u1db query.

        Currently, Soledad uses the default SQLCipher cipher, i.e.
        'aes-256-cbc'. We use scrypt to derive a 256-bit encryption key,
        and internally the SQLCipherDatabase initialization uses the 'raw
        PRAGMA key' format to handle the key to SQLCipher.
        """
        tohex = binascii.b2a_hex
        # sqlcipher only accepts the hex version
        key = tohex(self._secrets.get_local_storage_key())
        sync_db_key = tohex(self._secrets.get_sync_db_key())

        opts = sqlcipher.SQLCipherOptions(
            self._local_db_path, key,
            is_raw_key=True, create=True,
            defer_encryption=self._defer_encryption,
            sync_db_key=sync_db_key,
        )
        self._sqlcipher_opts = opts

        # the sync_db is used both for deferred encryption and decryption, so
        # we want to initialize it anyway to allow for all combinations of
        # deferred encryption and decryption configurations.
        self._initialize_sync_db(opts)
        self._dbpool = adbapi.getConnectionPool(
            opts, sync_enc_pool=self._sync_enc_pool)
Esempio n. 2
0
    def _init_u1db_sqlcipher_backend(self):
        """
        Initialize the U1DB SQLCipher database for local storage.

        Instantiates a modified twisted adbapi that will maintain a threadpool
        with a u1db-sqclipher connection for each thread, and will return
        deferreds for each u1db query.

        Currently, Soledad uses the default SQLCipher cipher, i.e.
        'aes-256-cbc'. We use scrypt to derive a 256-bit encryption key,
        and internally the SQLCipherDatabase initialization uses the 'raw
        PRAGMA key' format to handle the key to SQLCipher.
        """
        tohex = binascii.b2a_hex
        # sqlcipher only accepts the hex version
        key = tohex(self._secrets.get_local_storage_key())
        sync_db_key = tohex(self._secrets.get_sync_db_key())

        opts = SQLCipherOptions(
            self._local_db_path,
            key,
            is_raw_key=True,
            create=True,
            defer_encryption=self._defer_encryption,
            sync_db_key=sync_db_key,
        )
        self._sqlcipher_opts = opts
        self._dbpool = adbapi.getConnectionPool(opts)
Esempio n. 3
0
 def _get_dbpool(self):
     tmpdb = os.path.join(self.tempdir, "test.soledad")
     opts = SQLCipherOptions(tmpdb, "secret", create=True)
     return adbapi.getConnectionPool(opts)
Esempio n. 4
0
def debug(*args):
    if not silent:
        print(*args)


debug("[+] db path:", tmpdb)
debug("[+] num docs", numdocs)

if os.path.isfile(tmpdb):
    debug("[+] Removing existing db file...")
    os.remove(tmpdb)

start_time = datetime.datetime.now()

opts = SQLCipherOptions(tmpdb, "secret", create=True)
dbpool = adbapi.getConnectionPool(opts)


def createDoc(doc, doc_id):
    return dbpool.runU1DBQuery("create_doc", doc, doc_id=doc_id)


db_indexes = {'by-chash': ['chash'], 'by-number': ['number']}


def create_indexes(_):
    deferreds = []
    for index, definition in db_indexes.items():
        d = dbpool.runU1DBQuery("create_index", index, *definition)
        deferreds.append(d)
    return defer.gatherResults(deferreds)
def debug(*args):
    if not silent:
        print(*args)

debug("[+] db path:", tmpdb)
debug("[+] num docs", numdocs)

if os.path.isfile(tmpdb):
    debug("[+] Removing existing db file...")
    os.remove(tmpdb)

start_time = datetime.datetime.now()

opts = SQLCipherOptions(tmpdb, "secret", create=True)
dbpool = adbapi.getConnectionPool(opts)


def createDoc(doc, doc_id):
    return dbpool.runU1DBQuery("create_doc", doc, doc_id=doc_id)

db_indexes = {
    'by-chash': ['chash'],
    'by-number': ['number']}


def create_indexes(_):
    deferreds = []
    for index, definition in db_indexes.items():
        d = dbpool.runU1DBQuery("create_index", index, *definition)
        deferreds.append(d)
Esempio n. 6
0
 def _get_dbpool(self):
     tmpdb = os.path.join(self.tempdir, "test.soledad")
     opts = SQLCipherOptions(tmpdb, "secret", create=True)
     return adbapi.getConnectionPool(opts)