Class: WebAuthn::AttestationObject

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fmt:, att_stmt:, auth_data:) ⇒ AttestationObject

Returns a new instance of AttestationObject.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/web_authn/attestation_object.rb', line 12

def initialize(fmt:, att_stmt:, auth_data:)
  self.format = fmt
  self.attestation_statement = case format
  when 'none'
    nil
  when 'android-safetynet'
    AttestationStatement::AndroidSafetynet.decode att_stmt
  when 'packed', 'tpm', 'android-key', 'fido-u2f'
    raise NotImplementedError, "Unsupported Attestation Format: #{format}"
  else
    raise InvalidContext, 'Unknown Attestation Format'
  end
  self.authenticator_data = AuthenticatorData.decode auth_data
end

Instance Attribute Details

#attestation_statementObject Also known as: att_stmt

Returns the value of attribute attestation_statement.



3
4
5
# File 'lib/web_authn/attestation_object.rb', line 3

def attestation_statement
  @attestation_statement
end

#authenticator_dataObject Also known as: auth_data

Returns the value of attribute authenticator_data.



3
4
5
# File 'lib/web_authn/attestation_object.rb', line 3

def authenticator_data
  @authenticator_data
end

#formatObject Also known as: fmt

Returns the value of attribute format.



3
4
5
# File 'lib/web_authn/attestation_object.rb', line 3

def format
  @format
end

Class Method Details

.decode(encoded_attestation_object) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/web_authn/attestation_object.rb', line 32

def decode(encoded_attestation_object)
  cbor = CBOR.decode(
    Base64.urlsafe_decode64 encoded_attestation_object
  ).with_indifferent_access
  new(
    fmt: cbor[:fmt],
    att_stmt: cbor[:attStmt],
    auth_data: cbor[:authData]
  )
end

Instance Method Details

#verify_signature!(client_data_json) ⇒ Object



27
28
29
# File 'lib/web_authn/attestation_object.rb', line 27

def verify_signature!(client_data_json)
  attestation_statement.try(:verify!, authenticator_data, client_data_json)
end