Skip to content

Commit dbff817

Browse files
committed
Revert "Support multiple relying parties (#296)"
This reverts commit 2f54c92.
1 parent 5e44214 commit dbff817

20 files changed

Lines changed: 130 additions & 621 deletions

lib/webauthn/attestation_object.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,18 @@ module WebAuthn
1010
class AttestationObject
1111
extend Forwardable
1212

13-
def self.deserialize(attestation_object, relying_party)
14-
from_map(CBOR.decode(attestation_object), relying_party)
13+
def self.deserialize(attestation_object)
14+
from_map(CBOR.decode(attestation_object))
1515
end
1616

17-
def self.from_map(map, relying_party)
17+
def self.from_map(map)
1818
new(
1919
authenticator_data: WebAuthn::AuthenticatorData.deserialize(map["authData"]),
20-
attestation_statement: WebAuthn::AttestationStatement.from(
21-
map["fmt"],
22-
map["attStmt"],
23-
relying_party: relying_party
24-
)
20+
attestation_statement: WebAuthn::AttestationStatement.from(map["fmt"], map["attStmt"])
2521
)
2622
end
2723

28-
attr_reader :authenticator_data, :attestation_statement, :relying_party
24+
attr_reader :authenticator_data, :attestation_statement
2925

3026
def initialize(authenticator_data:, attestation_statement:)
3127
@authenticator_data = authenticator_data

lib/webauthn/attestation_statement.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ class FormatNotSupportedError < Error; end
2828
ATTESTATION_FORMAT_TPM => WebAuthn::AttestationStatement::TPM
2929
}.freeze
3030

31-
def self.from(format, statement, relying_party: WebAuthn.configuration.relying_party)
31+
def self.from(format, statement)
3232
klass = FORMAT_TO_CLASS[format]
3333

3434
if klass
35-
klass.new(statement, relying_party)
35+
klass.new(statement)
3636
else
3737
raise(FormatNotSupportedError, "Unsupported attestation format '#{format}'")
3838
end

lib/webauthn/attestation_statement/base.rb

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ class UnsupportedAlgorithm < Error; end
2626
class Base
2727
AAGUID_EXTENSION_OID = "1.3.6.1.4.1.45724.1.1.4"
2828

29-
def initialize(statement, relying_party = WebAuthn.configuration.relying_party)
29+
def initialize(statement)
3030
@statement = statement
31-
@relying_party = relying_party
3231
end
3332

3433
def valid?(_authenticator_data, _client_data_hash)
@@ -55,7 +54,7 @@ def attestation_certificate_key_id
5554

5655
private
5756

58-
attr_reader :statement, :relying_party
57+
attr_reader :statement
5958

6059
def matching_aaguid?(attested_credential_data_aaguid)
6160
extension = attestation_certificate&.extensions&.detect { |ext| ext.oid == AAGUID_EXTENSION_OID }
@@ -96,10 +95,10 @@ def attestation_trust_path
9695

9796
def trustworthy?(aaguid: nil, attestation_certificate_key_id: nil)
9897
if ATTESTATION_TYPES_WITH_ROOT.include?(attestation_type)
99-
relying_party.acceptable_attestation_types.include?(attestation_type) &&
98+
configuration.acceptable_attestation_types.include?(attestation_type) &&
10099
valid_certificate_chain?(aaguid: aaguid, attestation_certificate_key_id: attestation_certificate_key_id)
101100
else
102-
relying_party.acceptable_attestation_types.include?(attestation_type)
101+
configuration.acceptable_attestation_types.include?(attestation_type)
103102
end
104103
end
105104

