小编典典

通用Java套接字中没有密码套件

java

我最近一直在将SSL套接字用于消息传递系统。

我终于开始使用CA颁发的证书。我将其导入到密钥库中,设置了密钥库属性,并启动了客户端,但是当我尝试发送数据时,我一直收到握手异常。

我启用了调试模式,发现这是由于造成的no cipher suites supported。有什么想法吗?

如果有帮助,它还说它忽略了TLSV1和TLSV1.1中的大约10个密码套件。

我还安装了无限强度加密策略。

客户代码

public static void Message(String args){
    System.setProperty("https.protocols", "TLSv1");
    System.setProperty("javax.net.debug", "all");

    try
    {
        String host = "localhost";
        int port = 3498;
        InetAddress address = InetAddress.getByName(host);

        socket = (SSLSocket)SSLSocketFactory.getDefault().createSocket(address, port);

        //Send the message to the server
        OutputStream os = socket.getOutputStream();
        OutputStreamWriter osw = new OutputStreamWriter(os);
        BufferedWriter bw = new BufferedWriter(osw);

        String number = "Hello from the other side!";

        String sendMessage = number + "\n";
        bw.write(args);
        bw.flush();
        System.out.println("Message sent to the server : "+sendMessage);

        //Get the return message from the server

    }
    catch (Exception exception)
    {
        exception.printStackTrace();
    }
    finally
    {
        //Closing the socket
        try
        {
            socket.close();
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }
}

服务器代码

private void initListen() {
    System.setProperty("javax.net.ssl.keyStore", "/Users/181095/server.jks");
    try {


        SSLServerSocketFactory sf = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();

        SSLServerSocket serverSocket = (SSLServerSocket)sf.createServerSocket(Ting.port);



        System.out.println("Server Started and listening to the port "
                + Ting.port);

        // Server is running always. This is done using this while(true)
        // loop
        while (true) {

            // Reading the message from the client
            socket = (SSLSocket)serverSocket.accept();


            InputStream is = socket.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String input = br.readLine();
            System.out.println("Message received from client is " + input);
            /*if(PacketReader.isPacket(input)){
                if(PacketReader.shouldSendDataBack(input)){

                }
            }*/
            /*
             * 
             * if client has data waiting or client has new data
             * request new data.
             * else, wait 5 seconds and repeat
             * 
             * 
             */



            // Sending the response back to the client.
            /*OutputStream os = socket.getOutputStream();
            OutputStreamWriter osw = new OutputStreamWriter(os);
            BufferedWriter bw = new BufferedWriter(osw);
            bw.write("");*/

            //TODO Implement method to send this data to client storage data.

            //bw.flush();
        }
    //Check for exceptions and try to close the socket.
    } catch (Exception e) {

        e.printStackTrace();
        } finally {
            try {
                socket.close();
            } catch (Exception e) {
        }
    }
}

编辑: 我刚刚添加了密码,但是我的输入/证书没有密钥,这是否可能导致错误?我该如何解决?


阅读 185

收藏
2020-11-30

共1个答案

小编典典

令人惊讶的是,这可能意味着服务器找不到私钥/证书对。在这种情况下,这是因为您尚未通过来指定密钥库密码javax.net.ssl.keyStorePassword

2020-11-30