Skip to content

Commit

Permalink
handled bad encrypted names
Browse files Browse the repository at this point in the history
decryptName returns None if encrypted name is bad (i.e. extraneous or corrupted file), letting _walker to continue its enumeration
  • Loading branch information
maxpat78 committed Nov 6, 2024
1 parent 199db14 commit 1f9758f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
2 changes: 1 addition & 1 deletion pycryptomator/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
COPYRIGHT = '''Copyright (C)2024, by maxpat78.'''
__version__ = '1.12'
__version__ = '1.14'
__all__ = ["Vault", "init_vault", "backupDirIds"]
from .cryptomator import *
18 changes: 13 additions & 5 deletions pycryptomator/cryptomator.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ def encryptName(p, dirId, name):

def decryptName(p, dirId, name):
"Decrypt a .c9r name"
assert name[-4:] == b'.c9r'
dname = d64(name[:-4], 1)
return aes_siv_decrypt(p.pk, p.hk, dname, dirId)
try:
assert name[-4:] == b'.c9r'
dname = d64(name[:-4], 1)
return aes_siv_decrypt(p.pk, p.hk, dname, dirId)
except:
print('ERROR: could not decrypt name', name.decode())
return None

def getInfo(p, virtualpath):
"Query information about a vault's virtual path name and get a PathInfo object"
Expand Down Expand Up @@ -733,10 +737,14 @@ def _walker(p, pathname, mode='walk'):
if it.name.endswith('.c9s'): # deflated long name
# A c9s dir contains the original encrypted long name (name.c9s) and encrypted contents (contents.c9r)
ename = open(join(realpath, it.name, 'name.c9s')).read()
dname = p.decryptName(dirId.encode(), ename.encode()).decode()
dname = p.decryptName(dirId.encode(), ename.encode())
if dname == None: continue
dname = dname.decode()
if exists(join(realpath, it.name, 'contents.c9r')): is_dir = False
else:
dname = p.decryptName(dirId.encode(), it.name.encode()).decode()
dname = p.decryptName(dirId.encode(), it.name.encode())
if dname == None: continue
dname = dname.decode()
sl = join(realpath, it.name, 'symlink.c9r')
if is_dir and exists(sl):
# Decrypt and look at symbolic link target
Expand Down

0 comments on commit 1f9758f

Please sign in to comment.