2

i have the following code which works correctly in TLS 1.2 but fails in TLS 1.3 (in windows platform, linux this doesn't happen, in fact if you place the server end on windows, and client on linux it would fail, but not vice versa)

it just opens a socket sends some data and then closes it. but doing so in TLS 1.3 causes it to fail on the server side on socket close exception. if i understand correctly this is somehow related to different implementation of TLS 1.3, where connection can be closed on either side, and they even included a system property that should make it work as it did, but that doesn't work either. this is the most basic implementation there is, so i'm not sure exactly how it will ever work? i mean there should be a way for a client to do just that, send data once and close the socket.

java.net.SocketException: An established connection was aborted by the software in your host machine
    at java.base/sun.nio.ch.NioSocketImpl.implRead(NioSocketImpl.java:330)
    at java.base/sun.nio.ch.NioSocketImpl.read(NioSocketImpl.java:355)
    at java.base/sun.nio.ch.NioSocketImpl$1.read(NioSocketImpl.java:808)
    at java.base/java.net.Socket$SocketInputStream.read(Socket.java:966)
    at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:484)
    at java.base/sun.security.ssl.SSLSocketInputRecord.readHeader(SSLSocketInputRecord.java:478)
    at java.base/sun.security.ssl.SSLSocketInputRecord.bytesInCompletePacket(SSLSocketInputRecord.java:70)
    at java.base/sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1465)
    at java.base/sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:1069)
    at java.base/java.io.ObjectInputStream$PeekInputStream.read(ObjectInputStream.java:2897)
    at java.base/java.io.ObjectInputStream$PeekInputStream.readFully(ObjectInputStream.java:2913)
    at java.base/java.io.ObjectInputStream$BlockDataInputStream.readShort(ObjectInputStream.java:3410)
    at java.base/java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:954)
    at java.base/java.io.ObjectInputStream.<init>(ObjectInputStream.java:392)
    at TestChallenge/scratch.OO.lambda$main$0(OO.java:36)
    at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
    at java.base/java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:264)
    at java.base/java.util.concurrent.FutureTask.run(FutureTask.java)
    at --- Async.Stack.Trace --- (captured by IntelliJ IDEA debugger)
    at java.base/java.util.concurrent.FutureTask.<init>(FutureTask.java:151)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.<init>(ScheduledThreadPoolExecutor.java:215)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.schedule(ScheduledThreadPoolExecutor.java:561)
    at java.base/java.util.concurrent.ScheduledThreadPoolExecutor.execute(ScheduledThreadPoolExecutor.java:705)
    at TestChallenge/scratch.OO.main(OO.java:30)
public class OO {
    
