author | xuelei |
Sat, 24 Nov 2012 04:09:19 -0800 | |
changeset 14664 | e71aa0962e70 |
parent 5506 | 202f599c92aa |
child 23010 | 6dadb192ad81 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
5506 | 2 |
* Copyright (c) 1999, 2007, 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.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 |
*/ |
|
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
48 |
@Override |
2 | 49 |
protected KeyManager[] engineGetKeyManagers() { |
50 |
if (!isInitialized) { |
|
51 |
throw new IllegalStateException( |
|
52 |
"KeyManagerFactoryImpl is not initialized"); |
|
53 |
} |
|
54 |
return new KeyManager[] { keyManager }; |
|
55 |
} |
|
56 |
||
57 |
// Factory for the SunX509 keymanager |
|
58 |
public static final class SunX509 extends KeyManagerFactoryImpl { |
|
59 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
60 |
@Override |
2 | 61 |
protected void engineInit(KeyStore ks, char[] password) throws |
62 |
KeyStoreException, NoSuchAlgorithmException, |
|
63 |
UnrecoverableKeyException { |
|
64 |
if ((ks != null) && SunJSSE.isFIPS()) { |
|
65 |
if (ks.getProvider() != SunJSSE.cryptoProvider) { |
|
66 |
throw new KeyStoreException("FIPS mode: KeyStore must be " |
|
67 |
+ "from provider " + SunJSSE.cryptoProvider.getName()); |
|
68 |
} |
|
69 |
} |
|
70 |
keyManager = new SunX509KeyManagerImpl(ks, password); |
|
71 |
isInitialized = true; |
|
72 |
} |
|
73 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
74 |
@Override |
2 | 75 |
protected void engineInit(ManagerFactoryParameters spec) throws |
76 |
InvalidAlgorithmParameterException { |
|
77 |
throw new InvalidAlgorithmParameterException( |
|
78 |
"SunX509KeyManager does not use ManagerFactoryParameters"); |
|
79 |
} |
|
80 |
||
81 |
} |
|
82 |
||
83 |
// Factory for the X509 keymanager |
|
84 |
public static final class X509 extends KeyManagerFactoryImpl { |
|
85 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
86 |
@Override |
2 | 87 |
protected void engineInit(KeyStore ks, char[] password) throws |
88 |
KeyStoreException, NoSuchAlgorithmException, |
|
89 |
UnrecoverableKeyException { |
|
90 |
if (ks == null) { |
|
91 |
keyManager = new X509KeyManagerImpl( |
|
92 |
Collections.<Builder>emptyList()); |
|
93 |
} else { |
|
94 |
if (SunJSSE.isFIPS() && (ks.getProvider() != SunJSSE.cryptoProvider)) { |
|
95 |
throw new KeyStoreException("FIPS mode: KeyStore must be " |
|
96 |
+ "from provider " + SunJSSE.cryptoProvider.getName()); |
|
97 |
} |
|
98 |
try { |
|
99 |
Builder builder = Builder.newInstance(ks, |
|
100 |
new PasswordProtection(password)); |
|
101 |
keyManager = new X509KeyManagerImpl(builder); |
|
102 |
} catch (RuntimeException e) { |
|
103 |
throw new KeyStoreException("initialization failed", e); |
|
104 |
} |
|
105 |
} |
|
106 |
isInitialized = true; |
|
107 |
} |
|
108 |
||
14664
e71aa0962e70
8003950: Adds missing Override annotations and removes unnecessary imports in sun.security.ssl
xuelei
parents:
5506
diff
changeset
|
109 |
@Override |
2 | 110 |
protected void engineInit(ManagerFactoryParameters params) throws |
111 |
InvalidAlgorithmParameterException { |
|
112 |
if (params instanceof KeyStoreBuilderParameters == false) { |
|
113 |
throw new InvalidAlgorithmParameterException( |
|
114 |
"Parameters must be instance of KeyStoreBuilderParameters"); |
|
115 |
} |
|
116 |
if (SunJSSE.isFIPS()) { |
|
117 |
// XXX should be fixed |
|
118 |
throw new InvalidAlgorithmParameterException |
|
119 |
("FIPS mode: KeyStoreBuilderParameters not supported"); |
|
120 |
} |
|
121 |
List<Builder> builders = |
|
122 |
((KeyStoreBuilderParameters)params).getParameters(); |
|
123 |
keyManager = new X509KeyManagerImpl(builders); |
|
124 |
isInitialized = true; |
|
125 |
} |
|
126 |
||
127 |
} |
|
128 |
||
129 |
} |