Skip to content

Commit

Permalink
Re-encode signature for DSA.
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Dec 13, 2023
1 parent 37299ad commit a3b175d
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bark_core/signatures.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,19 @@ def ssh_verify_signature(
if isinstance(key, RSAPublicKey):
key.verify(signature, message, PKCS1v15(), h())
elif isinstance(key, EllipticCurvePublicKey):
# R and S encoded as bytestrings
r, signature = ssh_get_string(signature)
s, signature = ssh_get_string(signature)
signature = encode_dss_signature(
int.from_bytes(r, "big"), int.from_bytes(s, "big")
)
key.verify(signature, message, ECDSA(h()))
elif isinstance(key, DSAPublicKey):
# R and S encoded as 20 bytes each
r, s = signature[:20], signature[20:]
signature = encode_dss_signature(
int.from_bytes(r, "big"), int.from_bytes(s, "big")
)
key.verify(signature, message, h())
else:
key.verify(signature, message)
Expand Down

0 comments on commit a3b175d

Please sign in to comment.