2
|
1 |
/*
|
7039
|
2 |
* Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
|
2
|
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
|
5506
|
7 |
* published by the Free Software Foundation. Oracle designates this
|
2
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
5506
|
9 |
* by Oracle in the LICENSE file that accompanied this code.
|
2
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
5506
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
|
22 |
* or visit www.oracle.com if you need additional information or have any
|
|
23 |
* questions.
|
2
|
24 |
*/
|
|
25 |
|
|
26 |
package sun.security.ssl;
|
|
27 |
|
|
28 |
import java.io.IOException;
|
|
29 |
import java.io.PrintStream;
|
|
30 |
import java.security.AccessController;
|
|
31 |
import java.security.AccessControlContext;
|
4236
|
32 |
import java.security.Principal;
|
|
33 |
import java.security.PrivilegedAction;
|
2
|
34 |
import java.security.SecureRandom;
|
4236
|
35 |
import javax.crypto.SecretKey;
|
2
|
36 |
|
|
37 |
/**
|
4236
|
38 |
* A helper class that calls the KerberosClientKeyExchange implementation.
|
2
|
39 |
*/
|
4236
|
40 |
public class KerberosClientKeyExchange extends HandshakeMessage {
|
|
41 |
|
|
42 |
private static final String IMPL_CLASS =
|
|
43 |
"sun.security.ssl.krb5.KerberosClientKeyExchangeImpl";
|
2
|
44 |
|
4236
|
45 |
private static final Class<?> implClass = AccessController.doPrivileged(
|
|
46 |
new PrivilegedAction<Class<?>>() {
|
|
47 |
public Class<?> run() {
|
|
48 |
try {
|
|
49 |
return Class.forName(IMPL_CLASS, true, null);
|
|
50 |
} catch (ClassNotFoundException cnf) {
|
|
51 |
return null;
|
|
52 |
}
|
|
53 |
}
|
|
54 |
}
|
|
55 |
);
|
|
56 |
private final KerberosClientKeyExchange impl = createImpl();
|
2
|
57 |
|
4236
|
58 |
private KerberosClientKeyExchange createImpl() {
|
|
59 |
if (getClass() == KerberosClientKeyExchange.class) {
|
|
60 |
try {
|
|
61 |
return (KerberosClientKeyExchange)implClass.newInstance();
|
|
62 |
} catch (InstantiationException e) {
|
|
63 |
throw new AssertionError(e);
|
|
64 |
} catch (IllegalAccessException e) {
|
|
65 |
throw new AssertionError(e);
|
|
66 |
}
|
|
67 |
}
|
|
68 |
return null;
|
|
69 |
}
|
|
70 |
|
|
71 |
public KerberosClientKeyExchange() {
|
7039
|
72 |
// empty
|
4236
|
73 |
}
|
|
74 |
|
|
75 |
public KerberosClientKeyExchange(String serverName, boolean isLoopback,
|
2
|
76 |
AccessControlContext acc, ProtocolVersion protocolVersion,
|
|
77 |
SecureRandom rand) throws IOException {
|
|
78 |
|
4236
|
79 |
if (impl != null) {
|
|
80 |
init(serverName, isLoopback, acc, protocolVersion, rand);
|
|
81 |
} else {
|
|
82 |
throw new IllegalStateException("Kerberos is unavailable");
|
|
83 |
}
|
2
|
84 |
}
|
|
85 |
|
4236
|
86 |
public KerberosClientKeyExchange(ProtocolVersion protocolVersion,
|
|
87 |
ProtocolVersion clientVersion, SecureRandom rand,
|
|
88 |
HandshakeInStream input, SecretKey[] serverKeys) throws IOException {
|
2
|
89 |
|
4236
|
90 |
if (impl != null) {
|
|
91 |
init(protocolVersion, clientVersion, rand, input, serverKeys);
|
2
|
92 |
} else {
|
4236
|
93 |
throw new IllegalStateException("Kerberos is unavailable");
|
2
|
94 |
}
|
|
95 |
}
|
|
96 |
|
7039
|
97 |
@Override
|
2
|
98 |
int messageType() {
|
|
99 |
return ht_client_key_exchange;
|
|
100 |
}
|
|
101 |
|
7039
|
102 |
@Override
|
4236
|
103 |
public int messageLength() {
|
|
104 |
return impl.messageLength();
|
|
105 |
}
|
|
106 |
|
7039
|
107 |
@Override
|
4236
|
108 |
public void send(HandshakeOutStream s) throws IOException {
|
|
109 |
impl.send(s);
|
2
|
110 |
}
|
|
111 |
|
4236
|
112 |
@Override
|
|
113 |
public void print(PrintStream p) throws IOException {
|
|
114 |
impl.print(p);
|
2
|
115 |
}
|
|
116 |
|
4236
|
117 |
public void init(String serverName, boolean isLoopback,
|
|
118 |
AccessControlContext acc, ProtocolVersion protocolVersion,
|
|
119 |
SecureRandom rand) throws IOException {
|
2
|
120 |
|
4236
|
121 |
if (impl != null) {
|
|
122 |
impl.init(serverName, isLoopback, acc, protocolVersion, rand);
|
2
|
123 |
}
|
|
124 |
}
|
|
125 |
|
4236
|
126 |
public void init(ProtocolVersion protocolVersion,
|
|
127 |
ProtocolVersion clientVersion, SecureRandom rand,
|
|
128 |
HandshakeInStream input, SecretKey[] serverKeys) throws IOException {
|
2
|
129 |
|
4236
|
130 |
if (impl != null) {
|
|
131 |
impl.init(protocolVersion, clientVersion, rand, input, serverKeys);
|
2
|
132 |
}
|
|
133 |
}
|
|
134 |
|
4236
|
135 |
public byte[] getUnencryptedPreMasterSecret() {
|
|
136 |
return impl.getUnencryptedPreMasterSecret();
|
2
|
137 |
}
|
|
138 |
|
4236
|
139 |
public Principal getPeerPrincipal(){
|
|
140 |
return impl.getPeerPrincipal();
|
|
141 |
}
|
|
142 |
|
|
143 |
public Principal getLocalPrincipal(){
|
|
144 |
return impl.getLocalPrincipal();
|
2
|
145 |
}
|
|
146 |
}
|