Skip to content

Commit

Permalink
Merge branch 'master' into plugin-store
Browse files Browse the repository at this point in the history
  • Loading branch information
falkTX committed Nov 18, 2023
2 parents 78f60cd + 76b86cb commit 1ab2695
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 21 deletions.
18 changes: 9 additions & 9 deletions mod-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand All @@ -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"
40 changes: 30 additions & 10 deletions mod/communication/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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)
Expand All @@ -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)
4 changes: 2 additions & 2 deletions mod/screenshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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"
Expand Down

0 comments on commit 1ab2695

Please sign in to comment.