-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from RUB-NDS/supplementalDataHandshakeMessage…
…Support Added the SupplementalDataParser and its Unittests
- Loading branch information
Showing
9 changed files
with
306 additions
and
84 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
74 changes: 0 additions & 74 deletions
74
...s/tlsattacker/core/protocol/message/extension/SupplementalData/SupplementalDataEntry.java
This file was deleted.
Oops, something went wrong.
70 changes: 70 additions & 0 deletions
70
...ain/java/de/rub/nds/tlsattacker/core/protocol/message/suppData/SupplementalDataEntry.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...ava/de/rub/nds/tlsattacker/core/protocol/parser/suppData/SupplementalDataEntryParser.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
|
||
} |
74 changes: 74 additions & 0 deletions
74
...src/test/java/de/rub/nds/tlsattacker/core/protocol/parser/SupplementalDataParserTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|
||
} |
Oops, something went wrong.