@@ -1376,6 +1376,7 @@ public void testSessionInvalidate(SSLEngineTestParam param) throws Exception { |
1376 | 1376 | clientEngine = wrapEngine(clientSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT)); |
1377 | 1377 | serverEngine = wrapEngine(serverSslCtx.newEngine(UnpooledByteBufAllocator.DEFAULT)); |
1378 | 1378 | handshake(param.type(), param.delegate(), clientEngine, serverEngine); |
| 1379 | + pingPongPacketsUntilSessionAllocation(param, clientEngine, serverEngine); |
1379 | 1380 |
|
1380 | 1381 | SSLSession session = serverEngine.getSession(); |
1381 | 1382 | assertTrue(session.isValid(), "session should be valid: " + session); |
@@ -1417,43 +1418,7 @@ public void testSSLSessionId(SSLEngineTestParam param) throws Exception { |
1417 | 1418 | handshake(param.type(), param.delegate(), clientEngine, serverEngine); |
1418 | 1419 |
|
1419 | 1420 | if (param.protocolCipherCombo == ProtocolCipherCombo.TLSV13) { |
1420 | | - // Allocate something which is big enough for sure |
1421 | | - ByteBuffer packetBuffer = allocateBuffer(param.type(), 32 * 1024); |
1422 | | - ByteBuffer appBuffer = allocateBuffer(param.type(), 32 * 1024); |
1423 | | - |
1424 | | - appBuffer.clear().position(4).flip(); |
1425 | | - packetBuffer.clear(); |
1426 | | - |
1427 | | - do { |
1428 | | - SSLEngineResult result; |
1429 | | - |
1430 | | - do { |
1431 | | - result = serverEngine.wrap(appBuffer, packetBuffer); |
1432 | | - } while (appBuffer.hasRemaining() || result.bytesProduced() > 0); |
1433 | | - |
1434 | | - appBuffer.clear(); |
1435 | | - packetBuffer.flip(); |
1436 | | - do { |
1437 | | - result = clientEngine.unwrap(packetBuffer, appBuffer); |
1438 | | - } while (packetBuffer.hasRemaining() || result.bytesProduced() > 0); |
1439 | | - |
1440 | | - packetBuffer.clear(); |
1441 | | - appBuffer.clear().position(4).flip(); |
1442 | | - |
1443 | | - do { |
1444 | | - result = clientEngine.wrap(appBuffer, packetBuffer); |
1445 | | - } while (appBuffer.hasRemaining() || result.bytesProduced() > 0); |
1446 | | - |
1447 | | - appBuffer.clear(); |
1448 | | - packetBuffer.flip(); |
1449 | | - |
1450 | | - do { |
1451 | | - result = serverEngine.unwrap(packetBuffer, appBuffer); |
1452 | | - } while (packetBuffer.hasRemaining() || result.bytesProduced() > 0); |
1453 | | - |
1454 | | - packetBuffer.clear(); |
1455 | | - appBuffer.clear().position(4).flip(); |
1456 | | - } while (clientEngine.getSession().getId().length == 0); |
| 1421 | + pingPongPacketsUntilSessionAllocation(param, clientEngine, serverEngine); |
1457 | 1422 |
|
1458 | 1423 | // With TLS1.3 we should see pseudo IDs and so these should never match. |
1459 | 1424 | assertFalse(Arrays.equals(clientEngine.getSession().getId(), serverEngine.getSession().getId())); |
@@ -1472,6 +1437,47 @@ public void testSSLSessionId(SSLEngineTestParam param) throws Exception { |
1472 | 1437 | } |
1473 | 1438 | } |
1474 | 1439 |
|
| 1440 | + private void pingPongPacketsUntilSessionAllocation( |
| 1441 | + SSLEngineTestParam param, SSLEngine clientEngine, SSLEngine serverEngine) throws SSLException { |
| 1442 | + // Allocate something which is big enough for sure |
| 1443 | + ByteBuffer packetBuffer = allocateBuffer(param.type(), 32 * 1024); |
| 1444 | + ByteBuffer appBuffer = allocateBuffer(param.type(), 32 * 1024); |
| 1445 | + |
| 1446 | + appBuffer.clear().position(4).flip(); |
| 1447 | + packetBuffer.clear(); |
| 1448 | + |
| 1449 | + do { |
| 1450 | + SSLEngineResult result; |
| 1451 | + |
| 1452 | + do { |
| 1453 | + result = serverEngine.wrap(appBuffer, packetBuffer); |
| 1454 | + } while (appBuffer.hasRemaining() || result.bytesProduced() > 0); |
| 1455 | + |
| 1456 | + appBuffer.clear(); |
| 1457 | + packetBuffer.flip(); |
| 1458 | + do { |
| 1459 | + result = clientEngine.unwrap(packetBuffer, appBuffer); |
| 1460 | + } while (packetBuffer.hasRemaining() || result.bytesProduced() > 0); |
| 1461 | + |
| 1462 | + packetBuffer.clear(); |
| 1463 | + appBuffer.clear().position(4).flip(); |
| 1464 | + |
| 1465 | + do { |
| 1466 | + result = clientEngine.wrap(appBuffer, packetBuffer); |
| 1467 | + } while (appBuffer.hasRemaining() || result.bytesProduced() > 0); |
| 1468 | + |
| 1469 | + appBuffer.clear(); |
| 1470 | + packetBuffer.flip(); |
| 1471 | + |
| 1472 | + do { |
| 1473 | + result = serverEngine.unwrap(packetBuffer, appBuffer); |
| 1474 | + } while (packetBuffer.hasRemaining() || result.bytesProduced() > 0); |
| 1475 | + |
| 1476 | + packetBuffer.clear(); |
| 1477 | + appBuffer.clear().position(4).flip(); |
| 1478 | + } while (clientEngine.getSession().getId().length == 0); |
| 1479 | + } |
| 1480 | + |
1475 | 1481 | @MethodSource("newTestParams") |
1476 | 1482 | @ParameterizedTest |
1477 | 1483 | @Timeout(30) |
|