Skip to content

Commit

Permalink
(PUP-11935) Handle JRuby OpenSSL behavior
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mhashizume committed Sep 15, 2023
1 parent 2fcd7c7 commit 760ec82
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 17 additions & 0 deletions spec/unit/ssl/certificate_signer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

describe Puppet::SSL::CertificateSigner do
include PuppetSpec::Files

let(:wrong_key) { OpenSSL::PKey::RSA.new(512) }
let(:client_cert) { cert_fixture('signed.pem') }

# jruby-openssl >= 0.13.0 (JRuby >= 9.3.5.0) raises an error when signing a
# certificate when there is a discrepancy between the certificate and key.
it 'raises if client cert signature is invalid', if: Puppet::Util::Platform.jruby? && RUBY_VERSION.to_f >= 2.6 do
expect {
client_cert.sign(wrong_key, OpenSSL::Digest::SHA256.new)
}.to raise_error(OpenSSL::X509::CertificateError,
'invalid public key data')
end
end
4 changes: 2 additions & 2 deletions spec/unit/ssl/ssl_provider_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@
).to eq(['CN=signed', 'CN=Test CA Subauthority', 'CN=Test CA'])
end

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

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

Expand Down

0 comments on commit 760ec82

Please sign in to comment.