Skip to content

Commit

Permalink
Initial age Actual Good Encryption support, passphrase ONLY - decrypt…
Browse files Browse the repository at this point in the history
… only
  • Loading branch information
clach04 committed Nov 26, 2024
1 parent d4ef5c0 commit 30d5552
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
42 changes: 42 additions & 0 deletions puren_tonbo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ def __bool__(self):
except ImportError:
vimdecrypt = fake_module('vimdecrypt')

try:
#import ssage # https://github.com/esoadamo/ssage/ # does not (yet?) support passphrases
import age # https://github.com/jojonas/pyage
import age.file
import age.keys.password
except ImportError:
#ssage = fake_module('ssage')
age = fake_module('age')

try:
import puren_tonbo.mzipaes as mzipaes
Expand Down Expand Up @@ -636,6 +644,35 @@ def read_from(self, file_object):
def write_to(self, file_object, byte_data):
chi_io.write_encrypted_file(file_object, self.key, byte_data)

class Age(EncryptedFile):
description = 'AGE - Actually Good Encryption (passphrase ONLY)'
extensions = [
'.age',
]

def read_from(self, file_object):
# TODO catch exceptions and raise PurenTonboException()
# TODO AsciiArmoredInput()
#encrypted_bytes = file_object.read()
password = self.key
if not isinstance(password, bytes):
password = password.decode("utf-8")

identities = [age.keys.password.PasswordKey(password)]
with age.file.Decryptor(identities, file_object) as decryptor:
plaintext = decryptor.read()

return plaintext

def write_to(self, file_object, byte_data):
password = self.key
if not isinstance(password, bytes):
password = password.decode("utf-8")

raise NotImplementedError
crypted_bytes = b'TODO'
file_object.write(crypted_bytes)

# TODO AE-2 (no CRC), otherwise the same as AE-1 - see https://github.com/clach04/puren_tonbo/wiki/zip-format
class ZipEncryptedFileBase(EncryptedFile):
_filename = 'encrypted.md' # filename inside of (encrypted) zip file
Expand Down Expand Up @@ -777,6 +814,11 @@ class ZipBzip2AES(ZipAES):
for file_extension in enc_class.extensions:
file_type_handlers[file_extension] = enc_class

if age:
for enc_class in (Age, ):
for file_extension in enc_class.extensions:
file_type_handlers[file_extension] = enc_class

if jenc: # FIXME, handle this via introspection, see code above for RawFile

# https://github.com/clach04/jenc-py/issues/7
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ pyzipper; python_version > "2.7"
python-gnupg
openssl_enc_compat # https://github.com/clach04/openssl_enc_compat/
jenc>=0.0.3
age # 0.5.1
# pywin32 # Windows only - for GUI password prompt

percolator
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,13 @@
platforms='any', # or distutils.util.get_platform()
install_requires=install_requires,
extras_require={
'age': ['age', ], # 0.5.1
'chi_io': ['chi_io', ],
'jenc': ['jenc>=0.0.3', ],
#'ssage': ['ssage', ], # ssage-1.4.0
# TODO pyvim
# TODO python-gnupg (consider replacements before implementing https://github.com/clach04/puren_tonbo/issues/118)
'all': ['chi_io', 'jenc>=0.0.3', ], # convience, all of the above. NOTE duplicate of above
'all': ['age', 'chi_io', 'jenc>=0.0.3',], # convenience, all of the above. NOTE duplicate of above
},
zip_safe=True,
)

0 comments on commit 30d5552

Please sign in to comment.