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 java.security.cert;
27
28 import java.io.InputStream;
29 import java.util.Collection;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.security.Provider;
33 import java.security.Security;
34 import java.security.AccessController;
35 import java.security.PrivilegedAction;
36 import java.security.NoSuchAlgorithmException;
37 import java.security.NoSuchProviderException;
38
39 import sun.security.jca.*;
40 import sun.security.jca.GetInstance.Instance;
41
42 /**
43 * This class defines the functionality of a certificate factory, which is
44 * used to generate certificate, certification path ({@code CertPath})
45 * and certificate revocation list (CRL) objects from their encodings.
46 *
47 * <p>For encodings consisting of multiple certificates, use
48 * {@code generateCertificates} when you want to
49 * parse a collection of possibly unrelated certificates. Otherwise,
50 * use {@code generateCertPath} when you want to generate
51 * a {@code CertPath} (a certificate chain) and subsequently
52 * validate it with a {@code CertPathValidator}.
53 *
54 * <p>A certificate factory for X.509 must return certificates that are an
55 * instance of {@code java.security.cert.X509Certificate}, and CRLs
160 * CertificateFactorySpi implementation from the first
161 * Provider that supports the specified type is returned.
162 *
163 * <p> Note that the list of registered providers may be retrieved via
164 * the {@link Security#getProviders() Security.getProviders()} method.
165 *
166 * @implNote
167 * The JDK Reference Implementation additionally uses the
168 * {@code jdk.security.provider.preferred}
169 * {@link Security#getProperty(String) Security} property to determine
170 * the preferred provider order for the specified algorithm. This
171 * may be different than the order of providers returned by
172 * {@link Security#getProviders() Security.getProviders()}.
173 *
174 * @param type the name of the requested certificate type.
175 * See the CertificateFactory section in the <a href=
176 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
177 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
178 * for information about standard certificate types.
179 *
180 * @return a certificate factory object for the specified type.
181 *
182 * @exception CertificateException if no Provider supports a
183 * CertificateFactorySpi implementation for the
184 * specified type.
185 *
186 * @see java.security.Provider
187 */
188 public static final CertificateFactory getInstance(String type)
189 throws CertificateException {
190 try {
191 Instance instance = GetInstance.getInstance("CertificateFactory",
192 CertificateFactorySpi.class, type);
193 return new CertificateFactory((CertificateFactorySpi)instance.impl,
194 instance.provider, type);
195 } catch (NoSuchAlgorithmException e) {
196 throw new CertificateException(type + " not found", e);
197 }
198 }
199
200 /**
201 * Returns a certificate factory object for the specified
202 * certificate type.
203 *
204 * <p> A new CertificateFactory object encapsulating the
205 * CertificateFactorySpi implementation from the specified provider
206 * is returned. The specified provider must be registered
207 * in the security provider list.
208 *
209 * <p> Note that the list of registered providers may be retrieved via
210 * the {@link Security#getProviders() Security.getProviders()} method.
211 *
212 * @param type the certificate type.
213 * See the CertificateFactory section in the <a href=
214 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
215 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
216 * for information about standard certificate types.
217 *
218 * @param provider the name of the provider.
219 *
220 * @return a certificate factory object for the specified type.
221 *
222 * @exception CertificateException if a CertificateFactorySpi
223 * implementation for the specified algorithm is not
224 * available from the specified provider.
225 *
226 * @exception NoSuchProviderException if the specified provider is not
227 * registered in the security provider list.
228 *
229 * @exception IllegalArgumentException if the provider name is null
230 * or empty.
231 *
232 * @see java.security.Provider
233 */
234 public static final CertificateFactory getInstance(String type,
235 String provider) throws CertificateException,
236 NoSuchProviderException {
237 try {
238 Instance instance = GetInstance.getInstance("CertificateFactory",
239 CertificateFactorySpi.class, type, provider);
240 return new CertificateFactory((CertificateFactorySpi)instance.impl,
241 instance.provider, type);
242 } catch (NoSuchAlgorithmException e) {
243 throw new CertificateException(type + " not found", e);
244 }
245 }
246
247 /**
248 * Returns a certificate factory object for the specified
249 * certificate type.
250 *
251 * <p> A new CertificateFactory object encapsulating the
252 * CertificateFactorySpi implementation from the specified Provider
253 * object is returned. Note that the specified Provider object
254 * does not have to be registered in the provider list.
255 *
256 * @param type the certificate type.
257 * See the CertificateFactory section in the <a href=
258 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
259 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
260 * for information about standard certificate types.
261 * @param provider the provider.
262 *
263 * @return a certificate factory object for the specified type.
264 *
265 * @exception CertificateException if a CertificateFactorySpi
266 * implementation for the specified algorithm is not available
267 * from the specified Provider object.
268 *
269 * @exception IllegalArgumentException if the {@code provider} is
270 * null.
271 *
272 * @see java.security.Provider
273 *
274 * @since 1.4
275 */
276 public static final CertificateFactory getInstance(String type,
277 Provider provider) throws CertificateException {
278 try {
279 Instance instance = GetInstance.getInstance("CertificateFactory",
280 CertificateFactorySpi.class, type, provider);
281 return new CertificateFactory((CertificateFactorySpi)instance.impl,
282 instance.provider, type);
283 } catch (NoSuchAlgorithmException e) {
284 throw new CertificateException(type + " not found", e);
285 }
286 }
287
288 /**
289 * Returns the provider of this certificate factory.
290 *
291 * @return the provider of this certificate factory.
292 */
293 public final Provider getProvider() {
294 return this.provider;
295 }
296
297 /**
|
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 java.security.cert;
27
28 import java.io.InputStream;
29 import java.util.Collection;
30 import java.util.Iterator;
31 import java.util.List;
32 import java.util.Objects;
33 import java.security.Provider;
34 import java.security.Security;
35 import java.security.NoSuchAlgorithmException;
36 import java.security.NoSuchProviderException;
37
38 import sun.security.jca.*;
39 import sun.security.jca.GetInstance.Instance;
40
41 /**
42 * This class defines the functionality of a certificate factory, which is
43 * used to generate certificate, certification path ({@code CertPath})
44 * and certificate revocation list (CRL) objects from their encodings.
45 *
46 * <p>For encodings consisting of multiple certificates, use
47 * {@code generateCertificates} when you want to
48 * parse a collection of possibly unrelated certificates. Otherwise,
49 * use {@code generateCertPath} when you want to generate
50 * a {@code CertPath} (a certificate chain) and subsequently
51 * validate it with a {@code CertPathValidator}.
52 *
53 * <p>A certificate factory for X.509 must return certificates that are an
54 * instance of {@code java.security.cert.X509Certificate}, and CRLs
159 * CertificateFactorySpi implementation from the first
160 * Provider that supports the specified type is returned.
161 *
162 * <p> Note that the list of registered providers may be retrieved via
163 * the {@link Security#getProviders() Security.getProviders()} method.
164 *
165 * @implNote
166 * The JDK Reference Implementation additionally uses the
167 * {@code jdk.security.provider.preferred}
168 * {@link Security#getProperty(String) Security} property to determine
169 * the preferred provider order for the specified algorithm. This
170 * may be different than the order of providers returned by
171 * {@link Security#getProviders() Security.getProviders()}.
172 *
173 * @param type the name of the requested certificate type.
174 * See the CertificateFactory section in the <a href=
175 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
176 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
177 * for information about standard certificate types.
178 *
179 * @return a certificate factory object for the specified type
180 *
181 * @throws CertificateException if no {@code Provider} supports a
182 * {@code CertificateFactorySpi} implementation for the
183 * specified type
184 *
185 * @throws NullPointerException if {@code type} is {@code null}
186 *
187 * @see java.security.Provider
188 */
189 public static final CertificateFactory getInstance(String type)
190 throws CertificateException {
191 Objects.requireNonNull(type, "null type name");
192 try {
193 Instance instance = GetInstance.getInstance("CertificateFactory",
194 CertificateFactorySpi.class, type);
195 return new CertificateFactory((CertificateFactorySpi)instance.impl,
196 instance.provider, type);
197 } catch (NoSuchAlgorithmException e) {
198 throw new CertificateException(type + " not found", e);
199 }
200 }
201
202 /**
203 * Returns a certificate factory object for the specified
204 * certificate type.
205 *
206 * <p> A new CertificateFactory object encapsulating the
207 * CertificateFactorySpi implementation from the specified provider
208 * is returned. The specified provider must be registered
209 * in the security provider list.
210 *
211 * <p> Note that the list of registered providers may be retrieved via
212 * the {@link Security#getProviders() Security.getProviders()} method.
213 *
214 * @param type the certificate type.
215 * See the CertificateFactory section in the <a href=
216 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
217 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
218 * for information about standard certificate types.
219 *
220 * @param provider the name of the provider.
221 *
222 * @return a certificate factory object for the specified type
223 *
224 * @throws CertificateException if a {@code CertificateFactorySpi}
225 * implementation for the specified algorithm is not
226 * available from the specified provider
227 *
228 * @throws IllegalArgumentException if the provider name is {@code null}
229 * or empty
230 *
231 * @throws NoSuchProviderException if the specified provider is not
232 * registered in the security provider list
233 *
234 * @throws NullPointerException if {@code type} is {@code null}
235 *
236 * @see java.security.Provider
237 */
238 public static final CertificateFactory getInstance(String type,
239 String provider) throws CertificateException,
240 NoSuchProviderException {
241 Objects.requireNonNull(type, "null type name");
242 try {
243 Instance instance = GetInstance.getInstance("CertificateFactory",
244 CertificateFactorySpi.class, type, provider);
245 return new CertificateFactory((CertificateFactorySpi)instance.impl,
246 instance.provider, type);
247 } catch (NoSuchAlgorithmException e) {
248 throw new CertificateException(type + " not found", e);
249 }
250 }
251
252 /**
253 * Returns a certificate factory object for the specified
254 * certificate type.
255 *
256 * <p> A new CertificateFactory object encapsulating the
257 * CertificateFactorySpi implementation from the specified Provider
258 * object is returned. Note that the specified Provider object
259 * does not have to be registered in the provider list.
260 *
261 * @param type the certificate type.
262 * See the CertificateFactory section in the <a href=
263 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
264 * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
265 * for information about standard certificate types.
266 * @param provider the provider.
267 *
268 * @return a certificate factory object for the specified type
269 *
270 * @throws CertificateException if a {@code CertificateFactorySpi}
271 * implementation for the specified algorithm is not available
272 * from the specified {@code Provider} object
273 *
274 * @throws IllegalArgumentException if the {@code provider} is
275 * {@code null}
276 *
277 * @throws NullPointerException if {@code type} is {@code null}
278 *
279 * @see java.security.Provider
280 *
281 * @since 1.4
282 */
283 public static final CertificateFactory getInstance(String type,
284 Provider provider) throws CertificateException {
285 Objects.requireNonNull(type, "null type name");
286 try {
287 Instance instance = GetInstance.getInstance("CertificateFactory",
288 CertificateFactorySpi.class, type, provider);
289 return new CertificateFactory((CertificateFactorySpi)instance.impl,
290 instance.provider, type);
291 } catch (NoSuchAlgorithmException e) {
292 throw new CertificateException(type + " not found", e);
293 }
294 }
295
296 /**
297 * Returns the provider of this certificate factory.
298 *
299 * @return the provider of this certificate factory.
300 */
301 public final Provider getProvider() {
302 return this.provider;
303 }
304
305 /**
|