I have following Self Signed certificates generated using tls-gen tool:

I am able to establish Mutual TLS communication between RabbitMQ Server and RabbitMQ Java Client.

can I use the same Server Certificate (server_certificate.pem and server_key.pem ) converted into #PKCS12 to enable SSL in Spring Boot App ?
Also How to use same Client Certificates for RestTemplate to enable client authentication with REST API ?

RestTemplate Configuration :

private char[] password = "SpringClient".toCharArray();
    private char[] trustStorePassword = "SpringClient".toCharArray();

    public RestTemplate restTemplate(RestTemplateBuilder builder) throws Exception {

        SSLContext sslContext = SSLContextBuilder
                .loadKeyMaterial(readStore(), password)
                .loadTrustMaterial(readTrustStore(),new TrustSelfSignedStrategy())

        HttpClient client = HttpClients.custom()

        return builder
                .requestFactory( ()-> new HttpComponentsClientHttpRequestFactory(client))

    KeyStore readStore() throws Exception {
        try (InputStream keyStoreStream = this.getClass().getResourceAsStream("/certificates/client.p12")){
            KeyStore keyStore = KeyStore.getInstance("PKCS12");
            keyStore.load(keyStoreStream, password);
            return keyStore;

    private KeyStore readTrustStore() throws Exception {
       try (InputStream keyStoreStream = this.getClass().getResourceAsStream("/certificates/client_truststore")){
            KeyStore keyStore = KeyStore.getInstance("JKS");
            keyStore.load(keyStoreStream, trustStorePassword);
            return keyStore;

I tried to convert #PEM format client certificates into #PKCS12 and provided to KeyStore instance,But when I hit the REST API , I am getting following Error:

main, READ: TLSv1.2 Alert, length = 2
main, RECV TLSv1.2 ALERT:  fatal, bad_certificate
%% Invalidated:  [Session-1, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384]
main, called closeSocket()
main, handling exception: javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate

Any other Ways we can convert and use those certificates into Separate Spring Boot App ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.