Skip to content

Commit

Permalink
#2793 use memoryview_to_bytes to decrypt data with versions of python…
Browse files Browse the repository at this point in the history
…-cryptography older than 2.5

git-svn-id: https://xpra.org/svn/Xpra/trunk@26631 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Jun 5, 2020
1 parent da5feae commit 89505df
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/xpra/net/pycryptography_backend.py
@@ -1,10 +1,10 @@
# This file is part of Xpra.
# Copyright (C) 2011-2015 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2011-2020 Antoine Martin <antoine@xpra.org>
# Copyright (C) 2008, 2009, 2010 Nathaniel Smith <njs@pobox.com>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.

from xpra.os_util import strtobytes
from xpra.os_util import strtobytes, memoryview_to_bytes
from xpra.log import Logger

log = Logger("network", "crypto")
Expand Down Expand Up @@ -88,7 +88,25 @@ def get_encryptor(key, iv):

def get_decryptor(key, iv):
decryptor = _get_cipher(key, iv).decryptor()
decryptor.decrypt = decryptor.update
def i(s):
try:
return int(s)
except ValueError:
return 0
import cryptography
version = cryptography.__version__
supports_memoryviews = tuple(i(s) for s in version.split("."))>=(2, 5)
log("get_decryptor(..) python-cryptography supports_memoryviews(%s)=%s",
version, supports_memoryviews)
if supports_memoryviews:
decryptor.decrypt = decryptor.update
else:
del key, iv
#with older versions of python-cryptography,
#we have to copy the memoryview to a bytearray:
def decrypt(v):
return decryptor.update(memoryview_to_bytes(v))
decryptor.decrypt = decrypt
return decryptor


Expand Down

0 comments on commit 89505df

Please sign in to comment.