class WebAuthn::AuthenticatorData::AttestedCredentialData

Constants

AAGUID_LENGTH
Credential

TODO: use keyword_init when we dropped Ruby 2.4 support

ID_LENGTH_LENGTH
ZEROED_AAGUID

Public Class Methods

deserialize(data) click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 33
def self.deserialize(data)
  read(data)
rescue EOFError
  raise AttestedCredentialDataFormatError
end

Public Instance Methods

aaguid() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 43
def aaguid
  raw_aaguid.unpack("H8H4H4H4H12").join("-")
end
credential() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 47
def credential
  @credential ||=
    if valid?
      Credential.new(id, public_key)
    end
end
length() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 54
def length
  if valid?
    AAGUID_LENGTH + ID_LENGTH_LENGTH + id_length + public_key_length
  end
end
valid?() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 39
def valid?
  valid_credential_public_key?
end

Private Instance Methods

public_key() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 68
def public_key
  trailing_bytes[0..public_key_length - 1]
end
public_key_length() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 72
def public_key_length
  @public_key_length ||=
    CBOR.encode(CBOR::Unpacker.new(StringIO.new(trailing_bytes)).each.first).length
end
valid_credential_public_key?() click to toggle source
# File lib/webauthn/authenticator_data/attested_credential_data.rb, line 62
def valid_credential_public_key?
  cose_key = COSE::Key.deserialize(public_key)

  !!cose_key.alg && WebAuthn.configuration.algorithms.include?(COSE::Algorithm.find(cose_key.alg).name)
end