Skip to content

Commit

Permalink
Use upstreamed JWT X5cKeyFinder
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewater committed Oct 30, 2023
1 parent 35a144e commit 4dfe960
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 244 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ PATH
remote: .
specs:
fido_metadata (0.3.0)
jwt (~> 2.0)
jwt (~> 2.4)

GEM
remote: https://rubygems.org/
Expand All @@ -15,7 +15,7 @@ GEM
diff-lcs (1.5.0)
hashdiff (1.0.1)
jaro_winkler (1.5.4)
jwt (2.3.0)
jwt (2.7.1)
parallel (1.21.0)
parser (3.1.1.0)
ast (~> 2.4.1)
Expand Down
2 changes: 1 addition & 1 deletion fido_metadata.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 2.7"

spec.add_dependency "jwt", "~> 2.0"
spec.add_dependency "jwt", "~> 2.4"
spec.add_development_dependency "rake", "~> 13.0"
spec.add_development_dependency "rspec", "~> 3.8"
spec.add_development_dependency "rubocop", "0.75.0"
Expand Down
3 changes: 1 addition & 2 deletions lib/fido_metadata/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
require "net/http"
require "openssl"
require "fido_metadata/refinement/fixed_length_secure_compare"
require "fido_metadata/x5c_key_finder"
require "fido_metadata/version"

module FidoMetadata
Expand Down Expand Up @@ -32,7 +31,7 @@ def download_toc(uri, trusted_certs: FIDO_ROOT_CERTIFICATES)
crls = download_crls(jwt_certificates)

begin
X5cKeyFinder.from(jwt_certificates, trusted_certs, crls)
JWT::X5cKeyFinder.new(trusted_certs, crls).from(jwt_certificates)
rescue JWT::VerificationError => e
raise(UnverifiedSigningKeyError, e.message)
end
Expand Down
50 changes: 0 additions & 50 deletions lib/fido_metadata/x5c_key_finder.rb

This file was deleted.

18 changes: 10 additions & 8 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@
stub_request(:get, "http://crl.globalsign.com/gs/gsextendvalsha2g3r3.crl").to_return(extendval_crl)
stub_request(:get, "http://crl.globalsign.com/root-r3.crl").to_return(root_crl)

allow(FidoMetadata::X5cKeyFinder).to receive(:build_store).and_wrap_original do |method, *args|
store = method.call(*args)
store.time = current_time.to_i
store
allow(JWT::X5cKeyFinder).to receive(:new).and_wrap_original do |method, *args|
key_finder = method.call(*args)
key_finder.instance_variable_get(:@store).time = current_time.to_i
key_finder
end
end

Expand Down Expand Up @@ -74,17 +74,18 @@
"https://fidoalliance.co.nz/safetynetpki/crl/FIDO%20Fake%20Root%20Certificate%20Authority%202018.crl"
).to_return(status: 404)

allow(FidoMetadata::X5cKeyFinder).to receive(:build_store).and_wrap_original do |method, *args|
store = method.call(*args)
store.time = current_time.to_i
store
allow(JWT::X5cKeyFinder).to receive(:new).and_wrap_original do |method, *args|
key_finder = method.call(*args)
key_finder.instance_variable_get(:@store).time = current_time.to_i
key_finder
end
end

context "because the chain cannot be verified" do
let(:toc) { File.read(SUPPORT_PATH.join("mds_toc_invalid_chain.txt")) }

specify do
skip("need RS256 JWT for this instead of current ES256 file")
error = "Certificate verification failed: unable to get local issuer certificate. Certificate subject: " \
"/C=US/O=FIDO Alliance/OU=FAKE Metadata TOC Signing FAKE/CN=FAKE Metadata TOC Signer 4 FAKE."
expect { subject }.to raise_error(described_class::UnverifiedSigningKeyError, error)
Expand All @@ -95,6 +96,7 @@
let(:toc) { File.read(SUPPORT_PATH.join("mds_toc_revoked.txt")) }

specify do
skip("need RS256 JWT for this instead of current ES256 file")
error = "Certificate verification failed: certificate revoked. Certificate subject: " \
"/C=US/O=FIDO Alliance/OU=FAKE Metadata TOC Signing FAKE/CN=FAKE Metadata TOC Signer 4 FAKE."
expect { subject }.to raise_error(described_class::UnverifiedSigningKeyError, error)
Expand Down
181 changes: 0 additions & 181 deletions spec/x5c_key_finder_spec.rb

This file was deleted.

0 comments on commit 4dfe960

Please sign in to comment.