Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions lib/webauthn/authenticator_assertion_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ def valid?(original_challenge, original_origin, allowed_credentials:)
valid_signature?(credential_public_key(allowed_credentials))
end

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

private

attr_reader :credential_id, :authenticator_data_bytes, :signature
Expand All @@ -42,10 +46,6 @@ def valid_credential?(allowed_credentials)
allowed_credential_ids.include?(credential_id)
end

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

def credential_public_key(allowed_credentials)
matched_credential = allowed_credentials.find do |credential|
credential[:id] == credential_id
Expand Down
8 changes: 4 additions & 4 deletions lib/webauthn/authenticator_attestation_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def credential
authenticator_data.credential
end

private

attr_reader :attestation_object

def attestation_statement
@attestation_statement ||=
WebAuthn::AttestationStatement.from(attestation["fmt"], attestation["attStmt"])
Expand All @@ -47,6 +43,10 @@ def attestation
@attestation ||= CBOR.decode(attestation_object)
end

private

attr_reader :attestation_object

def type
WebAuthn::TYPES[:create]
end
Expand Down
24 changes: 12 additions & 12 deletions lib/webauthn/authenticator_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ def initialize(data)
@data = data
end

attr_reader :data

def valid?
if attested_credential_data_included?
data.length > base_length && attested_credential_data.valid?
Expand All @@ -29,6 +31,10 @@ def user_present?
flags[USER_PRESENT_FLAG_POSITION] == "1"
end

def attested_credential_data_included?
flags[ATTESTED_CREDENTIAL_DATA_INCLUDED_FLAG_POSITION] == "1"
end

def rp_id_hash
@rp_id_hash ||=
if valid?
Expand All @@ -40,15 +46,17 @@ def credential
attested_credential_data.credential
end

private

attr_reader :data

def attested_credential_data
@attested_credential_data ||=
AttestedCredentialData.new(data_at(attested_credential_data_position))
end

def flags
@flags ||= data_at(flags_position, FLAGS_LENGTH).unpack1("b*")
end

private

def attested_credential_data_position
base_length
end
Expand All @@ -57,18 +65,10 @@ def base_length
RP_ID_HASH_LENGTH + FLAGS_LENGTH + SIGN_COUNT_LENGTH
end

def flags
@flags ||= data_at(flags_position, FLAGS_LENGTH).unpack1("b*")
end

def flags_position
RP_ID_HASH_LENGTH
end

def attested_credential_data_included?
flags[ATTESTED_CREDENTIAL_DATA_INCLUDED_FLAG_POSITION] == "1"
end

def data_at(position, length = nil)
length ||= data.size - position

Expand Down
8 changes: 4 additions & 4 deletions lib/webauthn/authenticator_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ def valid?(original_challenge, original_origin)
authenticator_data.user_present?
end

def client_data
@client_data ||= WebAuthn::ClientData.new(client_data_json)
end

private

attr_reader :client_data_json
Expand All @@ -23,10 +27,6 @@ def valid_type?
client_data.type == type
end

def client_data
@client_data ||= WebAuthn::ClientData.new(client_data_json)
end

def valid_challenge?(original_challenge)
WebAuthn::Utils.authenticator_decode(client_data.challenge) == original_challenge
end
Expand Down