summaryrefslogtreecommitdiff
path: root/client/src/leap/soledad
diff options
context:
space:
mode:
authorTomás Touceda <chiiph@leap.se>2013-11-15 10:09:46 -0300
committerTomás Touceda <chiiph@leap.se>2013-11-15 10:09:46 -0300
commit0ade4a7e3a323df631c9772e4db5173a20979d46 (patch)
tree83af195334ff3cb0d25d65a76e4b8ecc782bd6b3 /client/src/leap/soledad
parent7dc16ac9286f0383c158e6028a028d99c5b1f373 (diff)
parent70aa832393c1e926512ff8f333ef6170aa11dab7 (diff)
Merge branch 'release-0.4.3'0.4.3
Diffstat (limited to 'client/src/leap/soledad')
-rw-r--r--client/src/leap/soledad/client/__init__.py5
-rw-r--r--client/src/leap/soledad/client/sqlcipher.py12
2 files changed, 15 insertions, 2 deletions
diff --git a/client/src/leap/soledad/client/__init__.py b/client/src/leap/soledad/client/__init__.py
index 534040ef..a159d773 100644
--- a/client/src/leap/soledad/client/__init__.py
+++ b/client/src/leap/soledad/client/__init__.py
@@ -847,8 +847,9 @@ class Soledad(object):
elif isinstance(content, str):
try:
result = chardet.detect(content)
- content = content.decode(result["encoding"]).encode("utf-8")\
- .decode("utf-8")
+ default = "utf-8"
+ encoding = result["encoding"] or default
+ content = content.decode(encoding)
except UnicodeError:
pass
return content
diff --git a/client/src/leap/soledad/client/sqlcipher.py b/client/src/leap/soledad/client/sqlcipher.py
index 3e01a4fb..894c6f97 100644
--- a/client/src/leap/soledad/client/sqlcipher.py
+++ b/client/src/leap/soledad/client/sqlcipher.py
@@ -70,6 +70,14 @@ sqlite_backend.dbapi2 = dbapi2
SQLITE_CHECK_SAME_THREAD = False
+# We set isolation_level to None to setup autocommit mode.
+# See: http://docs.python.org/2/library/sqlite3.html#controlling-transactions
+# This avoids problems with sequential operations using the same soledad object
+# trying to open new transactions
+# (The error was:
+# OperationalError:cannot start a transaction within a transaction.)
+SQLITE_ISOLATION_LEVEL = None
+
def open(path, password, create=True, document_factory=None, crypto=None,
raw_key=False, cipher='aes-256-cbc', kdf_iter=4000,
@@ -172,6 +180,7 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase):
with self.k_lock:
self._db_handle = dbapi2.connect(
sqlcipher_file,
+ isolation_level=SQLITE_ISOLATION_LEVEL,
check_same_thread=SQLITE_CHECK_SAME_THREAD)
# set SQLCipher cryptographic parameters
self._set_crypto_pragmas(
@@ -436,6 +445,7 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase):
with cls.k_lock:
db_handle = dbapi2.connect(
sqlcipher_file,
+ isolation_level=SQLITE_ISOLATION_LEVEL,
check_same_thread=SQLITE_CHECK_SAME_THREAD)
cls._set_crypto_pragmas(
db_handle, key, raw_key, cipher,
@@ -645,6 +655,7 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase):
passphrase that should be hashed to obtain the encyrption key.
:type raw_key: bool
"""
+ # XXX change key param!
if raw_key:
cls._pragma_rekey_raw(db_handle, key)
else:
@@ -683,6 +694,7 @@ class SQLCipherDatabase(sqlite_backend.SQLitePartialExpandDatabase):
"""
if not all(c in string.hexdigits for c in key):
raise NotAnHexString(key)
+ # XXX change passphrase param!
db_handle.cursor().execute('PRAGMA rekey = "x\'%s"' % passphrase)
def __del__(self):