Skip to content

Commit

Permalink
ensure correct password
Browse files Browse the repository at this point in the history
properly check pkcs7 in slowaes
  • Loading branch information
AdamISZ committed Aug 14, 2015
1 parent a2b34f7 commit 96626f7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,12 @@ def get_seed(self, seedarg):
try:
decrypted_seed = slowaes.decryptData(
password_key, encrypted_seed.decode('hex')).encode('hex')
decrypted = True
#there is a small probability of getting a valid PKCS7 padding
#by chance from a wrong password; sanity check the seed length
if len(decrypted_seed) == 32:
decrypted = True
else:
raise ValueError
except ValueError:
print 'Incorrect password'
decrypted = False
Expand Down
2 changes: 2 additions & 0 deletions lib/slowaes.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def strip_PKCS7_padding(s):
numpads = ord(s[-1])
if numpads > 16:
raise ValueError("String ending with %r can't be PCKS7-padded" % s[-1])
if not all(numpads == x for x in map(ord, s[-numpads:-1])):
raise ValueError("Invalid PKCS7 padding")
return s[:-numpads]


Expand Down

0 comments on commit 96626f7

Please sign in to comment.