private byte[] convertCompressions(List<CompressionMethod> compressionList) { ByteArrayOutputStream stream = new ByteArrayOutputStream(); for (CompressionMethod compression : compressionList) { try { stream.write(compression.getArrayValue()); } catch (IOException ex) { throw new PreparationException( "Could not prepare ClientHelloMessage. Failed to write Ciphersuites into message", ex); } } return stream.toByteArray(); }
private void adjustSelectedCompression(ServerHelloMessage message) { CompressionMethod method = null; if (message.getSelectedCompressionMethod() != null) { method = CompressionMethod.getCompressionMethod(message.getSelectedCompressionMethod().getValue()); } if (method != null) { tlsContext.setSelectedCompressionMethod(method); LOGGER.debug("Set SelectedCompressionMethod in Context to " + method.name()); } else { LOGGER.warn("Not adjusting CompressionMethod - Method is null!"); } }
@Override public CompressionMethod convert(String value) { try { return CompressionMethod.valueOf(value); } catch (IllegalArgumentException e) { throw new ParameterException("Value " + value + " cannot be converted to a compression method. " + "Available values are: " + Arrays.toString(CompressionMethod.values())); } } }
public static List<CompressionMethod> getCompressionMethods(byte[] values) { // TODO no stable enough, also add unit tests List<CompressionMethod> compressionMethods = new LinkedList<>(); for (int i = 0; i < values.length; i++) { compressionMethods.add(getCompressionMethod(values[i])); } return compressionMethods; }
private void prepareCompressionMethod() { if (chooser.getConfig().isEnforceSettings()) { msg.setSelectedCompressionMethod(chooser.getConfig().getDefaultSelectedCompressionMethod().getValue()); } else { CompressionMethod selectedCompressionMethod = null; for (CompressionMethod method : chooser.getConfig().getDefaultServerSupportedCompressionMethods()) { if (chooser.getClientSupportedCompressions().contains(method)) { selectedCompressionMethod = method; break; } } if (selectedCompressionMethod == null) { throw new WorkflowExecutionException("No Compression in common"); } msg.setSelectedCompressionMethod(selectedCompressionMethod.getValue()); } LOGGER.debug("SelectedCompressionMethod: " + msg.getSelectedCompressionMethod().getValue()); }
@Override public void execute(State state) throws WorkflowExecutionException { TlsContext tlsContext = state.getTlsContext(getConnectionAlias()); if (isExecuted()) { throw new WorkflowExecutionException("Action already executed!"); } oldValue = tlsContext.getSelectedCompressionMethod(); tlsContext.setSelectedCompressionMethod(newValue); LOGGER.info("Changed selected CompressionMethod from " + (oldValue == null ? "null" : oldValue.name()) + " to " + newValue.name()); setExecuted(true); }
private List<CompressionMethod> convertCompressionMethods(byte[] bytesToConvert) { List<CompressionMethod> list = new LinkedList<>(); for (byte b : bytesToConvert) { CompressionMethod method = CompressionMethod.getCompressionMethod(b); if (method == null) { LOGGER.warn("Could not convert " + b + " into a CompressionMethod"); } else { list.add(method); } } return list; }
/** * Generates the StatePlaintext for the SessionTicket, mayby put this as * static function in the StatePlaintext class for better testing/debugging * * @return A struct with Stateinformation defined in * https://tools.ietf.org/html/rfc5077#section-4 */ private StatePlaintext generateStatePlaintext() { StatePlaintext plainstate = new StatePlaintext(); plainstate.setCipherSuite(chooser.getSelectedCipherSuite().getValue()); plainstate.setCompressionMethod(chooser.getSelectedCompressionMethod().getValue()); plainstate.setMasterSecret(chooser.getMasterSecret()); plainstate.setProtocolVersion(chooser.getSelectedProtocolVersion().getValue()); long timestamp = TimeHelper.getTime() / 1000; plainstate.setTimestamp(timestamp); switch (chooser.getConfig().getClientAuthenticationType()) { case ANONYMOUS: plainstate.setClientAuthenticationType(ClientAuthenticationType.ANONYMOUS.getValue()); plainstate.setClientAuthenticationData(new byte[0]); plainstate.setClientAuthenticationDataLength(0); break; case CERTIFICATE_BASED: throw new UnsupportedOperationException("Certificate based ClientAuthentication is not supported"); case PSK: throw new UnsupportedOperationException("PSK ClientAuthentication is not supported"); default: throw new UnsupportedOperationException("Unknown ClientAuthenticationType"); } return plainstate; }
private void writeCompressionMethod(StatePlaintext statePlaintext) { appendByte(statePlaintext.getCompressionMethod().getValue()); LOGGER.debug("CompressionMethod: " + CompressionMethod.getCompressionMethod(statePlaintext.getCompressionMethod().getValue()).name()); }
if (getProtocolVersion() != null && getProtocolVersion().getValue() != null) { if (!ProtocolVersion.getProtocolVersion(getProtocolVersion().getValue()).isTLS13()) { sb.append(CompressionMethod.getCompressionMethod(selectedCompressionMethod.getValue())); } else { sb.append("null");
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())); }