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


86
87
88
89
90
91
92
# File 'lib/webauthn/authenticator_data.rb', line 86

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


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

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

#attested_credential_data_included?Boolean

Returns:

  • (Boolean)

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

def attested_credential_data_included?
  flags.attested_credential_data_included == 1
end

#credentialObject


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

def credential
  if attested_credential_data_included?
    attested_credential_data.credential
  end
end

#dataObject


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

def data
  to_binary_s
end

#extension_dataObject


82
83
84
# File 'lib/webauthn/authenticator_data.rb', line 82

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

#extension_data_included?Boolean

Returns:

  • (Boolean)

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

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