Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何将侦听器挂接到SSL握手?_Java_Ssl_Smtp_Listener_James - Fatal编程技术网

Java 如何将侦听器挂接到SSL握手?

Java 如何将侦听器挂接到SSL握手?,java,ssl,smtp,listener,james,Java,Ssl,Smtp,Listener,James,我希望在新的SSL连接启动和握手开始时收到通知。 我需要在调用密钥库之前获取证书 是否有某种方法将侦听器注册到此进程,以便我决定证书是否正常,是否应根据密钥库检查证书,或者立即取消证书 类似于此,但对于SMTP连接: URL req = new URL(getUrl); HttpsURLConnection con = (HttpsURLConnection) req.openConnection(); con.setHostnameVerifier(new HostnameVerifier

我希望在新的SSL连接启动和握手开始时收到通知。 我需要在调用密钥库之前获取证书

是否有某种方法将侦听器注册到此进程,以便我决定证书是否正常,是否应根据密钥库检查证书,或者立即取消证书

类似于此,但对于SMTP连接:

URL req = new URL(getUrl);

HttpsURLConnection con = (HttpsURLConnection) req.openConnection();

con.setHostnameVerifier(new HostnameVerifier()
{

    public boolean verify(String hostname, SSLSession session)
    {
        return true; //My decision
    }
});
我正在使用JAMES电子邮件服务器2.3.2(如果这意味着什么的话)


提前谢谢你

您需要设置连接的SSLFactory。以下示例不使用密钥管理器和默认信任管理器。您的支票将进入checkServerTrusted方法

HttpsURLConnection con = (HttpsURLConnection) req.openConnection();
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, // No Key Manager
             new TrustManager[] { new X509TrustManager()
               {
                 @Override
                 public void checkClientTrusted(X509Certificate[] arg0, String arg1)
                     throws CertificateException
                   {}

                 @Override
                 public void checkServerTrusted(X509Certificate[] arg0, String arg1)
                     throws CertificateException {
                      // check the certs
                 }

                 @Override
                 public X509Certificate[] getAcceptedIssuers()
                   {
                     return null;
                   }

               } }, // TrustManager 
             new java.security.SecureRandom());
con.setSSLSocketFactory(context.getSocketFactory());

非常感谢。这就是我想要的!:)