Skip to content

Commit 2d00998

Browse files
authored
Merge pull request #442 from RUB-NDS/supplementalDataHandshakeMessageSupport
Added the SupplementalDataParser and its Unittests
2 parents c8e0d0c + 46dfc01 commit 2d00998

File tree

9 files changed

+306
-84
lines changed

9 files changed

+306
-84
lines changed

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/constants/HandshakeByteLength.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,21 @@ public class HandshakeByteLength {
216216
*/
217217
public static final int CLIENT_AUTHENTICATION_TYPE = 1;
218218

219+
/**
220+
* Length of the Supplemental Data Field
221+
*/
222+
public static final int SUPPLEMENTAL_DATA_LENGTH = 3;
223+
224+
/**
225+
* Length of the Supplemental Data Entry Type
226+
*/
227+
public static final int SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH = 2;
228+
229+
/**
230+
* Length of the Supplemental Data Entry
231+
*/
232+
public static final int SUPPLEMENTAL_DATA_ENTRY_LENGTH = 2;
233+
219234
private HandshakeByteLength() {
220235
}
221236
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/message/SupplementalDataMessage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import de.rub.nds.tlsattacker.core.config.Config;
1818
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
1919
import de.rub.nds.tlsattacker.core.protocol.handler.SupplementalDataHandler;
20-
import de.rub.nds.tlsattacker.core.protocol.message.extension.SupplementalData.SupplementalDataEntry;
20+
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
2121
import de.rub.nds.tlsattacker.core.state.TlsContext;
2222
import java.util.LinkedList;
2323
import java.util.List;
@@ -65,6 +65,11 @@ public void setSupplementalDataLength(ModifiableInteger supplementalDataLength)
6565
this.supplementalDataLength = supplementalDataLength;
6666
}
6767

68+
public void setSupplementalDataLength(int supplementalDataLength) {
69+
this.supplementalDataLength = ModifiableVariableFactory.safelySetValue(this.supplementalDataLength,
70+
supplementalDataLength);
71+
}
72+
6873
public ModifiableByteArray getSupplementalDataBytes() {
6974
return supplementalDataBytes;
7075
}
@@ -96,10 +101,10 @@ public String toString() {
96101
sb.append("\n SupplementalDataEntries:\n");
97102
if (!entries.isEmpty()) {
98103
for (SupplementalDataEntry entry : entries) {
99-
sb.append("\n Supplemental Data Type: ").append(entry.getSupplementalDataType().getValue());
100-
sb.append("\n Supplemental Data Length: ").append(entry.getSupplementalDataLength().getValue());
104+
sb.append("\n Supplemental Data Type: ").append(entry.getSupplementalDataEntryType().getValue());
105+
sb.append("\n Supplemental Data Length: ").append(entry.getSupplementalDataEntryLength().getValue());
101106
sb.append("\n Supplemental Data : ").append(
102-
ArrayConverter.bytesToHexString(entry.getSupplementalData().getValue()));
107+
ArrayConverter.bytesToHexString(entry.getSupplementalDataEntry().getValue()));
103108
}
104109
} else {
105110
sb.append("null");

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/message/extension/SupplementalData/SupplementalDataEntry.java

Lines changed: 0 additions & 74 deletions
This file was deleted.
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.tlsattacker.core.protocol.message.suppData;
10+
11+
import de.rub.nds.modifiablevariable.ModifiableVariableFactory;
12+
import de.rub.nds.modifiablevariable.ModifiableVariableProperty;
13+
import de.rub.nds.modifiablevariable.bytearray.ModifiableByteArray;
14+
import de.rub.nds.modifiablevariable.integer.ModifiableInteger;
15+
16+
public class SupplementalDataEntry {
17+
18+
@ModifiableVariableProperty
19+
private ModifiableByteArray supplementalDataEntry;
20+
21+
@ModifiableVariableProperty
22+
private ModifiableInteger supplementalDataEntryType;
23+
24+
@ModifiableVariableProperty(type = ModifiableVariableProperty.Type.LENGTH)
25+
private ModifiableInteger supplementalDataEntryLength;
26+
27+
public SupplementalDataEntry() {
28+
29+
}
30+
31+
public ModifiableByteArray getSupplementalDataEntry() {
32+
return this.supplementalDataEntry;
33+
}
34+
35+
public void setSupplementalDataEntry(ModifiableByteArray supplementalDataEntry) {
36+
this.supplementalDataEntry = supplementalDataEntry;
37+
}
38+
39+
public void setSupplementalDataEntry(byte[] supplementalDataEntry) {
40+
this.supplementalDataEntry = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntry,
41+
supplementalDataEntry);
42+
}
43+
44+
public ModifiableInteger getSupplementalDataEntryType() {
45+
return supplementalDataEntryType;
46+
}
47+
48+
public void setSupplementalDataEntryType(ModifiableInteger supplementalDataEntryType) {
49+
this.supplementalDataEntryType = supplementalDataEntryType;
50+
}
51+
52+
public void setSupplementalDataEntryType(int supplementalDataEntryType) {
53+
this.supplementalDataEntryType = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntryType,
54+
supplementalDataEntryType);
55+
}
56+
57+
public ModifiableInteger getSupplementalDataEntryLength() {
58+
return supplementalDataEntryLength;
59+
}
60+
61+
public void setSupplementalDataEntryLength(ModifiableInteger supplementalDataEntryLength) {
62+
this.supplementalDataEntryLength = supplementalDataEntryLength;
63+
}
64+
65+
public void setSupplementalDataEntryLength(int supplementalDataEntryLength) {
66+
this.supplementalDataEntryLength = ModifiableVariableFactory.safelySetValue(this.supplementalDataEntryLength,
67+
supplementalDataEntryLength);
68+
}
69+
70+
}

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/message/extension/SupplementalData/SupplementalDataType.java renamed to TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/message/suppData/SupplementalDataType.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Licensed under Apache License 2.0
77
* http://www.apache.org/licenses/LICENSE-2.0
88
*/
9-
package de.rub.nds.tlsattacker.core.protocol.message.extension.SupplementalData;
9+
package de.rub.nds.tlsattacker.core.protocol.message.suppData;
1010

