問題描述
如何信任特定的自簽名證書?(不相信所有人) (How can I trust a specific self-sign certificates? (Not trust all))
How can I set my HttpsURLConnection
to trust a specific certificate only? Currently my code is set to trust all certificates. But the requirement is to trust only a specific certificate and do not trust the others. How can I do it in Java? I'm using JDK 1.5.
參考解法
方法 1:
You can trust a specific certificate by creating a custom SSLSocketFactory and providing your own TrustManager. See...
Trusting all certificates using HttpClient over HTTPS
and
How can I use different certificates on specific connections?
In your TrustManager, you will be handed the certificate chain from the client / server to verify against your specific certificate.
方法 2:
Import it into your client truststore.
(by Arci、Todd Trotter、user207421)