Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/306.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/rust/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 尝试从SSLSocket读取时获取EOFEException_Java_Ssl_Sockets_Eofexception - Fatal编程技术网

Java 尝试从SSLSocket读取时获取EOFEException

Java 尝试从SSLSocket读取时获取EOFEException,java,ssl,sockets,eofexception,Java,Ssl,Sockets,Eofexception,我正在开发一个SSL客户端,它将向SSL服务器发出一个简单的请求并等待响应。SSL握手和写入正常,但我无法从套接字读取数据。我打开了java.net.ssl的调试,得到了以下结果: [..] main, READ: TLSv1 Change Cipher Spec, length = 1 [Raw read]: length = 5 0000: 16 03 01 00 20 .... [Raw read]: length = 32 [..] main, R

我正在开发一个SSL客户端,它将向SSL服务器发出一个简单的请求并等待响应。SSL握手和写入正常,但我无法从套接字读取数据。我打开了java.net.ssl的调试,得到了以下结果:

[..] 
main, READ: TLSv1 Change Cipher Spec, length = 1 
[Raw read]: length = 5 0000: 16 03 01 00 20                 .... 
[Raw read]: length = 32 [..] 
main, READ: TLSv1 Handshake, length = 32 Padded plaintext after DECRYPTION:  len = 32 
[..]
    *** Finished verify_data:  { 29, 1, 139, 226, 25, 1, 96, 254, 176, 51, 206, 35 }
    *** %% Didn't cache non-resumable client session: [Session-1, SSL_RSA_WITH_RC4_128_MD5] [read] MD5 and SHA1 hashes:  len = 16 0000: 14 00 00 0C 1D 01 8B E2   19 01 60 FE B0 33 CE 23  ..........`..3.# Padded plaintext before ENCRYPTION:  len = 70 [..]                               a.j.y. 
main, WRITE: TLSv1 Application Data, length = 70 
[Raw write]: length = 75 
[..] 
Padded plaintext before ENCRYPTION:  len = 70 
[..] 
main, WRITE: TLSv1 Application Data, length = 70 
[Raw write]: length = 75 
[..] 
main, received EOFException: ignored main, called closeInternal(false) main, SEND TLSv1 ALERT:  warning, description = close_notify Padded plaintext before ENCRYPTION:  len = 18 [..] 
ain, WRITE: TLSv1 Alert, length = 18 [Raw write]: length = 23 
[..] main, called close() 
main, called closeInternal(true) 
main, called close() 
main, called closeInternal(true)
[…]是证书链

以下是一段代码片段:

try {
            System.setProperty("javax.net.debug","all");
            /*
             * Set up a key manager for client authentication
             * if asked by the server.  Use the implementation's
             * default TrustStore and secureRandom routines.
             */
            SSLSocketFactory factory = null;
            try {
            SSLContext ctx;
            KeyManagerFactory kmf;
            KeyStore ks;
            char[] passphrase = "importkey".toCharArray();

            ctx = SSLContext.getInstance("TLS");
            kmf = KeyManagerFactory.getInstance("SunX509");
            ks = KeyStore.getInstance("JKS");

            ks.load(new FileInputStream("keystore.jks"), passphrase);

            kmf.init(ks, passphrase);
            ctx.init(kmf.getKeyManagers(), null, null);

            factory = ctx.getSocketFactory();
            } catch (Exception e) {
                throw new IOException(e.getMessage());
            }

            SSLSocket socket = (SSLSocket)factory.createSocket("server ip", 9999);

            /*
             * send http request
             *
             * See SSLSocketClient.java for more information about why
             * there is a forced handshake here when using PrintWriters.
             */
            SSLSession session = socket.getSession();

            [build query]

            byte[] buff = query.toWire();

            out.write(buff);
            out.flush();

            InputStream input = socket.getInputStream();

            int readBytes = -1;
            int randomLength = 1024;
            byte[] buffer  = new byte[randomLength];
            while((readBytes = input.read(buffer, 0, randomLength)) != -1) {
                LOG.debug("Read: " + new String(buffer));
            }
            input.close();
            socket.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
我可以多次写入,没有任何错误,但EOFEException发生在第一次读取时

套接字或SSL身份验证是否有问题


谢谢。

问题出在我发送的数据包上。服务器正在获取数据包,检查数据包是否格式错误,并断开连接。修复数据包格式修复了问题。

问题可能在服务器上。那里的套接字是如何关闭的?我没有访问服务器的权限。同样的请求也适用于Perl脚本,所以我认为问题在于Java代码。请自己创建一个本地Apache实例,并将其配置为接受SSL连接。做了一点工作,但对测试来说肯定很棒。嗨,你到底是如何修复数据包格式的?我也有同样的问题。任何暗示都将不胜感激!这是我使用的特定服务的数据包格式的问题,而不是SSL格式的问题。