Skip to content

Commit 38b75dc

Browse files
committed
Raise error on incomplete RSA ANS.1 sequence
1 parent 6167a62 commit 38b75dc

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/jwt/jwk/rsa.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ def create_rsa_key_using_der(rsa_parameters)
137137

138138
if sequence.size > 2 # Append "two-prime" version for private key
139139
sequence.unshift(OpenSSL::ASN1::Integer.new(0))
140+
141+
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
140142
end
141143

142144
OpenSSL::PKey::RSA.new(OpenSSL::ASN1::Sequence(sequence).to_der)

spec/jwk/rsa_spec.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,14 @@
196196
subject(:rsa) { described_class.create_rsa_key_using_der(rsa_parameters) }
197197

198198
include_examples 'creating an RSA object from complete JWK parameters'
199+
200+
context 'when e, n, d is given' do
201+
let(:jwk_parameters) { all_jwk_parameters.slice(:e, :n, :d) }
202+
203+
it 'expects all CRT parameters given and raises error' do
204+
expect { subject }.to raise_error(JWT::JWKError, 'Creating a RSA key with a private key requires the CRT parameters to be defined')
205+
end
206+
end
199207
end
200208

201209
describe '.create_rsa_key_using_sets' do

0 commit comments

Comments
 (0)