Skip to content

Commit f92b8c2

Browse files
feature(FakeAuthenticator): add EdDSA credential keys support
1 parent 9827369 commit f92b8c2

3 files changed

Lines changed: 21 additions & 3 deletions

File tree

lib/webauthn/fake_authenticator.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,14 @@ def get_assertion(
8585
extensions: extensions
8686
).serialize
8787

88-
signature = credential_key.sign("SHA256", authenticator_data + client_data_hash)
88+
signature_digest_algorithm =
89+
case credential_key
90+
when OpenSSL::PKey::RSA, OpenSSL::PKey::EC
91+
'SHA256'
92+
when OpenSSL::PKey::PKey
93+
nil
94+
end
95+
signature = credential_key.sign(signature_digest_algorithm, authenticator_data + client_data_hash)
8996
credential[:sign_count] += 1
9097

9198
{

lib/webauthn/fake_authenticator/attestation_object.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ def authenticator_data
6161
begin
6262
credential_data =
6363
if attested_credential_data
64-
{ id: credential_id, public_key: credential_key.public_key }
64+
{ id: credential_id, public_key: credential_public_key }
6565
end
6666

6767
AuthenticatorData.new(
@@ -76,6 +76,15 @@ def authenticator_data
7676
)
7777
end
7878
end
79+
80+
def credential_public_key
81+
case credential_key
82+
when OpenSSL::PKey::RSA, OpenSSL::PKey::EC
83+
credential_key.public_key
84+
when OpenSSL::PKey::PKey
85+
OpenSSL::PKey.read(credential_key.public_to_der)
86+
end
87+
end
7988
end
8089
end
8190
end

lib/webauthn/fake_authenticator/authenticator_data.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ def cose_credential_public_key
140140

141141
key = COSE::Key::EC2.from_pkey(credential[:public_key])
142142
key.alg = alg[key.crv]
143-
143+
when OpenSSL::PKey::PKey
144+
key = COSE::Key::OKP.from_pkey(credential[:public_key])
145+
key.alg = -8
144146
end
145147

146148
key.serialize

0 commit comments

Comments
 (0)