问题原文
原帖链接 · Eugene S · CC BY-SA 3.0
My task is to retrieve emails from an imaps email server using Java so as a client I need to authenticate the email server using an appropriate certificate. It seems however, that this email server is using a self-signed certificate which does not included in the truststore(?) by default. From what I found here, the system properties javax.net.ssl.trustStore and javax.net.ssl.trustStorePassword need to be set. The example is given:
System.setProperty("javax.net.ssl.trustStore","clientTrustStore.key");
System.setProperty("javax.net.ssl.trustStorePassword","qwerty");
My question is how do I obtain this clientTrustStore.key and the related password? Is that something I can generate myself given I know the email server details or is that something that should be provided by the IT department who maintains this email server?
社区高分解答
原帖链接 · BillThor · CC BY-SA 3.0
The truststore password is not needed to read the truststore.
You will need to create a truststore which is usually done with the keytool utility. You will need to obtain the public certificate from the IMAPS server, which can be done in a number of ways. The openssl package has number of tools that will allow you to save the certificate. Many mail utilities, such as Thunderbird will allow you to export the certificate. You should be able to obtain the certificate by enabling ssl debugging and connecting with a simple class. Once you have this certificate, import it into a new keystore using the keytool utility.
If you are on a secure network you can just set the -Dtrust_all_cert=true property and ignore the truststore issue. This leaves you vulnerable to man-in-the-middle attacks. However, it is a pragmatic work-around for self-signed certificates, if this is a one-time retrieval. You can also do this in your code.
There are related questions that will point you in the right direction:
https://stackoverflow.com/questions/2642777/trusting-all-certificates-using-httpclient-over-https https://stackoverflow.com/questions/1219208/is-it-possible-to-get-java-to-ignore-the-trust-store-and-just-accept-whatever
摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。
