Skip to content

Commit 4b596d7

Browse files
committed
HTTPCORE-782: non-blocking TLS session can end up in an endless loop in case of a protocol negotiation
1 parent e94993b commit 4b596d7

File tree

1 file changed

+5
-13
lines changed

1 file changed

+5
-13
lines changed

httpcore5/src/main/java/org/apache/hc/core5/reactor/ssl/SSLIOSession.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -620,20 +620,12 @@ private void decryptData(final IOSession protocolSession) throws IOException {
620620
inPlainBuf.clear();
621621
}
622622
}
623-
if (result.getStatus() != SSLEngineResult.Status.OK) {
624-
if (result.getStatus() == SSLEngineResult.Status.BUFFER_UNDERFLOW && endOfStream) {
625-
throw new SSLException("Unable to decrypt incoming data due to unexpected end of stream");
626-
}
627-
break;
623+
if (result.getStatus() == SSLEngineResult.Status.BUFFER_UNDERFLOW && endOfStream) {
624+
throw new SSLException("Unable to decrypt incoming data due to unexpected end of stream");
628625
}
629-
if (result.bytesConsumed() == 0) {
630-
throw new SSLException(String.format("Unable to decrypt incoming data " +
631-
"[status = " + result.getStatus() +
632-
"; handshakeStatus = " + result.getHandshakeStatus() +
633-
"; bytesConsumed = " + result.bytesConsumed() +
634-
"; bytesProduced = " + result.bytesProduced() +
635-
"; end of stream = " + endOfStream +
636-
"]"));
626+
if (result.getStatus() != SSLEngineResult.Status.OK ||
627+
result.getHandshakeStatus() != HandshakeStatus.NOT_HANDSHAKING && result.getHandshakeStatus() != HandshakeStatus.FINISHED) {
628+
break;
637629
}
638630
} finally {
639631
inPlain.release();

0 commit comments

Comments
 (0)