我有一个java代码,试图创建ssl握手与网站。当网站的ssl证书是自签名的或使用不安全的选项时,我收到错误,代码无法提取证书。
SSLSocket socket=null;
SSLSocketFactory factory=null;
factory = HttpsURLConnection.getDefaultSSLSocketFactory();
try{
socket = (SSLSocket) factory.createSocket(host, port);
System.out.println("listen on port "+port+" for host "+host);
} //end try
catch (IOException ex)
{
//remote host is not listening on port 443
System.out.println("Can not listen on port "+port+" of host"+host);
} //end catch
System.out.println("Creating a SSL Socket For "+host+" on port "+port);
SSLSession ss = socket.getSession();
socket.startHandshake(); // start the handshake
System.out.println("Handshake Done");作为一个例子,我得到了以下错误:
Exception in thread "main" javax.net.ssl.SSLHandshakeException: Insecure renegotiation is not allowed如何让我的java代码接受带有自签名和弱ssl配置的完整握手?
发布于 2012-10-08 08:10:08
这里至少有3个可能的问题。削弱您的SSL/TLS配置几乎总是一个坏主意。
SSLSocket/SSLEngine上使用setEnabledCipherSuites启用特定的加密套件。值得一读的是关于特定cipher suites in the TLS specification的脚注和注释(尤其是匿名密码套件提供的安全性不足)。sun.security.ssl.allowUnsafeRenegotiation。顾名思义,这是不安全的。X509TrustManager构建SSLContext。这里或其他网站上有许多这种不安全代码的示例。JSSE的默认行为往往是相当合理的。引入不安全的行为应该谨慎行事。学习/实验是可以的,但在生产软件(甚至是原型)中这样做是值得怀疑的。
https://stackoverflow.com/questions/12764776
复制相似问题