Skip to content

Commit dbd5788

Browse files
Merge pull request #1281 from bmleite/nio-tls-v1.2-handshake-error
Fix unwrapping loop in case reading bytebuffer has exactly 1 handshake message
2 parents 07d9bfd + 7382a33 commit dbd5788

File tree

1 file changed

+2
-8
lines changed

1 file changed

+2
-8
lines changed

src/main/java/com/rabbitmq/client/impl/nio/SslEngineHelper.java

+2-8
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ private static SSLEngineResult.HandshakeStatus unwrap(ByteBuffer cipherIn, ByteB
110110
SSLEngineResult unwrapResult;
111111
do {
112112
int positionBeforeUnwrapping = cipherIn.position();
113+
LOGGER.debug("Before unwrapping cipherIn is {}, with {} remaining byte(s)", cipherIn, cipherIn.remaining());
113114
unwrapResult = sslEngine.unwrap(cipherIn, plainIn);
114115
LOGGER.debug("SSL engine result is {} after unwrapping", unwrapResult);
115116
status = unwrapResult.getStatus();
@@ -118,14 +119,7 @@ private static SSLEngineResult.HandshakeStatus unwrap(ByteBuffer cipherIn, ByteB
118119
plainIn.clear();
119120
if (unwrapResult.getHandshakeStatus() == NEED_TASK) {
120121
handshakeStatus = runDelegatedTasks(sslEngine);
121-
int newPosition = positionBeforeUnwrapping + unwrapResult.bytesConsumed();
122-
if (newPosition == cipherIn.limit()) {
123-
LOGGER.debug("Clearing cipherIn because all bytes have been read and unwrapped");
124-
cipherIn.clear();
125-
} else {
126-
LOGGER.debug("Setting cipherIn position to {} (limit is {})", newPosition, cipherIn.limit());
127-
cipherIn.position(positionBeforeUnwrapping + unwrapResult.bytesConsumed());
128-
}
122+
cipherIn.position(positionBeforeUnwrapping + unwrapResult.bytesConsumed());
129123
} else {
130124
handshakeStatus = unwrapResult.getHandshakeStatus();
131125
}

0 commit comments

Comments
 (0)