简体   繁体   English

JAVA,SSLSocket连接问题

[英]JAVA, Issue with SSLSocket connection

Im coding a client-server chat application. 我正在编写客户端-服务器聊天应用程序。 I want to encrypt connection between those two. 我想加密这两者之间的连接。 Im doing that for my first time and I find it difficult. 我是第一次这样做,我觉得很困难。 In my understanding I need a truststore for client and a keystore for server. 以我的理解,我需要一个用于客户端的信任库和一个用于服务器的密钥库。 I have followed this guide to generate them: http://peoplesofttutorial.com/generating-key-store-and-trust-store-using-keytool/ 我已按照本指南生成它们: http : //peoplesofttutorial.com/generating-key-store-and-trust-store-using-keytool/

Client: 客户:

        System.setProperty("javax.net.ssl.trustStore" , "hrms.truststore");
        System.setProperty("javax.net.ssl.trustStorePassword" , "123456");
        SSLSocketFactory sslsf = (SSLSocketFactory) SSLSocketFactory.getDefault();
        SSLsocket = (SSLSocket) sslsf.createSocket(server, port);   

Server: 服务器:

        System.setProperty("javax.net.ssl.keyStore" , "pskey.keystore");
        System.setProperty("javax.net.ssl.keyStorePassword","123456");
        SSLServerSocketFactory sslsocketfactory = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
        sslserversocket = (SSLServerSocket) sslsocketfactory.createServerSocket(Port);      

Server is starting correctly. 服务器正常启动。 When I connect a client which is run on the same computer as the server is then I can connect without any issues but when I connect from different computer which is on the same network I get this error: javax.net.ssl.SSLException: Received fatal alert: internal_error 当我连接与服务器在同一台计算机上运行的客户端时,我可以无任何问题地连接,但是当我从同一网络上的另一台计算机进行连接时,会出现此错误:javax.net.ssl.SSLException:收到致命警报:internal_error

Could anyone help me solve this error? 谁能帮我解决这个错误?

I have solved my issue. 我已经解决了我的问题。 My trust store and keystone were in my project files, but when I compiled it to runnable jar I thought that trust store and keystore are included in that runnable jar, unfortunately they are not. 我的信任库和密钥库位于我的项目文件中,但是当我将其编译为可运行的jar时,我认为该可运行的jar中包含了信任库和密钥库,但不幸的是,它们没有。 I solved it by putting truststore and keystore in one folder with the runnable jar. 我通过将truststore和keystore放在具有可运行jar的一个文件夹中来解决此问题。

Solution was really simple and the whole problem occurred because of my inexperience. 解决的方法非常简单,整个问题都是由于我的经验不足而发生的。

Thank you for help. 谢谢你的帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM