Skip to content

Commit 760ec82

Browse files
committed
(PUP-11935) Handle JRuby OpenSSL behavior
Starting with jruby-openssl 0.13.0[1] (which is included in JRuby >= 9.3.5.0), certificate signing raises an error when there is a discrepancy between the certificate and key. This behavior in JRuby differs from MRI OpenSSL. This commit adds a test for this JRuby-specific behavior and updates existing tests to skip when running on affected versions of JRuby. [1] jruby/jruby-openssl@4b2968b
1 parent 2fcd7c7 commit 760ec82

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
require 'spec_helper'
2+
3+
describe Puppet::SSL::CertificateSigner do
4+
include PuppetSpec::Files
5+
6+
let(:wrong_key) { OpenSSL::PKey::RSA.new(512) }
7+
let(:client_cert) { cert_fixture('signed.pem') }
8+
9+
# jruby-openssl >= 0.13.0 (JRuby >= 9.3.5.0) raises an error when signing a
10+
# certificate when there is a discrepancy between the certificate and key.
11+
it 'raises if client cert signature is invalid', if: Puppet::Util::Platform.jruby? && RUBY_VERSION.to_f >= 2.6 do
12+
expect {
13+
client_cert.sign(wrong_key, OpenSSL::Digest::SHA256.new)
14+
}.to raise_error(OpenSSL::X509::CertificateError,
15+
'invalid public key data')
16+
end
17+
end

spec/unit/ssl/ssl_provider_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@
298298
).to eq(['CN=signed', 'CN=Test CA Subauthority', 'CN=Test CA'])
299299
end
300300

301-
it 'raises if client cert signature is invalid' do
301+
it 'raises if client cert signature is invalid', unless: Puppet::Util::Platform.jruby? && RUBY_VERSION.to_f >= 2.6 do
302302
client_cert.sign(wrong_key, OpenSSL::Digest::SHA256.new)
303303
expect {
304304
subject.create_context(**config.merge(client_cert: client_cert))
@@ -337,7 +337,7 @@
337337
end
338338
end
339339

340-
it 'raises if intermediate CA signature is invalid' do
340+
it 'raises if intermediate CA signature is invalid', unless: Puppet::Util::Platform.jruby? && RUBY_VERSION.to_f >= 2.6 do
341341
int = global_cacerts.last
342342
int.sign(wrong_key, OpenSSL::Digest::SHA256.new)
343343

0 commit comments

Comments
 (0)