de.rub.nds.tlsbreaker.breakercommons.util.response.ResponseExtractor Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of breaker-commons Show documentation
Show all versions of breaker-commons Show documentation
A tool collection of various attacks on TLS based on TLS-Attacker
/**
* TLS-Breaker - A tool collection of various attacks on TLS based on TLS-Attacker
*
* Copyright 2021-2022 Ruhr University Bochum, Paderborn University, Hackmanit GmbH
*
* Licensed under Apache License, Version 2.0
* http://www.apache.org/licenses/LICENSE-2.0.txt
*/
package de.rub.nds.tlsbreaker.breakercommons.util.response;
import de.rub.nds.tlsattacker.core.constants.ProtocolMessageType;
import de.rub.nds.tlsattacker.core.protocol.ProtocolMessage;
import de.rub.nds.tlsattacker.core.record.AbstractRecord;
import de.rub.nds.tlsattacker.core.record.Record;
import de.rub.nds.tlsattacker.core.state.State;
import de.rub.nds.tlsattacker.core.workflow.action.ReceivingAction;
import de.rub.nds.tlsattacker.transport.socket.SocketState;
import de.rub.nds.tlsattacker.transport.tcp.ClientTcpTransportHandler;
import java.util.LinkedList;
import java.util.List;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
/**
*
*
*/
public class ResponseExtractor {
private static final Logger LOGGER = LogManager.getLogger();
/**
*
* @param state
* @param action
* @return
*/
public static ResponseFingerprint getFingerprint(State state, ReceivingAction action) {
List messageList = action.getReceivedMessages();
List recordList = action.getReceivedRecords();
SocketState socketState = extractSocketState(state);
return new ResponseFingerprint(messageList, recordList, socketState);
}
/**
*
* @param state
* @return
*/
public static ResponseFingerprint getFingerprint(State state) {
ReceivingAction action = state.getWorkflowTrace().getLastReceivingAction();
return getFingerprint(state, action);
}
private static SocketState extractSocketState(State state) {
if (state.getTlsContext().getTransportHandler() instanceof ClientTcpTransportHandler) {
SocketState socketState =
(((ClientTcpTransportHandler) (state.getTlsContext().getTransportHandler())).getSocketState());
return socketState;
} else {
return null;
}
}
private static List> extractRecordClasses(ReceivingAction action) {
List> classList = new LinkedList<>();
if (action.getReceivedRecords() != null) {
for (AbstractRecord record : action.getReceivedRecords()) {
classList.add((Class) record.getClass());
}
}
return classList;
}
private static List> extractMessageClasses(ReceivingAction action) {
List> classList = new LinkedList<>();
if (action.getReceivedMessages() != null) {
for (ProtocolMessage message : action.getReceivedMessages()) {
classList.add((Class) message.getClass());
}
}
return classList;
}
private static boolean didReceiveEncryptedAlert(ReceivingAction action) {
if (action.getReceivedRecords() != null) {
for (AbstractRecord abstractRecord : action.getReceivedRecords()) {
if (abstractRecord instanceof Record) {
Record record = (Record) abstractRecord;
if (record.getContentMessageType() == ProtocolMessageType.ALERT) {
if (record.getLength().getValue() > 6) {
return true;
}
}
}
}
}
return false;
}
private ResponseExtractor() {
}
}