FinishedHandler extends HandshakeMessageHandler<FinishedMessage> { @Override public void adjustTLSContext(FinishedMessage message) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { if (tlsContext.getTalkingConnectionEndType() != tlsContext.getChooser().getConnectionEndType()) { if (tlsContext.getTalkingConnectionEndType() == ConnectionEndType.SERVER) { adjustApplicationTrafficSecrets(); setServerRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS); } else { setClientRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS); } } else if (tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT || !tlsContext.isExtensionNegotiated(ExtensionType.EARLY_DATA)) { setClientRecordCipher(Tls13KeySetType.HANDSHAKE_TRAFFIC_SECRETS); } } if (tlsContext.getTalkingConnectionEndType() == ConnectionEndType.CLIENT) { tlsContext.setLastClientVerifyData(message.getVerifyData().getValue()); } else { tlsContext.setLastServerVerifyData(message.getVerifyData().getValue()); } } FinishedHandler(TlsContext context); @Override FinishedParser getParser(byte[] message, int pointer); @Override FinishedPreparator getPreparator(FinishedMessage message); @Override FinishedSerializer getSerializer(FinishedMessage message); @Override void adjustTLSContext(FinishedMessage message); @Override void adjustTlsContextAfterSerialize(FinishedMessage message);  }
@Test public void testAdjustTLSContext() { FinishedMessage message = new FinishedMessage(); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); handler.adjustTLSContext(message); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastClientVerifyData()); assertArrayEquals(null, context.getLastServerVerifyData()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveClientKeySetType()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ServerOutbound() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setConnection(new OutboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastServerVerifyData()); assertArrayEquals(null, context.getLastClientVerifyData()); assertEquals(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS, context.getActiveServerKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveClientKeySetType()); assertEquals(99, context.getWriteSequenceNumber()); assertEquals(0, context.getReadSequenceNumber()); assertArrayEquals( ArrayConverter.hexStringToByteArray("F8FAD34AEB9E4A8A3233A5F3C01D9E7B25CFAA4CBD7E255426A39B5EA8AE9840"), context.getClientApplicationTrafficSecret()); assertArrayEquals( ArrayConverter.hexStringToByteArray("2FC28A45C71076589231CE9095D933E120AFD9F38895CFE2EC8A56B89FBCEF33"), context.getServerApplicationTrafficSecret()); assertArrayEquals( ArrayConverter.hexStringToByteArray("9AD9F506B33C740C483E54321EBE59268F7D588356F07ADED4149164D0A18FCA"), context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ServerInbound() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setConnection(new InboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertEquals(Tls13KeySetType.HANDSHAKE_TRAFFIC_SECRETS, context.getActiveClientKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastServerVerifyData()); assertArrayEquals(null, context.getLastClientVerifyData()); assertEquals(99, context.getWriteSequenceNumber()); assertEquals(0, context.getReadSequenceNumber()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ClientOutbound() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.CLIENT); context.setConnection(new OutboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertEquals(Tls13KeySetType.HANDSHAKE_TRAFFIC_SECRETS, context.getActiveClientKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastClientVerifyData()); assertArrayEquals(null, context.getLastServerVerifyData()); assertEquals(0, context.getWriteSequenceNumber()); assertEquals(99, context.getReadSequenceNumber()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ClientInbound() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.CLIENT); context.setConnection(new InboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertEquals(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS, context.getActiveClientKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastClientVerifyData()); assertArrayEquals(null, context.getLastServerVerifyData()); assertEquals(99, context.getWriteSequenceNumber()); assertEquals(0, context.getReadSequenceNumber()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ServerInboundWithoutEarlyData() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setConnection(new InboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.getNegotiatedExtensionSet().remove(ExtensionType.EARLY_DATA); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertEquals(Tls13KeySetType.HANDSHAKE_TRAFFIC_SECRETS, context.getActiveClientKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastServerVerifyData()); assertArrayEquals(null, context.getLastClientVerifyData()); assertEquals(99, context.getWriteSequenceNumber()); assertEquals(0, context.getReadSequenceNumber()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }
@Test public void testAdjustTLSContextTls13ServerInboundWithEarlyData() { FinishedMessage message = new FinishedMessage(); context.setRecordLayer(RecordLayerFactory.getRecordLayer(RecordLayerType.RECORD, context)); context.setTalkingConnectionEndType(ConnectionEndType.SERVER); context.setConnection(new InboundConnection()); context.setSelectedProtocolVersion(ProtocolVersion.TLS13); context.setHandshakeSecret(new byte[] { 0, 1, 2, 3, 4 }); context.setSelectedCipherSuite(CipherSuite.TLS_AES_128_GCM_SHA256); message.setVerifyData(new byte[] { 0, 1, 2, 3, 4 }); context.getNegotiatedExtensionSet().add(ExtensionType.EARLY_DATA); context.setReadSequenceNumber(99); context.setWriteSequenceNumber(99); handler.adjustTLSContext(message); assertEquals(Tls13KeySetType.NONE, context.getActiveClientKeySetType()); assertEquals(Tls13KeySetType.NONE, context.getActiveServerKeySetType()); assertArrayEquals(new byte[] { 0, 1, 2, 3, 4 }, context.getLastServerVerifyData()); assertArrayEquals(null, context.getLastClientVerifyData()); assertEquals(99, context.getWriteSequenceNumber()); assertEquals(99, context.getReadSequenceNumber()); assertArrayEquals(null, context.getClientApplicationTrafficSecret()); assertArrayEquals(null, context.getServerApplicationTrafficSecret()); assertArrayEquals(null, context.getMasterSecret()); }