author | vinnie |
Thu, 12 Nov 2009 23:00:23 +0000 | |
changeset 4236 | 02f52c723b79 |
parent 2942 | 37d9baeb7518 |
child 5506 | 202f599c92aa |
permissions | -rw-r--r-- |
2 | 1 |
/* |
2942
37d9baeb7518
6578647: Undefined requesting URL in java.net.Authenticator.getPasswordAuthentication()
weijun
parents:
2
diff
changeset
|
2 |
* Copyright 2003-2009 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
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() { |
|
72 |
} |
|
73 |
||
74 |
public KerberosClientKeyExchange(String serverName, boolean isLoopback, |
|
2 | 75 |
AccessControlContext acc, ProtocolVersion protocolVersion, |
76 |
SecureRandom rand) throws IOException { |
|
77 |
||
4236 | 78 |
if (impl != null) { |
79 |
init(serverName, isLoopback, acc, protocolVersion, rand); |
|
80 |
} else { |
|
81 |
throw new IllegalStateException("Kerberos is unavailable"); |
|
82 |
} |
|
2 | 83 |
} |
84 |
||
4236 | 85 |
public KerberosClientKeyExchange(ProtocolVersion protocolVersion, |
86 |
ProtocolVersion clientVersion, SecureRandom rand, |
|
87 |
HandshakeInStream input, SecretKey[] serverKeys) throws IOException { |
|
2 | 88 |
|
4236 | 89 |
if (impl != null) { |
90 |
init(protocolVersion, clientVersion, rand, input, serverKeys); |
|
2 | 91 |
} else { |
4236 | 92 |
throw new IllegalStateException("Kerberos is unavailable"); |
2 | 93 |
} |
94 |
} |
|
95 |
||
96 |
int messageType() { |
|
97 |
return ht_client_key_exchange; |
|
98 |
} |
|
99 |
||
4236 | 100 |
public int messageLength() { |
101 |
return impl.messageLength(); |
|
102 |
} |
|
103 |
||
104 |
public void send(HandshakeOutStream s) throws IOException { |
|
105 |
impl.send(s); |
|
2 | 106 |
} |
107 |
||
4236 | 108 |
@Override |
109 |
public void print(PrintStream p) throws IOException { |
|
110 |
impl.print(p); |
|
2 | 111 |
} |
112 |
||
4236 | 113 |
public void init(String serverName, boolean isLoopback, |
114 |
AccessControlContext acc, ProtocolVersion protocolVersion, |
|
115 |
SecureRandom rand) throws IOException { |
|
2 | 116 |
|
4236 | 117 |
if (impl != null) { |
118 |
impl.init(serverName, isLoopback, acc, protocolVersion, rand); |
|
2 | 119 |
} |
120 |
} |
|
121 |
||
4236 | 122 |
public void init(ProtocolVersion protocolVersion, |
123 |
ProtocolVersion clientVersion, SecureRandom rand, |
|
124 |
HandshakeInStream input, SecretKey[] serverKeys) throws IOException { |
|
2 | 125 |
|
4236 | 126 |
if (impl != null) { |
127 |
impl.init(protocolVersion, clientVersion, rand, input, serverKeys); |
|
2 | 128 |
} |
129 |
} |
|
130 |
||
4236 | 131 |
public byte[] getUnencryptedPreMasterSecret() { |
132 |
return impl.getUnencryptedPreMasterSecret(); |
|
2 | 133 |
} |
134 |
||
4236 | 135 |
public Principal getPeerPrincipal(){ |
136 |
return impl.getPeerPrincipal(); |
|
137 |
} |
|
138 |
||
139 |
public Principal getLocalPrincipal(){ |
|
140 |
return impl.getLocalPrincipal(); |
|
2 | 141 |
} |
142 |
} |