author | asmotrak |
Mon, 27 Apr 2015 21:02:40 +0800 | |
changeset 30038 | 632939157af2 |
child 31429 | ce4193650b40 |
permissions | -rw-r--r-- |
30038
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
1 |
/* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
2 |
* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
4 |
* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
8 |
* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
13 |
* accompanied this code). |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
14 |
* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
18 |
* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
21 |
* questions. |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
22 |
*/ |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
23 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
24 |
import java.io.IOException; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
25 |
import java.security.NoSuchAlgorithmException; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
26 |
import java.security.PrivilegedActionException; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
27 |
import java.util.HashMap; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
28 |
import java.util.Map; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
29 |
import javax.security.auth.login.LoginException; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
30 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
31 |
/* |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
32 |
* @test |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
33 |
* @bug 8025123 |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
34 |
* @summary Checks if an unbound server uses a service principal |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
35 |
* from sun.security.krb5.principal system property if specified |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
36 |
* @run main/othervm UnboundSSLPrincipalProperty |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
37 |
* unbound.ssl.jaas.conf server_star |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
38 |
* @run main/othervm UnboundSSLPrincipalProperty |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
39 |
* unbound.ssl.jaas.conf server_multiple_principals |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
40 |
*/ |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
41 |
public class UnboundSSLPrincipalProperty { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
42 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
43 |
public static void main(String[] args) throws IOException, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
44 |
NoSuchAlgorithmException,LoginException, PrivilegedActionException, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
45 |
InterruptedException { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
46 |
UnboundSSLPrincipalProperty test = new UnboundSSLPrincipalProperty(); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
47 |
test.start(args[0], args[1]); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
48 |
} |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
49 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
50 |
public void start(String jaacConfigFile, String serverJaasConfig) |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
51 |
throws IOException, NoSuchAlgorithmException,LoginException, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
52 |
PrivilegedActionException, InterruptedException { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
53 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
54 |
// define principals |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
55 |
String service1host = "service1." + UnboundSSLUtils.HOST; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
56 |
String service3host = "service3." + UnboundSSLUtils.HOST; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
57 |
String service1Principal = "host/" + service1host + "@" |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
58 |
+ UnboundSSLUtils.REALM; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
59 |
String service3Principal = "host/" + service3host |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
60 |
+ "@" + UnboundSSLUtils.REALM; |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
61 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
62 |
Map<String, String> principals = new HashMap<>(); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
63 |
principals.put(UnboundSSLUtils.USER_PRINCIPAL, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
64 |
UnboundSSLUtils.USER_PASSWORD); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
65 |
principals.put(UnboundSSLUtils.KRBTGT_PRINCIPAL, null); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
66 |
principals.put(service1Principal, null); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
67 |
principals.put(service3Principal, null); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
68 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
69 |
System.setProperty("java.security.krb5.conf", |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
70 |
UnboundSSLUtils.KRB5_CONF_FILENAME); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
71 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
72 |
// start a local KDC instance |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
73 |
UnboundSSLUtils.startKDC(UnboundSSLUtils.REALM, principals, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
74 |
UnboundSSLUtils.KTAB_FILENAME, UnboundSSLUtils.KtabMode.APPEND); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
75 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
76 |
System.setProperty("java.security.auth.login.config", |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
77 |
UnboundSSLUtils.TEST_SRC + UnboundSSLUtils.FS + jaacConfigFile); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
78 |
System.setProperty("javax.security.auth.useSubjectCredsOnly", "false"); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
79 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
80 |
// start an SSL server instance |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
81 |
try (final SSLEchoServer server = SSLEchoServer.init( |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
82 |
UnboundSSLUtils.TLS_KRB5_FILTER, UnboundSSLUtils.SNI_PATTERN)) { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
83 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
84 |
// specify a service principal for the server |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
85 |
System.setProperty("sun.security.krb5.principal", |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
86 |
service3Principal); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
87 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
88 |
UnboundSSLUtils.startServerWithJaas(server, serverJaasConfig); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
89 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
90 |
// wait for the server is ready |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
91 |
while (!server.isReady()) { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
92 |
Thread.sleep(UnboundSSLUtils.DELAY); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
93 |
} |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
94 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
95 |
int port = server.getPort(); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
96 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
97 |
// connetion failure is expected |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
98 |
// since service3 principal was specified to use by the server |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
99 |
System.out.println("Connect: SNI hostname = " + service1host |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
100 |
+ ", connection failure is expected"); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
101 |
try { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
102 |
SSLClient.init(UnboundSSLUtils.HOST, port, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
103 |
UnboundSSLUtils.TLS_KRB5_FILTER, service1host) |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
104 |
.connect(); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
105 |
throw new RuntimeException("Test failed: " |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
106 |
+ "expected IOException not thrown"); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
107 |
} catch (IOException e) { |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
108 |
System.out.println("Expected exception: " + e); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
109 |
} |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
110 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
111 |
System.out.println("Connect: SNI hostname = " + service3host |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
112 |
+ ", successful connection is expected"); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
113 |
SSLClient.init(UnboundSSLUtils.HOST, port, |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
114 |
UnboundSSLUtils.TLS_KRB5_FILTER, service3host).connect(); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
115 |
} |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
116 |
|
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
117 |
System.out.println("Test passed"); |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
118 |
} |
632939157af2
8075007: Additional tests for krb5-related cipher suites with unbound server
asmotrak
parents:
diff
changeset
|
119 |
} |