figenc

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

commit 0d8a0c996c1c781df27e4e94504f3ee1327fcec9
parent 5d9544827000b2d85dc10cd959d129f8210111ec
Author: therealFIGBERT <figbertwelner@gmail.com>
Date:   Fri,  9 Aug 2019 09:10:38 -0700

2.0.5

Diffstat:
MScripts/check.py | 97+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----
MScripts/decrypt.py | 22++++++++++++++++++++++
MScripts/encrypt.py | 16++++++++++++++--
MScripts/figENC.py | 22++++++++++++++++------
MScripts/key.py | 8++++++++
MScripts/prompts.py | 18++++++++++++++++++
MScripts/version.txt | 4++--
MScripts/version_check.py | 5+++++
8 files changed, 178 insertions(+), 14 deletions(-)

diff --git a/Scripts/check.py b/Scripts/check.py @@ -2,6 +2,13 @@ import os, inspect, sys import prompts def password_check(first_pass, second_pass): + """Returns `True` is the two passed strings match, + `False` otherwise. + + Keyword arguments: + first_pass -- the first password/string + second_pass -- the second password/string + """ if first_pass == second_pass: return True else: @@ -9,8 +16,8 @@ def password_check(first_pass, second_pass): # def find_path(filename): -# """Return the filepath from the filename when running from a -# pyinstaller application. +# """Return the correct filepath if you are running +# figENC as a bundled application # Keyword arguments: # filename -- the filename to convert to a filepath @@ -30,7 +37,12 @@ def password_check(first_pass, second_pass): def find_path(file): - """Return the correct filename if you are running it as a script""" + """Return the correct filepath if you are running + figENC as a script + + Keyword arguments: + file -- the filename to convert to a filepath + """ return os.path.dirname( os.path.abspath( inspect.getfile( @@ -41,6 +53,16 @@ def find_path(file): def key_enc(files, pass1, pass2, key_dir): + """Return `True` if all of the conditions are valid + for fresh-key passworded encryption. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + files -- a tuple of filepaths + pass1 -- the first password + pass2 -- the second password confirmation + key_dir -- the directory where the keys are to be saved + """ broken_paths = "" for fl in files: if not os.access(fl, os.W_OK): @@ -68,6 +90,14 @@ def key_enc(files, pass1, pass2, key_dir): def weak_key_enc(files, key_dir): + """Return `True` if all of the conditions are valid + for fresh-key passwordless encryption. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + files -- a tuple of filepaths + key_dir -- the directory where the keys are to be saved + """ broken_paths = "" for fl in files: if not os.access(fl, os.W_OK): @@ -92,6 +122,14 @@ def weak_key_enc(files, key_dir): def enc(files, key_dir): + """Return `True` if all of the conditions are valid + for generated key encryption. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + files -- a tuple of filepaths + key_dir -- the directory where the keys are located + """ broken_paths = "" rsa = True for fl in files: @@ -111,7 +149,40 @@ def enc(files, key_dir): prompts.missing_keys(key_dir) -def key(key_dir): +def key(key_dir, pass1, pass2): + """Return `True` if all of the conditions are valid + for generating passworded keys. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + key_dir -- the directory where are to be saved + pass1 -- the first password + pass2 -- the second confirmation password + """ + key_dir_access = True if os.access(key_dir, os.W_OK) else False + password_match = password_check(pass1, pass2) + priv = key_dir + "/private_key.pem" + pub = key_dir + "/public_key.pem" + sym = key_dir + "/symmetric_key.key" + write_key = prompts.overwrite_prompt() if os.path.exists(priv) or os.path.exists(pub) or os.path.exists(sym) else True + if key_dir_access and write_key and password_match: + return True + else: + if not key_dir_access: + prompts.key_dir_error(key_dir) + if not password_match: + prompts.password_error(pass1, pass2) + return False + + +def weak_key(key_dir): + """Return `True` if all of the conditions are valid + for generating passwordless keys. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + key_dir -- the directory where are to be saved + """ key_dir_access = True if os.access(key_dir, os.W_OK) else False priv = key_dir + "/private_key.pem" pub = key_dir + "/public_key.pem" @@ -126,6 +197,16 @@ def key(key_dir): def dec(files, pass1, pass2, key_dir): + """Return `True` if all of the conditions are valid + for passworded decryption. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + files -- a tuple of filepaths + pass1 -- the first password + pass2 -- the second confirmation password + key_dir -- the directory where the keys are located + """ broken_paths = "" rsa = True for fl in files: @@ -155,6 +236,14 @@ def dec(files, pass1, pass2, key_dir): def weak_dec(files, key_dir): + """Return `True` if all of the conditions are valid + for passwordless decryption. Otherwise, return + `False` and prompt the user of the errors. + + Keyword arguments: + files -- a tuple of filepaths + key_dir -- the directory where the keys are located + """ broken_paths = "" rsa = True for fl in files: diff --git a/Scripts/decrypt.py b/Scripts/decrypt.py @@ -7,6 +7,13 @@ from cryptography.fernet import Fernet def rsa_dec(file, priv, passkey): + """Decrypt the passed file with a private key + + Keyword arguments: + file -- the filepath to file to decrypt + priv -- the filepath to the private key + passkey -- the password to the private key (OPTIONAL) + """ with open(priv, "rb") as priv_src, \ open(file, "rb") as read_file: private_key = serialization.load_pem_private_key( @@ -27,6 +34,14 @@ def rsa_dec(file, priv, passkey): write_file.write(original_message) def mixed_dec(file, priv, sym, passkey): + """Decrypt the passed file with an encrypted symmetric key + + Keyword arguments: + file -- the filepath to file to decrypt + priv -- the filepath to the private key + sym -- the filepath to the symmetric key + passkey -- the password to the private key (OPTIONAL) + """ with open(priv, "rb") as priv_src, \ open(sym, "rb") as sym_src, \ open(file, "rb") as read_file: @@ -55,6 +70,13 @@ def mixed_dec(file, priv, sym, passkey): def dec_manager(files, key_dir, passkey): + """Decrypt all of the passed files based on their respective tags + + Keyword arguments: + files -- a tuple of filepaths to decrypt + key_dir -- the directory where the keys are located + passkey -- the password to the private key (OPTIONAL) + """ priv = key_dir + "/private_key.pem" sym = key_dir + "/symmetric_key.key" rsa = True diff --git a/Scripts/encrypt.py b/Scripts/encrypt.py @@ -8,6 +8,12 @@ from cryptography.fernet import Fernet def RSA(target_file, public_key_source): + """Encrypts the passed file with the passed RSA public key + + Keyword arguments: + target_file -- the filepath to the file to be encrypted + public_key_source -- the filepath to the public key + """ with open(public_key_source, "rb") as public_key_file, \ open(target_file) as read_file: public_key = serialization.load_pem_public_key( @@ -30,7 +36,13 @@ def RSA(target_file, public_key_source): write_file.write(data) -def Symmetric(target_file, public_key_source, symmetric_key_source): +def Symmetric(target_file, symmetric_key_source): + """Encrypts the passed file with the passed symmetric key + + Keyword arguments: + target_file -- the filepath to the file to be encrypted + symmetric_key_source -- the filepath to the symmetric key + """ with open(symmetric_key_source, "rb") as symmetric_key_file: symmetric_key_data = symmetric_key_file.read() symmetric_key = Fernet(symmetric_key_data) @@ -63,7 +75,7 @@ def enc_manager(target_files, save_folder): else: for fl in target_files: if os.path.getsize(fl) > 446: - Symmetric(fl, pub_src, sym_src) + Symmetric(fl, sym_src) else: RSA(fl, pub_src) with open(pub_src, "rb") as pub_file, \ diff --git a/Scripts/figENC.py b/Scripts/figENC.py @@ -1,4 +1,4 @@ -import sys, json +import sys, json, getpass import tkinter as tk from tkinter import filedialog from random import choice @@ -520,8 +520,8 @@ class App(): self.settings_window.mainloop() def launch_app(self, root): - """Deiconifies the passed root window, destroys the launcher - window and updates the frame + """Deiconify the passed root window, destroy the launcher + window and update the frame Keyword arguments: root -- the main app window @@ -819,9 +819,9 @@ class App(): dec_manager(target_files, key_dir, passkey) elif mode == "weak_dec" and check.weak_dec(target_files, key_dir): dec_manager(target_files, key_dir, passkey) - elif mode == "just_key" and check.key(key_dir): + elif mode == "just_key" and check.key(key_dir, passkey, passcheck): key.just_key_manager(self.type_control.get(), key_dir, passkey) - elif mode == "weak_key" and check.key(key_dir): + elif mode == "weak_key" and check.weak_key(key_dir): key.just_key_manager(self.type_control.get(), key_dir, passkey) def pick_tip(self): @@ -880,10 +880,20 @@ class App(): self.show_pass = not self.show_pass def select_filepaths(self): + """Set the cryptofilepath variable to the tuple result of a + tkinter filenames filedialog + """ self.crypto_filepaths = filedialog.askopenfilenames() def select_key_dir(self): - self.key_paths = filedialog.askdirectory() + """Set the key_paths variable to the string result of a tkinter + askdirectory filedialog. If on MacOS, the start directory will + be home folder of the current user. + """ + if sys.platform == "darwin": + self.key_paths = filedialog.askdirectory(initialdir="/Users/%s"%getpass.getuser()) + else: + self.key_paths = filedialog.askdirectory() if __name__ == "__main__": diff --git a/Scripts/key.py b/Scripts/key.py @@ -79,6 +79,14 @@ def key_manager(target_files, save_folder, passkey): ) def just_key_manager(mode, save_folder, passkey): + """Call either the `rsa_key` function or the `mixed_key` + function, according to passed mode. + + Keyword arguments: + mode -- either 0 (RSA) or 1 (Mixed) + save_folder -- the directory to save the keys + passkey -- the password to enhance the RSA encryption (OPTIONAL) + """ rsa = True if mode == 0 else False pub_src = save_folder + "/public_key.pem" priv_src = save_folder + "/private_key.pem" diff --git a/Scripts/prompts.py b/Scripts/prompts.py @@ -29,6 +29,12 @@ def password_error(one, two): ) def file_access_error(broken_paths): + """Raise an error informing the user that some files aren't + accessible by figENC. + + Keyword arguments: + broken_paths -- a string with newlines seperating filepaths + """ messagebox.showwarning( "Filepath Access Failure", ( @@ -38,6 +44,12 @@ def file_access_error(broken_paths): ) def key_dir_error(folder): + """Raise an error informing the user that the key directory isn't + accessible by figENC. + + Keyword arguments: + folder -- a directory filepath string + """ messagebox.showwarning( "Directory Access Failure", ( @@ -48,6 +60,12 @@ def key_dir_error(folder): ) def missing_keys(folder): + """Raise an error informing the user that some keys are missing + from the passed directory + + Keyword arguments: + folder -- a directory filepath string + """ messagebox.showwarning( "Directory Missing Keys", ( diff --git a/Scripts/version.txt b/Scripts/version.txt @@ -1 +1 @@ -2.0.1 -\ No newline at end of file +2.0.5 +\ No newline at end of file diff --git a/Scripts/version_check.py b/Scripts/version_check.py @@ -2,6 +2,11 @@ import os, inspect, requests, sys from check import find_path def update_available(): + """Check against the current app version for + update availability. Return "available" if there's + an update available, "updated" if there's none available, + and "offline" if figENC can't establish a connection. + """ try: git_import = requests.get( ("https://raw.githubusercontent.com/therealFIGBERT/figENC/"