webauthn 2.3.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build.yml +32 -0
- data/.github/workflows/git.yml +21 -0
- data/.rubocop.yml +57 -1
- data/CHANGELOG.md +79 -0
- data/README.md +8 -5
- data/SECURITY.md +6 -3
- data/docs/advanced_configuration.md +174 -0
- data/docs/u2f_migration.md +14 -20
- data/lib/cose/rsapkcs1_algorithm.rb +7 -0
- data/lib/webauthn/attestation_object.rb +9 -5
- data/lib/webauthn/attestation_statement/android_key.rb +0 -4
- data/lib/webauthn/attestation_statement/android_safetynet.rb +1 -5
- data/lib/webauthn/attestation_statement/apple.rb +65 -0
- data/lib/webauthn/attestation_statement/base.rb +18 -32
- data/lib/webauthn/attestation_statement/none.rb +7 -1
- data/lib/webauthn/attestation_statement/packed.rb +1 -1
- data/lib/webauthn/attestation_statement/tpm.rb +2 -2
- data/lib/webauthn/attestation_statement.rb +6 -3
- data/lib/webauthn/authenticator_assertion_response.rb +4 -3
- data/lib/webauthn/authenticator_attestation_response.rb +10 -7
- data/lib/webauthn/authenticator_data/attested_credential_data.rb +10 -5
- data/lib/webauthn/authenticator_data.rb +10 -2
- data/lib/webauthn/authenticator_response.rb +7 -7
- data/lib/webauthn/configuration.rb +38 -42
- data/lib/webauthn/credential.rb +5 -4
- data/lib/webauthn/credential_creation_options.rb +2 -0
- data/lib/webauthn/credential_request_options.rb +2 -0
- data/lib/webauthn/fake_authenticator/attestation_object.rb +8 -0
- data/lib/webauthn/fake_authenticator/authenticator_data.rb +20 -5
- data/lib/webauthn/fake_authenticator.rb +19 -3
- data/lib/webauthn/fake_client.rb +20 -5
- data/lib/webauthn/public_key_credential/creation_options.rb +3 -3
- data/lib/webauthn/public_key_credential/entity.rb +3 -4
- data/lib/webauthn/public_key_credential/options.rb +9 -8
- data/lib/webauthn/public_key_credential/request_options.rb +11 -1
- data/lib/webauthn/public_key_credential.rb +24 -5
- data/lib/webauthn/public_key_credential_with_assertion.rb +14 -1
- data/lib/webauthn/relying_party.rb +120 -0
- data/lib/webauthn/u2f_migrator.rb +4 -1
- data/lib/webauthn/version.rb +1 -1
- data/webauthn.gemspec +7 -8
- metadata +40 -59
- data/.travis.yml +0 -39
- data/Appraisals +0 -21
- data/gemfiles/cose_head.gemfile +0 -7
- data/gemfiles/openssl_2_0.gemfile +0 -7
- data/gemfiles/openssl_2_1.gemfile +0 -7
- data/gemfiles/openssl_2_2.gemfile +0 -7
- data/gemfiles/openssl_head.gemfile +0 -7
- data/lib/webauthn/security_utils.rb +0 -20
- data/script/ci/install-openssl +0 -7
- data/script/ci/install-ruby +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b133f46bd003c9bfb9a8557bb8caeca7239fcd6c185f78e74e0ae578444d576e
|
4
|
+
data.tar.gz: 14a32debc72ddcfe7e752118ebd4db832b8a46a5628ee54830f30eada4159bcf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b4ff5cee18575b517473fef7d8000d7e41f113b178378e64a4d2b9036d248f4295edd846a519ab76036a270c3066020fbe44847019812c2a5758f2b1b428f4c
|
7
|
+
data.tar.gz: f3ab22709cbf537982e163acc60dbe114217f223b18cb4cf681a3d932e2f31276f8286091e49da392356c1958ada7e2c07a5b86b48d57b597f965a57c1bcf63d
|
@@ -0,0 +1,32 @@
|
|
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.2'
|
20
|
+
- '3.1'
|
21
|
+
- '3.0'
|
22
|
+
- '2.7'
|
23
|
+
- '2.6'
|
24
|
+
- '2.5'
|
25
|
+
- truffleruby
|
26
|
+
steps:
|
27
|
+
- uses: actions/checkout@v3
|
28
|
+
- uses: ruby/setup-ruby@v1
|
29
|
+
with:
|
30
|
+
ruby-version: ${{ matrix.ruby }}
|
31
|
+
bundler-cache: true
|
32
|
+
- 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@v3
|
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.
|
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,5 +1,69 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [v3.0.0] - 2023-02-15
|
4
|
+
|
5
|
+
### Added
|
6
|
+
|
7
|
+
- Add the capability of handling appid extension #319 [@santiagorodriguez96]
|
8
|
+
- Add support for credential backup flags #378 [@santiagorodriguez96]
|
9
|
+
- Update dependencies to make gem compatible with OpenSSL 3.1 ([@bdewater],[@santiagorodriguez96])
|
10
|
+
|
11
|
+
## [v3.0.0.alpha2] - 2022-09-12
|
12
|
+
|
13
|
+
### Added
|
14
|
+
|
15
|
+
- 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])
|
16
|
+
|
17
|
+
### BREAKING CHANGES
|
18
|
+
|
19
|
+
- Bumped minimum required Ruby version to 2.5 ([@bdewater])
|
20
|
+
|
21
|
+
## [v3.0.0.alpha1] - 2020-06-27
|
22
|
+
|
23
|
+
### Added
|
24
|
+
|
25
|
+
- Ability to define multiple relying parties with the introduction of the `WebAuthn::RelyingParty` class ([@padulafacundo], [@brauliomartinezlm])
|
26
|
+
|
27
|
+
## [v2.5.2] - 2022-07-13
|
28
|
+
|
29
|
+
### Added
|
30
|
+
|
31
|
+
- Updated dependencies to make the gem compatible with openssl-3 [@ClearlyClaire]
|
32
|
+
|
33
|
+
## [v2.5.1] - 2022-03-20
|
34
|
+
|
35
|
+
### Added
|
36
|
+
|
37
|
+
- Updated openssl support to be ~>2.2 [@bdewater]
|
38
|
+
|
39
|
+
### Removed
|
40
|
+
|
41
|
+
- Removed dependency [secure_compare dependency] (https://rubygems.org/gems/secure_compare/versions/0.0.1) and use OpenSSL#secure_compare instead [@bdewater]
|
42
|
+
|
43
|
+
## [v2.5.0] - 2021-03-14
|
44
|
+
|
45
|
+
### Added
|
46
|
+
|
47
|
+
- Support 'apple' attestation statement format ([#343](https://github.com/cedarcode/webauthn-ruby/pull/343) / [@juanarias93], [@santiagorodriguez96])
|
48
|
+
- Allow specifying an array of ids as `allow_credentials:` for `FakeClient#get` method ([#335](https://github.com/cedarcode/webauthn-ruby/pull/335) / [@kingjan1999])
|
49
|
+
|
50
|
+
### Removed
|
51
|
+
|
52
|
+
- 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])
|
53
|
+
|
54
|
+
## [v2.4.1] - 2021-02-15
|
55
|
+
|
56
|
+
### Fixed
|
57
|
+
|
58
|
+
- 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.
|
59
|
+
|
60
|
+
## [v2.4.0] - 2020-09-03
|
61
|
+
|
62
|
+
### Added
|
63
|
+
|
64
|
+
- Support for ES256K credentials
|
65
|
+
- `FakeClient#get` accepts `user_handle:` keyword argument ([@lgarron])
|
66
|
+
|
3
67
|
## [v2.3.0] - 2020-06-27
|
4
68
|
|
5
69
|
### Added
|
@@ -294,6 +358,14 @@ Note: Both additions should help making it compatible with Chrome for Android 70
|
|
294
358
|
- `WebAuthn::AuthenticatorAttestationResponse.valid?` can be used to validate fido-u2f attestations returned by the browser
|
295
359
|
- Works with ruby 2.5
|
296
360
|
|
361
|
+
[v3.0.0]: https://github.com/cedarcode/webauthn-ruby/compare/2-stable...v3.0.0/
|
362
|
+
[v3.0.0.alpha2]: https://github.com/cedarcode/webauthn-ruby/compare/2-stable...v3.0.0.alpha2/
|
363
|
+
[v3.0.0.alpha1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.3.0...v3.0.0.alpha1
|
364
|
+
[v2.5.2]: https://github.com/cedarcode/webauthn-ruby/compare/v2.5.1...v2.5.2/
|
365
|
+
[v2.5.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.5.0...v2.5.1/
|
366
|
+
[v2.5.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.4.1...v2.5.0/
|
367
|
+
[v2.4.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.4.0...v2.4.1/
|
368
|
+
[v2.4.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.3.0...v2.4.0/
|
297
369
|
[v2.3.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.2.1...v2.3.0/
|
298
370
|
[v2.2.1]: https://github.com/cedarcode/webauthn-ruby/compare/v2.2.0...v2.2.1/
|
299
371
|
[v2.2.0]: https://github.com/cedarcode/webauthn-ruby/compare/v2.1.0...v2.2.0/
|
@@ -321,6 +393,7 @@ Note: Both additions should help making it compatible with Chrome for Android 70
|
|
321
393
|
[v0.2.0]: https://github.com/cedarcode/webauthn-ruby/compare/v0.1.0...v0.2.0/
|
322
394
|
[v0.1.0]: https://github.com/cedarcode/webauthn-ruby/compare/v0.0.0...v0.1.0/
|
323
395
|
|
396
|
+
[@brauliomartinezlm]: https://github.com/brauliomartinezlm
|
324
397
|
[@bdewater]: https://github.com/bdewater
|
325
398
|
[@jdongelmans]: https://github.com/jdongelmans
|
326
399
|
[@kalebtesfay]: https://github.com/kalebtesfay
|
@@ -329,3 +402,9 @@ Note: Both additions should help making it compatible with Chrome for Android 70
|
|
329
402
|
[@ssuttner]: https://github.com/ssuttner
|
330
403
|
[@padulafacundo]: https://github.com/padulafacundo
|
331
404
|
[@santiagorodriguez96]: https://github.com/santiagorodriguez96
|
405
|
+
[@lgarron]: https://github.com/lgarron
|
406
|
+
[@juanarias93]: https://github.com/juanarias93
|
407
|
+
[@kingjan1999]: https://github.com/@kingjan1999
|
408
|
+
[@jdongelmans]: https://github.com/jdongelmans
|
409
|
+
[@petergoldstein]: https://github.com/petergoldstein
|
410
|
+
[@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.
|
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
|
|
@@ -16,7 +16,7 @@ Makes your Ruby/Rails web server become a functional [WebAuthn Relying Party](ht
|
|
16
16
|
|
17
17
|
Takes care of the [server-side operations](https://www.w3.org/TR/webauthn/#rp-operations) needed to
|
18
18
|
[register](https://www.w3.org/TR/webauthn/#registration) or [authenticate](https://www.w3.org/TR/webauthn/#authentication)
|
19
|
-
a user [credential](https://www.w3.org/TR/webauthn/#public-key-credential), including the necessary cryptographic checks.
|
19
|
+
a user's [public key credential](https://www.w3.org/TR/webauthn/#public-key-credential) (also called a "passkey"), including the necessary cryptographic checks.
|
20
20
|
|
21
21
|
## Table of Contents
|
22
22
|
|
@@ -52,7 +52,7 @@ WebAuthn (Web Authentication) is a W3C standard for secure public-key authentica
|
|
52
52
|
|
53
53
|
- WebAuthn [W3C Recommendation](https://www.w3.org/TR/webauthn/) (i.e. "The Standard")
|
54
54
|
- [Web Authentication API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Authentication_API) in MDN
|
55
|
-
- How to use
|
55
|
+
- How to use WebAuthn in native [Android](https://developers.google.com/identity/fido/android/native-apps) or [macOS/iOS/iPadOS](https://developer.apple.com/documentation/authenticationservices/public-private_key_authentication) apps.
|
56
56
|
- [Security Benefits for WebAuthn Servers (a.k.a Relying Parties)](https://www.w3.org/TR/webauthn/#sctn-rp-benefits)
|
57
57
|
|
58
58
|
## Prerequisites
|
@@ -89,13 +89,15 @@ Or install it yourself as:
|
|
89
89
|
|
90
90
|
## Usage
|
91
91
|
|
92
|
-
You can find a working example on how to use this gem in a __Rails__ app in [webauthn-rails-demo-app](https://github.com/cedarcode/webauthn-rails-demo-app).
|
92
|
+
You can find a working example on how to use this gem in a pasword-less login in a __Rails__ app in [webauthn-rails-demo-app](https://github.com/cedarcode/webauthn-rails-demo-app). If you want to see an example on how to use this gem as a second factor authenticator in a __Rails__ application instead, you can check it in [webauthn-2fa-rails-demo](https://github.com/cedarcode/webauthn-2fa-rails-demo).
|
93
93
|
|
94
94
|
If you are migrating an existing application from the legacy FIDO U2F JavaScript API to WebAuthn, also refer to
|
95
95
|
[`docs/u2f_migration.md`](docs/u2f_migration.md).
|
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
|
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.
|
8
|
-
| 2.
|
9
|
-
| 2.
|
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_registration(
|
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`.
|
data/docs/u2f_migration.md
CHANGED
@@ -53,7 +53,7 @@ migrated_credential.authenticator_data.sign_count
|
|
53
53
|
|
54
54
|
## Authenticate migrated U2F credentials
|
55
55
|
|
56
|
-
Following the documentation on the [authentication initiation](https://github.com/cedarcode/webauthn-ruby/blob/master/README.md#
|
56
|
+
Following the documentation on the [authentication initiation](https://github.com/cedarcode/webauthn-ruby/blob/master/README.md#initiation-phase-1),
|
57
57
|
you need to specify the [FIDO AppID extension](https://www.w3.org/TR/webauthn/#sctn-appid-extension) for U2F migratedq
|
58
58
|
credentials. The WebAuthn standard explains:
|
59
59
|
|
@@ -65,32 +65,26 @@ For the earlier given example `domain` this means:
|
|
65
65
|
- FIDO AppID: `https://login.example.com`
|
66
66
|
- Valid RP IDs: `login.example.com` (default) and `example.com`
|
67
67
|
|
68
|
+
You can request the use of the `appid` extension by setting the AppID in the configuration, like this:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
WebAuthn.configure do |config|
|
72
|
+
config.legacy_u2f_appid = "https://login.example.com"
|
73
|
+
end
|
74
|
+
```
|
75
|
+
|
76
|
+
By doing this, the `appid` extension will be automatically requested when generating the options for get:
|
77
|
+
|
68
78
|
```ruby
|
69
|
-
|
70
|
-
credential_request_options[:extensions] = { appid: domain.to_s }
|
79
|
+
options = WebAuthn::Credential.options_for_get
|
71
80
|
```
|
72
81
|
|
73
82
|
On the frontend, in the resolved value from `navigator.credentials.get({ "publicKey": credentialRequestOptions })` add
|
74
83
|
a call to [getClientExtensionResults()](https://www.w3.org/TR/webauthn/#dom-publickeycredential-getclientextensionresults)
|
75
84
|
and send its result to your backend alongside the `id`/`rawId` and `response` values. If the authenticator used the AppID
|
76
|
-
extension, the returned value will contain `{ "appid": true }`.
|
85
|
+
extension, the returned value will contain `{ "appid": true }`.
|
77
86
|
|
78
|
-
During authentication verification phase, you
|
87
|
+
During authentication verification phase, if you followed the [verification phase documentation](https://github.com/cedarcode/webauthn-ruby#verification-phase-1) and have set the AppID in the config, the method `PublicKeyCredentialWithAssertion#verify` will be smart enough to determine if it should use the AppID or the RP ID to verify the WebAuthn credential, depending on the output of the `appid` client extension:
|
79
88
|
|
80
89
|
> If true, the AppID was used and thus, when verifying an assertion, the Relying Party MUST expect the `rpIdHash` to be
|
81
90
|
> the hash of the _AppID_, not the RP ID.
|
82
|
-
|
83
|
-
```ruby
|
84
|
-
assertion_response = WebAuthn::AuthenticatorAssertionResponse.new(
|
85
|
-
credential_id: params[:id],
|
86
|
-
authenticator_data: params[:response][:authenticatorData],
|
87
|
-
client_data_json: params[:response][:clientDataJSON],
|
88
|
-
signature: params[:response][:signature],
|
89
|
-
)
|
90
|
-
|
91
|
-
assertion_response.verify(
|
92
|
-
expected_challenge,
|
93
|
-
allowed_credentials: [credential],
|
94
|
-
rp_id: params[:clientExtensionResults][:appid] ? domain.to_s : domain.host,
|
95
|
-
)
|
96
|
-
```
|
@@ -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"))
|
@@ -10,18 +10,22 @@ module WebAuthn
|
|
10
10
|
class AttestationObject
|
11
11
|
extend Forwardable
|
12
12
|
|
13
|
-
def self.deserialize(attestation_object)
|
14
|
-
from_map(CBOR.decode(attestation_object))
|
13
|
+
def self.deserialize(attestation_object, relying_party)
|
14
|
+
from_map(CBOR.decode(attestation_object), relying_party)
|
15
15
|
end
|
16
16
|
|
17
|
-
def self.from_map(map)
|
17
|
+
def self.from_map(map, relying_party)
|
18
18
|
new(
|
19
19
|
authenticator_data: WebAuthn::AuthenticatorData.deserialize(map["authData"]),
|
20
|
-
attestation_statement: WebAuthn::AttestationStatement.from(
|
20
|
+
attestation_statement: WebAuthn::AttestationStatement.from(
|
21
|
+
map["fmt"],
|
22
|
+
map["attStmt"],
|
23
|
+
relying_party: relying_party
|
24
|
+
)
|
21
25
|
)
|
22
26
|
end
|
23
27
|
|
24
|
-
attr_reader :authenticator_data, :attestation_statement
|
28
|
+
attr_reader :authenticator_data, :attestation_statement, :relying_party
|
25
29
|
|
26
30
|
def initialize(authenticator_data:, attestation_statement:)
|
27
31
|
@authenticator_data = authenticator_data
|
@@ -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
|
51
|
+
def certificates
|
56
52
|
attestation_response.certificate_chain[0..-2]
|
57
53
|
end
|
58
54
|
|