大网数据广告活动
服务器运维问答

How to certify a self-signed imap email server

· 52CE 我爱测

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 certific…

问题原文

原帖链接 · 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

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2017-05-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。