Skip to content

Commit

Permalink
Raise error on incomplete RSA ANS.1 sequence
Browse files Browse the repository at this point in the history
  • Loading branch information
anakinj committed Oct 30, 2022
1 parent 6167a62 commit 38b75dc
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/jwt/jwk/rsa.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ def create_rsa_key_using_der(rsa_parameters)

if sequence.size > 2 # Append "two-prime" version for private key
sequence.unshift(OpenSSL::ASN1::Integer.new(0))

raise JWT::JWKError, 'Creating a RSA key with a private key requires the CRT parameters to be defined' if sequence.size < RSA_ASN1_SEQUENCE.size
end

OpenSSL::PKey::RSA.new(OpenSSL::ASN1::Sequence(sequence).to_der)
Expand Down
8 changes: 8 additions & 0 deletions spec/jwk/rsa_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@
subject(:rsa) { described_class.create_rsa_key_using_der(rsa_parameters) }

include_examples 'creating an RSA object from complete JWK parameters'

context 'when e, n, d is given' do
let(:jwk_parameters) { all_jwk_parameters.slice(:e, :n, :d) }

it 'expects all CRT parameters given and raises error' do
expect { subject }.to raise_error(JWT::JWKError, 'Creating a RSA key with a private key requires the CRT parameters to be defined')
end
end
end

describe '.create_rsa_key_using_sets' do
Expand Down

0 comments on commit 38b75dc

Please sign in to comment.