From daba177e8c842c52bce91057f53d869180e6c603 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sun, 28 Jul 2024 14:45:20 +0700 Subject: [PATCH] call update method directly we used to have different backends, so we needed an alias for this method, but this made things unnecessarily complicated and could cause compatibility issues with versions of python-cryptography if they decide to use slots or cythonize the modules --- tests/unittests/unit/net/crypto_test.py | 6 +++--- xpra/net/crypto.py | 13 ++++--------- xpra/net/protocol/socket_handler.py | 4 ++-- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/tests/unittests/unit/net/crypto_test.py b/tests/unittests/unit/net/crypto_test.py index 18b2ca0959..f8dd87e77e 100755 --- a/tests/unittests/unit/net/crypto_test.py +++ b/tests/unittests/unit/net/crypto_test.py @@ -63,7 +63,7 @@ def mustequ(l): #test encoding of a message: encrypted = [] for i in range(encrypt_count): - v = enc.encrypt(message) + v = enc.update(message) #print("%s%s=%s" % (enc.encrypt, (message,), hexstr(v))) assert v is not None if i==0: @@ -72,8 +72,8 @@ def mustequ(l): #test decoding of the message: decrypted = [] for i in range(decrypt_count): - v = dec.decrypt(encrypted[0]) - log("%s%s=%s" % (dec.decrypt, (encrypted[0],), hexstr(v))) + v = dec.update(encrypted[0]) + log("%s%s=%s" % (dec.update, (encrypted[0],), hexstr(v))) assert v is not None if i==0: decrypted.append(v) diff --git a/xpra/net/crypto.py b/xpra/net/crypto.py index f127175ad0..4abf5b56fb 100644 --- a/xpra/net/crypto.py +++ b/xpra/net/crypto.py @@ -142,10 +142,10 @@ def validate_backend() -> None: else: test_messages.append(message[:block_size]) for m in test_messages: - ev = enc.encrypt(m) + ev = enc.update(m) evs = hexstr(ev) log(" encrypted(%s)=%s", m, evs) - dv = dec.decrypt(ev) + dv = dec.update(ev) log(" decrypted(%s)=%s", evs, dv) if dv != m: raise RuntimeError(f"expected {m!r} but got {dv!r}") @@ -235,9 +235,7 @@ def get_encryptor(ciphername: str, iv: str, password, key_salt, key_hash: str, k def get_cipher_encryptor(key, iv: str, mode: str): - encryptor = _get_cipher(key, iv, mode).encryptor() - encryptor.encrypt = encryptor.update - return encryptor + return _get_cipher(key, iv, mode).encryptor() def get_decryptor(ciphername: str, iv: str, password, key_salt, key_hash: str, key_size: int, iterations: int): @@ -255,10 +253,7 @@ def get_decryptor(ciphername: str, iv: str, password, key_salt, key_hash: str, k def get_cipher_decryptor(key, iv: str, mode: str): - decryptor = _get_cipher(key, iv, mode).decryptor() - # the function we expect to call is named 'decrypt': - decryptor.decrypt = decryptor.update - return decryptor + return _get_cipher(key, iv, mode).decryptor() def get_block_size(mode: str) -> int: diff --git a/xpra/net/protocol/socket_handler.py b/xpra/net/protocol/socket_handler.py index ec32b42413..427f8fb9d8 100644 --- a/xpra/net/protocol/socket_handler.py +++ b/xpra/net/protocol/socket_handler.py @@ -431,7 +431,7 @@ def _add_chunks_to_queue(self, packet_type: str | int, actual_size += padding_size if len(padded) != actual_size: raise RuntimeError(f"expected padded size to be {actual_size}, but got {len(padded)}") - data = self.cipher_out.encrypt(padded) + data = self.cipher_out.update(padded) if len(data) != actual_size: raise RuntimeError(f"expected encrypted size to be {actual_size}, but got {len(data)}") cryptolog("sending %s bytes %s encrypted with %s bytes of padding", @@ -1006,7 +1006,7 @@ def check_packet_size(size_to_check, packet_header): return cryptolog("received %i %s encrypted bytes with %i padding", payload_size, self.cipher_in_name, padding_size) - data = self.cipher_in.decrypt(data) + data = self.cipher_in.update(data) if padding_size > 0: def debug_str(s): try: