Skip to content

Commit ed13a72

Browse files
committed
GEODE-6664 CI failure: org.apache.geode.ClusterCommunicationsDUnitTest.receiveBigResponse
Ensure that the encrypted buffer is at least as big as the SSLSession's packet buffer size. That's required for proper decryption of incoming packets. (cherry picked from commit ff703dd)
1 parent e0c29b1 commit ed13a72

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

geode-core/src/main/java/org/apache/geode/internal/net/NioSslEngine.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,18 +308,17 @@ void expandPeerAppData(ByteBuffer wrappedBuffer) {
308308
}
309309
}
310310

311-
/*
312-
* NioSslEngine doesn't need to ensure capacity in network buffers because they
313-
* are fixed in size by the SslContext. The size recommended by the context is
314-
* big enough for the SslEngine to do its work.
315-
*/
316311
@Override
317312
public ByteBuffer ensureWrappedCapacity(int amount, ByteBuffer wrappedBuffer,
318313
Buffers.BufferType bufferType, DMStats stats) {
319-
if (wrappedBuffer == null) {
320-
wrappedBuffer = Buffers.acquireBuffer(bufferType, amount, stats);
314+
ByteBuffer buffer = wrappedBuffer;
315+
int requiredSize = engine.getSession().getPacketBufferSize();
316+
if (buffer == null) {
317+
buffer = Buffers.acquireBuffer(bufferType, requiredSize, stats);
318+
} else if (buffer.capacity() < requiredSize) {
319+
buffer = Buffers.expandWriteBufferIfNeeded(bufferType, buffer, requiredSize, stats);
321320
}
322-
return wrappedBuffer;
321+
return buffer;
323322
}
324323

325324
@Override

geode-core/src/test/java/org/apache/geode/internal/net/NioSslEngineTest.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,13 +373,21 @@ public void closeWhenSocketWriteError() throws Exception {
373373
}
374374

375375
@Test
376-
public void ensureWrappedCapacity() {
377-
ByteBuffer buffer = ByteBuffer.allocate(10);
376+
public void ensureWrappedCapacityOfSmallMessage() {
377+
ByteBuffer buffer = ByteBuffer.allocate(netBufferSize);
378378
assertThat(
379379
nioSslEngine.ensureWrappedCapacity(10, buffer, Buffers.BufferType.UNTRACKED, mockStats))
380380
.isEqualTo(buffer);
381381
}
382382

383+
@Test
384+
public void ensureWrappedCapacityWithNoBuffer() {
385+
assertThat(
386+
nioSslEngine.ensureWrappedCapacity(10, null, Buffers.BufferType.UNTRACKED, mockStats)
387+
.capacity())
388+
.isEqualTo(netBufferSize);
389+
}
390+
383391
@Test
384392
public void readAtLeast() throws Exception {
385393
final int amountToRead = 150;

0 commit comments

Comments
 (0)