I am trying to configure SSL in my Java (Thrift) client. (mTLS) I need a truststore that contains my CA certificate, so that the client can trust the server certificate.
First I'm try to use openssl generate p12 file
openssl pkcs12 -export -in "ca.crt" -out "truststore.p12" -nokeys
But when connecting, I get: javax.net.ssl.SSLHandshakeException: No trusted certificate found
When i try use keytool
keytool -import -file ca.crt -alias ca -keystore truststore.p12
The connect is working
Server Code:
auto ssl_factory = std::make_shared<apache::thrift::transport::TSSLSocketFactory>(
apache::thrift::transport::SSLProtocol::TLSv1_2);
ssl_factory->loadCertificate(cert.crt);
ssl_factory->loadPrivateKey(cert.key);
ssl_factory->loadTrustedCertificates(ca.crt);
ssl_factory->authenticate(true);
ssl_factory->server(true);
server_socket = new apache::thrift::transport::TSSLServerSocket(bind_address, port, ssl_factory);
Client Code:
TSSLTransportFactory.TSSLTransportParameters sslParam =
new TSSLTransportFactory.TSSLTransportParameters("TLSv1.2", null, false);
sslParam.setKeyStore(cert.p12, password, "SunX509", "PKCS12");
sslParam.setTrustStore(truststore.p12, password, "SunX509", "PKCS12");
clientSocket = TSSLTransportFactory.getClientSocket(key.hostname, key.port, timeoutMs, sslParam);
Why is there a difference between the OpenSSL-generated PKCS12 (with only CA cert, -nokeys) and the keytool-generated PKCS12?
Why does Java not accept the OpenSSL version as a valid truststore?
It is working correctly now, so the code and the other certificates are not the problem.
I just want to understand the difference between a truststore.p12 generated with keytool and one generated with OpenSSL.
Did keytool apply some special handling that OpenSSL did not?
keytool -list -keystore truststore.p12print? When I follow your steps it printsyour keystore contains 0 entries.-nokeysthe command can't execute$ openssl pkcs12 -export -in "ca.crt" -out "truststore.p12" unable to load private key 140304383473472:error:0909006C:PEM routines:get_name:no start line:crypto/pem/pem_lib.c:745:Expecting: ANY PRIVATE KEYopensslcommand, but I'm rusty enough not to know what it is.keytoolcommand.