Skip to content

Commit

Permalink
Merge pull request #400 from cedarcode/sr--support-eddsa-keys-in-fake…
Browse files Browse the repository at this point in the history
…-authenticator

[FakeAuthenticator] Support EdDSA credential keys
  • Loading branch information
brauliomartinezlm authored Oct 22, 2024
2 parents b7e1e05 + f92b8c2 commit d02bd04
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
9 changes: 8 additions & 1 deletion lib/webauthn/fake_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ def get_assertion(
extensions: extensions
).serialize

signature = credential_key.sign("SHA256", authenticator_data + client_data_hash)
signature_digest_algorithm =
case credential_key
when OpenSSL::PKey::RSA, OpenSSL::PKey::EC
'SHA256'
when OpenSSL::PKey::PKey
nil
end
signature = credential_key.sign(signature_digest_algorithm, authenticator_data + client_data_hash)
credential[:sign_count] += 1

{
Expand Down
11 changes: 10 additions & 1 deletion lib/webauthn/fake_authenticator/attestation_object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def authenticator_data
begin
credential_data =
if attested_credential_data
{ id: credential_id, public_key: credential_key.public_key }
{ id: credential_id, public_key: credential_public_key }
end

AuthenticatorData.new(
Expand All @@ -76,6 +76,15 @@ def authenticator_data
)
end
end

def credential_public_key
case credential_key
when OpenSSL::PKey::RSA, OpenSSL::PKey::EC
credential_key.public_key
when OpenSSL::PKey::PKey
OpenSSL::PKey.read(credential_key.public_to_der)
end
end
end
end
end
4 changes: 3 additions & 1 deletion lib/webauthn/fake_authenticator/authenticator_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,9 @@ def cose_credential_public_key

key = COSE::Key::EC2.from_pkey(credential[:public_key])
key.alg = alg[key.crv]

when OpenSSL::PKey::PKey
key = COSE::Key::OKP.from_pkey(credential[:public_key])
key.alg = -8
end

key.serialize
Expand Down

0 comments on commit d02bd04

Please sign in to comment.