【问题标题】:No cipher suites in common java sockets普通 Java 套接字中没有密码套件
【发布时间】:2016-10-20 15:22:35
【问题描述】:

我最近一直在将 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) {
        }
    }
}

编辑: 我刚刚添加了密码,但我的条目/证书没有密钥,这会导致错误吗?我该如何解决?

【问题讨论】:

    标签: java sockets ssl


    【解决方案1】:

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

    【讨论】:

    • 我做了这个但是还是不行,因为我是从外部获取的,我需要设置一个密钥吗,因为使用keytool,它找不到密钥。我需要生成密钥吗?
    • 您不能“从外部来源获取 [证书]”并将其用作您自己的证书。您必须首先创建一个密钥对,然后是一个 CSR,然后对其进行签名,然后将签名证书导入到具有相同别名且不带 -trustcacerts 选项的同一密钥库中。
    • 好的,我所做的是使用我网站上的 SSL。我的网站正在使用 SSL。我从生成的 CSR 下载了 SSL 证书。这是通过 NameCheap 完成的,我相信他们是通过 Comodo SSL 完成的。我不相信它带有钥匙,因为当我在上面使用 keytool 时,它说没有钥匙。这是怎么回事?
    • 没有“SSL”之类的东西。您的意思是“SSL 证书”吗?它一定起源于一把钥匙。没有其他进程。
    • 是的,原来是 NameCheap 的问题,他们做得不好。谢谢
    猜你喜欢
    • 2014-03-02
    • 2015-12-06
    • 1970-01-01
    • 2020-01-07
    • 1970-01-01
    • 2017-08-28
    相关资源
    最近更新 更多