gpt4 book ai didi

java - SSLException 错误证书

转载 作者:太空宇宙 更新时间:2023-11-03 14:17:01 25 4
gpt4 key购买 nike

我的类(class)有一个简短的任务,即扩展一个简单的 Java 服务器以在 Ubuntu 上支持 SSL。

好的,首先,我这样做了:

私有(private)静态 SSLServerSocketFactory 工厂;

private static SSLServerSocket serverSocket;



public SimpleWebServer () throws Exception {

//dServerSocket = new ServerSocket (PORT);

factory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();

serverSocket = (SSLServerSocket)factory.createServerSocket(8081);

}



public void run() throws Exception {

while (true) {

/* wait for a connection from a client */

//Socket s = dServerSocket.accept();

SSLSocket s = (SSLSocket)serverSocket.accept();

/* then process the client's request */

processRequest(s);

}

}

看起来基本没问题,我按如下方式运行服务器:

java -Djavax.net.ssl.keyStore=com/learnsecurity/keystore.jks -Djavax.net.ssl.keyStorePassword=123456 com/learnsecurity/SimpleWebServer     

但是,当我从 Firefox 向 https://localhost:8081 发送请求时,服务器向我发送了这个垃圾邮件:

Exception in thread "main" javax.net.ssl.SSLHandshakeException: Received fatal alert: bad_certificate
at sun.security.ssl.Alerts.getSSLException(Alerts.java:192)
at sun.security.ssl.Alerts.getSSLException(Alerts.java:154)
at sun.security.ssl.SSLSocketImpl.recvAlert(SSLSocketImpl.java:1796)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:1039)
at sun.security.ssl.SSLSocketImpl.waitForClose(SSLSocketImpl.java:1574)
at sun.security.ssl.HandshakeOutStream.flush(HandshakeOutStream.java:122)
at sun.security.ssl.Handshaker.sendChangeCipherSpec(Handshaker.java:705)
at sun.security.ssl.ServerHandshaker.sendChangeCipherAndFinish(ServerHandshaker.java:1297)
at sun.security.ssl.ServerHandshaker.clientFinished(ServerHandshaker.java:1257)
at sun.security.ssl.ServerHandshaker.processMessage(ServerHandshaker.java:244)
at sun.security.ssl.Handshaker.processLoop(Handshaker.java:609)
at sun.security.ssl.Handshaker.process_record(Handshaker.java:545)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:978)
at sun.security.ssl.SSLSocketImpl.performInitialHandshake(SSLSocketImpl.java:1223)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:838)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:94)
at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:282)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:324)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:176)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.fill(BufferedReader.java:153)
at java.io.BufferedReader.readLine(BufferedReader.java:316)
at java.io.BufferedReader.readLine(BufferedReader.java:379)
at com.learnsecurity.SimpleWebServer.processRequest(SimpleWebServer.java:62)
at com.learnsecurity.SimpleWebServer.run(SimpleWebServer.java:45)
at com.learnsecurity.SimpleWebServer.main(SimpleWebServer.java:178)

我按照本教程生成了证书: http://www.sslshopper.com/article-how-to-create-a-self-signed-certificate-using-java-keytool.html

我一直在四处寻找解决方案,但一直没有成功。我在想,因为服务器正在运行,所以它与证书有关。有人能指出我正确的方向吗?

最佳答案

您的服务器没有问题,它已准备好接受来自它“信任”的客户端的 SSL 连接,这意味着其证书在您服务器的 keystore 中可用。而且,在上述情况下,这是不正确的,因为您的 FireFox 中的证书未在服务器的 keystore 中列为受信任的。因此,导出您的 Firefox 证书并将它们作为受信任的证书导入到您服务器的 keystore 中。

How to export certificates from FireFox

How to export certificates from Firefox 2

关于java - SSLException 错误证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17663976/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com