Class: WebAuthn::AuthenticatorAssertionResponse

Inherits:
AuthenticatorResponse show all
Defined in:
lib/webauthn/authenticator_assertion_response.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from AuthenticatorResponse

#client_data, #valid?

Constructor Details

#initialize(authenticator_data:, signature:, user_handle: nil, **options) ⇒ AuthenticatorAssertionResponse

Returns a new instance of AuthenticatorAssertionResponse.



32
33
34
35
36
37
38
# File 'lib/webauthn/authenticator_assertion_response.rb', line 32

def initialize(authenticator_data:, signature:, user_handle: nil, **options)
  super(**options)

  @authenticator_data_bytes = authenticator_data
  @signature = signature
  @user_handle = user_handle
end

Instance Attribute Details

#user_handleObject (readonly)

Returns the value of attribute user_handle.



30
31
32
# File 'lib/webauthn/authenticator_assertion_response.rb', line 30

def user_handle
  @user_handle
end

Class Method Details

.from_client(response, relying_party: WebAuthn.configuration.relying_party) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/webauthn/authenticator_assertion_response.rb', line 13

def self.from_client(response, relying_party: WebAuthn.configuration.relying_party)
  encoder = relying_party.encoder

  user_handle =
    if response["userHandle"]
      encoder.decode(response["userHandle"])
    end

  new(
    authenticator_data: encoder.decode(response["authenticatorData"]),
    client_data_json: encoder.decode(response["clientDataJSON"]),
    signature: encoder.decode(response["signature"]),
    user_handle: user_handle,
    relying_party: relying_party
  )
end

Instance Method Details

#authenticator_dataObject



62
63
64
# File 'lib/webauthn/authenticator_assertion_response.rb', line 62

def authenticator_data
  @authenticator_data ||= WebAuthn::AuthenticatorData.deserialize(authenticator_data_bytes)
end

#verify(expected_challenge, expected_origin = nil, public_key:, sign_count:, user_presence: nil, user_verification: nil, rp_id: nil) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/webauthn/authenticator_assertion_response.rb', line 40

def verify(
  expected_challenge,
  expected_origin = nil,
  public_key:,
  sign_count:,
  user_presence: nil,
  user_verification: nil,
  rp_id: nil
)
  super(
    expected_challenge,
    expected_origin,
    user_presence: user_presence,
    user_verification: user_verification,
    rp_id: rp_id
  )
  verify_item(:signature, WebAuthn::PublicKey.deserialize(public_key))
  verify_item(:sign_count, sign_count)

  true
end