    public static void main(String[] args) throws Exception {

        enum STATE {
            CURR
        }
        final SSLContext sslContext = getSslContext();
        final ServerSocketFactory serverSocketFactory = sslContext.getServerSocketFactory();

        final SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(1888);
        final ScheduledExecutorService scheduledExecutorService = Executors.newScheduledThreadPool(20);
        scheduledExecutorService.execute(() -> {
            while (!serverSocket.isClosed()) {
                try {
                    final SSLSocket socket = (SSLSocket) serverSocket.accept();
                    try {
                        try(final InputStream inputStream = socket.getInputStream()){
                            final ObjectInputStream objectInputStream = new ObjectInputStream(inputStream);
                            final Object o = objectInputStream.readObject();
                            System.out.println(o);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                    //   socket.setSoLinger(true,10);

                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });


        final javax.net.SocketFactory socketFactory = sslContext.getSocketFactory();
        scheduledExecutorService.scheduleWithFixedDelay(() -> {
            try {

                try (final SSLSocket socket = (SSLSocket) socketFactory.createSocket("127.0.0.1", 1888)) {
                    //                socket.setSoLinger(true,10);
                    socket.startHandshake();
                    final OutputStream outputStream = socket.getOutputStream();
                    try (final ObjectOutputStream oo = new ObjectOutputStream(socket.getOutputStream())) {
                        oo.writeObject(STATE.CURR);
                        outputStream.flush();
                    }
                }
            } catch (IOException e) {
                e.printStackTrace();
            }
        }, 0, 1, TimeUnit.SECONDS);

        new CountDownLatch(1).await();
    }

    @NotNull
    public static SSLContext getSslContext() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {
        final KeyStore keyStore = KeyStore.getInstance("pkcs12");
        final String s1 ="MIIKZAIBAzCCCg4GCSqGSIb3DQEHAaCCCf8Eggn7MIIJ9zCCBa4GCSqGSIb3DQEHAaCCBZ8EggWbMIIFlzCCBZMGCyqGSIb3DQEMCgECoIIFQDCCBTwwZgYJKoZIhvcNAQUNMFkwOAYJKoZIhvcNAQUMMCsEFBCnlxptM/N5OqAPpFkoEY3r+0QWAgInEAIBIDAMBggqhkiG9w0CCQUAMB0GCWCGSAFlAwQBKgQQG/RKlEAGPpW5betwGewIlwSCBNAeNZ9REZgWvKz5X+CeV6fhqHitJ//P7vNAs4iJVZc4611iMZi3F/8MKFJhEKLmlWFn3dUwaWjTIlIJaKqGEBjduokc9V5aA6hFXcHdCDiZq7TN+CspYqrS/4yRknXODQ2Li4aT42DTyCca44bv9O5C6Z/ozf0ZO/YYLUoY1GOZXgrnm1UeCGHJKHD45n9hJ6BkVcwPPbEV3grqebUTdJah1phtZG2wyVQigROBub2uikNkyptYHoFW6Xam2hqb6m19CTMHMuB5Pmq5zpnEhCI93DUPsf8VL35Fdpm+SB9vhC4AU9uhlOtIoB/avQN7snI/2zzQd5+W0VSqa6panFjYiaVNFUa022vjF7kVxtE7cmmnkJjJwx0Mqnj57IyYscHCMUBp2Ndo7vVtugndOwmnG2UZNNar/RjIQ9T9x6fXjxPMExi8liZMqQhrQ4Sbzqgk6WEZ6dHJwh+vrakznZTtkM7q485axNAX0tBUucD6T6BrB6+XbtIiZ/+8qdK4E0goJRYzLG8fbjdHkYUSxeAIqtz8OZxW3Ar96/7u/LMaoRoE3YO9xh3Wd+OT62nl3zQM5aEwj0mKHtSzaHCXqCIBBcz2hp60/wS7k4De69BBSQWYP9oJaBTk8ApFtnkLnY/VamoFn/ESf7i+2I/sbp/npPZ/0JWhqdpoCl8O6E7eoI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TECeDxGjxfhzX0YcjCL5dJPmrgFTNgkX50Byy8HNrcQbv9gPLqdK1aNil7jP37DQuE0wT+apuNZ3mMBK2BybgAuMU60sBrPttnR+40isjDk5SmlCYcybYfsniQUkzD5onkeGaM6EmSsqecu0eCU9u2I00RB+6Adt0QW2jamorDFkIXgJhEbPnCFvM2PVaxZsQjJjW9epSYT28neI1YbBJmopUucWH6fNJpRzRNpaaiZj3ikjpXPR+A2FyvPni4OG4msfX3anxafvbOFVmbdSMbgXEsCCB4hhJUyJawVOm7ghluCnGZEv6TAvR68Y3awi3UCoXLMdWNKk/gm1rxX/F7MwTTAxMA0GCWCGSAFlAwQCAQUABCCc2JJy7S1mfMQneJJTmvPE2/LuiNeMv7DeQE/YDncLMQQUb6aXsTU8mdD1bBLHAQVu34YDRvACAicQ";//
        final byte[] decode = Base64.getDecoder().decode(s1.getBytes());
        try (final InputStream inputStream = new ByteArrayInputStream(decode)) {///Files.newInputStream(path)
            keyStore.load(inputStream, "".toCharArray());
        }

        final KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
        kmf.init(keyStore, "".toCharArray());
        final KeyManager[] keyManagers = kmf.getKeyManagers();
        final TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
        tmf.init(keyStore);
        final TrustManager[] trustManagers = tmf.getTrustManagers();
        String s = "TLSv1.3";
          //   s = "TLSv1.2";
        ///s="TLS";

        final SSLContext sslContext = SSLContext.getInstance(s);

        sslContext.init(keyManagers, trustManagers, new SecureRandom());
        return sslContext;
    }
}
9
  • What is the (full) Java version / release number on the client and server sides? Commented Jul 8 at 2:11
  • java coretto 17.0.15.6.1, but i've tried with other builds, microsoft java , java 11, later versions of java 8 (that supported TLS 1.3) same behavior. Commented Jul 8 at 6:59
  • In both cases, http 1.1 or Http/2 is used at runtime? Commented Jul 8 at 14:56
  • neither, this is a raw java serialization, but it can happen with just byte arrays, that's why i've attached the source, you could run it as it is and see it fail. Commented Jul 8 at 17:05
  • 1
    Post your details as edits to the Question rather than Comments. Commented Jul 9 at 15:17

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.