1111
import java.util.HashMap;
1212
import java.util.Map;

TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/protocol/parser/SupplementalDataParser.java

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
*/
99
package de.rub.nds.tlsattacker.core.protocol.parser;
1010

11+
import de.rub.nds.modifiablevariable.util.ArrayConverter;
1112
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
1213
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
14+
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
15+
import de.rub.nds.tlsattacker.core.exceptions.ParserException;
1316
import de.rub.nds.tlsattacker.core.protocol.message.SupplementalDataMessage;
17+
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
18+
import de.rub.nds.tlsattacker.core.protocol.parser.suppData.SupplementalDataEntryParser;
19+
import java.util.LinkedList;
20+
import java.util.List;
1421

15-
/**
16-
* TODO
17-
*/
1822
public class SupplementalDataParser extends HandshakeMessageParser<SupplementalDataMessage> {
1923

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

4248
@Override
4349
protected SupplementalDataMessage createHandshakeMessage() {
44-
throw new UnsupportedOperationException("Not Implemented");
50+
return new SupplementalDataMessage();
51+
}
52+
53+
private void parseSupplementalDataLength(SupplementalDataMessage msg) {
54+
msg.setSupplementalDataLength(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_LENGTH));
55+
LOGGER.debug("SupplementalDataLength: " + msg.getSupplementalDataLength().getValue());
56+
}
57+
58+
private void parseSupplementalDataBytes(SupplementalDataMessage msg) {
59+
msg.setSupplementalDataBytes(parseByteArrayField(msg.getSupplementalDataLength().getValue()));
60+
LOGGER.debug("SupplementalDataBytes: "
61+
+ ArrayConverter.bytesToHexString(msg.getSupplementalDataBytes().getValue()));
62+
}
63+
64+
private void parseSupplementalDataEntries(SupplementalDataMessage msg) {
65+
int pointer = 0;
66+
List<SupplementalDataEntry> entryList = new LinkedList<>();
67+
while (pointer < msg.getSupplementalDataLength().getValue()) {
68+
SupplementalDataEntryParser parser = new SupplementalDataEntryParser(pointer, msg
69+
.getSupplementalDataBytes().getValue());
70+
entryList.add(parser.parse());
71+
if (pointer == parser.getPointer()) {
72+
throw new ParserException("Ran into infinite Loop while parsing SupplementalDataEntries");
73+
}
74+
pointer = parser.getPointer();
75+
}
76+
msg.setEntries(entryList);
4577
}
4678
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.tlsattacker.core.protocol.parser.suppData;
10+
11+
import de.rub.nds.modifiablevariable.util.ArrayConverter;
12+
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
13+
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
14+
import de.rub.nds.tlsattacker.core.protocol.parser.Parser;
15+
16+
public class SupplementalDataEntryParser extends Parser<SupplementalDataEntry> {
17+
18+
public SupplementalDataEntryParser(int startposition, byte[] array) {
19+
super(startposition, array);
20+
}
21+
22+
@Override
23+
public SupplementalDataEntry parse() {
24+
LOGGER.debug("Parsing SupplementalDataEntry");
25+
SupplementalDataEntry entry = new SupplementalDataEntry();
26+
parseSupplementalDataEntryType(entry);
27+
parseSupplementalDataEntryLength(entry);
28+
parseSupplementalDataEntry(entry);
29+
return entry;
30+
}
31+
32+
private void parseSupplementalDataEntryType(SupplementalDataEntry entry) {
33+
entry.setSupplementalDataEntryType(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH));
34+
LOGGER.debug("SupplementalDataEntryType: " + entry.getSupplementalDataEntryType().getValue());
35+
}
36+
37+
private void parseSupplementalDataEntryLength(SupplementalDataEntry entry) {
38+
entry.setSupplementalDataEntryLength(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_ENTRY_LENGTH));
39+
LOGGER.debug("SupplementalDataEntryLength: " + entry.getSupplementalDataEntryLength().getValue());
40+
}
41+
42+
private void parseSupplementalDataEntry(SupplementalDataEntry entry) {
43+
entry.setSupplementalDataEntry(parseByteArrayField(entry.getSupplementalDataEntryLength().getValue()));
44+
LOGGER.debug("SupplementalDataEntry: "
45+
+ ArrayConverter.bytesToHexString(entry.getSupplementalDataEntry().getValue()));
46+
}
47+
48+
}
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/**
2+
* TLS-Attacker - A Modular Penetration Testing Framework for TLS
3+
*
4+
* Copyright 2014-2017 Ruhr University Bochum / Hackmanit GmbH
5+
*
6+
* Licensed under Apache License 2.0
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*/
9+
package de.rub.nds.tlsattacker.core.protocol.parser;
10+
11+
import de.rub.nds.modifiablevariable.util.ArrayConverter;
12+
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
13+
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
14+
import de.rub.nds.tlsattacker.core.protocol.message.SupplementalDataMessage;
15+
import java.util.Arrays;
16+
import java.util.Collection;
17+
import static org.junit.Assert.assertArrayEquals;
18+
import static org.junit.Assert.assertTrue;
19+
import org.junit.Test;
20+
import org.junit.runner.RunWith;
21+
import org.junit.runners.Parameterized;
22+
23+
@RunWith(Parameterized.class)
24+
public class SupplementalDataParserTest {
25+
26+
@Parameterized.Parameters
27+
public static Collection<Object[]> generateData() {
28+
return Arrays
29+
.asList(new Object[][] {
30+
{ ArrayConverter.hexStringToByteArray("1700001100000e4002000a0008010005aaaaaaaaaa"),
31+
HandshakeMessageType.SUPPLEMENTAL_DATA, 17, 14,
32+
ArrayConverter.hexStringToByteArray("4002000a0008010005aaaaaaaaaa"),
33+
ProtocolVersion.TLS11 },
34+
{
35+
ArrayConverter
36+
.hexStringToByteArray("1700001F00001c4002000a0008010005aaaaaaaaaa4002000a0008010005aaaaaaaaaa"),
37+
HandshakeMessageType.SUPPLEMENTAL_DATA,
38+
31,
39+
28,
40+
ArrayConverter
41+
.hexStringToByteArray("4002000a0008010005aaaaaaaaaa4002000a0008010005aaaaaaaaaa"),
42+
ProtocolVersion.TLS11 } });
43+
}
44+
45+
private byte[] message;
46+
private HandshakeMessageType type;
47+
private int length;
48+
49+
private int supplementalDataLength;
50+
private byte[] supplementalDataBytes;
51+
private ProtocolVersion version;
52+
53+
public SupplementalDataParserTest(byte[] message, HandshakeMessageType type, int length,
54+
int supplementalDataLength, byte[] supplementalDataBytes, ProtocolVersion version) {
55+
this.message = message;
56+
this.type = type;
57+
this.length = length;
58+
this.supplementalDataLength = supplementalDataLength;
59+
this.supplementalDataBytes = supplementalDataBytes;
60+
this.version = version;
61+
}
62+
63+
@Test
64+
public void testParse() {
65+
SupplementalDataParser parser = new SupplementalDataParser(0, message, version);
66+
SupplementalDataMessage suppDataMessage = parser.parse();
67+
assertArrayEquals(suppDataMessage.getCompleteResultingMessage().getValue(), message);
68+
assertTrue(suppDataMessage.getType().getValue() == type.getValue());
69+
assertTrue(suppDataMessage.getLength().getValue() == length);
70+
assertTrue(suppDataMessage.getSupplementalDataLength().getValue() == supplementalDataLength);
71+
assertArrayEquals(suppDataMessage.getSupplementalDataBytes().getValue(), supplementalDataBytes);
72+
}
73+
74+
}

0 commit comments

Comments
 (0)