8259662: Don't wrap SocketExceptions into SSLExceptions in SSLSocketImpl

Reviewed-by: xuelei
This commit is contained in:
Clive Verghese 2021-02-22 18:36:30 +00:00 committed by Xue-Lei Andrew Fan
parent cf0019d964
commit 63f8fc87cd
7 changed files with 199 additions and 22 deletions

View file

@ -74,6 +74,16 @@ import jdk.internal.access.SharedSecrets;
public final class SSLSocketImpl
extends BaseSSLSocketImpl implements SSLTransport {
/**
* ERROR HANDLING GUIDELINES
* (which exceptions to throw and catch and which not to throw and catch)
*
* - if there is an IOException (SocketException) when accessing the
* underlying Socket, pass it through
*
* - do not throw IOExceptions, throw SSLExceptions (or a subclass)
*/
final SSLContextImpl sslContext;
final TransportContext conContext;
@ -446,6 +456,8 @@ public final class SSLSocketImpl
throw conContext.fatal(Alert.HANDSHAKE_FAILURE,
"Couldn't kickstart handshaking", iioe);
}
} catch (SocketException se) {
handleException(se);
} catch (IOException ioe) {
throw conContext.fatal(Alert.HANDSHAKE_FAILURE,
"Couldn't kickstart handshaking", ioe);
@ -1405,9 +1417,9 @@ public final class SSLSocketImpl
conContext.isNegotiated) {
return 0;
}
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw ssle;
} catch (SSLException | InterruptedIOException | SocketException se) {
// don't change exception in case of timeouts or interrupts or SocketException
throw se;
} catch (IOException ioe) {
throw new SSLException("readHandshakeRecord", ioe);
}
@ -1468,9 +1480,9 @@ public final class SSLSocketImpl
buffer.position() > 0) {
return buffer;
}
} catch (SSLException | InterruptedIOException ssle) {
// don't change exception in case of timeouts or interrupts
throw ssle;
} catch (SSLException | InterruptedIOException | SocketException se) {
// don't change exception in case of timeouts or interrupts or SocketException.
throw se;
} catch (IOException ioe) {
throw new SSLException("readApplicationRecord", ioe);
}
@ -1678,6 +1690,16 @@ public final class SSLSocketImpl
}
}
if (cause instanceof SocketException) {
try {
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);
}

View file

@ -28,6 +28,7 @@ package sun.security.ssl;
import java.io.EOFException;
import java.io.IOException;
import java.io.InterruptedIOException;
import java.net.SocketException;
import java.nio.ByteBuffer;
import javax.crypto.AEADBadTagException;
import javax.crypto.BadPaddingException;
@ -137,9 +138,9 @@ interface SSLTransport {
} catch (EOFException eofe) {
// rethrow EOFException, the call will handle it if neede.
throw eofe;
} catch (InterruptedIOException iioe) {
// don't close the Socket in case of timeouts or interrupts.
throw iioe;
} catch (InterruptedIOException | SocketException se) {
// don't close the Socket in case of timeouts or interrupts or SocketException.
throw se;
} catch (IOException ioe) {
throw context.fatal(Alert.UNEXPECTED_MESSAGE, ioe);
}