figenc

[RADIOACTIVE] rsa and symmetric key encryption scripts and executables
git clone git://git.figbert.com/figenc.git
Log | Files | Refs | README

commit 7ae8be836ad57055970fae163dd4f98a494a383f
parent aff7eadeb28ff44bfd2bd949e10eab2989c7812c
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Sun, 28 Jul 2019 16:08:34 -0700

Updating scripts to version 1.5.3 (enhanced encryption protocol, mild visual changes)

Diffstat:
MScripts/check.py | 381+++++++++++++++++++++++++++++++++++++++++++++++--------------------------------
MScripts/decrypt.py | 123++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----------------
MScripts/encrypt.py | 114+++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------
MScripts/figENC.py | 64+++++++++++++++++++++++++++-------------------------------------
MScripts/version.txt | 4++--
MScripts/version_check.py | 7+++++--
6 files changed, 437 insertions(+), 256 deletions(-)

diff --git a/Scripts/check.py b/Scripts/check.py @@ -2,6 +2,7 @@ import errno import os from os import makedirs, path import tempfile +import inspect import sys from sys import platform import tkinter as tk @@ -143,28 +144,73 @@ def missing_key_error(save_folder): ) -def path_error(*args): +def path_error(paths): """Raise an error informing the user that the provided pathnames are invalid. Arguments: - *args -- all of the broken filepaths + paths -- all of the broken filepaths """ - errors = "" - num_errors = 0 - for arg in args: - errors += (str(arg) + "\n") - num_errors += 1 messagebox.showwarning( "Path Error", ( "One or more of the filepaths provided are invalid." "\nCheck that the filepath was entered correctly, or that the user " "has permission to edit the file." - "\n\nBroken Filepaths:\n%s" % errors + "\n\nBroken Filepaths:\n%s" % paths ) ) +def password_error(one, two): + """"Raise an error informing the user that the provided passwords + do not match. + """ + messagebox.showwarning( + "Passwords Do Not Match", + ("The passwords provided do not match. Please Try again." + "\n\nFirst: {}\nSecond: {}".format(one, two) + ) + ) + +def password_check(first_pass, second_pass): + if first_pass == second_pass: + return True + else: + password_error(first_pass, second_pass) + return False + + +# def find_path(filename): +# """Return the filepath from the filename when running from a +# pyinstaller onefile application. + +# Keyword arguments: +# filename -- the filename to convert to a filepath +# """ +# if hasattr(sys, '_MEIPASS'): +# # PyInstaller >= 1.6 +# os.chdir(sys._MEIPASS) +# filename = os.path.join(sys._MEIPASS, filename) +# elif '_MEIPASS2' in os.environ: +# # PyInstaller < 1.6 (tested on 1.5 only) +# os.chdir(os.environ['_MEIPASS2']) +# filename = os.path.join(os.environ['_MEIPASS2'], filename) +# else: +# os.chdir(os.path.dirname(sys.argv[0])) +# filename = os.path.join(os.path.dirname(sys.argv[0]), filename) +# return filename + + +def find_path(file): + """Return the correct filename if you are running it as a script""" + return os.path.dirname( + os.path.abspath( + inspect.getfile( + inspect.currentframe() + ) + ) + ) + "/{}".format(file) + def quick_check(mode, target_file_raw=None, save_folder=None): """Return `True` only if both the target file and save folder provided @@ -176,182 +222,209 @@ def quick_check(mode, target_file_raw=None, save_folder=None): target_file_raw -- a string list of pathnames save_folder -- a string pathname to a directory """ - target_file_list = target_file_raw.split(":") - for target_file in target_file_list: - if mode is "just_key" or mode is "weak_key": + save_folder += "/" if save_folder[-1] is not "/" else "" + if mode is not "just_key" or mode is not "weak_key": + target_file_list = target_file_raw.split(":") + targets_exist = True + broken_paths = "" + for target_file in target_file_list: + if targets_exist: + if not os.path.exists(target_file): + target_file = False + broken_paths += (target_file + "\n") + else: + if not os.path.exists(target_file): + broken_paths += (target_file + "\n") + if not targets_exist: + path_error(broken_paths) + return False + if ( + mode is "just_key" + or mode is "weak_key" + or mode is "key_enc" + or mode is "weak_key_enc" + ): + if platform is "win32": + if is_path_exists_or_creatable_portable(save_folder): + try: + os.makedirs(save_folder) + return True + except OSError: + if ( + os.path.exists(save_folder + "symmetric_key.key") + or os.path.exists(save_folder + "private_key.pem") + or os.path.exists(save_folder + "public_key.pem") + ): + return overwrite() + else: + return True + else: + return False + else: + if is_path_exists_or_creatable(save_folder): + try: + os.makedirs(save_folder) + return True + except OSError: + if ( + os.path.exists(save_folder + "symmetric_key.key") + or os.path.exists(save_folder + "private_key.pem") + or os.path.exists(save_folder + "public_key.pem") + ): + return overwrite() + else: + return True + else: + return False + elif mode is "dec" or mode is "weak_dec": + encryption_type = "" + for target_file in target_file_list: + with open(target_file, "rb") as read_file: + content = read_file.read() + if ( + content[-1] == b"1" + and (encryption_type is "" or encryption_type is "SYM") + ): + encryption_type = "SYM" + elif ( + content[-1] == b"1" + and (encryption_type is "RSA" or encryption_type is "MIX") + ): + encryption_type = "MIX" + elif ( + content[-1] == b"0" + and (encryption_type is "" or encryption_type is "RSA") + ): + encryption_type = "RSA" + elif ( + content[-1] == b"0" + and (encryption_type is "SYM" or encryption_type is "MIX") + ): + encryption_type = "MIX" + if encryption_type is "RSA": if platform is "win32": - if (is_path_exists_or_creatable_portable(save_folder)): - try: - makedirs(save_folder) + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + ): return True - except OSError: - if save_folder[-1] != "/": - save_folder += "/" - if ( - path.exists(save_folder + "private_key.pem") - or path.exists(save_folder + "public_key.pem") - or path.exists(save_folder + "symmetric_key.key") - ): - return overwrite() - else: - return True + else: + missing_key_error(save_folder) + return False else: return False else: - if (is_path_exists_or_creatable(save_folder)): - try: - makedirs(save_folder) + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + ): return True - except OSError: - if save_folder[-1] != "/": - save_folder += "/" - if ( - path.exists(save_folder + "private_key.pem") - or path.exists(save_folder + "public_key.pem") - or path.exists(save_folder + "symmetric_key.key") - ): - return overwrite() - else: - return True + else: + missing_key_error(save_folder) + return False else: return False - elif mode is "dec" or mode is "weak_dec" or mode is "enc": - if ( - path.exists(target_file) - and path.exists(save_folder) - ): - if save_folder[-1] is not "/": - save_folder += "/" - if mode is "enc": + else: + if platform is "win32": + if os.path.exists(save_folder): if ( - path.exists(save_folder + "public_key.pem") - and path.exists(save_folder + "symmetric_key.key") + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + and os.path.exists(save_folder + "symmetric_key.key") ): return True else: missing_key_error(save_folder) return False else: + return False + else: + if os.path.exists(save_folder): if ( - path.exists(save_folder + "private_key.pem") - and path.exists(save_folder + "symmetric_key.key") + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + and os.path.exists(save_folder + "symmetric_key.key") ): return True else: missing_key_error(save_folder) return False + else: + return False + else: + encryption_type = "" + for target_file in target_file_list: + if ( + os.path.getsize(target_file) > 446 + and (encryption_type is "" or encryption_type is "SYM") + ): + encryption_type = "SYM" elif ( - path.exists(target_file) - and not path.exists(save_folder) + os.path.getsize(target_file) > 446 + and (encryption_type is "RSA" or encryption_type is "MIX") ): - path_error(save_folder) - return False + encryption_type = "MIX" elif ( - not path.exists(target_file) - and path.exists(save_folder) + os.path.getsize(target_file) <= 446 + and (encryption_type is "" or encryption_type is "RSA") ): - path_error(target_file) - return False + encryption_type = "RSA" elif ( - not path.exists(target_file) - and not path.exists(save_folder) + os.path.getsize(target_file) <= 446 + and (encryption_type is "SYM" or encryption_type is "MIX") ): - path_error(target_file, save_folder) - return False - else: + encryption_type = "MIX" + if encryption_type is "RSA": if platform is "win32": - if ( - path.exists(target_file) - and is_path_exists_or_creatable_portable(save_folder) - ): - try: - makedirs(save_folder) + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + ): return True - except OSError: - if save_folder[-1] != "/": - save_folder += "/" - if ( - path.exists(save_folder + "private_key.pem") - or path.exists(save_folder + "public_key.pem") - or path.exists(save_folder + "symmetric_key.key") - ): - return overwrite() - else: - return True - elif ( - path.exists(target_file) - and not is_path_exists_or_creatable_portable( - save_folder - ) - ): - path_error(save_folder) - return False - elif ( - not path.exists(target_file) - and is_path_exists_or_creatable_portable(save_folder) - ): - path_error(target_file) - return False - elif ( - not path.exists(target_file) - and not is_path_exists_or_creatable_portable( - save_folder - ) - ): - path_error(target_file, save_folder) + else: + missing_key_error(save_folder) + return False + else: return False else: - if ( - path.exists(target_file) - and is_path_exists_or_creatable(save_folder) - ): - try: - makedirs(save_folder) + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + ): return True - except OSError: - if save_folder[-1] != "/": - save_folder += "/" - if ( - path.exists(save_folder + "private_key.pem") - or path.exists(save_folder + "public_key.pem") - or path.exists(save_folder + "symmetric_key.key") - ): - return overwrite() - else: - return True - elif ( - path.exists(target_file) - and not is_path_exists_or_creatable(save_folder) - ): - path_error(save_folder) - return False - elif ( - not path.exists(target_file) - and is_path_exists_or_creatable(save_folder) - ): - path_error(target_file) + else: + missing_key_error(save_folder) + return False + else: return False - elif ( - not path.exists(target_file) - and not is_path_exists_or_creatable(save_folder) - ): - path_error(target_file, save_folder) + else: + if platform is "win32": + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + and os.path.exists(save_folder + "symmetric_key.key") + ): + return True + else: + missing_key_error(save_folder) + return False + else: return False - -def password_check(first_pass, second_pass): - if first_pass == second_pass: - return True - else: - password_error(first_pass, second_pass) - return False - -def password_error(one, two): - """"Raise an error informing the user that the provided passwords - do not match. - """ - messagebox.showwarning( - "Passwords Do Not Match", - ("The passwords provided do not match. Please Try again." - "\n\nFirst: {}\nSecond: {}".format(one, two) - ) - ) -\ No newline at end of file + else: + if os.path.exists(save_folder): + if ( + os.path.exists(save_folder + "private_key.pem") + and os.path.exists(save_folder + "public_key.pem") + and os.path.exists(save_folder + "symmetric_key.key") + ): + return True + else: + missing_key_error(save_folder) + return False + else: + return False +\ No newline at end of file diff --git a/Scripts/decrypt.py b/Scripts/decrypt.py @@ -1,3 +1,5 @@ +import os +from check import find_path from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization @@ -24,37 +26,106 @@ def rsa_dec(target_file_raw, save_folder, passkey): private_key_source = save_folder + "private_key.pem" symmetric_key_source = save_folder + "symmetric_key.key" #Creating the keys from the source files - with open(private_key_source, "rb") as private_key_file, \ - open(symmetric_key_source, "rb") as symmetric_key_file: - if passkey != "": - private_key = serialization.load_pem_private_key( - private_key_file.read(), - password = bytes(passkey, "utf-8"), - backend = default_backend() + print("3. Reached the decryption for loop") + for target_file in target_file_list: + with open(target_file, "rb") as read_file: + content = read_file.read() + print("4. Opened the target file") + if content[-1] == 48: + print("5. Dectected encryption type as RSA") + with open(private_key_source, "rb") as private_key_file: + if passkey != "": + print("6. Passcode") + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = bytes(passkey, "utf-8"), + backend = default_backend() + ) + else: + print("6. No passcode") + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = None, + backend = default_backend() + ) + print("7. Private key loaded") + encrypted_data = content[:-1] + print("8. Removed final character from encrypted data") + original_message = private_key.decrypt( + encrypted_data, + padding.OAEP( + mgf=padding.MGF1(algorithm=hashes.SHA256()), + algorithm=hashes.SHA256(), + label=None ) - else: - private_key = serialization.load_pem_private_key( - private_key_file.read(), - password = None, - backend = default_backend() ) - encoded_key_data = symmetric_key_file.read() + print("9. Decrypted data") + with open(target_file, "wb") as write_file: + write_file.write(original_message) + print("10. Wrote decrypted data to file") + elif content[-1] == 49: + print("5. Detected the encryption type as symmetric") + with open(private_key_source, "rb") as private_key_file, \ + open(symmetric_key_source, "rb") as symmetric_key_file: + if passkey != "": + print("6. Passcode") + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = bytes(passkey, "utf-8"), + backend = default_backend() + ) + else: + print("6. Passcode") + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = None, + backend = default_backend() + ) + print("7. Private key loaded") + encoded_key_data = symmetric_key_file.read() + print("8. Symmetric key loaded") + symmetric_key_data = private_key.decrypt( + encoded_key_data, + padding.OAEP( + mgf = padding.MGF1(algorithm = hashes.SHA256()), + algorithm = hashes.SHA256(), + label = None + ) + ) + print("9. Symmetric key data activated") + symmetric_key = Fernet(symmetric_key_data) + print("10. Symmetric key activated") + #Decrypting and outputting the data + encrypted_data = content[:-1] + print("11. Removed final characted from encrypted data") + original_message = symmetric_key.decrypt(encrypted_data) + print("12. Decrypted data") + with open(target_file, "wb") as write_file: + write_file.write(original_message) + print("13. Wrote decrypted data to file") + if os.path.exists(symmetric_key_source): + with open(private_key_source, "rb") as private_key_file, \ + open(symmetric_key_source, "rb") as symmetric_key_file: + if passkey != "": + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = bytes(passkey, "utf-8"), + backend = default_backend() + ) + else: + private_key = serialization.load_pem_private_key( + private_key_file.read(), + password = None, + backend = default_backend() + ) + encoded_key_data = symmetric_key_file.read() symmetric_key_data = private_key.decrypt( encoded_key_data, padding.OAEP( mgf = padding.MGF1(algorithm = hashes.SHA256()), algorithm = hashes.SHA256(), label = None - ) ) - symmetric_key = Fernet(symmetric_key_data) - #Decrypting and outputting the data - for target_file in target_file_list: - with open(target_file, "rb") as read_file: - encrypted_data = read_file.read() - original_message = symmetric_key.decrypt(encrypted_data) - with open(target_file, "wb") as write_file: - write_file.write(original_message) - #Outputting the decrypted symmetric key - with open(symmetric_key_source, "wb") as symmetric_file: - symmetric_file.write(symmetric_key_data) -\ No newline at end of file + ) + with open(symmetric_key_source, "wb") as symmetric_out: + symmetric_out.write(symmetric_key_data) +\ No newline at end of file diff --git a/Scripts/encrypt.py b/Scripts/encrypt.py @@ -1,3 +1,6 @@ +import os +import inspect +from check import find_path from cryptography.hazmat.backends import default_backend from cryptography.hazmat.primitives.asymmetric import rsa from cryptography.hazmat.primitives import serialization @@ -6,6 +9,45 @@ from cryptography.hazmat.primitives.asymmetric import padding from cryptography.fernet import Fernet +def RSA(target_file, public_key_source): + with open(public_key_source, "rb") as public_key_file, \ + open(target_file) as read_file: + public_key = serialization.load_pem_public_key( + public_key_file.read(), + backend=default_backend() + ) + file_data = read_file.read() + if not isinstance(file_data, bytes): + file_data = bytes(file_data, "utf-8") + data = public_key.encrypt( + file_data, + padding.OAEP( + mgf=padding.MGF1(algorithm=hashes.SHA256()), + algorithm=hashes.SHA256(), + label=None + ) + ) + data += b"0" + with open(target_file, "wb") as write_file: + write_file.write(data) + + +def Symmetric(target_file, public_key_source, symmetric_key_source): + with open(symmetric_key_source, "rb") as symmetric_key_file: + symmetric_key_data = symmetric_key_file.read() + symmetric_key = Fernet(symmetric_key_data) + try: + with open(target_file) as read_file: + file_data = read_file.read() + file_data = bytes(file_data, "utf-8") + except UnicodeDecodeError: + with open(target_file, "rb") as read_file: + file_data = read_file.read() + data = symmetric_key.encrypt(file_data) + data += b"1" + with open(target_file, "wb") as write_file: + write_file.write(data) + def rsa_enc(target_file_raw, save_folder): """Encrypt all files passed to the function with the symmetric key, and then replace the symmetric key file's contents with an encrypted @@ -17,40 +59,42 @@ def rsa_enc(target_file_raw, save_folder): """ #Turning target_file_raw from a list in string form to a list target_file_list = target_file_raw.split(":") - if save_folder[-1] != '/': - save_folder += '/' + if save_folder[-1] != "/": + save_folder += "/" #Determining the key source - public_key_source = save_folder + 'public_key.pem' - symmetric_key_source = save_folder + 'symmetric_key.key' + public_key_source = save_folder + "public_key.pem" + symmetric_key_source = save_folder + "symmetric_key.key" + encryption_type = "" for target_file in target_file_list: - #Creating the keys from the source files - with open(public_key_source, 'rb') as public_key_file, \ - open(symmetric_key_source, 'rb') as symmetric_key_file: - public_key = serialization.load_pem_public_key( - public_key_file.read(), - backend = default_backend() + if os.path.getsize(target_file) > 446: + Symmetric(target_file, public_key_source, symmetric_key_source) + if encryption_type is "" or encryption_type is "SYM": + encryption_type = "SYM" + else: + encryption_type = "MIX" + else: + RSA(target_file, public_key_source) + if encryption_type is "" or encryption_type is "RSA": + encryption_type = "RSA" + else: + encryption_type = "MIX" + if encryption_type is "RSA": + os.remove(symmetric_key_source) + else: + with open(public_key_source, "rb") as public_key_file, \ + open(symmetric_key_source, "rb") as symmetric_key_file: + public_key = serialization.load_pem_public_key( + public_key_file.read(), + backend=default_backend() + ) + symmetric_key_data = symmetric_key_file.read() + encrypted_key = public_key.encrypt( + symmetric_key_data, + padding.OAEP( + mgf = padding.MGF1(algorithm = hashes.SHA256()), + algorithm = hashes.SHA256(), + label = None + ) ) - symmetric_key_data = symmetric_key_file.read() - symmetric_key = Fernet(symmetric_key_data) - #Encrypting and outputting the data - try: - with open(target_file) as read_file: - file_data = read_file.read() - data = symmetric_key.encrypt(bytes(file_data, 'utf-8')) - except UnicodeDecodeError: - with open(target_file, "rb") as read_file: - file_data = read_file.read() - data = symmetric_key.encrypt(file_data) - with open(target_file, 'wb') as write_file: - write_file.write(data) - #Encrypting and outputting the symmetric key - encrypted_key = public_key.encrypt( - symmetric_key_data, - padding.OAEP( - mgf = padding.MGF1(algorithm = hashes.SHA256()), - algorithm = hashes.SHA256(), - label = None - ) - ) - with open(symmetric_key_source, 'wb') as crypto_key_file: - crypto_key_file.write(encrypted_key) -\ No newline at end of file + with open(symmetric_key_source, "wb") as crypto_key_file: + crypto_key_file.write(encrypted_key) +\ No newline at end of file diff --git a/Scripts/figENC.py b/Scripts/figENC.py @@ -8,6 +8,7 @@ from encrypt import rsa_enc from decrypt import rsa_dec import version_check import check +from check import find_path class App(): @@ -20,8 +21,8 @@ class App(): """ self.crypto_mode = "" self.show_pass = False - self.settings_file = self.find_path("settings.json") - self.tips_file = self.find_path("tips.json") + self.settings_file = find_path("settings.json") + self.tips_file = find_path("tips.json") with open(self.settings_file) as settings_file: settings = json.load(settings_file) @@ -110,7 +111,7 @@ class App(): highlightthickness=0, highlightbackground="#1A181C", pady="3", - command=lambda: self.setup(self.action_list.curselection()) + command=lambda: self.setup(self.action_list.curselection(), self.frame, self.canvas) ) else: self.submit_action = tk.Button( @@ -119,7 +120,7 @@ class App(): font=("Arial", str(settings["font_size"] - 2)), bg="#643181", fg="#B494C7", - command=lambda: self.setup(self.action_list.curselection()) + command=lambda: self.setup(self.action_list.curselection(), self.frame, self.canvas) ) self.submit_action.pack() self.step_two = tk.Frame(self.frame, bg="#1A181C") @@ -298,7 +299,7 @@ class App(): font=("Arial", "10"), highlightthickness=5, highlightbackground="#1A181C", - command=lambda: self.launch_app(root, self.launcher) + command=lambda: self.launch_app(root, self.launcher, self.frame, self.canvas) ) else: self.launch_button = tk.Button( @@ -307,7 +308,7 @@ class App(): bg="#643181", text="Launch App", font=("Arial", "10"), - command=lambda: self.launch_app(root, self.launcher) + command=lambda: self.launch_app(root, self.launcher, self.frame, self.canvas) ) if sys.platform == "darwin": self.settings_button = tk.Button( @@ -332,9 +333,11 @@ class App(): self.settings_button.pack(side=tk.RIGHT) root.mainloop() - def launch_app(self, root, launcher): + def launch_app(self, root, launcher, frame, canvas): root.deiconify() launcher.destroy() + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) def open_settings(self, root): """Open the settings window and temporarily minimize the root window @@ -580,7 +583,7 @@ class App(): entry_widget.delete(0,tk.END) entry_widget.insert(0,"") - def setup(self, mode): + def setup(self, mode, frame, canvas): """"Change the GUI to match the app mode, based on the user's action_list selection. @@ -626,6 +629,8 @@ class App(): self.submit.config(text="Encrypt file/s") self.submit.pack(pady="10") self.crypto_mode = "key_enc" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 1: #Encrypt with fresh keys (no password) self.reset() self.file_frame.pack(fill="both") @@ -649,6 +654,8 @@ class App(): self.submit.config(text="Encrypt file/s") self.submit.pack(pady="10") self.crypto_mode = "weak_key_enc" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 2: #Encrypt with generated keys self.reset() self.file_frame.pack(fill="both") @@ -667,6 +674,8 @@ class App(): self.submit.config(text="Encrypt file/s") self.submit.pack(pady="10") self.crypto_mode = "enc" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 3: #Decrypt with generated keys (password locked) self.reset() self.file_frame.pack(fill="both") @@ -699,6 +708,8 @@ class App(): self.submit.config(text="Decrypt file/s") self.submit.pack(pady="10") self.crypto_mode = "dec" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 4: #Decrypt with generated keys (no password) self.reset() self.file_frame.pack(fill="both") @@ -717,6 +728,8 @@ class App(): self.submit.config(text="Decrypt file/s") self.submit.pack(pady="10") self.crypto_mode = "weak_dec" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 5: #Only create fresh keys (password locked) self.reset() self.passcode_frame.pack(fill="both") @@ -749,6 +762,8 @@ class App(): self.submit.config(text="Create keys") self.submit.pack(pady="10") self.crypto_mode = "just_key" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) elif mode == 6: #Only create fresh keys (no password) self.reset() self.save.pack(fill="both") @@ -767,6 +782,8 @@ class App(): self.submit.config(text="Create keys") self.submit.pack(pady="10") self.crypto_mode = "weak_key" + frame.update() + canvas.config(scrollregion=canvas.bbox("all")) def go( self, @@ -793,6 +810,7 @@ class App(): target_file_raw=target_file, save_folder=save_folder ): + print("1. Quick check works") if mode == "key_enc" and check.password_check(passkey, passcheck): rsa_key(passkey, save_folder) rsa_enc(target_file, save_folder) @@ -804,6 +822,7 @@ class App(): elif mode == "dec" and check.password_check(passkey, passcheck): rsa_dec(target_file, save_folder, passkey) elif mode == "weak_dec": + print("2. Reached function call") rsa_dec(target_file, save_folder, passkey) elif mode == "just_key" and check.password_check(passkey, passcheck): @@ -888,35 +907,6 @@ class App(): self.confirm_input.config(show="*") self.show_pass = not self.show_pass - def find_path(self, filename): - """Return the filepath from the filename when running from a - pyinstaller onefile application. - - Keyword arguments: - filename -- the filename to convert to a filepath - """ - if hasattr(sys, '_MEIPASS'): - # PyInstaller >= 1.6 - os.chdir(sys._MEIPASS) - filename = os.path.join(sys._MEIPASS, filename) - elif '_MEIPASS2' in os.environ: - # PyInstaller < 1.6 (tested on 1.5 only) - os.chdir(os.environ['_MEIPASS2']) - filename = os.path.join(os.environ['_MEIPASS2'], filename) - else: - os.chdir(os.path.dirname(sys.argv[0])) - filename = os.path.join(os.path.dirname(sys.argv[0]), filename) - return filename - - # def find_path(self, file): - # """Return the correct filename if you are running it as a script""" - # return os.path.dirname( - # os.path.abspath( - # inspect.getfile( - # inspect.currentframe() - # ) - # ) - # ) + "/{}".format(file) if __name__ == "__main__": root = tk.Tk() diff --git a/Scripts/version.txt b/Scripts/version.txt @@ -1 +1 @@ -1.0.3 -\ No newline at end of file +1.5.3 +\ No newline at end of file diff --git a/Scripts/version_check.py b/Scripts/version_check.py @@ -1,5 +1,7 @@ +import os +import inspect import requests -import subprocess +from check import find_path def update_available(): try: @@ -10,7 +12,8 @@ def update_available(): ).text except requests.exceptions.ConnectionError: return "offline" - with open("version.txt") as local: + version_file = find_path("version.txt") + with open(version_file) as local: local_version = local.read() if local_version < git_import: return "available"