Skip to content

Fix unwrapping loop in case reading bytebuffer has exactly 1 handshake message #1281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 8, 2024
Merged
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
10 changes: 2 additions & 8 deletions src/main/java/com/rabbitmq/client/impl/nio/SslEngineHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ private static SSLEngineResult.HandshakeStatus unwrap(ByteBuffer cipherIn, ByteB
SSLEngineResult unwrapResult;
do {
int positionBeforeUnwrapping = cipherIn.position();
LOGGER.debug("Before unwrapping cipherIn is {}, with {} remaining byte(s)", cipherIn, cipherIn.remaining());
unwrapResult = sslEngine.unwrap(cipherIn, plainIn);
LOGGER.debug("SSL engine result is {} after unwrapping", unwrapResult);
status = unwrapResult.getStatus();
Expand All @@ -118,14 +119,7 @@ private static SSLEngineResult.HandshakeStatus unwrap(ByteBuffer cipherIn, ByteB
plainIn.clear();
if (unwrapResult.getHandshakeStatus() == NEED_TASK) {
handshakeStatus = runDelegatedTasks(sslEngine);
int newPosition = positionBeforeUnwrapping + unwrapResult.bytesConsumed();
if (newPosition == cipherIn.limit()) {
LOGGER.debug("Clearing cipherIn because all bytes have been read and unwrapped");
cipherIn.clear();
} else {
LOGGER.debug("Setting cipherIn position to {} (limit is {})", newPosition, cipherIn.limit());
cipherIn.position(positionBeforeUnwrapping + unwrapResult.bytesConsumed());
}
cipherIn.position(positionBeforeUnwrapping + unwrapResult.bytesConsumed());
} else {
handshakeStatus = unwrapResult.getHandshakeStatus();
}
Expand Down