Skip to content

Commit

Permalink
ptrecrypt and experimental v002 jenc support #170
Browse files Browse the repository at this point in the history
  • Loading branch information
clach04 committed Nov 17, 2024
1 parent 19709f5 commit 0efb97e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
13 changes: 11 additions & 2 deletions puren_tonbo/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,16 @@ class JencV001(Jenc):
'.v001_jenc', # md and txt?
# Do NOT include generic .jenc
]
_jenc_version = None # use default (latest)
_jenc_version = 'V001'

class JencV002(Jenc):
description = 'Markor / jpencconverter pbkdf2-hmac-sha512 iterations 210000 AES-256-GCM'
extensions = [
'.v002.jenc', # md and txt?
'.v002_jenc', # md and txt?
# Do NOT include generic .jenc
]
_jenc_version = 'V002'


class TomboBlowfish(EncryptedFile):
Expand Down Expand Up @@ -757,7 +766,7 @@ class ZipBzip2AES(ZipAES):
file_type_handlers[file_extension] = enc_class

if jenc: # FIXME, handle this via introspection, see code above for RawFile
for enc_class in (JencV001, JencU001, Jenc): # order significant for filename extension lookup
for enc_class in (JencV002, JencV001, JencU001, Jenc): # order significant for filename extension lookup
for file_extension in enc_class.extensions:
file_type_handlers[file_extension] = enc_class

Expand Down
26 changes: 26 additions & 0 deletions puren_tonbo/tools/ptrecrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,16 @@
python -m puren_tonbo.tools.ptrecrypt --existing_files skip --cipher .v001_jenc --new_extension .jenc -p password --destination_directory /tmp/all_jenc puren_tonbo/tests/data/
python -m puren_tonbo.tools.ptrecrypt --existing_files replace --cipher .v001_jenc --new_extension .jenc -p password --destination_directory /tmp/all_jenc puren_tonbo/tests/data/
git clone https://github.com/Zettelkasten-Method/10000-markdown-files
cd 10000-markdown-files
python -m puren_tonbo.tools.ptrecrypt --cipher .v001_jenc --new_extension .jenc -p password --destination_directory 10k_v001_jenc "10000 markdown files"
python -m puren_tonbo.tools.ptrecrypt --cipher .v002_jenc --new_extension .jenc -p password --destination_directory 10k_v002wip_jenc "10000 markdown files"
python -m puren_tonbo.tools.ptrecrypt --cipher .u001_jenc --new_extension .jenc -p password --destination_directory /tmp/all_jenc puren_tonbo/tests/data/merge3_base.txt
python -m puren_tonbo.tools.ptrecrypt --cipher .v001_jenc --new_extension .jenc -p password --destination_directory /tmp/all_jenc puren_tonbo/tests/data/merge3_base.txt
python -m puren_tonbo.tools.ptrecrypt --cipher .v002_jenc --new_extension .jenc -p password --destination_directory /tmp/all_jenc puren_tonbo/tests/data/merge3_base.txt
python -m puren_tonbo.tools.ptrecrypt --simulate -p password --force_recrypt_same_format_password --existing_files replace --skip_unencrypted puren_tonbo/tests/data/
"""

Expand Down Expand Up @@ -227,6 +237,22 @@ def usage():
parser.print_usage()

if options.cipher:
if options.cipher == '.v002_jenc':
# hack time
import jenc

# https://github.com/clach04/jenc-py/issues/7
if 'V002' not in jenc.jenc_version_details:
jenc.jenc_version_details['V002'] = {
'keyFactory': jenc.JENC_PBKDF2WithHmacSHA512,
'keyIterationCount': 210000, # taken 2024-11-12 from https://cheatsheetseries.owasp.org/cheatsheets/Password_Storage_Cheat_Sheet.html#pbkdf2
'keyLength': 256,
'keyAlgorithm': 'AES',
'keySaltLength': 64, # in bytes
'cipher': jenc.JENC_AES_GCM_NoPadding,
'nonceLenth': 32, # nonceLenth (sic.) == Nonce Length, i.e. IV length # in bytes
}

handler_class_newfile = puren_tonbo.filename2handler('_.' + options.cipher) # TODO options.cipher to filename extension is less than ideal
else:
handler_class_newfile = None
Expand Down

0 comments on commit 0efb97e

Please sign in to comment.