Class: WebAuthn::AuthenticatorData

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/webauthn/authenticator_data.rb,
lib/webauthn/authenticator_data/attested_credential_data.rb

Defined Under Namespace

Classes: AttestedCredentialData

Constant Summary collapse

RP_ID_HASH_LENGTH =
32
FLAGS_LENGTH =
1
SIGN_COUNT_LENGTH =
4

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.deserialize(data) ⇒ Object



33
34
35
36
37
# File 'lib/webauthn/authenticator_data.rb', line 33

def self.deserialize(data)
  read(data)
rescue EOFError
  raise AuthenticatorDataFormatError
end

Instance Method Details

#aaguidObject



94
95
96
97
98
99
100
# File 'lib/webauthn/authenticator_data.rb', line 94

def aaguid
  raw_aaguid = attested_credential_data.raw_aaguid

  unless raw_aaguid == WebAuthn::AuthenticatorData::AttestedCredentialData::ZEROED_AAGUID
    attested_credential_data.aaguid
  end
end

#attested_credential_dataObject



83
84
85
86
87
88
# File 'lib/webauthn/authenticator_data.rb', line 83

def attested_credential_data
  @attested_credential_data ||=
    AttestedCredentialData.deserialize(trailing_bytes)
rescue AttestedCredentialDataFormatError
  raise AuthenticatorDataFormatError
end

#attested_credential_data_included?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/webauthn/authenticator_data.rb', line 69

def attested_credential_data_included?
  flags.attested_credential_data_included == 1
end

#credentialObject



77
78
79
80
81
# File 'lib/webauthn/authenticator_data.rb', line 77

def credential
  if attested_credential_data_included?
    attested_credential_data.credential
  end
end

#credential_backed_up?Boolean

Returns:

  • (Boolean)


65
66
67
# File 'lib/webauthn/authenticator_data.rb', line 65

def credential_backed_up?
  flags.backup_state == 1
end

#credential_backup_eligible?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/webauthn/authenticator_data.rb', line 61

def credential_backup_eligible?
  flags.backup_eligibility == 1
end

#dataObject



39
40
41
# File 'lib/webauthn/authenticator_data.rb', line 39

def data
  to_binary_s
end

#extension_dataObject



90
91
92
# File 'lib/webauthn/authenticator_data.rb', line 90

def extension_data
  @extension_data ||= CBOR.decode(raw_extension_data)
end

#extension_data_included?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/webauthn/authenticator_data.rb', line 73

def extension_data_included?
  flags.extension_data_included == 1
end

#user_flagged?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/webauthn/authenticator_data.rb', line 49

def user_flagged?
  user_present? || user_verified?
end

#user_present?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/webauthn/authenticator_data.rb', line 53

def user_present?
  flags.user_present == 1
end

#user_verified?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/webauthn/authenticator_data.rb', line 57

def user_verified?
  flags.user_verified == 1
end

#valid?Boolean

Returns:

  • (Boolean)


43
44
45
46
47
# File 'lib/webauthn/authenticator_data.rb', line 43

def valid?
  (!attested_credential_data_included? || attested_credential_data.valid?) &&
    (!extension_data_included? || extension_data) &&
    valid_length?
end