Skip to content

Commit

Permalink
Re-encode ECDSA signature for cryptography.
Browse files Browse the repository at this point in the history
  • Loading branch information
dainnilsson committed Dec 11, 2023
1 parent 292c31c commit e4a50a1
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 @@ -27,6 +27,7 @@
from cryptography.hazmat.primitives.asymmetric.rsa import RSAPublicKey
from cryptography.hazmat.primitives.asymmetric.ed25519 import Ed25519PublicKey
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
from cryptography.hazmat.primitives.asymmetric.utils import encode_dss_signature
from cryptography.hazmat.primitives.serialization import (
SSHPublicKeyTypes,
load_ssh_public_key,
Expand Down Expand Up @@ -213,6 +214,11 @@ def ssh_verify_signature(
if isinstance(key, RSAPublicKey):
key.verify(signature, message, PKCS1v15(), h())
elif isinstance(key, EllipticCurvePublicKey):
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()))
else:
key.verify(signature, message)
Expand Down

0 comments on commit e4a50a1

Please sign in to comment.