Skip to content
Open
Changes from 1 commit
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
4dca99e
Added example config file
Kenneth-W-Chen Mar 28, 2023
6283424
Changed prints to use python3 syntax
Kenneth-W-Chen Mar 28, 2023
b0e669b
Changed functions to match updated praw functions
Kenneth-W-Chen Mar 28, 2023
da47fdf
Fixed byte + str issues; Switched to use cryptodome inherent pad func…
Kenneth-W-Chen Mar 31, 2023
e0213de
Adjusted to use the subreddit obj instead
Kenneth-W-Chen Mar 31, 2023
ed55f49
Changed to wxPython's new window filter namings
Kenneth-W-Chen Mar 31, 2023
539d3b7
Added extra info; may not need username, password fields anymore in w…
Kenneth-W-Chen Mar 31, 2023
2b24b85
Removed pathname; only filename is posted now
Kenneth-W-Chen Mar 31, 2023
6450947
Getting files now works. Doesn't resolve filename conflicts though
Kenneth-W-Chen Mar 31, 2023
3beea76
Fixed bug from putting full pathname in Get window's fileToGetField f…
Kenneth-W-Chen Mar 31, 2023
7622a48
Added some PEP suppressions
Kenneth-W-Chen Mar 31, 2023
c70ae7f
Updated to stop using deprecated libraries and functions
Kenneth-W-Chen Mar 31, 2023
05338ca
Removed unused globals
Kenneth-W-Chen Mar 31, 2023
dc5f6f3
Renamed vars to more descriptive names
Kenneth-W-Chen Mar 31, 2023
f9d4ec9
Removed unnecessary fields in window
Kenneth-W-Chen Mar 31, 2023
1ed5b9f
Added praw.ini which stores passwords and secrets
Kenneth-W-Chen Mar 31, 2023
84c12a9
Rewrote to be more descriptive
Kenneth-W-Chen Mar 31, 2023
2c87532
Update gitignore to include project dependency directories
Kenneth-W-Chen Apr 7, 2023
5086cf5
Put app initialization into its own function
Kenneth-W-Chen Apr 7, 2023
c709e16
Create 'main.py'; this is the new script to run
Kenneth-W-Chen Apr 7, 2023
6e30655
Renamed some vars to be more descriptive
Kenneth-W-Chen Apr 8, 2023
fea2aa9
Password is hashed with argon2id; now using AES-GCM
Kenneth-W-Chen Apr 8, 2023
d63f936
Update encrypt to include MAC in post content; adjust encrypt logic
Kenneth-W-Chen Apr 8, 2023
1d363a3
Decrypt set up; Added DocString; Refactoring to be more descriptive
Kenneth-W-Chen Apr 9, 2023
a5e1635
Subreddit is now set in the config file instead of redditglobals.py
Kenneth-W-Chen Apr 9, 2023
d07533f
Adjusted to match new decryption stuff
Kenneth-W-Chen Apr 9, 2023
67b9765
Changed typehints to Tuple
Kenneth-W-Chen Apr 9, 2023
e43b44b
Encryption and decryption now works; parameters are in post text
Kenneth-W-Chen Apr 9, 2023
3426a02
Adjusted note about Reddit search
Kenneth-W-Chen Apr 9, 2023
22fe8ef
Reformatting and improve DocString
Kenneth-W-Chen Apr 10, 2023
720c855
Merge remote-tracking branch 'origin/python3' into python3
Kenneth-W-Chen Apr 12, 2023
a1b22ea
Now encrypts as it reads file instead of loading entire file first; s…
Kenneth-W-Chen Apr 12, 2023
923f4b7
Added sleep to prevent rate limiting/banning
Kenneth-W-Chen Apr 12, 2023
c399205
Some documentation
Kenneth-W-Chen Apr 12, 2023
d84cea9
Documentation done.
Kenneth-W-Chen Apr 12, 2023
e237340
Added DocString to some vars
Kenneth-W-Chen Apr 12, 2023
69fb85d
Added DocString to some vars
Kenneth-W-Chen Apr 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions crypt.py

@Kenneth-W-Chen Kenneth-W-Chen Apr 12, 2023

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to say a1b22ea will make it slightly faster because we don't have to load the entire file into memory and then encrypt it, with both the ciphertext and plaintext stored at once

Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,37 @@ def __init__(self, key: str):
"""
# argon2 outputs a single string with all parameters delimited by a '$'
self.argon2 = self.hasher.hash(key)
"""The argon2 parameters, salt, and hash, as output by PasswordHasher"""

self.argon2params, self.salt, self.hash = self.extract_parameters(self.argon2)

# argon2-cffi encodes the values in base64, so we decode it here to get our byte values
# And we need to add padding '=' because reasons b64 needs that number of chars
self.key: bytes = b64decode(self.hash + '=') # Should be 32 bytes long
"""The key for encrypting, in raw byte form; 32 bytes long"""
self.secret = key
"""The password hashed to generate the key"""

# encrypts a file and returns a comment to be posted
def encrypt_file(self, file_path: str) -> Tuple[bytes, bytes, bytes]:
"""
Encrypts a file and returns the ciphertext and associated MAC
:param file_path: The path to the file to encrypt
:return: A list containing [ciphertext, MAC]
:return: A list containing [ciphertext, MAC, nonce]
"""
cipher = AES.new(self.key, AES.MODE_GCM)
ciphertext = b''
with open(file_path, 'rb') as fo:
plaintext = fo.read()
enc = self._encrypt(plaintext)
while True:
plaintext = fo.read(20000)
if not plaintext:
break
ciphertext += cipher.encrypt(plaintext)
mac = cipher.digest()
# comment = enc.decode('ISO-8859-1').encode('ascii')
print('\nEncryption info:\nMAC: ', enc[1], '\nSalt: ', self.salt, '\nKey: ', self.hash, '\nSecret: ',
print('\nEncryption info:\nMAC: ', mac, '\nSalt: ', self.salt, '\nKey: ', self.hash, '\nSecret: ',
self.secret)
return enc[0], enc[1], enc[2]
return ciphertext, mac, cipher.nonce

# takes in a comment to be posted and decrypts it into a file

Expand Down Expand Up @@ -67,16 +78,16 @@ def decrypt_to_file(self, encrypt_items: Tuple[bytes, List[str]], file_path: str
with open(file_path, 'wb') as fo:
fo.write(dec)

# encrypts plaintext and generates IV (initialization vector)
def _encrypt(self, plaintext: Union[str, bytes]) -> Tuple[bytes, bytes, bytes]:
"""
Returns the AES-GCM-encrypted ciphertext and MAC
:param plaintext: The plaintext to encrypt
:return: A Tuple containing [ciphertext, MAC]
"""
cipher = AES.new(self.key, AES.MODE_GCM)
ciphertext_mac = cipher.encrypt_and_digest(plaintext)
return ciphertext_mac[0], ciphertext_mac[1], cipher.nonce
# # encrypts plaintext and generates IV (initialization vector)
# def _encrypt(self, plaintext: Union[str, bytes]) -> Tuple[bytes, bytes, bytes]:
# """
# Returns the AES-GCM-encrypted ciphertext and MAC
# :param plaintext: The plaintext to encrypt
# :return: A Tuple containing [ciphertext, MAC]
# """
# cipher = AES.new(self.key, AES.MODE_GCM)
# ciphertext_mac = cipher.encrypt_and_digest(plaintext)
# return ciphertext_mac[0], ciphertext_mac[1], cipher.nonce

# decrypts ciphertexts
def _decrypt(self, ciphertext: bytes, mac_tag: bytes, salt: bytes, nonce: bytes,
Expand Down