diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SSLExceptionHelper.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SSLExceptionHelper.java index c954671cc96c4..d1d4bc330fdbd 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SSLExceptionHelper.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SSLExceptionHelper.java @@ -8,8 +8,10 @@ import io.netty.handler.codec.DecoderException; import io.netty.handler.ssl.NotSslRecordException; +import org.elasticsearch.common.regex.Regex; import javax.net.ssl.SSLException; +import javax.net.ssl.SSLHandshakeException; public class SSLExceptionHelper { @@ -22,6 +24,11 @@ public static boolean isNotSslRecordException(Throwable e) { } public static boolean isCloseDuringHandshakeException(Throwable e) { + return isCloseDuringHandshakeSSLException(e) + || isCloseDuringHandshakeSSLException(e.getCause()); + } + + private static boolean isCloseDuringHandshakeSSLException(Throwable e) { return e instanceof SSLException && e.getCause() == null && "Received close_notify during handshake".equals(e.getMessage()); @@ -32,4 +39,10 @@ public static boolean isReceivedCertificateUnknownException(Throwable e) { && e.getCause() instanceof SSLException && "Received fatal alert: certificate_unknown".equals(e.getCause().getMessage()); } + + public static boolean isInsufficientBufferRemainingException(Throwable e) { + return e instanceof DecoderException + && e.getCause() instanceof SSLHandshakeException + && Regex.simpleMatch("Insufficient buffer remaining for AEAD cipher fragment*", e.getCause().getMessage()); + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SecurityTransportExceptionHandler.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SecurityTransportExceptionHandler.java index 44789e81ce960..fea3abedc3213 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SecurityTransportExceptionHandler.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/security/transport/SecurityTransportExceptionHandler.java @@ -34,6 +34,9 @@ public void accept(TcpChannel channel, Exception e) { } else if (SSLExceptionHelper.isCloseDuringHandshakeException(e)) { logger.debug("connection {} closed during handshake", channel); CloseableChannel.closeChannel(channel); + } else if (SSLExceptionHelper.isInsufficientBufferRemainingException(e)) { + logger.debug("connection {} closed abruptly", channel); + CloseableChannel.closeChannel(channel); } else if (SSLExceptionHelper.isReceivedCertificateUnknownException(e)) { logger.warn("client did not trust this server's certificate, closing connection {}", channel); CloseableChannel.closeChannel(channel); diff --git a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/SecurityHttpExceptionHandler.java b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/SecurityHttpExceptionHandler.java index 761d9e1428dd0..aae0e3d8c4b31 100644 --- a/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/SecurityHttpExceptionHandler.java +++ b/x-pack/plugin/security/src/main/java/org/elasticsearch/xpack/security/transport/SecurityHttpExceptionHandler.java @@ -13,6 +13,7 @@ import java.util.function.BiConsumer; import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isCloseDuringHandshakeException; +import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isInsufficientBufferRemainingException; import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isNotSslRecordException; import static org.elasticsearch.xpack.core.security.transport.SSLExceptionHelper.isReceivedCertificateUnknownException; @@ -39,6 +40,9 @@ public void accept(HttpChannel channel, Exception e) { } else if (isCloseDuringHandshakeException(e)) { logger.debug("connection {} closed during ssl handshake", channel); CloseableChannel.closeChannel(channel); + } else if (isInsufficientBufferRemainingException(e)) { + logger.debug("connection {} closed abruptly", channel); + CloseableChannel.closeChannel(channel); } else if (isReceivedCertificateUnknownException(e)) { logger.warn("http client did not trust this server's certificate, closing connection {}", channel); CloseableChannel.closeChannel(channel);