mirror of
https://github.com/HACKERALERT/Picocrypt.git
synced 2025-01-01 12:22:25 +00:00
Added bulletproof reliability with minor fixes
This commit is contained in:
parent
5063ea3ac1
commit
061c096338
1 changed files with 20 additions and 69 deletions
|
@ -10,8 +10,8 @@ try:
|
||||||
from Crypto.Cipher import ChaCha20_Poly1305
|
from Crypto.Cipher import ChaCha20_Poly1305
|
||||||
except:
|
except:
|
||||||
from os import system
|
from os import system
|
||||||
system("python3 -m pip install argon2-cffi")
|
system("python3 -m pip install argon2-cffi --user")
|
||||||
system("python3 -m pip install pycryptodome")
|
system("python3 -m pip install pycryptodome --user")
|
||||||
|
|
||||||
from tkinter import filedialog,messagebox
|
from tkinter import filedialog,messagebox
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
|
@ -38,14 +38,13 @@ corruptedNotice = "Error. The input file is corrupted."
|
||||||
modifiedNotice = "Error. The input file has been intentionally modified."
|
modifiedNotice = "Error. The input file has been intentionally modified."
|
||||||
kCorruptedNotice = "The input file is corrupted, but the output has been kept."
|
kCorruptedNotice = "The input file is corrupted, but the output has been kept."
|
||||||
kModifiedNotice = "The input file has been intentionally modified, but the output has been kept."
|
kModifiedNotice = "The input file has been intentionally modified, but the output has been kept."
|
||||||
derivingNotice = "Deriving key... (takes a few seconds)"
|
derivingNotice = "Deriving key (takes a few seconds)..."
|
||||||
keepNotice = "Keep decrypted output even if it's corrupted or modified"
|
keepNotice = "Keep decrypted output even if it's corrupted or modified"
|
||||||
kept = False
|
kept = False
|
||||||
eraseNotice = "Securely erase and delete original file"
|
eraseNotice = "Securely erase and delete original file"
|
||||||
working = False
|
working = False
|
||||||
overwriteNotice = "Output file already exists. Would you like to overwrite it?"
|
overwriteNotice = "Output file already exists. Would you like to overwrite it?"
|
||||||
unknownErrorNotice = "Unknown error occured. Please try again or view the logs."
|
unknownErrorNotice = "Unknown error occured. Please try again."
|
||||||
log = ""
|
|
||||||
|
|
||||||
tk = tkinter.Tk()
|
tk = tkinter.Tk()
|
||||||
tk.geometry("480x420")
|
tk.geometry("480x420")
|
||||||
|
@ -60,9 +59,9 @@ s = tkinter.ttk.Style()
|
||||||
s.configure("TCheckbutton",background="#f5f6f7")
|
s.configure("TCheckbutton",background="#f5f6f7")
|
||||||
|
|
||||||
def inputSelected():
|
def inputSelected():
|
||||||
global inputFile,working,log
|
global inputFile,working
|
||||||
dummy.focus()
|
dummy.focus()
|
||||||
log += "File selection dialog opened\n"
|
|
||||||
try:
|
try:
|
||||||
suffix = ""
|
suffix = ""
|
||||||
tmp = filedialog.askopenfilename(
|
tmp = filedialog.askopenfilename(
|
||||||
|
@ -90,7 +89,6 @@ def inputSelected():
|
||||||
adLabelString.set("File metadata (read only):")
|
adLabelString.set("File metadata (read only):")
|
||||||
keepBtn["state"] = "normal"
|
keepBtn["state"] = "normal"
|
||||||
eraseBtn["state"] = "disabled"
|
eraseBtn["state"] = "disabled"
|
||||||
log += "File selected, will decrypt\n"
|
|
||||||
else:
|
else:
|
||||||
eraseBtn["state"] = "normal"
|
eraseBtn["state"] = "normal"
|
||||||
keepBtn["state"] = "disabled"
|
keepBtn["state"] = "disabled"
|
||||||
|
@ -98,17 +96,18 @@ def inputSelected():
|
||||||
adArea.delete("1.0",tkinter.END)
|
adArea.delete("1.0",tkinter.END)
|
||||||
suffix = " (will be encrypted)"
|
suffix = " (will be encrypted)"
|
||||||
adLabelString.set(adString)
|
adLabelString.set(adString)
|
||||||
log += "File selected, will encrypt\n"
|
|
||||||
inputString.set(inputFile.split("/")[-1]+suffix)
|
inputString.set(inputFile.split("/")[-1]+suffix)
|
||||||
passwordInput["state"] = "normal"
|
passwordInput["state"] = "normal"
|
||||||
|
passwordInput.delete(0,"end")
|
||||||
startBtn["state"] = "normal"
|
startBtn["state"] = "normal"
|
||||||
statusString.set("Ready.")
|
statusString.set("Ready.")
|
||||||
progress["value"] = 0
|
progress["value"] = 0
|
||||||
except UnicodeDecodeError as e:
|
except UnicodeDecodeError:
|
||||||
log += str(e)+"\n"
|
passwordInput["state"] = "normal"
|
||||||
|
passwordInput.delete(0,"end")
|
||||||
statusString.set(corruptedNotice)
|
statusString.set(corruptedNotice)
|
||||||
except Exception as e:
|
except:
|
||||||
log += str(e)+"\n"
|
pass
|
||||||
finally:
|
finally:
|
||||||
dummy.focus()
|
dummy.focus()
|
||||||
working = False
|
working = False
|
||||||
|
@ -155,9 +154,7 @@ passwordInput.grid(sticky="nesw")
|
||||||
passwordInput["state"] = "disabled"
|
passwordInput["state"] = "disabled"
|
||||||
|
|
||||||
def start():
|
def start():
|
||||||
global inputFile,outputFile,password,ad,kept,working,log
|
global inputFile,outputFile,password,ad,kept,working
|
||||||
|
|
||||||
log += "Starting the encryption/decryption process\n"
|
|
||||||
|
|
||||||
if ".pcf" not in inputFile:
|
if ".pcf" not in inputFile:
|
||||||
mode = "encrypt"
|
mode = "encrypt"
|
||||||
|
@ -168,10 +165,8 @@ def start():
|
||||||
try:
|
try:
|
||||||
getsize(outputFile)
|
getsize(outputFile)
|
||||||
force = messagebox.askyesno("Warning",overwriteNotice)
|
force = messagebox.askyesno("Warning",overwriteNotice)
|
||||||
log += "Overwrite set to true\n"
|
|
||||||
dummy.focus()
|
dummy.focus()
|
||||||
if force!=1:
|
if force!=1:
|
||||||
log += "Cancelled because overwrite set to false\n"
|
|
||||||
return
|
return
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
@ -181,12 +176,9 @@ def start():
|
||||||
password = passwordInput.get().encode("utf-8")
|
password = passwordInput.get().encode("utf-8")
|
||||||
ad = adArea.get("1.0",tkinter.END).encode("utf-8")
|
ad = adArea.get("1.0",tkinter.END).encode("utf-8")
|
||||||
wipe = erase.get()==1
|
wipe = erase.get()==1
|
||||||
if wipe and mode=="encrypt":
|
|
||||||
log += "Secure wipe enabled\n"
|
|
||||||
elif not wipe and mode=="encrypt":
|
|
||||||
log += "Secure wipe disabled\n"
|
|
||||||
|
|
||||||
selectFileInput["state"] = "disabled"
|
selectFileInput["state"] = "disabled"
|
||||||
|
eraseBtn["state"] = "disabled"
|
||||||
passwordInput["state"] = "disabled"
|
passwordInput["state"] = "disabled"
|
||||||
adArea["state"] = "disabled"
|
adArea["state"] = "disabled"
|
||||||
startBtn["state"] = "disabled"
|
startBtn["state"] = "disabled"
|
||||||
|
@ -226,8 +218,6 @@ def start():
|
||||||
progress.config(mode="indeterminate")
|
progress.config(mode="indeterminate")
|
||||||
progress.start(15)
|
progress.start(15)
|
||||||
|
|
||||||
log += "Generating key through Argon2\n"
|
|
||||||
|
|
||||||
key = hash_secret_raw(
|
key = hash_secret_raw(
|
||||||
password,
|
password,
|
||||||
salt,
|
salt,
|
||||||
|
@ -245,9 +235,7 @@ def start():
|
||||||
check = sha3_512(key).digest()
|
check = sha3_512(key).digest()
|
||||||
|
|
||||||
if mode=="decrypt":
|
if mode=="decrypt":
|
||||||
log += "Checking if key is correct"
|
|
||||||
if not compare_digest(check,cs):
|
if not compare_digest(check,cs):
|
||||||
log += "\nIncorrect password\n"
|
|
||||||
statusString.set(passwordNotice)
|
statusString.set(passwordNotice)
|
||||||
fin.close()
|
fin.close()
|
||||||
fout.close()
|
fout.close()
|
||||||
|
@ -260,7 +248,6 @@ def start():
|
||||||
working = False
|
working = False
|
||||||
del key
|
del key
|
||||||
return
|
return
|
||||||
log += " (yes)\n"
|
|
||||||
|
|
||||||
cipher = ChaCha20_Poly1305.new(key=key,nonce=nonce)
|
cipher = ChaCha20_Poly1305.new(key=key,nonce=nonce)
|
||||||
crc = sha3_512()
|
crc = sha3_512()
|
||||||
|
@ -274,7 +261,6 @@ def start():
|
||||||
wiper = open(inputFile,"r+b")
|
wiper = open(inputFile,"r+b")
|
||||||
wiper.seek(0)
|
wiper.seek(0)
|
||||||
|
|
||||||
log += "Encryption/decryption starting\n"
|
|
||||||
while True:
|
while True:
|
||||||
piece = fin.read(chunkSize)
|
piece = fin.read(chunkSize)
|
||||||
if wipe:
|
if wipe:
|
||||||
|
@ -293,13 +279,11 @@ def start():
|
||||||
else:
|
else:
|
||||||
crcdg = crc.digest()
|
crcdg = crc.digest()
|
||||||
if not compare_digest(crccs,crcdg):
|
if not compare_digest(crccs,crcdg):
|
||||||
log += "Data is corrupted\n"
|
|
||||||
statusString.set(corruptedNotice)
|
statusString.set(corruptedNotice)
|
||||||
progress["value"] = 100
|
progress["value"] = 100
|
||||||
fin.close()
|
fin.close()
|
||||||
fout.close()
|
fout.close()
|
||||||
if keep.get()!=1:
|
if keep.get()!=1:
|
||||||
log += "Corrupted output has been kept\n"
|
|
||||||
remove(outputFile)
|
remove(outputFile)
|
||||||
selectFileInput["state"] = "normal"
|
selectFileInput["state"] = "normal"
|
||||||
passwordInput["state"] = "normal"
|
passwordInput["state"] = "normal"
|
||||||
|
@ -314,13 +298,11 @@ def start():
|
||||||
try:
|
try:
|
||||||
cipher.verify(digest)
|
cipher.verify(digest)
|
||||||
except:
|
except:
|
||||||
log += "Data has been modified\n"
|
|
||||||
statusString.set(modifiedNotice)
|
statusString.set(modifiedNotice)
|
||||||
progress["value"] = 100
|
progress["value"] = 100
|
||||||
fin.close()
|
fin.close()
|
||||||
fout.close()
|
fout.close()
|
||||||
if keep.get()!=1:
|
if keep.get()!=1:
|
||||||
log += "Modified output has been kept\n"
|
|
||||||
remove(outputFile)
|
remove(outputFile)
|
||||||
selectFileInput["state"] = "normal"
|
selectFileInput["state"] = "normal"
|
||||||
passwordInput["state"] = "normal"
|
passwordInput["state"] = "normal"
|
||||||
|
@ -407,13 +389,12 @@ def start():
|
||||||
kept = False
|
kept = False
|
||||||
working = False
|
working = False
|
||||||
del fin,fout,cipher,key
|
del fin,fout,cipher,key
|
||||||
log += "Process completed\n"
|
|
||||||
|
|
||||||
def wrapper():
|
def wrapper():
|
||||||
global working,log
|
global working
|
||||||
try:
|
try:
|
||||||
start()
|
start()
|
||||||
except Exception as e:
|
except:
|
||||||
selectFileInput["state"] = "normal"
|
selectFileInput["state"] = "normal"
|
||||||
passwordInput["state"] = "normal"
|
passwordInput["state"] = "normal"
|
||||||
adArea["state"] = "normal"
|
adArea["state"] = "normal"
|
||||||
|
@ -422,7 +403,6 @@ def wrapper():
|
||||||
statusString.set(unknownErrorNotice)
|
statusString.set(unknownErrorNotice)
|
||||||
dummy.focus()
|
dummy.focus()
|
||||||
working = False
|
working = False
|
||||||
log += str(e)+"\n"
|
|
||||||
finally:
|
finally:
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
@ -515,7 +495,7 @@ status = tkinter.ttk.Label(
|
||||||
status.place(x=17,y=356)
|
status.place(x=17,y=356)
|
||||||
status.config(background="#f5f6f7")
|
status.config(background="#f5f6f7")
|
||||||
|
|
||||||
hint = "(v1.4) Created by Evan Su. Click for details and source."
|
hint = "Created by Evan Su. Click for details and source."
|
||||||
creditsString = tkinter.StringVar(tk)
|
creditsString = tkinter.StringVar(tk)
|
||||||
creditsString.set(hint)
|
creditsString.set(hint)
|
||||||
credits = tkinter.ttk.Label(
|
credits = tkinter.ttk.Label(
|
||||||
|
@ -530,43 +510,14 @@ source = "https://github.com/HACKERALERT/Picocrypt"
|
||||||
credits.bind("<Button-1>",lambda e:webbrowser.open(source))
|
credits.bind("<Button-1>",lambda e:webbrowser.open(source))
|
||||||
|
|
||||||
versionString = tkinter.StringVar(tk)
|
versionString = tkinter.StringVar(tk)
|
||||||
versionString.set("Logs")
|
versionString.set("v1.5")
|
||||||
version = tkinter.ttk.Label(
|
version = tkinter.ttk.Label(
|
||||||
tk,
|
tk,
|
||||||
textvariable=versionString,
|
textvariable=versionString
|
||||||
cursor="hand2"
|
|
||||||
)
|
)
|
||||||
version["state"] = "disabled"
|
version["state"] = "disabled"
|
||||||
version.config(background="#f5f6f7")
|
version.config(background="#f5f6f7")
|
||||||
version.place(x=430,y=386)
|
version.place(x=436,y=386)
|
||||||
version.bind("<Button-1>",lambda e:showLog())
|
|
||||||
|
|
||||||
def showLogWrapper():
|
|
||||||
logger = tkinter.Tk()
|
|
||||||
logger.geometry("480x420")
|
|
||||||
logger.title("Logs")
|
|
||||||
logger.resizable(0,0)
|
|
||||||
loggerFrame = tkinter.Frame(
|
|
||||||
logger,
|
|
||||||
width=480,
|
|
||||||
height=420
|
|
||||||
)
|
|
||||||
loggerFrame.place(x=0,y=0)
|
|
||||||
loggerFrame.columnconfigure(0,weight=10)
|
|
||||||
loggerFrame.grid_propagate(False)
|
|
||||||
box = tkinter.scrolledtext.ScrolledText(
|
|
||||||
loggerFrame,
|
|
||||||
)
|
|
||||||
box.config(font=("Consolas",11))
|
|
||||||
box.grid(sticky="nesw")
|
|
||||||
box.insert("1.0",log)
|
|
||||||
box["state"] = "disabled"
|
|
||||||
logger.mainloop()
|
|
||||||
sys.exit(0)
|
|
||||||
|
|
||||||
def showLog():
|
|
||||||
t = Thread(target=showLogWrapper,daemon=True)
|
|
||||||
t.start()
|
|
||||||
|
|
||||||
dummy = tkinter.ttk.Button(
|
dummy = tkinter.ttk.Button(
|
||||||
tk
|
tk
|
||||||
|
|
Loading…
Reference in a new issue