0

I'm trying to send +16kb data through multipart/formdata. SSL implementation is

    /*
     * SSL Context
     */
     SSLContext getSSLContext(Path keyStorePath, char[] keyStorePass) {
        try {
        var keyStore = KeyStore.getInstance("JKS");
        keyStore.load(new FileInputStream(keyStorePath.toFile()), keyStorePass);
        var keyManagerFactory = KeyManagerFactory.getInstance("SunX509");
        keyManagerFactory.init(keyStore, keyStorePass);
        var sslContext = SSLContext.getInstance("SSLv3");
        sslContext.init(keyManagerFactory.getKeyManagers(), null, null);
        return sslContext;
        }catch(Exception e) {
            log.e(e,Server.class.getName(),"getSSLContext");
            return null;
        }
    }
    /*
     * SSL Server Socket
     */
    ServerSocket getServerSocket(InetSocketAddress address) {
        try {
        int backlog = MaxConcurrentRequests * 10;
        var keyStorePath = Path.of("./keystore.jks");
        char[] keyStorePassword = "ZZZZZZ".toCharArray();
        var serverSocket = getSSLContext(keyStorePath, keyStorePassword)
                .getServerSocketFactory()
                .createServerSocket(address.getPort(), backlog, address.getAddress());
        Arrays.fill(keyStorePassword, '0');
        return serverSocket;
        }catch(Exception e) {
            log.e(e,Server.class.getName(),"getServerSocket");
            return null;
        }
    }

It doesn't read any data beyond 16384 bytes, I use `DataInputStream` and `DataOutputStream`.
Also, TLS Maximum record size is 16kb (I already know that).
Is there any workaround for this limitation?
Also, How does TLS/SSL behave when there's a +16kb of `multipart/form-data` is being sent to server, does the protocol make buffers 16kb each?

Read Function, s.available() always return 16384 if the file is larger than 16384 bytes.

    /*
     * Reads from socket into ArrayList
     */
    public static ArrayList<Byte> read(DataInputStream s,int MAX_REQ_SIZE) {
        ArrayList<Byte> result = new ArrayList<Byte>();
        int byteCounter = 0;
        try {
            do {
                if(byteCounter < MAX_REQ_SIZE*1000) {
                result.add(s.readByte());
                if(byteCounter == 0) log.s(s.available()+"");
                byteCounter ++;
                }else {
                    
                }
            } while (s.available() > 0);
            log.i(result.size()+" bytes as request");

        } catch (IOException e) {
            log.e(e,Network.class.getName(),"read");
        }
        return result;
    }

NOTE: I ran wireshark, it sends buffers of ~16000 bytes with ACK packets between, Is there any read function that can handle this?
  • *"I use `DataInputStream` and `DataOutputStream`."* - please show the code which uses these. The TLS setup itself is less relevant. – Steffen Ullrich Dec 06 '21 at 11:58
  • See also [here](https://www.ibm.com/docs/en/sdk-java-technology/7?topic=interfaces-sslsocket-sslserversocket-classes): *"the available() method on the object obtained by SSLSocket.getInputStream() returns a count of the __number of application data bytes successfully decrypted from the SSL connection but not yet read by the application__"* – Steffen Ullrich Dec 06 '21 at 19:55
  • Also posted here: https://coderanch.com/t/747813/java/SSL-TLS-Record-reading-java – Ron McLeod Dec 06 '21 at 20:35

0 Answers0