How can I use different certificates on specific connections?

后端 未结 5 2004
星月不相逢
星月不相逢 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:26

    We copy the JRE's truststore and add our custom certificates to that truststore, then tell the application to use the custom truststore with a system property. This way we leave the default JRE truststore alone.

    The downside is that when you update the JRE you don't get its new truststore automatically merged with your custom one.

    You could maybe handle this scenario by having an installer or startup routine that verifies the truststore/jdk and checks for a mismatch or automatically updates the truststore. I don't know what happens if you update the truststore while the application is running.

    This solution isn't 100% elegant or foolproof but it's simple, works, and requires no code.

提交回复
热议问题