webauthn 3.0.0.alpha1 → 3.0.0.alpha2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/build.yml +31 -0
  3. data/.github/workflows/git.yml +21 -0
  4. data/.rubocop.yml +57 -1
  5. data/CHANGELOG.md +63 -1
  6. data/README.md +5 -2
  7. data/SECURITY.md +6 -3
  8. data/docs/advanced_configuration.md +174 -0
  9. data/docs/u2f_migration.md +3 -2
  10. data/lib/cose/rsapkcs1_algorithm.rb +7 -0
  11. data/lib/webauthn/attestation_statement/android_key.rb +0 -4
  12. data/lib/webauthn/attestation_statement/android_safetynet.rb +1 -5
  13. data/lib/webauthn/attestation_statement/apple.rb +65 -0
  14. data/lib/webauthn/attestation_statement/base.rb +11 -22
  15. data/lib/webauthn/attestation_statement/none.rb +7 -1
  16. data/lib/webauthn/attestation_statement/packed.rb +1 -1
  17. data/lib/webauthn/attestation_statement/tpm.rb +2 -2
  18. data/lib/webauthn/attestation_statement.rb +4 -1
  19. data/lib/webauthn/authenticator_data/attested_credential_data.rb +2 -3
  20. data/lib/webauthn/authenticator_response.rb +1 -2
  21. data/lib/webauthn/credential_creation_options.rb +2 -0
  22. data/lib/webauthn/credential_request_options.rb +2 -0
  23. data/lib/webauthn/fake_authenticator/authenticator_data.rb +1 -1
  24. data/lib/webauthn/fake_authenticator.rb +11 -3
  25. data/lib/webauthn/fake_client.rb +10 -3
  26. data/lib/webauthn/public_key_credential/entity.rb +3 -4
  27. data/lib/webauthn/relying_party.rb +2 -2
  28. data/lib/webauthn/u2f_migrator.rb +4 -1
  29. data/lib/webauthn/version.rb +1 -1
  30. data/webauthn.gemspec +7 -8
  31. metadata +45 -59
  32. data/.travis.yml +0 -39
  33. data/Appraisals +0 -21
  34. data/gemfiles/cose_head.gemfile +0 -7
  35. data/gemfiles/openssl_2_0.gemfile +0 -7
  36. data/gemfiles/openssl_2_1.gemfile +0 -7
  37. data/gemfiles/openssl_2_2.gemfile +0 -7
  38. data/gemfiles/openssl_head.gemfile +0 -7
  39. data/lib/webauthn/security_utils.rb +0 -20
  40. data/script/ci/install-openssl +0 -7
  41. data/script/ci/install-ruby +0 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1f418eb52a085d8e7c03bd1c3d11b88ed8fe467f4ec01d3178836689d470f436
4
- data.tar.gz: 4ab67e8804cbd7d785e29b94760af6db9d6b1e52de1a58bafc74aed19b5b7e21
3
+ metadata.gz: 9f9f14328571fd39b5e19c9a6ec5b427cfd4dea9fc2ab4774135f4453e14b676
4
+ data.tar.gz: 1e33b7564ea1b3b8aeb32864782a0dad1e0207f1c70c037eb80140db2272ae01
5
5
  SHA512:
