How can I use different certificates on specific connections?

后端 未结 5 2007
星月不相逢
星月不相逢 2020-11-22 01:22

A module I\'m adding to our large Java application has to converse with another company\'s SSL-secured website. The problem is that the site uses a self-signed certificate.

5条回答
  •  囚心锁ツ
    2020-11-22 01:33

    If creating a SSLSocketFactory is not an option, just import the key into the JVM

    1. Retrieve the public key: $openssl s_client -connect dev-server:443, then create a file dev-server.pem that looks like

      -----BEGIN CERTIFICATE----- 
      lklkkkllklklklklllkllklkl
      lklkkkllklklklklllkllklkl
      lklkkkllklk....
      -----END CERTIFICATE-----
      
    2. Import the key: #keytool -import -alias dev-server -keystore $JAVA_HOME/jre/lib/security/cacerts -file dev-server.pem. Password: changeit

    3. Restart JVM

    Source: How to solve javax.net.ssl.SSLHandshakeException?

提交回复
热议问题