Java 如何将侦听器挂接到SSL握手?
我希望在新的SSL连接启动和握手开始时收到通知。 我需要在调用密钥库之前获取证书 是否有某种方法将侦听器注册到此进程,以便我决定证书是否正常,是否应根据密钥库检查证书,或者立即取消证书 类似于此,但对于SMTP连接: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
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());
非常感谢。这就是我想要的!:)