6
- metadata.gz: ccdcd22e494079eb67c122c03e3061166f91de50dd0c2bf8662748c976483a9d472fa9f8d6b67db9abf484e8eac182195b5f1e1cca8aaaf88146d831919f1c93
7
- data.tar.gz: b2506b530c796ee57e5d037e7dd3692b1e359408fd9757141b6c4f042c43d57344baa09dc63d17ace549927eeea50abaa8c0771a0ab6da0ece5d880362d890db
6
+ metadata.gz: b1e22bb07b1ebced7851c592a2a4e8b0e6772e502f402bd841383f8071963e3b0df8c75da66db5623840a32f14799439d09a52c8dabcdd4e5edbef8a0a419a00
7
+ data.tar.gz: 1a1b1c647a06398edad9d1da94ca8de53202e184f8930b2fe001f82e17d8416516cbaf4db4fd012fd44d1ac5da32c6d8d32c971507584bf00ef9d74b15d535b5
@@ -0,0 +1,31 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: build
9
+
10
+ on: push
11
+
12
+ jobs:
13
+ test:
14
+ runs-on: ubuntu-20.04
15
+ strategy:
16
+ fail-fast: false
17
+ matrix:
18
+ ruby:
19
+ - '3.1'
20
+ - '3.0'
21
+ - '2.7'
22
+ - '2.6'
23
+ - '2.5'
24
+ - truffleruby
25
+ steps:
26
+ - uses: actions/checkout@v2
27
+ - uses: ruby/setup-ruby@v1
28
+ with:
29
+ ruby-version: ${{ matrix.ruby }}
30
+ bundler-cache: true
31
+ - run: bundle exec rake
@@ -0,0 +1,21 @@
1
+ # Syntax reference:
2
+ # https://help.github.com/en/actions/automating-your-workflow-with-github-actions/workflow-syntax-for-github-actions
3
+ name: Git Checks
4
+
5
+ on:
6
+ pull_request:
7
+ types: [opened, synchronize]
8
+
9
+ jobs:
10
+ # Fixup commits are OK in pull requests, but should generally be squashed
11
+ # before merging to master, e.g. using `git rebase -i --autosquash master`.
12
+ # See https://github.com/marketplace/actions/block-autosquash-commits
13
+ block-fixup:
14
+ runs-on: ubuntu-latest
15
+
16
+ steps:
17
+ - uses: actions/checkout@v2.0.0
18
+ - name: Block autosquash commits
19
+ uses: xt0rted/block-autosquash-commits-action@v2
20
+ with:
21
+ repo-token: ${{ secrets.GITHUB_TOKEN }}
data/.rubocop.yml CHANGED
@@ -1,13 +1,15 @@
1
1
  require:
2
2
  - rubocop-rspec
3
+ - rubocop-rake
3
4
 
4
5
  inherit_mode:
5
6
  merge:
6
7
  - AllowedNames
7
8
 
8
9
  AllCops:
9
- TargetRubyVersion: 2.4
10
+ TargetRubyVersion: 2.5
10
11
  DisabledByDefault: true
12
+ NewCops: disable
11
13
  Exclude:
12
14
  - "gemfiles/**/*"
13
15
  - "vendor/**/*"
@@ -24,6 +26,12 @@ Layout:
24
26
  Layout/ClassStructure:
25
27
  Enabled: true
26
28
 
29
+ Layout/EmptyLineBetweenDefs:
30
+ AllowAdjacentOneLineDefs: true
31
+
32
+ Layout/EmptyLinesAroundAttributeAccessor:
33
+ Enabled: true
34
+
27
35
  Layout/FirstMethodArgumentLineBreak:
28
36
  Enabled: true
29
37
 
@@ -38,12 +46,60 @@ Layout/MultilineAssignmentLayout:
38
46
  Layout/MultilineMethodArgumentLineBreaks:
39
47
  Enabled: true
40
48
 
49
+ Layout/SpaceAroundMethodCallOperator:
50
+ Enabled: true
51
+
41
52
  Lint:
42
53
  Enabled: true
43
54
 
55
+ Lint/DeprecatedOpenSSLConstant:
56
+ Enabled: true
57
+
58
+ Lint/MixedRegexpCaptureTypes:
59
+ Enabled: true
60
+
61
+ Lint/RaiseException:
62
+ Enabled: true
63
+
64
+ Lint/StructNewOverride:
65
+ Enabled: true
66
+
67
+ Lint/BinaryOperatorWithIdenticalOperands:
68
+ Enabled: true
69
+
70
+ Lint/DuplicateElsifCondition:
71
+ Enabled: true
72
+
73
+ Lint/DuplicateRescueException:
74
+ Enabled: true
75
+
76
+ Lint/EmptyConditionalBody:
77
+ Enabled: true
78
+
79
+ Lint/FloatComparison:
80
+ Enabled: true
81
+
82
+ Lint/MissingSuper:
83
+ Enabled: true
84
+
85
+ Lint/OutOfRangeRegexpRef:
86
+ Enabled: true
87
+
88
+ Lint/SelfAssignment:
89
+ Enabled: true
90
+
91
+ Lint/TopLevelReturnWithArgument:
92
+ Enabled: true
93
+
94
+ Lint/UnreachableLoop:
95
+ Enabled: true
96
+
44
97
  Naming:
45
98
  Enabled: true
46
99
 
100
+ Naming/VariableNumber:
101
+ Enabled: false
102
+
47
103
  RSpec/Be:
48
104
  Enabled: true
49
105
 
data/CHANGELOG.md CHANGED
@@ -1,11 +1,61 @@
1
1
  # Changelog
2
2
 
