Skip to content

Commit e43e041

Browse files
author
jan
committed
Added SupplementalDataEntryParser and SupplementalDataParser
Added Constants for these two Parsers
1 parent 43ed99e commit e43e041

File tree

4 files changed

+64
-11
lines changed

4 files changed

+64
-11
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ public class ExtensionByteLength {
235235
public static final int CERTIFICATE_STATUS_REQUEST_V2_LIST = 2;
236236

237237
public static final int RENEGOTIATION_INFO = 1;
238-
238+
239239
/**
240240
* Length of the Supplemental Data Entry Type
241241
*/
242242
public static final int SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH = 2;
243-
243+
244244
/**
245245
* Length of the Supplemental Data Entry
246246
*/

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ public class HandshakeByteLength {
215215
* length of the ClientAuthenticationType in the TLS byte arrays
216216
*/
217217
public static final int CLIENT_AUTHENTICATION_TYPE = 1;
218-
218+
219219
/**
220220
* Length of the Supplemental Data Field
221221
*/

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

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
import de.rub.nds.tlsattacker.core.constants.HandshakeMessageType;
1313
import de.rub.nds.tlsattacker.core.constants.ProtocolVersion;
1414
import de.rub.nds.tlsattacker.core.constants.HandshakeByteLength;
15+
import de.rub.nds.tlsattacker.core.exceptions.ParserException;
1516
import de.rub.nds.tlsattacker.core.protocol.message.SupplementalDataMessage;
16-
import de.rub.nds.tlsattacker.core.protocol.message.extension.SupplementalData.SupplementalDataEntry;
17-
import de.rub.nds.tlsattacker.core.protocol.parser.extension.SupplementalDataEntryParser;
17+
import de.rub.nds.tlsattacker.core.protocol.message.suppData.SupplementalDataEntry;
18+
import de.rub.nds.tlsattacker.core.protocol.parser.suppData.SupplementalDataEntryParser;
1819
import java.util.LinkedList;
1920
import java.util.List;
2021

@@ -44,27 +45,33 @@ protected void parseHandshakeMessageContent(SupplementalDataMessage msg) {
4445
LOGGER.debug("Parsing SupplementalDataMessage");
4546
parseSupplementalDataLength(msg);
4647
parseSupplementalDataBytes(msg);
48+
parseSupplementalDataEntries(msg);
4749
}
4850

4951
@Override
5052
protected SupplementalDataMessage createHandshakeMessage() {
5153
return new SupplementalDataMessage();
5254
}
53-
55+
5456
private void parseSupplementalDataLength(SupplementalDataMessage msg) {
5557
msg.setSupplementalDataLength(parseIntField(HandshakeByteLength.SUPPLEMENTAL_DATA_LENGTH));
5658
LOGGER.debug("SupplementalDataLength: " + msg.getSupplementalDataLength().getValue());
5759
}
5860

5961
private void parseSupplementalDataBytes(SupplementalDataMessage msg) {
60-
byte[] supplementalDataBytes = parseByteArrayField(msg.getSupplementalDataLength().getValue());
61-
msg.setSupplementalDataBytes(supplementalDataBytes);
62+
msg.setSupplementalDataBytes(parseByteArrayField(msg.getSupplementalDataLength().getValue()));
6263
LOGGER.debug("SupplementalDataBytes: " + ArrayConverter.bytesToHexString(msg.getSupplementalDataBytes().getValue()));
63-
List<SupplementalDataEntry> entryList = new LinkedList<>();
64+
}
65+
66+
private void parseSupplementalDataEntries(SupplementalDataMessage msg) {
6467
int pointer = 0;
65-
while (pointer < supplementalDataBytes.length) {
66-
SupplementalDataEntryParser parser = new SupplementalDataEntryParser(pointer, supplementalDataBytes);
68+
List<SupplementalDataEntry> entryList = new LinkedList<>();
69+
while (pointer < msg.getSupplementalDataLength().getValue()) {
70+
SupplementalDataEntryParser parser = new SupplementalDataEntryParser(pointer, msg.getSupplementalDataBytes().getValue());
6771
entryList.add(parser.parse());
72+
if (pointer == parser.getPointer()) {
73+
throw new ParserException("Ran into infinite Loop while parsing SupplementalDataEntries");
74+
}
6875
pointer = parser.getPointer();
6976
}
7077
msg.setEntries(entryList);
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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.ExtensionByteLength;
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+
return entry;
29+
}
30+
31+
private void parseSupplementalDataEntryType(SupplementalDataEntry entry) {
32+
entry.setSupplementalDataEntryType(parseIntField(ExtensionByteLength.SUPPLEMENTAL_DATA_ENTRY_TYPE_LENGTH));
33+
LOGGER.debug("SupplementalDataEntryType: " + entry.getSupplementalDataEntryType().getValue());
34+
}
35+
36+
private void parseSupplementalDataEntryLength(SupplementalDataEntry entry) {
37+
entry.setSupplementalDataEntryLength(parseIntField(ExtensionByteLength.SUPPLEMENTAL_DATA_ENTRY_LENGTH));
38+
LOGGER.debug("SupplementalDataEntryLength: " + entry.getSupplementalDataEntryLength().getValue());
39+
}
40+
41+
private void parseSupplementalDataEntryBytes(SupplementalDataEntry entry) {
42+
entry.setSupplementalDataEntry(parseByteArrayField(entry.getSupplementalDataEntryLength().getValue()));
43+
LOGGER.debug("SupplementalDataEntry: " + ArrayConverter.bytesToHexString(entry.getSupplementalDataEntry().getValue()));
44+
}
45+
46+
}

0 commit comments

Comments
 (0)