History

My first initial commit with all of mine experimental changes.

Dmitry Kabak (userdima committed 13 years ago

Commit d37b88d1 parent 3f5b46618352 files · +2598093 −-8690Browse files

Showing the changes to java/pkg/sun/security/ssl/KerberosClientKeyExchange.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/ssl/KerberosClientKeyExchange.java+146−0
@@ -0,0 +1,146 @@
1+/*
2+ * Copyright (c) 2003, 2010, Oracle and/or its affiliates. All rights reserved.
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. Oracle designates this
8+ * particular file as subject to the "Classpath" exception as provided
9+ * by Oracle 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 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.
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;
32+import java.security.Principal;
33+import java.security.PrivilegedAction;
34+import java.security.SecureRandom;
35+import javax.crypto.SecretKey;
36+
37+/**
38+ * A helper class that calls the KerberosClientKeyExchange implementation.
39+ */
40+public class KerberosClientKeyExchange extends HandshakeMessage {
41+
42+ private static final String IMPL_CLASS =
43+ "sun.security.ssl.krb5.KerberosClientKeyExchangeImpl";
44+
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();
57+
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+ // empty
73+ }
74+
75+ public KerberosClientKeyExchange(String serverName, boolean isLoopback,
76+ AccessControlContext acc, ProtocolVersion protocolVersion,
77+ SecureRandom rand) throws IOException {
78+
79+ if (impl != null) {
80+ init(serverName, isLoopback, acc, protocolVersion, rand);
81+ } else {
82+ throw new IllegalStateException("Kerberos is unavailable");
83+ }
84+ }
85+
86+ public KerberosClientKeyExchange(ProtocolVersion protocolVersion,
87+ ProtocolVersion clientVersion, SecureRandom rand,
88+ HandshakeInStream input, SecretKey[] serverKeys) throws IOException {
89+
90+ if (impl != null) {
91+ init(protocolVersion, clientVersion, rand, input, serverKeys);
92+ } else {
93+ throw new IllegalStateException("Kerberos is unavailable");
94+ }
95+ }
96+
97+ @Override
98+ int messageType() {
99+ return ht_client_key_exchange;
100+ }
101+
102+ @Override
103+ public int messageLength() {
104+ return impl.messageLength();
105+ }
106+
107+ @Override
108+ public void send(HandshakeOutStream s) throws IOException {
109+ impl.send(s);
110+ }
111+
112+ @Override
113+ public void print(PrintStream p) throws IOException {
114+ impl.print(p);
115+ }
116+
117+ public void init(String serverName, boolean isLoopback,
118+ AccessControlContext acc, ProtocolVersion protocolVersion,
119+ SecureRandom rand) throws IOException {
120+
121+ if (impl != null) {
122+ impl.init(serverName, isLoopback, acc, protocolVersion, rand);
123+ }
124+ }
125+
126+ public void init(ProtocolVersion protocolVersion,
127+ ProtocolVersion clientVersion, SecureRandom rand,
128+ HandshakeInStream input, SecretKey[] serverKeys) throws IOException {
129+
130+ if (impl != null) {
131+ impl.init(protocolVersion, clientVersion, rand, input, serverKeys);
132+ }
133+ }
134+
135+ public byte[] getUnencryptedPreMasterSecret() {
136+ return impl.getUnencryptedPreMasterSecret();
137+ }
138+
139+ public Principal getPeerPrincipal(){
140+ return impl.getPeerPrincipal();
141+ }
142+
143+ public Principal getLocalPrincipal(){
144+ return impl.getLocalPrincipal();
145+ }
146+}