Commit 5fe66ea1 by Luciano Barletta

Fixed encryption mode

1 parent 6f4ef1a5
...@@ -30,8 +30,8 @@ def data(): ...@@ -30,8 +30,8 @@ def data():
prefix = newprefix() prefix = newprefix()
key = request.files.get('key') key = request.files.get('key')
if key != None: if key != None:
key.save(prefix + "_key") key.save(prefix + "_key.enc")
request.files['data'].save(prefix) request.files['data'].save(prefix + ".enc")
filename[prefix] = request.files['data'].filename filename[prefix] = request.files['data'].filename
return prefix return prefix
...@@ -54,16 +54,18 @@ def msg(): ...@@ -54,16 +54,18 @@ def msg():
process = Process('messages.db') process = Process('messages.db')
prefix = request.values['id'] prefix = request.values['id']
if not os.path.exists(prefix): if prefix not in filename:
return "El id de la data es invalido" return "El id de la data es invalido"
# symetric key was sent, decrypt data # symetric key was sent, decrypt data
if os.path.exists(prefix + "_key"): if os.path.exists(prefix + "_key.enc"):
# decrypt random key with stored private key and store in host folder # decrypt random key with stored private key and store in host folder
os.system("openssl rsautl -decrypt -inkey rsa_key.pri -in " + prefix + "_key -out " + prefix + "_key") os.system("openssl rsautl -decrypt -inkey rsa_key.pri -in " + prefix + "_key.enc -out " + prefix + "_key")
# decrypt JSON with decrypted random key and store in dir folder # decrypt JSON with decrypted random key and store in dir folder
os.system("openssl enc -d -aes-256-cbc -in " + prefix + " -out " + prefix + " -pass file:" + prefix + "_key") os.system("openssl enc -d -aes-256-cbc -in " + prefix + ".enc -out " + prefix + " -pass file:" + prefix + "_key")
# delete key # delete garbage
os.system("rm " + prefix + ".enc")
os.system("rm " + prefix + "_key.enc")
os.system("rm " + prefix + "_key") os.system("rm " + prefix + "_key")
query = { query = {
......
Styling with Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!