Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 26 additions & 43 deletions src/java.base/share/classes/sun/security/ssl/SSLSocketImpl.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -28,13 +28,13 @@
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -77,10 +77,10 @@ public final class SSLSocketImpl
/**
* ERROR HANDLING GUIDELINES
* (which exceptions to throw and catch and which not to throw and catch)
*
* <p>
* - if there is an IOException (SocketException) when accessing the
* underlying Socket, pass it through
*
* <p>
* - do not throw IOExceptions, throw SSLExceptions (or a subclass)
*/

Expand Down Expand Up @@ -454,12 +454,12 @@ private void startHandshake(boolean resumable) throws IOException {
if (!conContext.isNegotiated) {
readHandshakeRecord();
}
} catch (InterruptedIOException iioe) {
} catch (SocketTimeoutException e) {
if(resumable){
handleException(iioe);
handleException(e);
} else{
throw conContext.fatal(Alert.HANDSHAKE_FAILURE,
"Couldn't kickstart handshaking", iioe);
"Couldn't kickstart handshaking", e);
}
} catch (SocketException se) {
handleException(se);
Expand Down Expand Up @@ -1427,7 +1427,7 @@ private int readHandshakeRecord() throws IOException {
return 0;
}
} catch (SSLException |
InterruptedIOException | SocketException se) {
SocketTimeoutException | SocketException se) {
// Don't change exception in case of timeouts or interrupts
// or SocketException.
throw se;
Expand Down Expand Up @@ -1486,7 +1486,7 @@ private ByteBuffer readApplicationRecord(
return buffer;
}
} catch (SSLException |
InterruptedIOException | SocketException se) {
SocketTimeoutException | SocketException se) {
// Don't change exception in case of timeouts or interrupts
// or SocketException.
throw se;
Expand Down Expand Up @@ -1677,40 +1677,23 @@ private void handleException(Exception cause) throws IOException {
SSLLogger.warning("handling exception", cause);
}

// Don't close the Socket in case of timeouts or interrupts.
if (cause instanceof InterruptedIOException) {
throw (IOException)cause;
}

// need to perform error shutdown
boolean isSSLException = (cause instanceof SSLException);
Alert alert;
if (isSSLException) {
if (cause instanceof SSLHandshakeException) {
alert = Alert.HANDSHAKE_FAILURE;
} else {
alert = Alert.UNEXPECTED_MESSAGE;
}
} else {
if (cause instanceof IOException) {
alert = Alert.UNEXPECTED_MESSAGE;
} else {
// RuntimeException
alert = Alert.INTERNAL_ERROR;
}
}

if (cause instanceof SocketException) {
try {
throw conContext.fatal(alert, cause);
} catch (Exception e) {
// Just delivering the fatal alert, re-throw the socket exception instead.
}

throw (SocketException)cause;
}

throw conContext.fatal(alert, cause);
throw switch (cause) {
// Don't close the Socket in case of timeouts.
case SocketTimeoutException ste -> ste;
// Send TLS alert with "fatal", then throw the socket exception.
case SocketException se -> {
try {
throw conContext.fatal(Alert.UNEXPECTED_MESSAGE, se);
} catch (Exception _) {
}
yield se;
}
case SSLHandshakeException sslhe ->
conContext.fatal(Alert.HANDSHAKE_FAILURE, sslhe);
case IOException ioe ->
conContext.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
default -> conContext.fatal(Alert.INTERNAL_ERROR, cause);
};
}

private Plaintext handleEOF(EOFException eofe) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1996, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1996, 2026, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2020, Azul Systems, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
Expand Down Expand Up @@ -27,10 +27,10 @@
package sun.security.ssl;

import java.io.EOFException;
import java.io.InterruptedIOException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import java.security.GeneralSecurityException;
import java.util.ArrayList;
Expand Down Expand Up @@ -180,7 +180,7 @@ Plaintext[] decode(ByteBuffer[] srcs, int srcsOffset,
if (plaintext == null) {
plaintext = decodeInputRecord();
}
} catch(InterruptedIOException e) {
} catch (SocketTimeoutException e) {
// do not clean header and recordBody in case of Socket Timeout
cleanInBuffer = false;
throw e;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,8 +27,8 @@

import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.nio.ByteBuffer;
import javax.crypto.AEADBadTagException;
import javax.crypto.BadPaddingException;
Expand Down Expand Up @@ -138,7 +138,7 @@ static Plaintext decode(TransportContext context,
} catch (EOFException eofe) {
// rethrow EOFException, the call will handle it if needed.
throw eofe;
} catch (InterruptedIOException | SocketException se) {
} catch (SocketTimeoutException | SocketException se) {
// don't close the Socket in case of timeouts or interrupts or SocketException.
throw se;
} catch (IOException ioe) {
Expand Down
10 changes: 4 additions & 6 deletions test/jdk/javax/net/ssl/SSLSession/TestEnabledProtocols.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2001, 2021, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2001, 2026, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -40,10 +40,10 @@

import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.SocketTimeoutException;
import java.security.Security;
import java.util.Arrays;

Expand Down Expand Up @@ -88,11 +88,9 @@ protected void runServerApplication(SSLSocket socket) throws Exception {
// log it for debugging
System.out.println("Server SSLHandshakeException:");
se.printStackTrace(System.out);
} catch (InterruptedIOException ioe) {
// must have been interrupted, no harm
} catch (SSLException | SocketException se) {
} catch (SocketTimeoutException | SSLException | SocketException se) {
// The client side may have closed the socket.
System.out.println("Server SSLException:");
System.out.println("Server exception:");
se.printStackTrace(System.out);
} catch (Exception e) {
System.out.println("Server exception:");
Expand Down