Class: Fido2Client::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/fido2_client.rb

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.



11
12
13
14
# File 'lib/fido2_client.rb', line 11

def initialize
  @origin = "https://app.simplicity.kiwi"
  @rp_id = "simplicity.kiwi"
end

Instance Method Details

#get_assertion(passkey, challenge) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/fido2_client.rb', line 16

def get_assertion(passkey, challenge)
  collected_client_data = {
    type: "webauthn.get",
    challenge: challenge,
    origin: @origin,
    crossOrigin: false,
  }
  client_data_json = JSON.dump(collected_client_data)
  client_data_hash = Digest::SHA256.digest(client_data_json)

  # Assertion
  auth_data = generate_auth_data
  private_key = parse_private_key(passkey.keyAlgorithm, passkey.keyCurve, passkey.keyValue)
  signature = generate_signature(auth_data, client_data_hash, private_key)

  Assertion.new(
    authenticator_data: Base64.urlsafe_encode64(auth_data.pack("c*"), padding: false),
    client_data_json: Base64.urlsafe_encode64(client_data_json, padding: false),
    credential_id: Base64.urlsafe_encode64(guid_to_raw_format(passkey.credentialId), padding: false),
    user_handle: passkey.userHandle,
    signature: Base64.urlsafe_encode64(signature, padding: false),
  )
end