From bd577ef52f178ceb9e2f0d9b718a5397afb2578b Mon Sep 17 00:00:00 2001 From: Norman Maurer Date: Thu, 25 Jun 2020 14:55:35 +0200 Subject: [PATCH] Ensure we feed all data to the SSLEngine during handshaking in our tests (#10373) Motivation: Due a bug in our test we may dropped data on the floor which are generated during handshaking (or slightly after). This could lead to corrupt state in the engine itself and so fail tests. This is especially true for TLS1.3 which generates the sessions on the server after the "actual handshake" is done. Modifications: Contine with wrap / unwrap until all data was consumed Result: Correctly feed all data to the engine during testing --- .../java/io/netty/handler/ssl/SSLEngineTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java index 9d0b757e22..e7ea8dcfb5 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SSLEngineTest.java @@ -1483,6 +1483,9 @@ public abstract class SSLEngineTest { boolean clientHandshakeFinished = false; boolean serverHandshakeFinished = false; + boolean cTOsHasRemaining; + boolean sTOcHasRemaining; + do { int cTOsPos = cTOs.position(); int sTOcPos = sTOc.position(); @@ -1547,9 +1550,16 @@ public abstract class SSLEngineTest { assertFalse(cTOs.hasRemaining()); } + cTOsHasRemaining = cTOs.hasRemaining(); + sTOcHasRemaining = sTOc.hasRemaining(); + sTOc.compact(); cTOs.compact(); - } while (!clientHandshakeFinished || !serverHandshakeFinished); + } while (!clientHandshakeFinished || !serverHandshakeFinished || + // We need to ensure we feed all the data to the engine to not end up with a corrupted state. + // This is especially important with TLS1.3 which may produce sessions after the "main handshake" is + // done + cTOsHasRemaining || sTOcHasRemaining); } private static boolean isHandshakeFinished(SSLEngineResult result) {