author | ssahoo |
Wed, 27 Nov 2019 22:11:08 -0800 | |
changeset 59302 | 24e8cdead5f3 |
parent 47216 | 71c04702a3d5 |
permissions | -rw-r--r-- |
22068 | 1 |
/* |
59302
24e8cdead5f3
8234725: sun/security/ssl/SSLContextImpl tests support TLSv1.3
ssahoo
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2013, 2019, Oracle and/or its affiliates. All rights reserved. |
22068 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
*/ |
|
23 |
||
24 |
// SunJSSE does not support dynamic system properties, no way to re-use |
|
25 |
// system properties in samevm/agentvm mode. |
|
26 |
||
27 |
/* |
|
28 |
* @test |
|
59302
24e8cdead5f3
8234725: sun/security/ssl/SSLContextImpl tests support TLSv1.3
ssahoo
parents:
47216
diff
changeset
|
29 |
* @bug 7093640 8234725 |
22068 | 30 |
* @summary Enable TLS 1.1 and TLS 1.2 by default in client side of SunJSSE |
31 |
* @run main/othervm -Djdk.tls.client.protocols="XSLv3,TLSv1" |
|
32 |
* IllegalProtocolProperty |
|
33 |
*/ |
|
34 |
||
35 |
import javax.net.ssl.*; |
|
36 |
import java.security.NoSuchAlgorithmException; |
|
37 |
||
38 |
public class IllegalProtocolProperty { |
|
39 |
static enum ContextVersion { |
|
40 |
TLS_CV_01("SSL", "TLSv1", "TLSv1.2", true), |
|
41 |
TLS_CV_02("TLS", "TLSv1", "TLSv1.2", true), |
|
42 |
TLS_CV_03("SSLv3", "TLSv1", "TLSv1.2", false), |
|
43 |
TLS_CV_04("TLSv1", "TLSv1", "TLSv1.2", false), |
|
44 |
TLS_CV_05("TLSv1.1", "TLSv1.1", "TLSv1.2", false), |
|
45 |
TLS_CV_06("TLSv1.2", "TLSv1.2", "TLSv1.2", false), |
|
59302
24e8cdead5f3
8234725: sun/security/ssl/SSLContextImpl tests support TLSv1.3
ssahoo
parents:
47216
diff
changeset
|
46 |
TLS_CV_07("Default", "TLSv1", "TLSv1.2", true), |
24e8cdead5f3
8234725: sun/security/ssl/SSLContextImpl tests support TLSv1.3
ssahoo
parents:
47216
diff
changeset
|
47 |
TLS_CV_08("TLSv1.3", "TLSv1.3", "TLSv1.3", false); |
22068 | 48 |
|
49 |
final String contextVersion; |
|
50 |
final String defaultProtocolVersion; |
|
51 |
final String supportedProtocolVersion; |
|
52 |
final boolean impacted; |
|
53 |
||
54 |
ContextVersion(String contextVersion, String defaultProtocolVersion, |
|
55 |
String supportedProtocolVersion, boolean impacted) { |
|
56 |
this.contextVersion = contextVersion; |
|
57 |
this.defaultProtocolVersion = defaultProtocolVersion; |
|
58 |
this.supportedProtocolVersion = supportedProtocolVersion; |
|
59 |
this.impacted = impacted; |
|
60 |
} |
|
61 |
} |
|
62 |
||
63 |
public static void main(String[] args) throws Exception { |
|
64 |
for (ContextVersion cv : ContextVersion.values()) { |
|
65 |
System.out.println("Checking SSLContext of " + cv.contextVersion); |
|
66 |
||
67 |
SSLContext context; |
|
68 |
try { |
|
69 |
context = SSLContext.getInstance(cv.contextVersion); |
|
70 |
if (cv.impacted) { |
|
71 |
throw new Exception( |
|
72 |
"illegal system property jdk.tls.client.protocols: " + |
|
73 |
System.getProperty("jdk.tls.client.protocols")); |
|
74 |
} |
|
75 |
} catch (NoSuchAlgorithmException nsae) { |
|
76 |
if (cv.impacted) { |
|
77 |
System.out.println( |
|
78 |
"\tIgnore: illegal system property " + |
|
79 |
"jdk.tls.client.protocols=" + |
|
80 |
System.getProperty("jdk.tls.client.protocols")); |
|
81 |
continue; |
|
82 |
} else { |
|
83 |
throw nsae; |
|
84 |
} |
|
85 |
} |
|
86 |
||
87 |
// Default SSLContext is initialized automatically. |
|
88 |
if (!cv.contextVersion.equals("Default")) { |
|
89 |
// Use default TK, KM and random. |
|
90 |
context.init((KeyManager[])null, (TrustManager[])null, null); |
|
91 |
} |
|
92 |
||
93 |
SSLParameters parameters = context.getDefaultSSLParameters(); |
|
94 |
||
95 |
String[] protocols = parameters.getProtocols(); |
|
96 |
String[] ciphers = parameters.getCipherSuites(); |
|
97 |
||
98 |
if (protocols.length == 0 || ciphers.length == 0) { |
|
99 |
throw new Exception("No default protocols or cipher suites"); |
|
100 |
} |
|
101 |
||
102 |
boolean isMatch = false; |
|
103 |
for (String protocol : protocols) { |
|
104 |
System.out.println("\tdefault protocol version " + protocol); |
|
105 |
if (protocol.equals(cv.defaultProtocolVersion)) { |
|
106 |
isMatch = true; |
|
107 |
break; |
|
108 |
} |
|
109 |
} |
|
110 |
||
111 |
if (!isMatch) { |
|
112 |
throw new Exception("No matched default protocol"); |
|
113 |
} |
|
114 |
||
115 |
parameters = context.getSupportedSSLParameters(); |
|
116 |
||
117 |
protocols = parameters.getProtocols(); |
|
118 |
ciphers = parameters.getCipherSuites(); |
|
119 |
||
120 |
if (protocols.length == 0 || ciphers.length == 0) { |
|
121 |
throw new Exception("No supported protocols or cipher suites"); |
|
122 |
} |
|
123 |
||
124 |
isMatch = false; |
|
125 |
for (String protocol : protocols) { |
|
126 |
System.out.println("\tsupported protocol version " + protocol); |
|
127 |
if (protocol.equals(cv.supportedProtocolVersion)) { |
|
128 |
isMatch = true; |
|
129 |
break; |
|
130 |
} |
|
131 |
} |
|
132 |
||
133 |
if (!isMatch) { |
|
134 |
throw new Exception("No matched supported protocol"); |
|
135 |
} |
|
136 |
System.out.println("\t... Success"); |
|
137 |
} |
|
138 |
} |
|
139 |
} |