This commit is contained in:
luke
2021-03-04 20:21:19 -05:00
parent 5240242223
commit dd449eee16

View File

@@ -1,9 +1,10 @@
import socket import socket
from Crypto.Cipher import PKCS1_OAEP as RSA from Crypto.Cipher import PKCS1_OAEP as RSA
from Crypto.Cipher import AES #from Crypto.Cipher import AES
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
import os import os
import glob import glob
import time
# global vars # global vars
endmessage = "---endmessage---" endmessage = "---endmessage---"
@@ -25,12 +26,18 @@ def getStream(bytelen):
while not done: while not done:
msg = c.recv(bytelen) msg = c.recv(bytelen)
if newmsg: if newmsg:
msglen = int(msg[:HEADERSIZE]) msglen = int(str(msg[:HEADERSIZE].decode("utf-8")))
print(str(msglen))
newmsg = False newmsg = False
fullmsg += msg.decode("utf-8") fullmsg += msg.decode("utf-8")
if len(fullmsg) - HEADERSIZE == msglen: if len(fullmsg) - HEADERSIZE == msglen:
print(f"{len(fullmsg) - HEADERSIZE} : {msglen}")
done = True done = True
return fullmsg[HEADERSIZE:] return fullmsg[HEADERSIZE:]
else:
if len(fullmsg) - HEADERSIZE > msglen:
done = True
print(f"{len(fullmsg) - HEADERSIZE} | {msglen}")
# TODO decrypt text with PGP key # TODO decrypt text with PGP key
def decryptPGP(text): def decryptPGP(text):
@@ -53,6 +60,7 @@ s.bind((host, port))
s.listen(5) s.listen(5)
while True: while True:
'''
# initial vars, connect with client device # initial vars, connect with client device
c, addr = s.accept() c, addr = s.accept()
print(f'Got connection from {addr}') print(f'Got connection from {addr}')
@@ -66,22 +74,25 @@ while True:
# update user because this might take some time # update user because this might take some time
print("Recieved data (" + str(i+1) + "/" + str(numFiles) + ")") print("Recieved data (" + str(i+1) + "/" + str(numFiles) + ")")
c.close() c.close()
'''
# decrypt the files # decrypt the files
print("Decrypting files...") print("Decrypting files...")
# get all video and key files in array (strings of file locations) # get all video and key files in array (strings of file locations)
vidset = [file for file in glob.glob("videos/encrypted/*", recursive=False)] vidset = [file for file in glob.glob("videos/encrypted/*", recursive=False)]
keyset = [file for file in glob.glob("keys/*", recursive=False)] keyset = [file for file in glob.glob("keys/*", recursive=False)]
location = "videos/plaintext/" + str(int(time.time()))
os.mkdir(location)
for i in range(len(vidset)): for i in range(len(vidset)):
# read the key and video file into vars # read the key and video file into vars
key = bytes(open(keyset[i], "r").read(), 'utf-8') key = bytes(open(keyset[i], "r").read(), 'utf-8')
text = bytes(str(open(vidset[i], "r").read()), 'utf-8') text = bytes(str(open(vidset[i], "r").read()), 'utf-8')
# write the decrypted video file info into an mp4 file # write the decrypted video file info into an mp4 file
with open("videos/plaintext/"+str(i+1)+".mp4", "wb+") as mp4: with open(location + "/" + str(i+1) + ".mp4", "wb+") as mp4:
mp4.write(decryptText(text, key)) mp4.write(decryptText(text, key))
# delete the old files # delete the old files
os.remove(vidset[i]) #os.remove(vidset[i])
os.remove(keyset[i]) #os.remove(keyset[i])
print(f"(dev mode) Would have deleted {vidset[i]} and {keyset[i]}")
print('Done') print('Done')
exit() exit()