ServerHelloHandler extends HandshakeMessageHandler<ServerHelloMessage> { @Override public void adjustTLSContext(ServerHelloMessage message) { adjustSelectedProtocolVersion(message); adjustSelectedCompression(message); adjustSelectedSessionID(message); adjustSelectedCiphersuite(message); adjustServerRandom(message); adjustExtensions(message, HandshakeMessageType.SERVER_HELLO); if (!message.isTls13HelloRetryRequest()) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { adjustHandshakeTrafficSecrets(); if (tlsContext.getTalkingConnectionEndType() != tlsContext.getChooser().getConnectionEndType()) { setServerRecordCipher(); } } adjustPRF(message); if (tlsContext.hasSession(tlsContext.getChooser().getServerSessionId())) { LOGGER.info("Resuming Session"); LOGGER.debug("Loading Mastersecret"); Session session = tlsContext.getSession(tlsContext.getChooser().getServerSessionId()); tlsContext.setMasterSecret(session.getMasterSecret()); setRecordCipher(); } } } ServerHelloHandler(TlsContext tlsContext); @Override ServerHelloPreparator getPreparator(ServerHelloMessage message); @Override ServerHelloSerializer getSerializer(ServerHelloMessage message); @Override ServerHelloParser getParser(byte[] message, int pointer); @Override void adjustTLSContext(ServerHelloMessage message); @Override void adjustTlsContextAfterSerialize(ServerHelloMessage message);  }
@Test public void testAdjustTLSContext() { ServerHelloMessage message = new ServerHelloMessage(); message.setUnixTime(new byte[] { 0, 1, 2 }); message.setRandom(new byte[] { 0, 1, 2, 3, 4, 5 }); message.setSelectedCompressionMethod(CompressionMethod.DEFLATE.getValue()); message.setSelectedCipherSuite(CipherSuite.TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384.getByteValue()); message.setSessionId(new byte[] { 6, 6, 6 }); message.setProtocolVersion(ProtocolVersion.TLS12.getValue()); handler.adjustTLSContext(message); assertArrayEquals(context.getServerRandom(), new byte[] { 0, 1, 2, 3, 4, 5 }); assertTrue(context.getSelectedCompressionMethod() == CompressionMethod.DEFLATE); assertArrayEquals(context.getServerSessionId(), new byte[] { 6, 6, 6 }); assertArrayEquals(context.getSelectedCipherSuite().getByteValue(), CipherSuite.TLS_CECPQ1_ECDSA_WITH_AES_256_GCM_SHA384.getByteValue()); assertArrayEquals(context.getSelectedProtocolVersion().getValue(), ProtocolVersion.TLS12.getValue()); }
@Test public void testAdjustTLSContextTls13() { ServerHelloMessage message = new ServerHelloMessage(); context.getConfig().setKeySharePrivate( new BigInteger(ArrayConverter .hexStringToByteArray("03BD8BCA70C19F657E897E366DBE21A466E4924AF6082DBDF573827BCDDE5DEF"))); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); message.setUnixTime(new byte[] { 0, 1, 2 }); message.setRandom(new byte[] { 0, 1, 2, 3, 4, 5 }); message.setSelectedCompressionMethod(CompressionMethod.DEFLATE.getValue()); message.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256.getByteValue()); message.setSessionId(new byte[] { 6, 6, 6 }); message.setProtocolVersion(ProtocolVersion.TLS13.getValue()); context.setServerKeyShareStoreEntry(new KeyShareStoreEntry(NamedGroup.ECDH_X25519, ArrayConverter .hexStringToByteArray("9c1b0a7421919a73cb57b3a0ad9d6805861a9c47e11df8639d25323b79ce201c"))); context.addNegotiatedExtension(ExtensionType.KEY_SHARE); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); handler.adjustTLSContext(message); assertArrayEquals( ArrayConverter.hexStringToByteArray("EA2F968FD0A381E4B041E6D8DDBF6DA93DE4CEAC862693D3026323E780DB9FC3"), context.getHandshakeSecret()); assertArrayEquals( ArrayConverter.hexStringToByteArray("C56CAE0B1A64467A0E3A3337F8636965787C9A741B0DAB63E503076051BCA15C"), context.getClientHandshakeTrafficSecret()); assertArrayEquals( ArrayConverter.hexStringToByteArray("DBF731F5EE037C4494F24701FF074AD4048451C0E2803BC686AF1F2D18E861F5"), context.getServerHandshakeTrafficSecret()); }
@Test public void testAdjustTLSContextTls13PWD() { ServerHelloMessage message = new ServerHelloMessage(); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); message.setUnixTime(new byte[] { 0, 1, 2 }); message.setRandom(new byte[] { 0, 1, 2, 3, 4, 5 }); message.setSelectedCompressionMethod(CompressionMethod.DEFLATE.getValue()); message.setSelectedCipherSuite(CipherSuite.TLS_ECCPWD_WITH_AES_128_GCM_SHA256.getByteValue()); message.setSessionId(new byte[] { 6, 6, 6 }); message.setProtocolVersion(ProtocolVersion.TLS13.getValue()); context.setServerKeyShareStoreEntry(new KeyShareStoreEntry( NamedGroup.BRAINPOOLP256R1, ArrayConverter .hexStringToByteArray("9EE17F2ECF74028F6C1FD70DA1D05A4A85975D7D270CAA6B8605F1C6EBB875BA87579167408F7C9E77842C2B3F3368A25FD165637E9B5D57760B0B704659B87420669244AA67CB00EA72C09B84A9DB5BB824FC3982428FCD406963AE080E677A48"))); context.addNegotiatedExtension(ExtensionType.KEY_SHARE); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); handler.adjustTLSContext(message); assertArrayEquals( ArrayConverter.hexStringToByteArray("09E4B18F6B4F59BD8ADED8E875CD9B9A7694A8C5345EDB3381A47D1F860BF209"), context.getHandshakeSecret()); }