Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: validate attestation statement when format is 'none' when regis… #11

Merged
merged 1 commit into from
May 22, 2018
Merged
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
feat: validate attestation statement when format is 'none' when regis…
…tering a new credential
  • Loading branch information
grzuy committed May 22, 2018
commit 2aa56bfa0b70223a8a30cdd60d7125a4815dce76
16 changes: 15 additions & 1 deletion lib/webauthn/validator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

module WebAuthn
class Validator
ATTESTATION_FORMAT_NONE = "none"
AUTHENTICATOR_DATA_MIN_LENGTH = 37
USER_PRESENT_BIT_POSITION = 0

Expand All @@ -17,7 +18,8 @@ def valid?
valid_type? &&
valid_challenge? &&
valid_authenticator_data? &&
user_present?
user_present? &&
valid_attestation_statement?
end

private
Expand All @@ -36,6 +38,14 @@ def valid_authenticator_data?
authenticator_data.length > AUTHENTICATOR_DATA_MIN_LENGTH
end

def valid_attestation_statement?
if attestation_format == ATTESTATION_FORMAT_NONE
true
else
raise "Unsupported attestation format '#{attestation_format}'"
end
end

def user_present?
authenticator_data_flags[USER_PRESENT_BIT_POSITION] == "1"
end
Expand All @@ -59,6 +69,10 @@ def authenticator_data
@authenticator_data ||= attestation["authData"]
end

def attestation_format
attestation["fmt"]
end

def attestation
@attestation ||= CBOR.decode(Base64.urlsafe_decode64(attestation_object))
end
Expand Down