Skip to content

Commit

Permalink
Merge pull request #442 from RUB-NDS/supplementalDataHandshakeMessage…
Browse files Browse the repository at this point in the history
…Support

Added the SupplementalDataParser and its Unittests
  • Loading branch information
ic0ns authored Jun 1, 2018
2 parents c8e0d0c + 46dfc01 commit 2d00998
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,21 @@ public class HandshakeByteLength {
*/
public static final int CLIENT_AUTHENTICATION_TYPE = 1;

/**
* Length of the Supplemental Data Field
*/
public static final int SUPPLEMENTAL_DATA_LENGTH = 3;

/**
* Length of the Supplemental Data Entry Type
*/
public static final int SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH = 2;

/**
* Length of the Supplemental Data Entry
*/
public static final int SUPPLEMENTAL_DATA_ENTRY_LENGTH = 2;

private HandshakeByteLength() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import de.rub.nds.tlsattacker.core.config.Config;
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
import de.rub.nds.tlsattacker.core.protocol.handler.SupplementalDataHandler;
import de.rub.nds.tlsattacker.core.protocol.message.extension.SupplementalData.SupplementalDataEntry;
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
import de.rub.nds.tlsattacker.core.state.TlsContext;
import java.util.LinkedList;
import java.util.List;
Expand Down Expand Up @@ -65,6 +65,11 @@ public void setSupplementalDataLength(ModifiableInteger supplementalDataLength)
this.supplementalDataLength = supplementalDataLength;
}

public void setSupplementalDataLength(int supplementalDataLength) {
this.supplementalDataLength = ModifiableVariableFactory.safelySetValue(this.supplementalDataLength,
supplementalDataLength);
}

