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 javax.net.ssl;
27
28 import java.security.Security;
29 import java.security.*;
30
31 import sun.security.jca.GetInstance;
32
33 /**
34 * This class acts as a factory for key managers based on a
35 * source of key material. Each key manager manages a specific
36 * type of key material for use by secure sockets. The key
37 * material is based on a KeyStore and/or provider specific sources.
38 *
39 * @since 1.4
40 * @see KeyManager
41 */
42 public class KeyManagerFactory {
43 // The provider
44 private Provider provider;
45
46 // The provider implementation (delegate)
47 private KeyManagerFactorySpi factorySpi;
48
49 // The name of the key management algorithm.
113 * KeyManagerFactorySpi implementation from the first
114 * Provider that supports the specified algorithm is returned.
115 *
116 * <p> Note that the list of registered providers may be retrieved via
117 * the {@link Security#getProviders() Security.getProviders()} method.
118 *
119 * @implNote
120 * The JDK Reference Implementation additionally uses the
121 * {@code jdk.security.provider.preferred}
122 * {@link Security#getProperty(String) Security} property to determine
123 * the preferred provider order for the specified algorithm. This
124 * may be different than the order of providers returned by
125 * {@link Security#getProviders() Security.getProviders()}.
126 *
127 * @param algorithm the standard name of the requested algorithm.
128 * See the <a href=
129 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
130 * Java Secure Socket Extension Reference Guide </a>
131 * for information about standard algorithm names.
132 *
133 * @return the new <code>KeyManagerFactory</code> object.
134 *
135 * @exception NoSuchAlgorithmException if no Provider supports a
136 * KeyManagerFactorySpi implementation for the
137 * specified algorithm.
138 * @exception NullPointerException if <code>algorithm</code> is null.
139 *
140 * @see java.security.Provider
141 */
142 public static final KeyManagerFactory getInstance(String algorithm)
143 throws NoSuchAlgorithmException {
144 GetInstance.Instance instance = GetInstance.getInstance
145 ("KeyManagerFactory", KeyManagerFactorySpi.class,
146 algorithm);
147 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
148 instance.provider, algorithm);
149 }
150
151 /**
152 * Returns a <code>KeyManagerFactory</code> object that acts as a
153 * factory for key managers.
154 *
155 * <p> A new KeyManagerFactory object encapsulating the
156 * KeyManagerFactorySpi implementation from the specified provider
157 * is returned. The specified provider must be registered
158 * in the security provider list.
159 *
160 * <p> Note that the list of registered providers may be retrieved via
161 * the {@link Security#getProviders() Security.getProviders()} method.
162
163 * @param algorithm the standard name of the requested algorithm.
164 * See the <a href=
165 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
166 * Java Secure Socket Extension Reference Guide </a>
167 * for information about standard algorithm names.
168 *
169 * @param provider the name of the provider.
170 *
171 * @return the new <code>KeyManagerFactory</code> object.
172 *
173 * @throws NoSuchAlgorithmException if a KeyManagerFactorySpi
174 * implementation for the specified algorithm is not
175 * available from the specified provider.
176 *
177 * @throws NoSuchProviderException if the specified provider is not
178 * registered in the security provider list.
179 *
180 * @throws IllegalArgumentException if the provider name is null or empty.
181 * @throws NullPointerException if <code>algorithm</code> is null.
182 *
183 * @see java.security.Provider
184 */
185 public static final KeyManagerFactory getInstance(String algorithm,
186 String provider) throws NoSuchAlgorithmException,
187 NoSuchProviderException {
188 GetInstance.Instance instance = GetInstance.getInstance
189 ("KeyManagerFactory", KeyManagerFactorySpi.class,
190 algorithm, provider);
191 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
192 instance.provider, algorithm);
193 }
194
195 /**
196 * Returns a <code>KeyManagerFactory</code> object that acts as a
197 * factory for key managers.
198 *
199 * <p> A new KeyManagerFactory object encapsulating the
200 * KeyManagerFactorySpi implementation from the specified Provider
201 * object is returned. Note that the specified Provider object
202 * does not have to be registered in the provider list.
203 *
204 * @param algorithm the standard name of the requested algorithm.
205 * See the <a href=
206 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
207 * Java Secure Socket Extension Reference Guide </a>
208 * for information about standard algorithm names.
209 *
210 * @param provider an instance of the provider.
211 *
212 * @return the new <code>KeyManagerFactory</code> object.
213 *
214 * @throws NoSuchAlgorithmException if a KeyManagerFactorySpi
215 * implementation for the specified algorithm is not available
216 * from the specified Provider object.
217 *
218 * @throws IllegalArgumentException if provider is null.
219 * @throws NullPointerException if <code>algorithm</code> is null.
220 *
221 * @see java.security.Provider
222 */
223 public static final KeyManagerFactory getInstance(String algorithm,
224 Provider provider) throws NoSuchAlgorithmException {
225 GetInstance.Instance instance = GetInstance.getInstance
226 ("KeyManagerFactory", KeyManagerFactorySpi.class,
227 algorithm, provider);
228 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
229 instance.provider, algorithm);
230 }
231
232 /**
233 * Returns the provider of this <code>KeyManagerFactory</code> object.
234 *
235 * @return the provider of this <code>KeyManagerFactory</code> object
236 */
237 public final Provider getProvider() {
238 return this.provider;
239 }
240
241
242 /**
243 * Initializes this factory with a source of key material.
244 * <P>
|
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 javax.net.ssl;
27
28 import java.security.Security;
29 import java.security.*;
30 import java.util.Objects;
31
32 import sun.security.jca.GetInstance;
33
34 /**
35 * This class acts as a factory for key managers based on a
36 * source of key material. Each key manager manages a specific
37 * type of key material for use by secure sockets. The key
38 * material is based on a KeyStore and/or provider specific sources.
39 *
40 * @since 1.4
41 * @see KeyManager
42 */
43 public class KeyManagerFactory {
44 // The provider
45 private Provider provider;
46
47 // The provider implementation (delegate)
48 private KeyManagerFactorySpi factorySpi;
49
50 // The name of the key management algorithm.
114 * KeyManagerFactorySpi implementation from the first
115 * Provider that supports the specified algorithm is returned.
116 *
117 * <p> Note that the list of registered providers may be retrieved via
118 * the {@link Security#getProviders() Security.getProviders()} method.
119 *
120 * @implNote
121 * The JDK Reference Implementation additionally uses the
122 * {@code jdk.security.provider.preferred}
123 * {@link Security#getProperty(String) Security} property to determine
124 * the preferred provider order for the specified algorithm. This
125 * may be different than the order of providers returned by
126 * {@link Security#getProviders() Security.getProviders()}.
127 *
128 * @param algorithm the standard name of the requested algorithm.
129 * See the <a href=
130 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
131 * Java Secure Socket Extension Reference Guide </a>
132 * for information about standard algorithm names.
133 *
134 * @return the new {@code KeyManagerFactory} object
135 *
136 * @throws NoSuchAlgorithmException if no {@code Provider} supports a
137 * {@code KeyManagerFactorySpi} implementation for the
138 * specified algorithm
139 *
140 * @throws NullPointerException if {@code algorithm} is {@code null}
141 *
142 * @see java.security.Provider
143 */
144 public static final KeyManagerFactory getInstance(String algorithm)
145 throws NoSuchAlgorithmException {
146 Objects.requireNonNull(algorithm, "null algorithm name");
147 GetInstance.Instance instance = GetInstance.getInstance
148 ("KeyManagerFactory", KeyManagerFactorySpi.class,
149 algorithm);
150 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
151 instance.provider, algorithm);
152 }
153
154 /**
155 * Returns a <code>KeyManagerFactory</code> object that acts as a
156 * factory for key managers.
157 *
158 * <p> A new KeyManagerFactory object encapsulating the
159 * KeyManagerFactorySpi implementation from the specified provider
160 * is returned. The specified provider must be registered
161 * in the security provider list.
162 *
163 * <p> Note that the list of registered providers may be retrieved via
164 * the {@link Security#getProviders() Security.getProviders()} method.
165
166 * @param algorithm the standard name of the requested algorithm.
167 * See the <a href=
168 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
169 * Java Secure Socket Extension Reference Guide </a>
170 * for information about standard algorithm names.
171 *
172 * @param provider the name of the provider.
173 *
174 * @return the new {@code KeyManagerFactory} object
175 *
176 * @throws IllegalArgumentException if the provider name is {@code null}
177 * or empty
178 *
179 * @throws NoSuchAlgorithmException if a {@code KeyManagerFactorySpi}
180 * implementation for the specified algorithm is not
181 * available from the specified provider
182 *
183 * @throws NoSuchProviderException if the specified provider is not
184 * registered in the security provider list
185 *
186 * @throws NullPointerException if {@code algorithm} is {@code null}
187 *
188 * @see java.security.Provider
189 */
190 public static final KeyManagerFactory getInstance(String algorithm,
191 String provider) throws NoSuchAlgorithmException,
192 NoSuchProviderException {
193 Objects.requireNonNull(algorithm, "null algorithm name");
194 GetInstance.Instance instance = GetInstance.getInstance
195 ("KeyManagerFactory", KeyManagerFactorySpi.class,
196 algorithm, provider);
197 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
198 instance.provider, algorithm);
199 }
200
201 /**
202 * Returns a <code>KeyManagerFactory</code> object that acts as a
203 * factory for key managers.
204 *
205 * <p> A new KeyManagerFactory object encapsulating the
206 * KeyManagerFactorySpi implementation from the specified Provider
207 * object is returned. Note that the specified Provider object
208 * does not have to be registered in the provider list.
209 *
210 * @param algorithm the standard name of the requested algorithm.
211 * See the <a href=
212 * "{@docRoot}/../technotes/guides/security/jsse/JSSERefGuide.html">
213 * Java Secure Socket Extension Reference Guide </a>
214 * for information about standard algorithm names.
215 *
216 * @param provider an instance of the provider.
217 *
218 * @return the new {@code KeyManagerFactory} object
219 *
220 * @throws IllegalArgumentException if provider is {@code null}
221 *
222 * @throws NoSuchAlgorithmException if a {@code @KeyManagerFactorySpi}
223 * implementation for the specified algorithm is not available
224 * from the specified Provider object
225 *
226 * @throws NullPointerException if {@code algorithm} is {@code null}
227 *
228 * @see java.security.Provider
229 */
230 public static final KeyManagerFactory getInstance(String algorithm,
231 Provider provider) throws NoSuchAlgorithmException {
232 Objects.requireNonNull(algorithm, "null algorithm name");
233 GetInstance.Instance instance = GetInstance.getInstance
234 ("KeyManagerFactory", KeyManagerFactorySpi.class,
235 algorithm, provider);
236 return new KeyManagerFactory((KeyManagerFactorySpi)instance.impl,
237 instance.provider, algorithm);
238 }
239
240 /**
241 * Returns the provider of this <code>KeyManagerFactory</code> object.
242 *
243 * @return the provider of this <code>KeyManagerFactory</code> object
244 */
245 public final Provider getProvider() {
246 return this.provider;
247 }
248
249
250 /**
251 * Initializes this factory with a source of key material.
252 * <P>
|