Skip to content

Commit

Permalink
Make code robust for XML keys with garbage input data
Browse files Browse the repository at this point in the history
  • Loading branch information
hannob committed Feb 1, 2025
1 parent cdda53d commit cc8b4ed
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion keyfinder.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ def getxmlkey(kstr):
n = int.from_bytes(base64.b64decode(n), byteorder="big")
e = int.from_bytes(base64.b64decode(e), byteorder="big")
d = int.from_bytes(base64.b64decode(d), byteorder="big")
except binascii.Error:
except (binascii.Error, ValueError):
return None
return makersa(n, e, d)

Expand Down
11 changes: 11 additions & 0 deletions tests/data/invalid/xkms-invalidbinary.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<RSAKeyPair xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.w3.org/2002/03/xkms#">
<!-- XKMS key with binary garbage data -->
<Modulus>sÔ¶ç”Q{FTH</Modulus>
<Exponent>AQAB</Exponent>
<P>Xgjziw==</P>
<Q>30OIuw==</Q>
<DP>c8y+Rw==</DP>
<DQ>Enz9Bw==</DQ>
<InverseQ>jXsByw==</InverseQ>
<D>TValP0==</D>
</RSAKeyPair>

0 comments on commit cc8b4ed

Please sign in to comment.