@@ -123,7 +122,7 @@ def attestation_root_certificates_store(aaguid: nil, attestation_certificate_key
123122

124123
def root_certificates(aaguid: nil, attestation_certificate_key_id: nil)
125124
root_certificates =
126-
relying_party.attestation_root_certificates_finders.reduce([]) do |certs, finder|
125+
configuration.attestation_root_certificates_finders.reduce([]) do |certs, finder|
127126
if certs.empty?
128127
finder.find(
129128
attestation_format: format,
@@ -170,10 +169,14 @@ def verification_data(authenticator_data, client_data_hash)
170169
def cose_algorithm
171170
@cose_algorithm ||=
172171
COSE::Algorithm.find(algorithm).tap do |alg|
173-
alg && relying_party.algorithms.include?(alg.name) ||
172+
alg && configuration.algorithms.include?(alg.name) ||
174173
raise(UnsupportedAlgorithm, "Unsupported algorithm #{algorithm}")
175174
end
176175
end
176+
177+
def configuration
178+
WebAuthn.configuration
179+
end
177180
end
178181
end
179182
end

lib/webauthn/authenticator_assertion_response.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class SignatureVerificationError < VerificationError; end
1010
class SignCountVerificationError < VerificationError; end
1111

1212
class AuthenticatorAssertionResponse < AuthenticatorResponse
13-
def self.from_client(response, relying_party: WebAuthn.configuration.relying_party)
14-
encoder = relying_party.encoder
13+
def self.from_client(response)
14+
encoder = WebAuthn.configuration.encoder
1515

1616
user_handle =
1717
if response["userHandle"]
@@ -22,8 +22,7 @@ def self.from_client(response, relying_party: WebAuthn.configuration.relying_par
2222
authenticator_data: encoder.decode(response["authenticatorData"]),
2323
client_data_json: encoder.decode(response["clientDataJSON"]),
2424
signature: encoder.decode(response["signature"]),
25-
user_handle: user_handle,
26-
relying_party: relying_party
25+
user_handle: user_handle
2726
)
2827
end
2928

lib/webauthn/authenticator_attestation_response.rb

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,12 @@ class AttestedCredentialVerificationError < VerificationError; end
1818
class AuthenticatorAttestationResponse < AuthenticatorResponse
1919
extend Forwardable
2020

21-
def self.from_client(response, relying_party: WebAuthn.configuration.relying_party)
22-
encoder = relying_party.encoder
21+
def self.from_client(response)
22+
encoder = WebAuthn.configuration.encoder
2323

2424
new(
2525
attestation_object: encoder.decode(response["attestationObject"]),
26-
client_data_json: encoder.decode(response["clientDataJSON"]),
27-
relying_party: relying_party
26+
client_data_json: encoder.decode(response["clientDataJSON"])
2827
)
2928
end
3029

@@ -34,22 +33,21 @@ def initialize(attestation_object:, **options)
3433
super(**options)
3534

3635
@attestation_object_bytes = attestation_object
37-
@relying_party = relying_party
3836
end
3937

4038
def verify(expected_challenge, expected_origin = nil, user_verification: nil, rp_id: nil)
4139
super
4240

4341
verify_item(:attested_credential)
44-
if relying_party.verify_attestation_statement
42+
if WebAuthn.configuration.verify_attestation_statement
4543
verify_item(:attestation_statement)
4644
end
4745

4846
true
4947
end
5048

5149
def attestation_object
52-
@attestation_object ||= WebAuthn::AttestationObject.deserialize(attestation_object_bytes, relying_party)
50+
@attestation_object ||= WebAuthn::AttestationObject.deserialize(attestation_object_bytes)
5351
end
5452

5553
def_delegators(
@@ -65,15 +63,14 @@ def attestation_object
6563

6664
private
6765

68-
attr_reader :attestation_object_bytes, :relying_party
66+
attr_reader :attestation_object_bytes
6967

7068
def type
7169
WebAuthn::TYPES[:create]
7270
end
7371

7472
def valid_attested_credential?
75-
attestation_object.valid_attested_credential? &&
76-
relying_party.algorithms.include?(authenticator_data.credential.algorithm)
73+
attestation_object.valid_attested_credential?
7774
end
7875

7976
def valid_attestation_statement?

lib/webauthn/authenticator_data/attested_credential_data.rb

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class AttestedCredentialData < BinData::Record
2424

2525
# TODO: use keyword_init when we dropped Ruby 2.4 support
2626
Credential =
27-
Struct.new(:id, :public_key, :algorithm) do
27+
Struct.new(:id, :public_key) do
2828
def public_key_object
2929
COSE::Key.deserialize(public_key).to_pkey
3030
end
@@ -47,7 +47,7 @@ def aaguid
4747
def credential
4848
@credential ||=
4949
if valid?
50-
Credential.new(id, public_key, algorithm)
50+
Credential.new(id, public_key)
5151
end
5252
end
5353

@@ -59,16 +59,10 @@ def length
5959

6060
private
6161

62-
def algorithm
63-
COSE::Algorithm.find(cose_key.alg).name
64-
end
65-
6662
def valid_credential_public_key?
67-
!!cose_key.alg
68-
end
63+
cose_key = COSE::Key.deserialize(public_key)
6964

70-
def cose_key
71-
@cose_key ||= COSE::Key.deserialize(public_key)
65+
!!cose_key.alg && WebAuthn.configuration.algorithms.include?(COSE::Algorithm.find(cose_key.alg).name)
7266
end
7367

7468
def public_key

lib/webauthn/authenticator_response.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,13 @@ class UserPresenceVerificationError < VerificationError; end
2020
class UserVerifiedVerificationError < VerificationError; end
2121

2222
class AuthenticatorResponse
23-
def initialize(client_data_json:, relying_party: WebAuthn.configuration.relying_party)
23+
def initialize(client_data_json:)
2424
@client_data_json = client_data_json
25-
@relying_party = relying_party
2625
end
2726

2827
def verify(expected_challenge, expected_origin = nil, user_verification: nil, rp_id: nil)
29-
expected_origin ||= relying_party.origin || raise("Unspecified expected origin")
30-
rp_id ||= relying_party.id
28+
expected_origin ||= WebAuthn.configuration.origin || raise("Unspecified expected origin")
29+
rp_id ||= WebAuthn.configuration.rp_id
3130

3231
verify_item(:type)
3332
verify_item(:token_binding)
@@ -36,7 +35,7 @@ def verify(expected_challenge, expected_origin = nil, user_verification: nil, rp
3635
verify_item(:authenticator_data)
3736
verify_item(:rp_id, rp_id || rp_id_from_origin(expected_origin))
3837

39-
if !relying_party.silent_authentication
38+
if !WebAuthn.configuration.silent_authentication
4039
verify_item(:user_presence)
4140
end
4241

@@ -59,7 +58,7 @@ def client_data
5958

6059
private
6160

62-
attr_reader :client_data_json, :relying_party
61+
attr_reader :client_data_json
6362

6463
def verify_item(item, *args)
6564
if send("valid_#{item}?", *args)

lib/webauthn/configuration.rb

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# frozen_string_literal: true
22

3-
require 'forwardable'
4-
require 'webauthn/relying_party'
3+
require "openssl"
4+
require "webauthn/encoder"
5+
require "webauthn/error"
56

67
module WebAuthn
78
def self.configuration
@@ -12,49 +13,50 @@ def self.configure
1213
yield(configuration)
1314
end
1415

16+
class RootCertificateFinderNotSupportedError < Error; end
17+
1518
class Configuration
16-
extend Forwardable
17-
18-
def_delegators :@relying_party,
19-
:algorithms,
20-
:algorithms=,
21-
:encoding,
22-
:encoding=,
23-
:origin,
24-
:origin=,
25-
:verify_attestation_statement,
26-
:verify_attestation_statement=,
27-
:credential_options_timeout,
28-
:credential_options_timeout=,
29-
:silent_authentication,
30-
:silent_authentication=,
31-
:acceptable_attestation_types,
32-
:acceptable_attestation_types=,
33-
:attestation_root_certificates_finders,
34-
:attestation_root_certificates_finders=,
35-
:encoder,
36-
:encoder=
37-
38-
attr_reader :relying_party
19+
DEFAULT_ALGORITHMS = ["ES256", "PS256", "RS256"].compact.freeze
20+
21+
attr_accessor :algorithms
22+
attr_accessor :encoding
23+
attr_accessor :origin
24+
attr_accessor :rp_id
25+
attr_accessor :rp_name
26+
attr_accessor :verify_attestation_statement
27+
attr_accessor :credential_options_timeout
28+
attr_accessor :silent_authentication
29+
attr_accessor :acceptable_attestation_types
30+
attr_reader :attestation_root_certificates_finders
3931

4032
def initialize
41-
@relying_party = RelyingParty.new
33+
@algorithms = DEFAULT_ALGORITHMS.dup
34+
@encoding = WebAuthn::Encoder::STANDARD_ENCODING
35+
@verify_attestation_statement = true
36+
@credential_options_timeout = 120000
37+
@silent_authentication = false
38+
@acceptable_attestation_types = ['None', 'Self', 'Basic', 'AttCA', 'Basic_or_AttCA']
39+
@attestation_root_certificates_finders = []
4240
end
4341

44-
def rp_name
45-
relying_party.name
42+
# This is the user-data encoder.
43+
# Used to decode user input and to encode data provided to the user.
44+
def encoder
45+
@encoder ||= WebAuthn::Encoder.new(encoding)
4646
end
4747

48-
def rp_name=(name)
49-
relying_party.name = name
50-
end
48+
def attestation_root_certificates_finders=(finders)
49+
if !finders.respond_to?(:each)
50+
finders = [finders]
51+
end
5152

52-
def rp_id
53-
relying_party.id
54-
end
53+
finders.each do |finder|
54+
unless finder.respond_to?(:find)
55+
raise RootCertificateFinderNotSupportedError, "Finder must implement `find` method"
56+
end
57+
end
5558

56-
def rp_id=(id)
57-
relying_party.id = id
59+
@attestation_root_certificates_finders = finders
5860
end
5961
end
6062
end

lib/webauthn/credential.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
require "webauthn/public_key_credential/request_options"
55
require "webauthn/public_key_credential_with_assertion"
66
require "webauthn/public_key_credential_with_attestation"
7-
require "webauthn/relying_party"
87

98
module WebAuthn
109
module Credential
@@ -16,12 +15,12 @@ def self.options_for_get(**keyword_arguments)
1615
WebAuthn::PublicKeyCredential::RequestOptions.new(**keyword_arguments)
1716
end
1817

19-
def self.from_create(credential, relying_party: WebAuthn.configuration.relying_party)
20-
WebAuthn::PublicKeyCredentialWithAttestation.from_client(credential, relying_party: relying_party)
18+
def self.from_create(credential)
19+
WebAuthn::PublicKeyCredentialWithAttestation.from_client(credential)
2120
end
2221

23-
def self.from_get(credential, relying_party: WebAuthn.configuration.relying_party)
24-
WebAuthn::PublicKeyCredentialWithAssertion.from_client(credential, relying_party: relying_party)
22+
def self.from_get(credential)
23+
WebAuthn::PublicKeyCredentialWithAssertion.from_client(credential)
2524
end
2625
end
2726
end

lib/webauthn/fake_client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ module WebAuthn
1010
class FakeClient
1111
TYPES = { create: "webauthn.create", get: "webauthn.get" }.freeze
1212

13-
attr_reader :origin, :token_binding, :encoding
13+
attr_reader :origin, :token_binding
1414

1515
def initialize(
1616
origin = fake_origin,
@@ -105,7 +105,7 @@ def get(challenge: fake_challenge,
105105

106106
private
107107

108-
attr_reader :authenticator
108+
attr_reader :authenticator, :encoding
109109

110110
def data_json_for(method, challenge)
111111
data = {

0 commit comments

Comments
 (0)