Skip to content

Commit

Permalink
feat(FakeAuthenticator): ability to choose alg when creating a cred…
Browse files Browse the repository at this point in the history
…ential
  • Loading branch information
santiagorodriguez96 committed Oct 24, 2024
1 parent d02bd04 commit d2644e7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
20 changes: 17 additions & 3 deletions lib/webauthn/fake_authenticator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ def make_credential(
backup_eligibility: false,
backup_state: false,
attested_credential_data: true,
algorithm: nil,
sign_count: nil,
extensions: nil
)
credential_id, credential_key, credential_sign_count = new_credential
credential_id, credential_key, credential_sign_count = new_credential(algorithm)
sign_count ||= credential_sign_count

credentials[rp_id] ||= {}
Expand Down Expand Up @@ -109,8 +110,21 @@ def get_assertion(

attr_reader :credentials

def new_credential
[SecureRandom.random_bytes(16), OpenSSL::PKey::EC.generate("prime256v1"), 0]
def new_credential(algorithm)
algorithm ||= 'ES256'
credential_key =
case algorithm
when 'ES256'
OpenSSL::PKey::EC.generate('prime256v1')
when 'RS256'
OpenSSL::PKey::RSA.new(2048)
when 'EdDSA'
OpenSSL::PKey.generate_key("ED25519")
else
raise "Unsupported algorithm #{algorithm}"
end

[SecureRandom.random_bytes(16), credential_key, 0]
end

def hashed(target)
Expand Down
2 changes: 2 additions & 0 deletions lib/webauthn/fake_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def create(
backup_eligibility: false,
backup_state: false,
attested_credential_data: true,
credential_algorithm: nil,
extensions: nil
)
rp_id ||= URI.parse(origin).host
Expand All @@ -47,6 +48,7 @@ def create(
backup_eligibility: backup_eligibility,
backup_state: backup_state,
attested_credential_data: attested_credential_data,
algorithm: credential_algorithm,
extensions: extensions
)

Expand Down

0 comments on commit d2644e7

Please sign in to comment.