public ModifiableByteArray getSupplementalDataBytes() {
return supplementalDataBytes;
}
Expand Down Expand Up @@ -96,10 +101,10 @@ public String toString() {
sb.append("\n SupplementalDataEntries:\n");
if (!entries.isEmpty()) {
for (SupplementalDataEntry entry : entries) {
sb.append("\n Supplemental Data Type: ").append(entry.getSupplementalDataType().getValue());
sb.append("\n Supplemental Data Length: ").append(entry.getSupplementalDataLength().getValue());
sb.append("\n Supplemental Data Type: ").append(entry.getSupplementalDataEntryType().getValue());
sb.append("\n Supplemental Data Length: ").append(entry.getSupplementalDataEntryLength().getValue());
sb.append("\n Supplemental Data : ").append(
ArrayConverter.bytesToHexString(entry.getSupplementalData().getValue()));
ArrayConverter.bytesToHexString(entry.getSupplementalDataEntry().getValue()));
}
} else {
sb.append("null");
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/**
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.tlsattacker.core.protocol.message.suppData;

import de.rub.nds.modifiablevariable.ModifiableVariableFactory;
import de.rub.nds.modifiablevariable.ModifiableVariableProperty;
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
import de.rub.nds.modifiablevariable.integer.ModifiableInteger;

public class SupplementalDataEntry {

@ModifiableVariableProperty
private ModifiableByteArray supplementalDataEntry;

@ModifiableVariableProperty
private ModifiableInteger supplementalDataEntryType;

@ModifiableVariableProperty(type = ModifiableVariableProperty.Type.LENGTH)
private ModifiableInteger supplementalDataEntryLength;

public SupplementalDataEntry() {

}

public ModifiableByteArray getSupplementalDataEntry() {
return this.supplementalDataEntry;
}

public void setSupplementalDataEntry(ModifiableByteArray supplementalDataEntry) {
this.supplementalDataEntry = supplementalDataEntry;
}

public void setSupplementalDataEntry(byte[] supplementalDataEntry) {
this.supplementalDataEntry = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntry,
supplementalDataEntry);
}

public ModifiableInteger getSupplementalDataEntryType() {
return supplementalDataEntryType;
}

public void setSupplementalDataEntryType(ModifiableInteger supplementalDataEntryType) {
this.supplementalDataEntryType = supplementalDataEntryType;
}

public void setSupplementalDataEntryType(int supplementalDataEntryType) {
this.supplementalDataEntryType = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntryType,
supplementalDataEntryType);
}

public ModifiableInteger getSupplementalDataEntryLength() {
return supplementalDataEntryLength;
}

public void setSupplementalDataEntryLength(ModifiableInteger supplementalDataEntryLength) {
this.supplementalDataEntryLength = supplementalDataEntryLength;
}

public void setSupplementalDataEntryLength(int supplementalDataEntryLength) {
this.supplementalDataEntryLength = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntryLength,
supplementalDataEntryLength);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.tlsattacker.core.protocol.message.extension.SupplementalData;
package de.rub.nds.tlsattacker.core.protocol.message.suppData;

import java.util.HashMap;
import java.util.Map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
*/
package de.rub.nds.tlsattacker.core.protocol.parser;

import de.rub.nds.modifiablevariable.util.ArrayConverter;
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
import de.rub.nds.tlsattacker.core.exceptions.ParserException;
import de.rub.nds.tlsattacker.core.protocol.message.SupplementalDataMessage;
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
import de.rub.nds.tlsattacker.core.protocol.parser.suppData.SupplementalDataEntryParser;
import java.util.LinkedList;
import java.util.List;

/**
* TODO
*/
public class SupplementalDataParser extends HandshakeMessageParser<SupplementalDataMessage> {

/**
Expand All @@ -36,11 +40,39 @@ public SupplementalDataParser(int pointer, byte[] array, ProtocolVersion version
@Override
protected void parseHandshakeMessageContent(SupplementalDataMessage msg) {
LOGGER.debug("Parsing SupplementalDataMessage");
throw new UnsupportedOperationException("Not Implemented");
parseSupplementalDataLength(msg);
parseSupplementalDataBytes(msg);
parseSupplementalDataEntries(msg);
}

@Override
protected SupplementalDataMessage createHandshakeMessage() {
throw new UnsupportedOperationException("Not Implemented");
return new SupplementalDataMessage();
}

private void parseSupplementalDataLength(SupplementalDataMessage msg) {
msg.setSupplementalDataLength(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_LENGTH));
LOGGER.debug("SupplementalDataLength: " + msg.getSupplementalDataLength().getValue());
}

private void parseSupplementalDataBytes(SupplementalDataMessage msg) {
msg.setSupplementalDataBytes(parseByteArrayField(msg.getSupplementalDataLength().getValue()));
LOGGER.debug("SupplementalDataBytes: "
+ ArrayConverter.bytesToHexString(msg.getSupplementalDataBytes().getValue()));
}

private void parseSupplementalDataEntries(SupplementalDataMessage msg) {
int pointer = 0;
List<SupplementalDataEntry> entryList = new LinkedList<>();
while (pointer < msg.getSupplementalDataLength().getValue()) {
SupplementalDataEntryParser parser = new SupplementalDataEntryParser(pointer, msg
.getSupplementalDataBytes().getValue());
entryList.add(parser.parse());
if (pointer == parser.getPointer()) {
throw new ParserException("Ran into infinite Loop while parsing SupplementalDataEntries");
}
pointer = parser.getPointer();
}
msg.setEntries(entryList);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.tlsattacker.core.protocol.parser.suppData;

import de.rub.nds.modifiablevariable.util.ArrayConverter;
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
import de.rub.nds.tlsattacker.core.protocol.parser.Parser;

public class SupplementalDataEntryParser extends Parser<SupplementalDataEntry> {

public SupplementalDataEntryParser(int startposition, byte[] array) {
super(startposition, array);
}

@Override
public SupplementalDataEntry parse() {
LOGGER.debug("Parsing SupplementalDataEntry");
SupplementalDataEntry entry = new SupplementalDataEntry();
parseSupplementalDataEntryType(entry);
parseSupplementalDataEntryLength(entry);
parseSupplementalDataEntry(entry);
return entry;
}

private void parseSupplementalDataEntryType(SupplementalDataEntry entry) {
entry.setSupplementalDataEntryType(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH));
LOGGER.debug("SupplementalDataEntryType: " + entry.getSupplementalDataEntryType().getValue());
}

private void parseSupplementalDataEntryLength(SupplementalDataEntry entry) {
entry.setSupplementalDataEntryLength(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_ENTRY_LENGTH));
LOGGER.debug("SupplementalDataEntryLength: " + entry.getSupplementalDataEntryLength().getValue());
}

private void parseSupplementalDataEntry(SupplementalDataEntry entry) {
entry.setSupplementalDataEntry(parseByteArrayField(entry.getSupplementalDataEntryLength().getValue()));
LOGGER.debug("SupplementalDataEntry: "
+ ArrayConverter.bytesToHexString(entry.getSupplementalDataEntry().getValue()));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
*
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
*
* Licensed under Apache License 2.0
* http://www.apache.org/licenses/LICENSE-2.0
*/
package de.rub.nds.tlsattacker.core.protocol.parser;

import de.rub.nds.modifiablevariable.util.ArrayConverter;
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
import de.rub.nds.tlsattacker.core.protocol.message.SupplementalDataMessage;
import java.util.Arrays;
import java.util.Collection;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

@RunWith(Parameterized.class)
public class SupplementalDataParserTest {

@Parameterized.Parameters
public static Collection<Object[]> generateData() {
return Arrays
.asList(new Object[][] {
{ ArrayConverter.hexStringToByteArray("1700001100000e4002000a0008010005aaaaaaaaaa"),
HandshakeMessageType.SUPPLEMENTAL_DATA, 17, 14,
ArrayConverter.hexStringToByteArray("4002000a0008010005aaaaaaaaaa"),
ProtocolVersion.TLS11 },
{
ArrayConverter
.hexStringToByteArray("1700001F00001c4002000a0008010005aaaaaaaaaa4002000a0008010005aaaaaaaaaa"),
HandshakeMessageType.SUPPLEMENTAL_DATA,
31,
28,
ArrayConverter
.hexStringToByteArray("4002000a0008010005aaaaaaaaaa4002000a0008010005aaaaaaaaaa"),
ProtocolVersion.TLS11 } });
}

private byte[] message;
private HandshakeMessageType type;
private int length;

private int supplementalDataLength;
private byte[] supplementalDataBytes;
private ProtocolVersion version;

public SupplementalDataParserTest(byte[] message, HandshakeMessageType type, int length,
int supplementalDataLength, byte[] supplementalDataBytes, ProtocolVersion version) {
this.message = message;
this.type = type;
this.length = length;
this.supplementalDataLength = supplementalDataLength;
this.supplementalDataBytes = supplementalDataBytes;
this.version = version;
}

@Test
public void testParse() {
SupplementalDataParser parser = new SupplementalDataParser(0, message, version);
SupplementalDataMessage suppDataMessage = parser.parse();
assertArrayEquals(suppDataMessage.getCompleteResultingMessage().getValue(), message);
assertTrue(suppDataMessage.getType().getValue() == type.getValue());
assertTrue(suppDataMessage.getLength().getValue() == length);
assertTrue(suppDataMessage.getSupplementalDataLength().getValue() == supplementalDataLength);
assertArrayEquals(suppDataMessage.getSupplementalDataBytes().getValue(), supplementalDataBytes);
}

}
Loading

0 comments on commit 2d00998

Please sign in to comment.