Search code examples
ssl-certificatespring-oauth2oauth2client

Certificates needed for Https connection to REST oauth2 client


I have a spring-boot application, I want to access a REST API (oauth2) to get user information. I need to add certificates for this to my application as the connection is https. I was provided with two files

    XXX_Root_CA_3_DER.crt and 
    XXX_Root_CA_3_PEM.cer. 
XXX_Sub_CA_3_DER.crt and 
    XXX_Sub_CA_3_PEM.cer

I need to use these certificates with spring Webclient to get the connection. I coded the webclient part, now I need to make this certificate conversion and place them in the application somewhere.

I converted these certificates in gitbash as

 winpty openssl pkcs12 -in XXX_Root_CA_3_DER.crt -out XXX_Root_CA_3.p12

Now I have just one file XXX_Root_CA_3.p12 but I dont how to use it because I am referring to this (https://www.baeldung.com/spring-boot-https-self-signed-certificate) where I need to have some password to store in the trustore in my client application.

Could someone please suggest some steps that I need to follow for conversion of certificate files, which files I need to use and how to use these files with WebClient. There is lot of information on the internet I am confused how to implement this.


Solution

  • As a client, you just need to ensure that your Java runtime trusts the server. You seem to have been given two certificate authorities:

    • A root CA
    • An intermediate CA

    You should just need to run commands like this:

    sudo "$JAVA_HOME/bin/keytool" -import -alias xxxroot -cacerts -file ./XXX_Root_CA_3_DER.crt -storepass changeit -noprompt
    
    sudo "$JAVA_HOME/bin/keytool" -import -alias xxxintermediate -cacerts -file ./XXX_Sub_CA_3_DER.crt -storepass changeit -noprompt
    

    My development SSL blog post provides further info. See also my example certs and ensure that your CA certs have a similar format to the one called mycompany.ca.pem.