@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()); }
@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 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 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); }
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); }
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);  }