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/KeyManagerFactoryImpl.java (1 of 18352 files). Show all

Unified · Split

java/pkg/sun/security/ssl/KeyManagerFactoryImpl.java+124−0
@@ -0,0 +1,124 @@
1+/*
2+ * Copyright (c) 1999, 2007, 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.util.List;
29+import java.util.Collections;
30+
31+import java.security.*;
32+import java.security.KeyStore.*;
33+
34+import javax.net.ssl.*;
35+
36+abstract class KeyManagerFactoryImpl extends KeyManagerFactorySpi {
37+
38+ X509ExtendedKeyManager keyManager;
39+ boolean isInitialized;
40+
41+ KeyManagerFactoryImpl() {
42+ // empty
43+ }
44+
45+ /**
46+ * Returns one key manager for each type of key material.
47+ */
48+ protected KeyManager[] engineGetKeyManagers() {
49+ if (!isInitialized) {
50+ throw new IllegalStateException(
51+ "KeyManagerFactoryImpl is not initialized");
52+ }
53+ return new KeyManager[] { keyManager };
54+ }
55+
56+ // Factory for the SunX509 keymanager
57+ public static final class SunX509 extends KeyManagerFactoryImpl {
58+
59+ protected void engineInit(KeyStore ks, char[] password) throws
60+ KeyStoreException, NoSuchAlgorithmException,
61+ UnrecoverableKeyException {
62+ if ((ks != null) && SunJSSE.isFIPS()) {
63+ if (ks.getProvider() != SunJSSE.cryptoProvider) {
64+ throw new KeyStoreException("FIPS mode: KeyStore must be "
65+ + "from provider " + SunJSSE.cryptoProvider.getName());
66+ }
67+ }
68+ keyManager = new SunX509KeyManagerImpl(ks, password);
69+ isInitialized = true;
70+ }
71+
72+ protected void engineInit(ManagerFactoryParameters spec) throws
73+ InvalidAlgorithmParameterException {
74+ throw new InvalidAlgorithmParameterException(
75+ "SunX509KeyManager does not use ManagerFactoryParameters");
76+ }
77+
78+ }
79+
80+ // Factory for the X509 keymanager
81+ public static final class X509 extends KeyManagerFactoryImpl {
82+
83+ protected void engineInit(KeyStore ks, char[] password) throws
84+ KeyStoreException, NoSuchAlgorithmException,
85+ UnrecoverableKeyException {
86+ if (ks == null) {
87+ keyManager = new X509KeyManagerImpl(
88+ Collections.<Builder>emptyList());
89+ } else {
90+ if (SunJSSE.isFIPS() && (ks.getProvider() != SunJSSE.cryptoProvider)) {
91+ throw new KeyStoreException("FIPS mode: KeyStore must be "
92+ + "from provider " + SunJSSE.cryptoProvider.getName());
93+ }
94+ try {
95+ Builder builder = Builder.newInstance(ks,
96+ new PasswordProtection(password));
97+ keyManager = new X509KeyManagerImpl(builder);
98+ } catch (RuntimeException e) {
99+ throw new KeyStoreException("initialization failed", e);
100+ }
101+ }
102+ isInitialized = true;
103+ }
104+
105+ protected void engineInit(ManagerFactoryParameters params) throws
106+ InvalidAlgorithmParameterException {
107+ if (params instanceof KeyStoreBuilderParameters == false) {
108+ throw new InvalidAlgorithmParameterException(
109+ "Parameters must be instance of KeyStoreBuilderParameters");
110+ }
111+ if (SunJSSE.isFIPS()) {
112+ // XXX should be fixed
113+ throw new InvalidAlgorithmParameterException
114+ ("FIPS mode: KeyStoreBuilderParameters not supported");
115+ }
116+ List<Builder> builders =
117+ ((KeyStoreBuilderParameters)params).getParameters();
118+ keyManager = new X509KeyManagerImpl(builders);
119+ isInitialized = true;
120+ }
121+
122+ }
123+
124+}