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
67module 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
6062end
0 commit comments