Skip to content

Commit

Permalink
call update method directly
Browse files Browse the repository at this point in the history
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
  • Loading branch information
totaam committed Jul 28, 2024
1 parent 0b77241 commit daba177
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 14 deletions.
6 changes: 3 additions & 3 deletions tests/unittests/unit/net/crypto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)
Expand Down
13 changes: 4 additions & 9 deletions xpra/net/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions xpra/net/protocol/socket_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit daba177

Please sign in to comment.