Skip to content

Commit 3c7fee2

Browse files
authored
Merge pull request #399 from RUB-NDS/issue-339
Issue 339: Added SSL2ServerHelloParserTest
2 parents 95f2532 + 3559266 commit 3c7fee2

File tree

1 file changed

+103
-0
lines changed

1 file changed

+103
-0
lines changed
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
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.SSL2ServerHelloMessage;
15+
import static de.rub.nds.tlsattacker.core.protocol.parser.Parser.LOGGER;
16+
import java.util.Arrays;
17+
import java.util.Collection;
18+
import static org.junit.Assert.*;
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 SSL2ServerHelloParserTest {
25+
26+
/*
27+
* Constructing a SSL2 ServerHelloMessage
28+
*/
29+
@Parameterized.Parameters
30+
public static Collection<Object[]> generateData() {
31+
return Arrays
32+
.asList(new Object[][] { {
33+
ArrayConverter
34+
.hexStringToByteArray("820e020001000201ed00060010308201e930820152020106300d06092a864886f70d0101040500305b310b3009060355040613024155311330110603550408130a517565656e736c616e64311a3018060355040a13114372797074536f667420507479204c7464311b301906035504031312546573742043412028313032342062697429301e170d3030313031363232333130335a170d3033303131343232333130335a3063310b3009060355040613024155311330110603550408130a517565656e736c616e64311a3018060355040a13114372797074536f667420507479204c7464312330210603550403131a5365727665722074657374206365727420283531322062697429305c300d06092a864886f70d0101010500034b0030480241009fb3c3842795ff1231520f15ef4611c4ad80e6365b0fdd80d7618de0fc72450934fe556645434c68976afea8a0a5df5f78ffeed764b83f04cb6fff2afefeb9ed0203010001300d06092a864886f70d01010405000381810093d20ac541e65aa986f91187e4db45e2c595781a6c806d731fb46d44a3ba8688c858cd1c06356c446288dfe4f6646195ef4aa67f6571d76b8839f632bfac936769518c93ec485fc9b142f955d27e4ef4f2216b9057e6d7999e41ca80bf1a28a2ca5b504aed84e782c7d2cf369e6a67b988a7f38ad004f8e8c617e3c529bc17f10400800200807aa9b1cbab16a84bd99416f443587d0c"),
35+
ProtocolVersion.SSL2,
36+
0x820e,
37+
HandshakeMessageType.SERVER_HELLO,
38+
0 /* 0x00 */,
39+
1 /* 0x01 */,
40+
ProtocolVersion.SSL2.getValue(),
41+
493 /* 0x01ed */,
42+
6 /* 0x0006 */,
43+
16 /* 0x0010 */,
44+
ArrayConverter
45+
.hexStringToByteArray("308201e930820152020106300d06092a864886f70d0101040500305b310b3009060355040613024155311330110603550408130a517565656e736c616e64311a3018060355040a13114372797074536f667420507479204c7464311b301906035504031312546573742043412028313032342062697429301e170d3030313031363232333130335a170d3033303131343232333130335a3063310b3009060355040613024155311330110603550408130a517565656e736c616e64311a3018060355040a13114372797074536f667420507479204c7464312330210603550403131a5365727665722074657374206365727420283531322062697429305c300d06092a864886f70d0101010500034b0030480241009fb3c3842795ff1231520f15ef4611c4ad80e6365b0fdd80d7618de0fc72450934fe556645434c68976afea8a0a5df5f78ffeed764b83f04cb6fff2afefeb9ed0203010001300d06092a864886f70d01010405000381810093d20ac541e65aa986f91187e4db45e2c595781a6c806d731fb46d44a3ba8688c858cd1c06356c446288dfe4f6646195ef4aa67f6571d76b8839f632bfac936769518c93ec485fc9b142f955d27e4ef4f2216b9057e6d7999e41ca80bf1a28a2ca5b504aed84e782c7d2cf369e6a67b988a7f38ad004f8e8c617e3c529bc17f1"),
46+
ArrayConverter.hexStringToByteArray("040080020080"),
47+
ArrayConverter.hexStringToByteArray("7aa9b1cbab16a84bd99416f443587d0c") } });
48+
}
49+
50+
private final byte[] message;
51+
private final ProtocolVersion version;
52+
private final int messageLength;
53+
private final HandshakeMessageType type;
54+
private final int sessionIdHit;
55+
private final int certificateType;
56+
private final byte[] protocolVersion;
57+
private final int certificateLength;
58+
private final int cipherSuitesLength;
59+
private final int sessionIdLength;
60+
private final byte[] certificate;
61+
private final byte[] cipherSuites;
62+
private final byte[] sessionId;
63+
64+
public SSL2ServerHelloParserTest(byte[] message, ProtocolVersion version, int messageLength,
65+
HandshakeMessageType type, int sessionIdHit, int certificateType, byte[] protocolVersion,
66+
int certificateLength, int cipherSuitesLength, int sessionIdLength, byte[] certificate,
67+
byte[] cipherSuites, byte[] sessionId) {
68+
this.message = message;
69+
this.version = version;
70+
this.messageLength = messageLength;
71+
this.type = type;
72+
this.sessionIdHit = sessionIdHit;
73+
this.certificateType = certificateType;
74+
this.protocolVersion = protocolVersion;
75+
this.certificateLength = certificateLength;
76+
this.cipherSuitesLength = cipherSuitesLength;
77+
this.sessionIdLength = sessionIdLength;
78+
this.certificate = certificate;
79+
this.cipherSuites = cipherSuites;
80+
this.sessionId = sessionId;
81+
}
82+
83+
/**
84+
* Test of parse method, of class SSL2ServerHelloParser.
85+
*/
86+
@Test
87+
public void parseTest() {
88+
SSL2ServerHelloParser parser = new SSL2ServerHelloParser(message, 0, version);
89+
SSL2ServerHelloMessage msg = (SSL2ServerHelloMessage) parser.parse();
90+
assertArrayEquals(message, msg.getCompleteResultingMessage().getValue());
91+
assertTrue(msg.getMessageLength().getValue() == messageLength);
92+
assertTrue(msg.getType().getValue() == type.getValue());
93+
assertTrue(msg.getSessionIdHit().getValue() == sessionIdHit);
94+
assertTrue(msg.getCertificateType().getValue() == certificateType);
95+
assertArrayEquals(protocolVersion, msg.getProtocolVersion().getValue());
96+
assertTrue(msg.getCertificateLength().getValue() == certificateLength);
97+
assertTrue(msg.getCipherSuitesLength().getValue() == cipherSuitesLength);
98+
assertTrue(msg.getSessionIdLength().getValue() == sessionIdLength);
99+
assertArrayEquals(certificate, msg.getCertificate().getValue());
100+
assertArrayEquals(cipherSuites, msg.getCipherSuites().getValue());
101+
assertArrayEquals(sessionId, msg.getSessionId().getValue());
102+
}
103+
}

0 commit comments

Comments
 (0)