ClientHelloHandler extends HandshakeMessageHandler<ClientHelloMessage> { @Override public void adjustTLSContext(ClientHelloMessage message) { adjustProtocolVersion(message); adjustSessionID(message); adjustClientSupportedCipherSuites(message); adjustClientSupportedCompressions(message); if (isCookieFieldSet(message)) { adjustDTLSCookie(message); } adjustExtensions(message, HandshakeMessageType.CLIENT_HELLO); adjustRandomContext(message); if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13() && tlsContext.isExtensionNegotiated(ExtensionType.EARLY_DATA)) { try { adjustEarlyTrafficSecret(); setClientRecordCipherEarly(); } catch (CryptoException ex) { throw new AdjustmentException("Could not adjust", ex); } } } ClientHelloHandler(TlsContext tlsContext); @Override ClientHelloParser getParser(byte[] message, int pointer); @Override ClientHelloPreparator getPreparator(ClientHelloMessage message); @Override ClientHelloSerializer getSerializer(ClientHelloMessage message); @Override void adjustTLSContext(ClientHelloMessage message); @Override void adjustTlsContextAfterSerialize(ClientHelloMessage message);  }
@Test public void testAdjustTLSContext() { ClientHelloMessage message = new ClientHelloMessage(); message.setUnixTime(new byte[] { 0, 1, 2 }); message.setRandom(new byte[] { 0, 1, 2, 3, 4, 5 }); message.setCompressions(new byte[] { 0, 1 }); message.setCipherSuites(new byte[] { 0x00, 0x01, 0x00, 0x02 }); message.setSessionId(new byte[] { 6, 6, 6 }); message.setProtocolVersion(ProtocolVersion.TLS12.getValue()); handler.adjustTLSContext(message); assertArrayEquals(context.getClientRandom(), new byte[] { 0, 1, 2, 3, 4, 5 }); assertTrue(context.getClientSupportedCompressions().contains(CompressionMethod.DEFLATE)); assertTrue(context.getClientSupportedCompressions().contains(CompressionMethod.NULL)); assertTrue(context.getClientSupportedCompressions().size() == 2); assertArrayEquals(context.getClientSessionId(), new byte[] { 6, 6, 6 }); assertTrue(context.getClientSupportedCiphersuites().size() == 2); assertTrue(context.getClientSupportedCiphersuites().contains(CipherSuite.TLS_RSA_WITH_NULL_SHA)); assertTrue(context.getClientSupportedCiphersuites().contains(CipherSuite.TLS_RSA_WITH_NULL_MD5)); assertNull(context.getDtlsCookie()); assertArrayEquals(context.getHighestClientProtocolVersion().getValue(), ProtocolVersion.TLS12.getValue()); }
@Test public void testAdjustTLSContextWithCookie() { ClientHelloMessage message = new ClientHelloMessage(); message.setUnixTime(new byte[] { 0, 1, 2 }); message.setRandom(new byte[] { 0, 1, 2, 3, 4, 5 }); message.setCompressions(new byte[] { 0, 1 }); message.setCipherSuites(new byte[] { 0x00, 0x01, 0x00, 0x02 }); message.setSessionId(new byte[] { 6, 6, 6 }); message.setCookie(new byte[] { 2, 2, 3, }); message.setProtocolVersion(ProtocolVersion.TLS12.getValue()); handler.adjustTLSContext(message); assertArrayEquals(context.getClientRandom(), new byte[] { 0, 1, 2, 3, 4, 5 }); assertTrue(context.getClientSupportedCompressions().contains(CompressionMethod.DEFLATE)); assertTrue(context.getClientSupportedCompressions().contains(CompressionMethod.NULL)); assertTrue(context.getClientSupportedCompressions().size() == 2); assertArrayEquals(context.getClientSessionId(), new byte[] { 6, 6, 6 }); assertTrue(context.getClientSupportedCiphersuites().size() == 2); assertTrue(context.getClientSupportedCiphersuites().contains(CipherSuite.TLS_RSA_WITH_NULL_SHA)); assertTrue(context.getClientSupportedCiphersuites().contains(CipherSuite.TLS_RSA_WITH_NULL_MD5)); assertArrayEquals(context.getDtlsCookie(), new byte[] { 2, 2, 3 }); assertArrayEquals(context.getHighestClientProtocolVersion().getValue(), ProtocolVersion.TLS12.getValue()); }