From fc843bde9f0b23cfab40c3bcc133378342a8a070 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 17 Nov 2023 23:53:40 +0100 Subject: [PATCH 1/3] crypto: compatibility with Cryptodome Signed-off-by: falkTX --- mod/communication/crypto.py | 40 +++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/mod/communication/crypto.py b/mod/communication/crypto.py index aa46e889..7061aeaa 100644 --- a/mod/communication/crypto.py +++ b/mod/communication/crypto.py @@ -5,10 +5,18 @@ import io import uuid -from Crypto.Cipher import PKCS1_OAEP, AES -from Crypto.PublicKey import RSA -from Crypto.Signature import PKCS1_v1_5 -from Crypto.Hash import SHA1 +try: + from Cryptodome.Cipher import PKCS1_OAEP, AES + from Cryptodome.Hash import SHA1 + from Cryptodome.PublicKey import RSA + from Cryptodome.Signature import pkcs1_15 as PKCS1_v1_5 + usingCryptodome = True +except ImportError: + from Crypto.Cipher import PKCS1_OAEP, AES + from Crypto.Hash import SHA1 + from Crypto.PublicKey import RSA + from Crypto.Signature import PKCS1_v1_5 + usingCryptodome = False def encrypt(recipient_key_txt: str, data: str): @@ -24,20 +32,25 @@ def encrypt(recipient_key_txt: str, data: str): # Encrypt the data with the AES session keynonce: str, nonce: str, cipher_aes = AES.new(session_key, AES.MODE_EAX, uuid.uuid4().bytes) - ciphertext, tag = cipher_aes.encrypt_and_digest(data) + if usingCryptodome: + ciphertext, tag = cipher_aes.encrypt_and_digest(bytes(data, 'utf-8')) + else: + ciphertext, tag = cipher_aes.encrypt_and_digest(data) [out.write(x) for x in (cipher_aes.nonce, tag, ciphertext)] out.seek(0) return out.getvalue() def decrypt(private_key_txt: str, encrypted: bytes): - private_key = RSA.importKey(private_key_txt) - private_key_size = int((private_key.size() + 1)/8) + if usingCryptodome: + private_key_size = int((private_key.size_in_bits() + 1)/8) + else: + private_key_size = int((private_key.size() + 1)/8) buffer = io.BytesIO(encrypted) session_key, nonce, tag, ciphertext = \ - [buffer .read(x) for x in (private_key_size, 16, 16, -1)] + [buffer.read(x) for x in (private_key_size, 16, 16, -1)] # Decrypt the session key with the public RSA key cipher_rsa = PKCS1_OAEP.new(private_key) @@ -56,8 +69,15 @@ def sign_message_sha1(key_txt: str, message: str): return PKCS1_v1_5.new(key).sign(sha1) -def verify_signature(sender_key_txt: str, contents: str, signature: str): +def verify_signature(sender_key_txt: str, contents: str, signature: bytes): sender_key = RSA.importKey(sender_key_txt) sha1 = SHA1.new() sha1.update(contents.encode()) - return PKCS1_v1_5.new(sender_key).verify(sha1, signature) + if usingCryptodome: + try: + PKCS1_v1_5.new(sender_key).verify(sha1, signature) + return True + except ValueError: + return False + else: + return PKCS1_v1_5.new(sender_key).verify(sha1, signature) From 1632868cf86997677e8b876e2bdf53873cd34f06 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 17 Nov 2023 23:54:01 +0100 Subject: [PATCH 2/3] Make mod-deploy.sh compatible with newer python Signed-off-by: falkTX --- mod-deploy.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/mod-deploy.sh b/mod-deploy.sh index a705b8d6..21a9bc99 100755 --- a/mod-deploy.sh +++ b/mod-deploy.sh @@ -27,9 +27,9 @@ ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/share/mod/html/css ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/share/mod/html/js ssh ${SSH_OPTIONS} ${TARGET} mkdir -p /usr/share/mod/html/css/fontello/{css,font} /usr/share/mod/html/js/{lib/slick/fonts,utils} -ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.4/site-packages/mod/*.py* -ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.4/site-packages/mod/communication/*.py* -ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.4/site-packages/modtools/*.py* +ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.*/site-packages/mod/*.py* +ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.*/site-packages/mod/communication/*.py* +ssh ${SSH_OPTIONS} ${TARGET} rm -f /usr/lib/python3.*/site-packages/modtools/*.py* scp ${SCP_OPTIONS} html/*.html ${TARGET}:/usr/share/mod/html/ scp ${SCP_OPTIONS} html/include/*.html ${TARGET}:/usr/share/mod/html/include/ @@ -45,12 +45,12 @@ scp ${SCP_OPTIONS} html/js/lib/slick/fonts/*.* ${TARGET}:/usr/share/mod/html/j scp ${SCP_OPTIONS} html/js/utils/*.js ${TARGET}:/usr/share/mod/html/js/utils/ scp ${SCP_OPTIONS} html/img/*.png ${TARGET}:/usr/share/mod/html/img/ scp ${SCP_OPTIONS} html/img/*.svg ${TARGET}:/usr/share/mod/html/img/ -scp ${SCP_OPTIONS} mod/*.py ${TARGET}:/usr/lib/python3.4/site-packages/mod/ -scp ${SCP_OPTIONS} mod/communication/*.py ${TARGET}:/usr/lib/python3.4/site-packages/mod/communication/ -scp ${SCP_OPTIONS} modtools/*.py ${TARGET}:/usr/lib/python3.4/site-packages/modtools/ +scp ${SCP_OPTIONS} mod/*.py ${TARGET}:/usr/lib/python3.*/site-packages/mod/ +scp ${SCP_OPTIONS} mod/communication/*.py ${TARGET}:/usr/lib/python3.*/site-packages/mod/communication/ +scp ${SCP_OPTIONS} modtools/*.py ${TARGET}:/usr/lib/python3.*/site-packages/modtools/ -ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.4/site-packages/mod/__pycache__ -ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.4/site-packages/mod/communication/__pycache__ -ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.4/site-packages/modtools/__pycache__ +ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.*/site-packages/mod/__pycache__ +ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.*/site-packages/mod/communication/__pycache__ +ssh ${SSH_OPTIONS} ${TARGET} rm -rf /usr/lib/python3.*/site-packages/modtools/__pycache__ echo "all ok" From 76b86cb96df5be2df4a677213c1978e6eecf1cdb Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 18 Nov 2023 08:02:11 +0100 Subject: [PATCH 3/3] Fix pedalboard screenshots for non app usage Signed-off-by: falkTX --- mod/screenshot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mod/screenshot.py b/mod/screenshot.py index eefdb9e1..de05d917 100644 --- a/mod/screenshot.py +++ b/mod/screenshot.py @@ -8,7 +8,7 @@ import logging from tornado.ioloop import IOLoop -from mod.settings import HTML_DIR, DEV_ENVIRONMENT, DEVICE_KEY, CACHE_DIR +from mod.settings import HTML_DIR, DEV_ENVIRONMENT, DEVICE_KEY, CACHE_DIR, APP def generate_screenshot(bundle_path, callback): @@ -24,7 +24,7 @@ def generate_screenshot(bundle_path, callback): cwd = os.path.abspath(os.path.join(os.path.dirname(__file__), '../')) # running packaged through cxfreeze - if os.path.isfile(sys.argv[0]): + if APP and os.path.isfile(sys.argv[0]): cmd = [os.path.join(cwd, 'mod-pedalboard'), 'take_screenshot', bundle_path, HTML_DIR, CACHE_DIR] if sys.platform == 'win32': cmd[0] += ".exe"