Skip to content

Commit

Permalink
fix ed25519 ssh key unpad() when padding not present (not needed)
Browse files Browse the repository at this point in the history
fixes #1306
  • Loading branch information
ploxiln authored and bitprophet committed Jun 21, 2019
1 parent c253bab commit 3a28eed
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions paramiko/ed25519key.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,12 @@ def unpad(data):
# really ought to be made constant time (possibly by upstreaming this logic
# into pyca/cryptography).
padding_length = six.indexbytes(data, -1)
if padding_length > 16:
if 0x20 <= padding_length < 0x7f:
return data # no padding, last byte part comment (printable ascii)
if padding_length > 15:
raise SSHException("Invalid key")
for i in range(1, padding_length + 1):
if six.indexbytes(data, -i) != (padding_length - i + 1):
for i in range(padding_length):
if six.indexbytes(data, i - padding_length) != i + 1:
raise SSHException("Invalid key")
return data[:-padding_length]

Expand Down

0 comments on commit 3a28eed

Please sign in to comment.