diff --git a/examples/puma/client-certs/ca_store.jks b/examples/puma/client-certs/ca_store.jks new file mode 100644 index 00000000..afe3497c Binary files /dev/null and b/examples/puma/client-certs/ca_store.jks differ diff --git a/ext/puma_http11/org/jruby/puma/MiniSSL.java b/ext/puma_http11/org/jruby/puma/MiniSSL.java index dd42f7af..1b9ab433 100644 --- a/ext/puma_http11/org/jruby/puma/MiniSSL.java +++ b/ext/puma_http11/org/jruby/puma/MiniSSL.java @@ -160,7 +160,12 @@ public class MiniSSL extends RubyObject { // MiniSSL::Engine truststoreType = keystoreType; } else if (!isDefaultSymbol(context, truststore)) { truststoreFile = truststore.convertToString().asJavaString(); - truststorePass = asStringValue(miniSSLContext.callMethod(context, "truststore_pass"), null).toCharArray(); + IRubyObject pass = miniSSLContext.callMethod(context, "truststore_pass"); + if (pass.isNil()) { + truststorePass = null; + } else { + truststorePass = asStringValue(pass, null).toCharArray(); + } truststoreType = asStringValue(miniSSLContext.callMethod(context, "truststore_type"), KeyStore::getDefaultType); } else { // self.truststore = :default truststoreFile = null; diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index 6808e589..ef36775d 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -489,6 +489,25 @@ class TestPumaServerSSLClient < Minitest::Test end end if Puma.jruby? + def test_verify_client_cert_with_truststore_without_pass + ctx = Puma::MiniSSL::Context.new + ctx.keystore = "#{CERT_PATH}/server.p12" + ctx.keystore_type = 'pkcs12' + ctx.keystore_pass = 'jruby_puma' + ctx.truststore = "#{CERT_PATH}/ca_store.jks" # cert entry can be read without password + ctx.truststore_type = 'jks' + ctx.verify_mode = Puma::MiniSSL::VERIFY_PEER + + assert_ssl_client_error_match(false, context: ctx) do |http| + key = "#{CERT_PATH}/client.key" + crt = "#{CERT_PATH}/client.crt" + http.key = OpenSSL::PKey::RSA.new File.read(key) + http.cert = OpenSSL::X509::Certificate.new File.read(crt) + http.ca_file = "#{CERT_PATH}/ca.crt" + http.verify_mode = OpenSSL::SSL::VERIFY_PEER + end + end if Puma.jruby? + end if ::Puma::HAS_SSL class TestPumaServerSSLWithCertPemAndKeyPem < Minitest::Test