@Override public boolean isUsingPadding() { return version.isTLS13() || context.getActiveKeySetTypeWrite() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS || context.getActiveKeySetTypeRead() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS; }
public static KeySet generateKeySet(TlsContext context, ProtocolVersion protocolVersion, Tls13KeySetType keySetType) throws NoSuchAlgorithmException, CryptoException { if (protocolVersion.isTLS13()) { return getTls13KeySet(context, keySetType); } else { return getTlsKeySet(context); } }
@Override protected NewSessionTicketMessage createHandshakeMessage() { return new NewSessionTicketMessage(!getVersion().isTLS13()); }
@Override public void adjustTlsContextAfterSerialize(ServerHelloMessage message) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { setServerRecordCipher(); } }
@Override public void prepareHandshakeMessageContents() { LOGGER.debug("Preparing CertificateMessage"); if (chooser.getSelectedProtocolVersion().isTLS13()) { prepareRequestContext(msg); prepareRequestContextLength(msg); } prepareCertificateListBytes(msg); }
@Override public void adjustTLSContext(NewSessionTicketMessage message) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { adjustPskSets(message); } }
@Override protected void prepareHandshakeMessageContents() { LOGGER.debug("Preparing NewSessionTicketMessage"); prepareTicketLifetimeHint(msg); if (chooser.getSelectedProtocolVersion().isTLS13()) { prepareTicketTls13(msg); } else { prepareTicket(msg); } }
@Override protected void parseHandshakeMessageContent(CertificateMessage msg) { LOGGER.debug("Parsing CertificateMessage"); if (getVersion().isTLS13()) { parseRequestContextLength(msg); parseRequestContextBytes(msg); } parseCertificatesListLength(msg); parseCertificateListBytes(msg); if (getVersion().isTLS13()) { parseCertificateList(msg); } }
@Override public EncryptionResult encrypt(EncryptionRequest request) { try { if (version.isTLS13() || context.getActiveKeySetTypeWrite() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS) { return encryptTLS13(request); } else { return encryptTLS12(request); } } catch (CryptoException E) { LOGGER.warn("Could not encrypt Data with the provided parameters. Returning unencrypted data."); LOGGER.debug(E); return new EncryptionResult(request.getPlainText()); } }
@Override public byte[] serializeHandshakeMessageContent() { LOGGER.debug("Serializing CertificateMessage"); if (version.isTLS13()) { writeRequestContextLength(msg); writeRequestContext(msg); } writeCertificatesListLength(msg); wirteCertificatesListBytes(msg); return getAlreadySerialized(); }
@Override public DecryptionResult decrypt(DecryptionRequest decryptionRequest) { try { byte[] decrypted; if (version.isTLS13() || context.getActiveKeySetTypeRead() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS) { decrypted = decryptTLS13(decryptionRequest); } else { decrypted = decryptTLS12(decryptionRequest); } return new DecryptionResult(null, decrypted, null); } catch (CryptoException E) { LOGGER.warn("Could not decrypt Data with the provided parameters. Returning undecrypted data."); LOGGER.debug(E); return new DecryptionResult(null, decryptionRequest.getCipherText(), false); } }
private void prepareSessionID() { if (chooser.getSelectedProtocolVersion().isTLS13()) { msg.setSessionId(new byte[0]); } else { msg.setSessionId(chooser.getServerSessionId()); } LOGGER.debug("SessionID: " + ArrayConverter.bytesToHexString(msg.getSessionId().getValue())); }
@Override protected byte[] serializeBytes() { LOGGER.debug("Serializing CertificatePair"); writeCertificateLength(pair); writeCertificate(pair); if (version.isTLS13()) { writeExtensionsLength(pair); if (pair.getExtensions() != null && pair.getExtensions().getValue() != null) { writeExtensions(pair); } } return getAlreadySerialized(); }
@Override public void adjustTlsContextAfterSerialize(FinishedMessage message) { if (tlsContext.getChooser().getSelectedProtocolVersion().isTLS13()) { if (tlsContext.getChooser().getConnectionEndType() == ConnectionEndType.CLIENT) { setClientRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS); } else { adjustApplicationTrafficSecrets(); setServerRecordCipher(Tls13KeySetType.APPLICATION_TRAFFIC_SECRETS); } } }
private void prepareCompressions(ClientHelloMessage msg) { if (chooser.getConfig().getHighestProtocolVersion().isTLS13()) { msg.setCompressions(CompressionMethod.NULL.getArrayValue()); } else { msg.setCompressions(convertCompressions(chooser.getConfig().getDefaultClientSupportedCompressionMethods())); } LOGGER.debug("Compressions: " + ArrayConverter.bytesToHexString(msg.getCompressions().getValue())); }
private void prepareContentType(Record record) { if ((chooser.getSelectedProtocolVersion().isTLS13() || chooser.getContext().getActiveKeySetTypeWrite() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS) && chooser.getContext().getActiveKeySetTypeWrite() != Tls13KeySetType.NONE) { record.setContentType(ProtocolMessageType.APPLICATION_DATA.getValue()); } else { record.setContentType(type.getValue()); } prepareConentMessageType(type); LOGGER.debug("ContentType: " + type.getValue()); }
@Override public void prepare() { LOGGER.debug("Preparing Record"); record.prepareComputations(); prepareContentType(record); prepareProtocolVersion(record); prepareSequenceNumber(record); if (chooser.getSelectedProtocolVersion().isTLS13() || chooser.getContext().getActiveKeySetTypeWrite() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS) { preparePaddingLength(record); } encryptor.encrypt(record); prepareLength(record); }
private void prepareProtocolVersion(Record record) { if (chooser.getSelectedProtocolVersion().isTLS13() || chooser.getContext().getActiveKeySetTypeWrite() == Tls13KeySetType.EARLY_TRAFFIC_SECRETS) { record.setProtocolVersion(ProtocolVersion.TLS12.getValue()); } else { record.setProtocolVersion(chooser.getSelectedProtocolVersion().getValue()); } LOGGER.debug("ProtocolVersion: " + ArrayConverter.bytesToHexString(record.getProtocolVersion().getValue())); }
private void prepareProtocolVersion(ClientHelloMessage msg) { if (chooser.getConfig().getHighestProtocolVersion().isTLS13()) { msg.setProtocolVersion(ProtocolVersion.TLS12.getValue()); } else { msg.setProtocolVersion(chooser.getConfig().getHighestProtocolVersion().getValue()); } LOGGER.debug("ProtocolVersion: " + ArrayConverter.bytesToHexString(msg.getProtocolVersion().getValue())); }
private void prepareSessionID() { if (chooser.getConfig().getHighestProtocolVersion().isTLS13()) { msg.setSessionId(new byte[0]); } else { if (chooser.getContext().getServerSessionId() == null) { msg.setSessionId(chooser.getClientSessionId()); } else { msg.setSessionId(chooser.getServerSessionId()); } } LOGGER.debug("SessionId: " + ArrayConverter.bytesToHexString(msg.getSessionId().getValue())); }