summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Shyba <victor1984@riseup.net>2017-02-15 17:43:17 -0300
committerVictor Shyba <victor1984@riseup.net>2017-02-15 17:43:17 -0300
commite6ed77ce83a37dd4fffb8ac560ae34fbee8acc22 (patch)
treeeb17a0354d718eb3935505bb369a2a41d6ee9e80
parent13fdd28cd7448b11a35c794e69e5c64e1c9cd154 (diff)
[tests] add tests for preamble encoding
-rw-r--r--client/src/leap/soledad/client/_crypto.py4
-rw-r--r--testing/tests/client/test_crypto.py31
2 files changed, 33 insertions, 2 deletions
diff --git a/client/src/leap/soledad/client/_crypto.py b/client/src/leap/soledad/client/_crypto.py
index 4bbdd044..9f403cc9 100644
--- a/client/src/leap/soledad/client/_crypto.py
+++ b/client/src/leap/soledad/client/_crypto.py
@@ -192,7 +192,7 @@ class BlobEncryptor(object):
sym_key = _get_sym_key_for_doc(doc_info.doc_id, secret)
self._aes = AESWriter(sym_key)
- self._aes.authenticate(self._make_preamble())
+ self._aes.authenticate(self._encode_preamble())
@property
def iv(self):
@@ -214,7 +214,7 @@ class BlobEncryptor(object):
d.addCallback(lambda _: self._end_crypto_stream())
return d
- def _make_preamble(self):
+ def _encode_preamble(self):
current_time = int(time.time())
return PACMAN.pack(
diff --git a/testing/tests/client/test_crypto.py b/testing/tests/client/test_crypto.py
index 5411a4e8..852448e0 100644
--- a/testing/tests/client/test_crypto.py
+++ b/testing/tests/client/test_crypto.py
@@ -235,6 +235,37 @@ class SoledadCryptoAESTestCase(BaseSoledadTest):
_crypto.decrypt_sym(cyphertext, wrongkey, iv)
+class PreambleTestCase(unittest.TestCase):
+ class doc_info:
+ doc_id = 'D-deadbeef'
+ rev = '397932e0c77f45fcb7c3732930e7e9b2:1'
+
+ def setUp(self):
+ inf = BytesIO(snowden1)
+ self.blob = _crypto.BlobEncryptor(
+ self.doc_info, inf,
+ secret='A' * 96)
+
+ def test_preamble_starts_with_magic_signature(self):
+ preamble = self.blob._encode_preamble()
+ assert preamble.startswith(_crypto.BLOB_SIGNATURE_MAGIC)
+
+ def test_preamble_has_cipher_metadata(self):
+ preamble = self.blob._encode_preamble()
+ unpacked = _crypto.PACMAN.unpack(preamble)
+ encryption_scheme, encryption_method = unpacked[1:3]
+ assert encryption_scheme in _crypto.ENC_SCHEME
+ assert encryption_method in _crypto.ENC_METHOD
+ assert unpacked[4] == self.blob.iv
+
+ def test_preamble_has_document_sync_metadata(self):
+ preamble = self.blob._encode_preamble()
+ unpacked = _crypto.PACMAN.unpack(preamble)
+ doc_id, doc_rev = unpacked[5:]
+ assert doc_id == self.doc_info.doc_id
+ assert doc_rev == self.doc_info.rev
+
+
def _aes_encrypt(key, iv, data):
backend = default_backend()
cipher = Cipher(algorithms.AES(key), modes.GCM(iv), backend=backend)