diff options
-rw-r--r-- | src/leap/soledad/client/_crypto.py | 6 | ||||
-rw-r--r-- | src/leap/soledad/common/preamble.py | 12 | ||||
-rw-r--r-- | testing/tests/client/test_crypto.py | 4 |
3 files changed, 11 insertions, 11 deletions
diff --git a/src/leap/soledad/client/_crypto.py b/src/leap/soledad/client/_crypto.py index 998b70fa..c0d9dde9 100644 --- a/src/leap/soledad/client/_crypto.py +++ b/src/leap/soledad/client/_crypto.py @@ -33,7 +33,7 @@ Encryption ---------- IV = os.urandom(16) -PREAMBLE = BLOB_SIGNATURE_MAGIC, ENC_SCHEME, ENC_METHOD, time, IV, doc_id, rev, +PREAMBLE = MAGIC, ENC_SCHEME, ENC_METHOD, time, IV, doc_id, rev, and size. PREAMBLE = base64_encoded(PREAMBLE) @@ -90,7 +90,7 @@ from leap.soledad.common.preamble import InvalidPreambleException from leap.soledad.common.preamble import decode_preamble from leap.soledad.common.preamble import Preamble from leap.soledad.common.preamble import ENC_SCHEME, ENC_METHOD -from leap.soledad.common.preamble import BLOB_SIGNATURE_MAGIC +from leap.soledad.common.preamble import MAGIC SECRET_LENGTH = 64 @@ -383,7 +383,7 @@ class BlobDecryptor(object): except InvalidPreambleException as e: raise InvalidBlob(e) - if preamble.magic != BLOB_SIGNATURE_MAGIC: + if preamble.magic != MAGIC: raise InvalidBlob # TODO check timestamp. Just as a sanity check, but for instance # we can refuse to process something that is in the future or diff --git a/src/leap/soledad/common/preamble.py b/src/leap/soledad/common/preamble.py index 72549031..d4065c38 100644 --- a/src/leap/soledad/common/preamble.py +++ b/src/leap/soledad/common/preamble.py @@ -15,9 +15,9 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. """ -Preamble is a metadata payload present on encrypted documents. It holds data -about encryption scheme, iv, document id and sync related data. - BLOB_SIGNATURE_MAGIC, -> used to differentiate from other data formats +Preamble is a binary packed metadata payload present on encrypted documents. It +holds data about encryption scheme, iv, document id and sync related data. + MAGIC, -> used to differentiate from other data formats ENC_SCHEME, -> cryptographic scheme (symmetric or asymmetric) ENC_METHOD, -> cipher used, such as AES-GCM or AES-CTR or GPG current_time, -> time.time() @@ -32,7 +32,7 @@ import time from collections import namedtuple PACMAN = struct.Struct('2sbbQ16s255p255pQ') LEGACY_PACMAN = struct.Struct('2sbbQ16s255p255p') # DEPRECATED -BLOB_SIGNATURE_MAGIC = '\x13\x37' +MAGIC = '\x13\x37' ENC_SCHEME = namedtuple('SCHEME', 'symkey external')(1, 2) ENC_METHOD = namedtuple('METHOD', 'aes_256_ctr aes_256_gcm pgp')(1, 2, 3) @@ -41,7 +41,7 @@ class InvalidPreambleException(Exception): pass -class Preamble: +class Preamble(object): def __init__(self, doc_id, rev, scheme, method, timestamp=0, iv='', magic=None, content_size=0): @@ -51,7 +51,7 @@ class Preamble: self.method = method self.iv = iv self.timestamp = int(timestamp) or int(time.time()) - self.magic = magic or BLOB_SIGNATURE_MAGIC + self.magic = magic or MAGIC self.content_size = int(content_size) def encode(self): diff --git a/testing/tests/client/test_crypto.py b/testing/tests/client/test_crypto.py index 2a93081c..62a13df7 100644 --- a/testing/tests/client/test_crypto.py +++ b/testing/tests/client/test_crypto.py @@ -140,7 +140,7 @@ class BlobTestCase(unittest.TestCase): assert len(preamble) == _preamble.PACMAN.size unpacked_data = _preamble.PACMAN.unpack(preamble) magic, sch, meth, ts, iv, doc_id, rev, _ = unpacked_data - assert magic == _crypto.BLOB_SIGNATURE_MAGIC + assert magic == _crypto.MAGIC assert sch == 1 assert meth == _crypto.ENC_METHOD.aes_256_gcm assert iv == self.blob.iv @@ -314,7 +314,7 @@ class PreambleTestCase(unittest.TestCase): def test_preamble_starts_with_magic_signature(self): preamble = self.blob._encode_preamble() - assert preamble.startswith(_crypto.BLOB_SIGNATURE_MAGIC) + assert preamble.startswith(_crypto.MAGIC) def test_preamble_has_cipher_metadata(self): preamble = self.blob._encode_preamble() |