Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor fixes #20

Merged
merged 3 commits into from
Oct 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
Next Next commit
Improve error message
  • Loading branch information
nolze committed Oct 16, 2018
commit 142b87ec66d3e64294d13c4aa404abdb266318ed
2 changes: 1 addition & 1 deletion msoffcrypto/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ def OfficeFile(file):
from .format.xls97 import Xls97File
return Xls97File(file)
else:
raise AssertionError("Unrecognized file format")
raise Exception("Unrecognized file format")
4 changes: 2 additions & 2 deletions msoffcrypto/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ def main():
return

if not olefile.isOleFile(args.infile):
raise AssertionError("Not OLE file")
raise Exception("Not OLE file")

file = OfficeFile(args.infile)

if args.password:
file.load_key(password=args.password)
else:
raise AssertionError("Password is required")
raise Exception("Password is required")

if args.outfile is None:
ifWIN32SetBinary(sys.stdout)
Expand Down
6 changes: 3 additions & 3 deletions msoffcrypto/format/doc97.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ def load_key(self, password=None):
self.key = password
self.salt = info['salt']
else:
raise AssertionError("Failed to verify password")
raise Exception("Failed to verify password")
elif vMajor in [0x0002, 0x0003, 0x0004] and vMinor == 0x0002: # RC4 CryptoAPI
info = _parse_header_RC4CryptoAPI(encryptionHeader)
if DocumentRC4CryptoAPI.verifypw(password, info['salt'], info['keySize'],
Expand All @@ -327,9 +327,9 @@ def load_key(self, password=None):
self.salt = info['salt']
self.keySize = info['keySize']
else:
raise AssertionError("Failed to verify password")
raise Exception("Failed to verify password")
else:
raise AssertionError("Unsupported encryption method")
raise Exception("Unsupported encryption method")

def decrypt(self, ofile):
# fd, _ofile_path = tempfile.mkstemp()
Expand Down
6 changes: 3 additions & 3 deletions msoffcrypto/format/ooxml.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def _parseinfo(ole):
elif versionMajor in [2, 3, 4] and versionMinor == 2: # Standard
return 'standard', _parseinfo_standard(ole)
elif versionMajor in [3, 4] and versionMinor == 3: # Extensible
raise AssertionError("Unsupported EncryptionInfo version (Extensible Encryption)")
raise Exception("Unsupported EncryptionInfo version (Extensible Encryption)")


class OOXMLFile(base.BaseOfficeFile):
Expand Down Expand Up @@ -113,14 +113,14 @@ def load_key(self, password=None, private_key=None, secret_key=None, strict=Fals
self.info['verifier']['encryptedVerifierHash']
)
if not verified:
raise AssertionError()
raise Exception("Key verification failed")
elif self.type == 'extensible':
pass
elif private_key:
if self.type == 'agile':
self.secret_key = ECMA376Agile.makekey_from_privkey(private_key, self.info['encryptedKeyValue'])
else:
raise AssertionError("Unsupported key type for the encryption method")
raise Exception("Unsupported key type for the encryption method")
elif secret_key:
self.secret_key = secret_key

Expand Down
10 changes: 5 additions & 5 deletions msoffcrypto/format/xls97.py
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ def load_key(self, password=None):
wEncryptionType, = unpack("<H", workbook.data.read(2))

if wEncryptionType == 0x0000: # XOR obfuscation
raise AssertionError("Unsupported encryption method")
raise Exception("Unsupported encryption method")
elif wEncryptionType == 0x0001: # RC4
pass

Expand All @@ -499,7 +499,7 @@ def load_key(self, password=None):
self.key = password
self.salt = info['salt']
else:
raise AssertionError("Failed to verify password")
raise Exception("Failed to verify password")
elif vMajor in [0x0002, 0x0003, 0x0004] and vMinor == 0x0002: # RC4 CryptoAPI
info = _parse_header_RC4CryptoAPI(encryptionInfo)
if DocumentRC4CryptoAPI.verifypw(password, info['salt'], info['keySize'],
Expand All @@ -509,9 +509,9 @@ def load_key(self, password=None):
self.salt = info['salt']
self.keySize = info['keySize']
else:
raise AssertionError("Failed to verify password")
raise Exception("Failed to verify password")
else:
raise AssertionError("Unsupported encryption method")
raise Exception("Unsupported encryption method")

def decrypt(self, ofile):
# fd, _ofile_path = tempfile.mkstemp()
Expand Down Expand Up @@ -619,6 +619,6 @@ def is_encrypted(self):
return True
elif wEncryptionType == 0x0000: # XOR obfuscation
# If not compatible no point stating that
raise AssertionError("Unsupported encryption method")
raise Exception("Unsupported encryption method")
else:
return False