diff --git a/puren_tonbo/__init__.py b/puren_tonbo/__init__.py index cc15e00..80e987f 100644 --- a/puren_tonbo/__init__.py +++ b/puren_tonbo/__init__.py @@ -544,6 +544,7 @@ class Jenc(EncryptedFile): extensions = [ '.jenc', # md and txt? ] + _jenc_version = None # use default (latest) def read_from(self, file_object): # TODO catch exceptions and raise PurenTonboException() @@ -560,9 +561,28 @@ def write_to(self, file_object, byte_data): if not isinstance(password, bytes): password = password.decode("utf-8") - crypted_bytes = jenc.encrypt(password, byte_data) + crypted_bytes = jenc.encrypt(password, byte_data, jenc_version=self._jenc_version) file_object.write(crypted_bytes) +class JencU001(Jenc): + description = 'Markor / jpencconverter U001 PBKDF2WithHmacSHA1 iterations 10000 AES-256-GCM' + extensions = [ + '.u001.jenc', # md and txt? + '.u001_jenc', # md and txt? + # Do NOT include generic .jenc + ] + _jenc_version = 'U001' # FIXME constant from jenc instead of literal + +class JencV001(Jenc): + description = 'Markor / jpencconverter pbkdf2-hmac-sha512 iterations 10000 AES-256-GCM' + extensions = [ + '.v001.jenc', # md and txt? + '.v001_jenc', # md and txt? + # Do NOT include generic .jenc + ] + _jenc_version = None # use default (latest) + + class TomboBlowfish(EncryptedFile): """Read/write Tombo (modified) Blowfish encrypted files Compatible with files in: @@ -728,8 +748,9 @@ class ZipBzip2AES(ZipAES): file_type_handlers[file_extension] = enc_class if jenc: # FIXME, handle this via introspection, see code above for RawFile - for file_extension in Jenc.extensions: - file_type_handlers[file_extension] = Jenc + for enc_class in (JencV001, JencU001, Jenc): # order significant for filename extension lookup + for file_extension in enc_class.extensions: + file_type_handlers[file_extension] = enc_class if chi_io: for file_extension in TomboBlowfish.extensions: @@ -767,6 +788,7 @@ class ZipBzip2AES(ZipAES): def filename2handler(filename, default_handler=None): filename = filename.lower() + # check for extensions with multiple periods/dots/fullstops if filename.endswith('.aes256.zip'): file_extn = '.aes.zip' elif filename.endswith('.aes.zip'): @@ -780,7 +802,7 @@ def filename2handler(filename, default_handler=None): elif filename.endswith('.oldstored.zip'): file_extn = '.oldstored.zip' else: - _dummy, file_extn = os.path.splitext(filename) + _dummy, file_extn = os.path.splitext(filename) # this is very agressive, splits on most-right-hand side (maybe want cipher name lookup ASWELL as filename extension) log.debug('clach04 DEBUG file_extn: %r', file_extn) log.debug('clach04 DEBUG file_type_handlers: %r', file_type_handlers) handler_class = file_type_handlers.get(file_extn) or default_handler diff --git a/puren_tonbo/tools/ptcipher.py b/puren_tonbo/tools/ptcipher.py index 3868332..3e1dd75 100755 --- a/puren_tonbo/tools/ptcipher.py +++ b/puren_tonbo/tools/ptcipher.py @@ -64,6 +64,12 @@ def file_replace(src, dst): ptcipher --cipher jenc --encrypt -p password README.md -o README.md.jenc + # NOTE underscore in cipher + ptcipher --cipher .u001_jenc --encrypt -p password README.md -o README.md.jenc + ptcipher --cipher .u001_jenc --encrypt -p password README.md -o README.md.u001.jenc + ptcipher --encrypt -p password README.md -o README.md.u001.jenc # DOES NOT YET WORK - https://github.com/clach04/puren_tonbo/issues/171 + ptcipher --encrypt -p password README.md -o README.md.jenc + """ def main(argv=None): @@ -163,6 +169,7 @@ def usage(): password = password.encode('us-ascii') if options.cipher: + #import pdb ; pdb.set_trace() handler_class = puren_tonbo.filename2handler('_.' + options.cipher) # TODO options.cipher to filename extension is less than ideal else: handler_class = None