3
+ ## [v3.0.0.alpha2] - 2022-09-12
4
+
5
+ ### Added
6
+
7
+ - Rebased support for multiple relying parties from v3.0.0.alpha1 on top of v2.5.2, the previous alpha version was based on v2.3.0 ([@bdewater])
8
+
9
+ ### BREAKING CHANGES
10
+
11
+ - Bumped minimum required Ruby version to 2.5 ([@bdewater])
12
+
3
13
  ## [v3.0.0.alpha1] - 2020-06-27
4
14
 
5
15
  ### Added
6
16
 
7
17
  - Ability to define multiple relying parties with the introduction of the `WebAuthn::RelyingParty` class ([@padulafacundo], [@brauliomartinezlm])
8
18
 
19
+ ## [v2.5.2] - 2022-07-13
20
+
21
+ ### Added
22
+
23
+ - Updated dependencies to make the gem compatible with openssl-3 [@ClearlyClaire]
24
+
25
+ ## [v2.5.1] - 2022-03-20
26
+
27
+ ### Added
28
+
29
+ - Updated openssl support to be ~>2.2 [@bdewater]
30
+
31
+ ### Removed
32
+
33
+ - Removed dependency [secure_compare dependency] (https://rubygems.org/gems/secure_compare/versions/0.0.1) and use OpenSSL#secure_compare instead [@bdewater]
34
+
35
+ ## [v2.5.0] - 2021-03-14
36
+
37
+ ### Added
38
+
39
+ - Support 'apple' attestation statement format ([#343](https://github.com/cedarcode/webauthn-ruby/pull/343) / [@juanarias93], [@santiagorodriguez96])
40
+ - Allow specifying an array of ids as `allow_credentials:` for `FakeClient#get` method ([#335](https://github.com/cedarcode/webauthn-ruby/pull/335) / [@kingjan1999])
41
+
42
+ ### Removed
43
+
44
+ - No longer accept "removed from the WebAuthn spec" options `rp: { icon: }` and `user: { icon: }` for `WebAuthn::Credential.options_for_create` method ([#326](https://github.com/cedarcode/webauthn-ruby/pull/326) / [@santiagorodriguez96])
45
+
46
+ ## [v2.4.1] - 2021-02-15
47
+
48
+ ### Fixed
49
+
50
+ - Fix verification of new credential if no attestation provided and 'None' type is not among configured `acceptable_attestation_types`. I.e. reject it instead of letting it go through.
51
+
52
+ ## [v2.4.0] - 2020-09-03
53
+
54
+ ### Added
55
+
56
+ - Support for ES256K credentials
57
+ - `FakeClient#get` accepts `user_handle:` keyword argument ([@lgarron])
58
+
9
59
  ## [v2.3.0] - 2020-06-27
10
60
 
11
61
  ### Added
@@ -300,7 +350,13 @@ Note: Both additions should help making it compatible with Chrome for Android 70
300
350
  - `WebAuthn::AuthenticatorAttestationResponse.valid?` can be used to validate fido-u2f attestations returned by the browser
301
351
  - Works with ruby 2.5
302
352
 
303
- [v3.0.0.alpha1]: https://github.com/cedarcode/webauthn-ruby/compare/2-stable...v3.0.0.alpha1/
353
+ [v3.0.0.alpha2]: https://github.com/cedarcode/webauthn-ruby/compare/2-stable...v3.0.0.alpha2/
354
+ [v3.0.0.alpha1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.3.0...v3.0.0.alpha1
355
+ [v2.5.2]: https://github.com/cedarcode/webauthn-ruby/compare/v2.5.1...v2.5.2/
356
+ [v2.5.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.5.0...v2.5.1/
357
+ [v2.5.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.4.1...v2.5.0/
358
+ [v2.4.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.4.0...v2.4.1/
359
+ [v2.4.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.3.0...v2.4.0/
304
360
  [v2.3.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.2.1...v2.3.0/
305
361
  [v2.2.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.2.0...v2.2.1/
306
362
  [v2.2.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.1.0...v2.2.0/
@@ -337,3 +393,9 @@ Note: Both additions should help making it compatible with Chrome for Android 70
337
393
  [@ssuttner]: https://github.com/ssuttner
338
394
  [@padulafacundo]: https://github.com/padulafacundo
339
395
  [@santiagorodriguez96]: https://github.com/santiagorodriguez96
396
+ [@lgarron]: https://github.com/lgarron
397
+ [@juanarias93]: https://github.com/juanarias93
398
+ [@kingjan1999]: https://github.com/@kingjan1999
399
+ [@jdongelmans]: https://github.com/jdongelmans
400
+ [@petergoldstein]: https://github.com/petergoldstein
401
+ [@ClearlyClaire]: https://github.com/ClearlyClaire
data/README.md CHANGED
@@ -6,7 +6,7 @@ For the current release version see https://github.com/cedarcode/webauthn-ruby/b
6
6
  ![banner](assets/webauthn-ruby.png)
7
7
 
8
8
  [![Gem](https://img.shields.io/gem/v/webauthn.svg?style=flat-square)](https://rubygems.org/gems/webauthn)
9
- [![Travis](https://img.shields.io/travis/cedarcode/webauthn-ruby/master.svg?style=flat-square)](https://travis-ci.org/cedarcode/webauthn-ruby)
9
+ [![Travis](https://img.shields.io/travis/cedarcode/webauthn-ruby/master.svg?style=flat-square)](https://travis-ci.com/cedarcode/webauthn-ruby)
10
10
  [![Conventional Commits](https://img.shields.io/badge/Conventional%20Commits-1.0.0-informational.svg?style=flat-square)](https://conventionalcommits.org)
11
11
  [![Join the chat at https://gitter.im/cedarcode/webauthn-ruby](https://badges.gitter.im/cedarcode/webauthn-ruby.svg)](https://gitter.im/cedarcode/webauthn-ruby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
12
12
 
@@ -96,6 +96,8 @@ If you are migrating an existing application from the legacy FIDO U2F JavaScript
96
96
 
97
97
  ### Configuration
98
98
 
99
+ If you have a multi-tenant application or just need to configure WebAuthn differently for separate parts of your application (e.g. if your users authenticate to different subdomains in the same application), we strongly recommend you look at this [Advanced Configuration](docs/advanced_configuration.md) section instead of this.
100
+
99
101
  For a Rails application this would go in `config/initializers/webauthn.rb`.
100
102
 
101
103
  ```ruby
@@ -408,7 +410,7 @@ credential.authenticator_extension_outputs
408
410
 
409
411
  ## Attestation
410
412
 
411
- ### Attestation Statement Format
413
+ ### Attestation Statement Formats
412
414
 
413
415
  | Attestation Statement Format | Supported? |
414
416
  | -------- | :--------: |
@@ -417,6 +419,7 @@ credential.authenticator_extension_outputs
417
419
  | tpm (x5c attestation) | Yes |
418
420
  | android-key | Yes |
419
421
  | android-safetynet | Yes |
422
+ | apple | Yes |
420
423
  | fido-u2f | Yes |
421
424
  | none | Yes |
422
425
 
data/SECURITY.md CHANGED
@@ -4,9 +4,12 @@
4
4
 
5
5
  | Version | Supported |
6
6
  | ------- | ------------------ |
7
- | 2.2.z | :white_check_mark: |
8
- | 2.1.z | :white_check_mark: |
9
- | 2.0.z | :white_check_mark: |
7
+ | 2.5.z | :white_check_mark: |
8
+ | 2.4.z | :white_check_mark: |
9
+ | 2.3.z | :white_check_mark: |
10
+ | 2.2.z | :x: |
11
+ | 2.1.z | :x: |
12
+ | 2.0.z | :x: |
10
13
  | 1.18.z | :white_check_mark: |
11
14
  | < 1.18 | :x: |
12
15
 
@@ -0,0 +1,174 @@
1
+ # Advanced Configuration
2
+
3
+ ## Global vs Instance Based Configuration
4
+
5
+ Which approach suits best your needs will depend on the architecture of your application and how do your users need to register and authenticate to it.
6
+
7
+ If you have a multi-tenant application, or any application segmenation, where your users register and authenticate to each of these tenants or segments individuallly using different hostnames, or with different security needs, you need to go through [Instance Based Configuration](#instance-based-configuration).
8
+
9
+ However, if your application is served for just one hostname, or else if your users authenticate to only one subdmain (e.g. your application serves www.example.com and admin.example.com but all you users authenticate through auth.example.com) you can still rely on one [Global Configuration](../README.md#configuration).
10
+
11
+ If you are still not sure, or want to keep your options open, be aware that [Instance Based Configuration](#instance-based-configuration) is also a valid way of defining a single instance configuration and how you share such configuration across your application, it's up to you.
12
+
13
+
14
+ ## Instance Based Configuration
15
+
16
+ Intead of the [Global Configuration](../README.md#configuration) you place in `config/initializers/webauthn.rb`,
17
+ you can now have an on-demand instance of `WebAuthn::RelyingParty` with the same configuration options, that
18
+ you can build anywhere in you application, in the following way:
19
+
20
+ ```ruby
21
+ relying_party = WebAuthn::RelyingParty.new(
22
+ # This value needs to match `window.location.origin` evaluated by
23
+ # the User Agent during registration and authentication ceremonies.
24
+ origin: "https://admin.example.com"
25
+
26
+ # Relying Party name for display purposes
27
+ name: "Admin Site for Example Inc."
28
+
29
+ # Optionally configure a client timeout hint, in milliseconds.
30
+ # This hint specifies how long the browser should wait for any
31
+ # interaction with the user.
32
+ # This hint may be overridden by the browser.
33
+ # https://www.w3.org/TR/webauthn/#dom-publickeycredentialcreationoptions-timeout
34
+ # credential_options_timeout: 120_000
35
+
36
+ # You can optionally specify a different Relying Party ID
37
+ # (https://www.w3.org/TR/webauthn/#relying-party-identifier)
38
+ # if it differs from the default one.
39
+ #
40
+ # In this case the default would be "admin.example.com", but you can set it to
41
+ # the suffix "example.com"
42
+ #
43
+ # id: "example.com"
44
+
45
+ # Configure preferred binary-to-text encoding scheme. This should match the encoding scheme
46
+ # used in your client-side (user agent) code before sending the credential to the server.
47
+ # Supported values: `:base64url` (default), `:base64` or `false` to disable all encoding.
48
+ #
49
+ # encoding: :base64url
50
+
51
+ # Possible values: "ES256", "ES384", "ES512", "PS256", "PS384", "PS512", "RS256", "RS384", "RS512", "RS1"
52
+ # Default: ["ES256", "PS256", "RS256"]
53
+ #
54
+ # algorithms: ["ES384"]
55
+ )
56
+ ```
57
+
58
+ ## Instance Based API
59
+
60
+ **DISCLAIMER: This API was released on version 3.0.0.alpha1 and is still under evaluation. Although it has been throughly tested and it is fully functional it might be changed until the final release of version 3.0.0.**
61
+
62
+ The explanation for each ceremony can be found in depth in [Credential Registration](../README.md#credential-registration) and [Credential Authentication](../README.md#credential-authentication) but if you choose this instance based approach to define your WebAuthn configurations and assuming `relying_party` is the result of an instance you get through `WebAuthn::RelytingParty.new(...)` the code in those explanations needs to be updated to:
63
+
64
+ ### Credential Registration
65
+
66
+ #### Initiation phase
67
+
68
+ ```ruby
69
+ # Generate and store the WebAuthn User ID the first time the user registers a credential
70
+ if !user.webauthn_id
71
+ user.update!(webauthn_id: WebAuthn.generate_user_id)
72
+ end
73
+
74
+ options = relying_party.options_for_create(
75
+ user: { id: user.webauthn_id, name: user.name },
76
+ exclude: user.credentials.map { |c| c.webauthn_id }
77
+ )
78
+
79
+ # Store the newly generated challenge somewhere so you can have it
80
+ # for the verification phase.
81
+ session[:creation_challenge] = options.challenge
82
+
83
+ # Send `options` back to the browser, so that they can be used
84
+ # to call `navigator.credentials.create({ "publicKey": options })`
85
+ #
86
+ # You can call `options.as_json` to get a ruby hash with a JSON representation if needed.
87
+
88
+ # If inside a Rails controller, `render json: options` will just work.
89
+ # I.e. it will encode and convert the options to JSON automatically.
90
+
91
+ # For your frontend code, you might find @github/webauthn-json npm package useful.
92
+ # Especially for handling the necessary decoding of the options, and sending the
93
+ # `PublicKeyCredential` object back to the server.
94
+ ```
95
+
96
+ #### Verification phase
97
+
98
+ ```ruby
99
+ # Assuming you're using @github/webauthn-json package to send the `PublicKeyCredential` object back
100
+ # in params[:publicKeyCredential]:
101
+ begin
102
+ webauthn_credential = relying_party.verify_registration(
103
+ params[:publicKeyCredential],
104
+ params[:create_challenge]
105
+ )
106
+
107
+ # Store Credential ID, Credential Public Key and Sign Count for future authentications
108
+ user.credentials.create!(
109
+ webauthn_id: webauthn_credential.id,
110
+ public_key: webauthn_credential.public_key,
111
+ sign_count: webauthn_credential.sign_count
112
+ )
113
+ rescue WebAuthn::Error => e
114
+ # Handle error
115
+ end
116
+ ```
117
+
118
+ ### Credential Authentication
119
+
120
+ #### Initiation phase
121
+
122
+ ```ruby
123
+ options = relying_party.options_for_get(allow: user.credentials.map { |c| c.webauthn_id })
124
+
125
+ # Store the newly generated challenge somewhere so you can have it
126
+ # for the verification phase.
127
+ session[:authentication_challenge] = options.challenge
128
+
129
+ # Send `options` back to the browser, so that they can be used
130
+ # to call `navigator.credentials.get({ "publicKey": options })`
131
+
132
+ # You can call `options.as_json` to get a ruby hash with a JSON representation if needed.
133
+
134
+ # If inside a Rails controller, `render json: options` will just work.
135
+ # I.e. it will encode and convert the options to JSON automatically.
136
+
137
+ # For your frontend code, you might find @github/webauthn-json npm package useful.
138
+ # Especially for handling the necessary decoding of the options, and sending the
139
+ # `PublicKeyCredential` object back to the server.
140
+ ```
141
+
142
+ #### Verification phase
143
+
144
+ ```ruby
145
+ begin
146
+ # Assuming you're using @github/webauthn-json package to send the `PublicKeyCredential` object back
147
+ # in params[:publicKeyCredential]:
148
+ webauthn_credential, stored_credential = relying_party.verify_authentication(
149
+ params[:publicKeyCredential],
150
+ session[:authentication_challenge]
151
+ ) do
152
+ # the returned object needs to respond to #public_key and #sign_count
153
+ user.credentials.find_by(webauthn_id: webauthn_credential.id)
154
+ end
155
+
156
+ # Update the stored credential sign count with the value from `webauthn_credential.sign_count`
157
+ stored_credential.update!(sign_count: webauthn_credential.sign_count)
158
+
159
+ # Continue with successful sign in or 2FA verification...
160
+
161
+ rescue WebAuthn::SignCountVerificationError => e
162
+ # Cryptographic verification of the authenticator data succeeded, but the signature counter was less then or equal
163
+ # to the stored value. This can have several reasons and depending on your risk tolerance you can choose to fail or
164
+ # pass authentication. For more information see https://www.w3.org/TR/webauthn/#sign-counter
165
+ rescue WebAuthn::Error => e
166
+ # Handle error
167
+ end
168
+ ```
169
+
170
+ ## Moving from Global to Instance Based Configuration
171
+
172
+ Adding a configuration for a new instance does not mean you need to get rid of your Global configuration. They can co-exist in your application and be both available for the different usages you might have. `WebAuthn.configuration.relying_party` will always return the global one while `WebAuthn::RelyingParty.new`, executed anywhere in your codebase, will allow you to create a different instance as you see the need. They will not collide and instead operate in isolation without any shared state.
173
+
174
+ The gem API described in the current [Usage](../README.md#usage) section for the [Global Configuration](../README.md#configuration) approach will still valid but the [Instance Based API](#instance-based-api) also works with the global `relying_party` that is maintain globally at `WebAuthn.configuration.relying_party`.
@@ -82,7 +82,7 @@ During authentication verification phase, you must pass either the original AppI
82
82
 
83
83
  ```ruby
84
84
  assertion_response = WebAuthn::AuthenticatorAssertionResponse.new(
85
- credential_id: params[:id],
85
+ user_handle: params[:response][:userHandle],
86
86
  authenticator_data: params[:response][:authenticatorData],
87
87
  client_data_json: params[:response][:clientDataJSON],
88
88
  signature: params[:response][:signature],
@@ -90,7 +90,8 @@ assertion_response = WebAuthn::AuthenticatorAssertionResponse.new(
90
90
 
91
91
  assertion_response.verify(
92
92
  expected_challenge,
93
- allowed_credentials: [credential],
93
+ public_key: credential.public_key,
94
+ sign_count: credential.count,
94
95
  rp_id: params[:clientExtensionResults][:appid] ? domain.to_s : domain.host,
95
96
  )
96
97
  ```
@@ -40,4 +40,11 @@ end
40
40
  COSE::Algorithm.register(RSAPKCS1Algorithm.new(-257, "RS256", hash_function: "SHA256"))
41
41
  COSE::Algorithm.register(RSAPKCS1Algorithm.new(-258, "RS384", hash_function: "SHA384"))
42
42
  COSE::Algorithm.register(RSAPKCS1Algorithm.new(-259, "RS512", hash_function: "SHA512"))
43
+
44
+ # Patch openssl-signature_algorithm gem to support discouraged/deprecated RSA-PKCS#1 with SHA-1
45
+ # (RS1 in JOSE/COSE terminology) algorithm needed for WebAuthn.
46
+ OpenSSL::SignatureAlgorithm::RSAPKCS1.const_set(
47
+ :ACCEPTED_HASH_FUNCTIONS,
48
+ OpenSSL::SignatureAlgorithm::RSAPKCS1::ACCEPTED_HASH_FUNCTIONS + ["SHA1"]
49
+ )
43
50
  COSE::Algorithm.register(RSAPKCS1Algorithm.new(-65535, "RS1", hash_function: "SHA1"))
@@ -20,10 +20,6 @@ module WebAuthn
20
20
 
21
21
  private
22
22
 
23
- def matching_public_key?(authenticator_data)
24
- attestation_certificate.public_key.to_der == authenticator_data.credential.public_key_object.to_der
25
- end
26
-
27
23
  def valid_attestation_challenge?(client_data_hash)
28
24
  android_key_attestation.verify_challenge(client_data_hash)
29
25
  rescue AndroidKeyAttestation::ChallengeMismatchError
@@ -16,10 +16,6 @@ module WebAuthn
16
16
  [attestation_type, attestation_trust_path]
17
17
  end
18
18
 
19
- def attestation_certificate
20
- attestation_trust_path.first
21
- end
22
-
23
19
  private
24
20
 
25
21
  def valid_response?(authenticator_data, client_data_hash)
@@ -52,7 +48,7 @@ module WebAuthn
52
48
  end
53
49
 
54
50
  # SafetyNetAttestation returns full chain including root, WebAuthn expects only the x5c certificates
55
- def attestation_trust_path
51
+ def certificates
56
52
  attestation_response.certificate_chain[0..-2]
57
53
  end
58
54
 
@@ -0,0 +1,65 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "openssl"
4
+ require "webauthn/attestation_statement/base"
5
+
6
+ module WebAuthn
7
+ module AttestationStatement
8
+ class Apple < Base
9
+ # Source: https://www.apple.com/certificateauthority/private/
10
+ ROOT_CERTIFICATE =
11
+ OpenSSL::X509::Certificate.new(<<~PEM)
12
+ -----BEGIN CERTIFICATE-----
13
+ MIICEjCCAZmgAwIBAgIQaB0BbHo84wIlpQGUKEdXcTAKBggqhkjOPQQDAzBLMR8w
14
+ HQYDVQQDDBZBcHBsZSBXZWJBdXRobiBSb290IENBMRMwEQYDVQQKDApBcHBsZSBJ
15
+ bmMuMRMwEQYDVQQIDApDYWxpZm9ybmlhMB4XDTIwMDMxODE4MjEzMloXDTQ1MDMx
16
+ NTAwMDAwMFowSzEfMB0GA1UEAwwWQXBwbGUgV2ViQXV0aG4gUm9vdCBDQTETMBEG
17
+ A1UECgwKQXBwbGUgSW5jLjETMBEGA1UECAwKQ2FsaWZvcm5pYTB2MBAGByqGSM49
18
+ AgEGBSuBBAAiA2IABCJCQ2pTVhzjl4Wo6IhHtMSAzO2cv+H9DQKev3//fG59G11k
19
+ xu9eI0/7o6V5uShBpe1u6l6mS19S1FEh6yGljnZAJ+2GNP1mi/YK2kSXIuTHjxA/
20
+ pcoRf7XkOtO4o1qlcaNCMEAwDwYDVR0TAQH/BAUwAwEB/zAdBgNVHQ4EFgQUJtdk
21
+ 2cV4wlpn0afeaxLQG2PxxtcwDgYDVR0PAQH/BAQDAgEGMAoGCCqGSM49BAMDA2cA
22
+ MGQCMFrZ+9DsJ1PW9hfNdBywZDsWDbWFp28it1d/5w2RPkRX3Bbn/UbDTNLx7Jr3
23
+ jAGGiQIwHFj+dJZYUJR786osByBelJYsVZd2GbHQu209b5RCmGQ21gpSAk9QZW4B
24
+ 1bWeT0vT
25
+ -----END CERTIFICATE-----
26
+ PEM
27
+
28
+ NONCE_EXTENSION_OID = "1.2.840.113635.100.8.2"
29
+
30
+ def valid?(authenticator_data, client_data_hash)
31
+ valid_nonce?(authenticator_data, client_data_hash) &&
32
+ matching_public_key?(authenticator_data) &&
33
+ trustworthy? &&
34
+ [attestation_type, attestation_trust_path]
35
+ end
36
+
37
+ private
38
+
39
+ def valid_nonce?(authenticator_data, client_data_hash)
40
+ extension = cred_cert&.find_extension(NONCE_EXTENSION_OID)
41
+
42
+ if extension
43
+ sequence = OpenSSL::ASN1.decode(extension.value_der)
44
+
45
+ sequence.tag == OpenSSL::ASN1::SEQUENCE &&
46
+ sequence.value.size == 1 &&
47
+ sequence.value[0].value[0].value ==
48
+ OpenSSL::Digest::SHA256.digest(authenticator_data.data + client_data_hash)
49
+ end
50
+ end
51
+
52
+ def attestation_type
53
+ WebAuthn::AttestationStatement::ATTESTATION_TYPE_ANONCA
54
+ end
55
+
56
+ def cred_cert
57
+ attestation_certificate
58
+ end
59
+
60
+ def default_root_certificates
61
+ [ROOT_CERTIFICATE]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -16,11 +16,13 @@ module WebAuthn
16
16
  ATTESTATION_TYPE_SELF = "Self"
17
17
  ATTESTATION_TYPE_ATTCA = "AttCA"
18
18
  ATTESTATION_TYPE_BASIC_OR_ATTCA = "Basic_or_AttCA"
19
+ ATTESTATION_TYPE_ANONCA = "AnonCA"
19
20
 
20
21
  ATTESTATION_TYPES_WITH_ROOT = [
21
22
  ATTESTATION_TYPE_BASIC,
22
23
  ATTESTATION_TYPE_BASIC_OR_ATTCA,
23
- ATTESTATION_TYPE_ATTCA
24
+ ATTESTATION_TYPE_ATTCA,
25
+ ATTESTATION_TYPE_ANONCA
24
26
  ].freeze
25
27
 
26
28
  class Base
@@ -43,14 +45,8 @@ module WebAuthn
43
45
  certificates&.first
44
46
  end
45
47
 
46
- def certificate_chain
47
- if certificates
48
- certificates[1..-1]
49
- end
50
- end
51
-
52
48
  def attestation_certificate_key_id
53
- raw_subject_key_identifier&.unpack("H*")&.[](0)
49
+ attestation_certificate.subject_key_identifier&.unpack("H*")&.[](0)
54
50
  end
55
51
 
56
52
  private
@@ -58,17 +54,19 @@ module WebAuthn
58
54
  attr_reader :statement, :relying_party
59
55
 
60
56
  def matching_aaguid?(attested_credential_data_aaguid)
61
- extension = attestation_certificate&.extensions&.detect { |ext| ext.oid == AAGUID_EXTENSION_OID }
57
+ extension = attestation_certificate&.find_extension(AAGUID_EXTENSION_OID)
62
58
  if extension
63
- # `extension.value` mangles data into ASCII, so we must manually compare bytes
64
- # see https://github.com/ruby/openssl/pull/234
65
- extension.to_der[-WebAuthn::AuthenticatorData::AttestedCredentialData::AAGUID_LENGTH..-1] ==
66
- attested_credential_data_aaguid
59
+ aaguid_value = OpenSSL::ASN1.decode(extension.value_der).value
60
+ aaguid_value == attested_credential_data_aaguid
67
61
  else
68
62
  true
69
63
  end
70
64
  end
71
65
 
66
+ def matching_public_key?(authenticator_data)
67
+ attestation_certificate.public_key.to_der == authenticator_data.credential.public_key_object.to_der
68
+ end
69
+
72
70
  def certificates
73
71
  @certificates ||=
74
72
  raw_certificates&.map do |raw_certificate|
@@ -142,15 +140,6 @@ module WebAuthn
142
140
  end
143
141
  end
144
142
 
145
- def raw_subject_key_identifier
146
- extension = attestation_certificate.extensions.detect { |ext| ext.oid == "subjectKeyIdentifier" }
147
- return unless extension
148
-
149
- ext_asn1 = OpenSSL::ASN1.decode(extension.to_der)
150
- ext_value = ext_asn1.value.last
151
- OpenSSL::ASN1.decode(ext_value.value).value
152
- end
153
-
154
143
  def valid_signature?(authenticator_data, client_data_hash, public_key = attestation_certificate.public_key)
155
144
  raise("Incompatible algorithm and key") unless cose_algorithm.compatible_key?(public_key)
156
145