author | dbuck |
Tue, 18 Aug 2015 04:29:28 -0700 | |
changeset 32417 | 6859107fc6c3 |
parent 31057 | babdeee3c007 |
permissions | -rw-r--r-- |
31057
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
1 |
/* |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
4 |
* |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
8 |
* |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
13 |
* accompanied this code). |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
14 |
* |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
18 |
* |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
21 |
* questions. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
22 |
*/ |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
23 |
|
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
24 |
import javax.net.ssl.SSLContext; |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
25 |
import javax.net.ssl.SSLEngine; |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
26 |
import javax.net.ssl.SSLException; |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
27 |
|
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
28 |
/** |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
29 |
* Testing SSLEngines handshake using each of the supported cipher suites with |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
30 |
* different maximum fragment length. Testing of MFLN extension. |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
31 |
*/ |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
32 |
public class MFLNTest extends SSLEngineTestCase { |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
33 |
|
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
34 |
public static void main(String[] args) { |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
35 |
setUpAndStartKDCIfNeeded(); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
36 |
System.setProperty("jsse.enableMFLNExtension", "true"); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
37 |
for (int mfl = 4096; mfl >= 256; mfl /= 2) { |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
38 |
System.out.println("==============================================" |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
39 |
+ "=============="); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
40 |
System.out.printf("Testsing DTLS handshake with MFL = %d%n", mfl); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
41 |
MFLNTest test = new MFLNTest(mfl); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
42 |
test.runTests(); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
43 |
} |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
44 |
} |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
45 |
|
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
46 |
protected MFLNTest(int maxPacketSize) { |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
47 |
super(maxPacketSize); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
48 |
} |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
49 |
|
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
50 |
@Override |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
51 |
protected void testOneCipher(String cipher) throws SSLException { |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
52 |
SSLContext context = getContext(); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
53 |
int maxPacketSize = getMaxPacketSize(); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
54 |
boolean useSNI = !TEST_MODE.equals("norm"); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
55 |
SSLEngine clientEngine = getClientSSLEngine(context, useSNI); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
56 |
SSLEngine serverEngine = getServerSSLEngine(context, useSNI); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
57 |
clientEngine.setEnabledCipherSuites(new String[]{cipher}); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
58 |
serverEngine.setEnabledCipherSuites(new String[]{cipher}); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
59 |
serverEngine.setNeedClientAuth(!cipher.contains("anon")); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
60 |
doHandshake(clientEngine, serverEngine, maxPacketSize, |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
61 |
HandshakeMode.INITIAL_HANDSHAKE); |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
62 |
} |
babdeee3c007
8072515: Test Task: Develop new tests for JEP 219: Datagram Transport Layer Security (DTLS)
kshefov
parents:
diff
changeset
|
63 |
} |