151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/*
294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is free software; you can redistribute it and/or modify it
651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * under the terms of the GNU General Public License version 2 only, as
751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * published by the Free Software Foundation.  Oracle designates this
851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * particular file as subject to the "Classpath" exception as provided
951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * by Oracle in the LICENSE file that accompanied this code.
1051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This code is distributed in the hope that it will be useful, but WITHOUT
1251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * version 2 for more details (a copy is included in the LICENSE file that
1551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * accompanied this code).
1651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
1751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * You should have received a copy of the GNU General Public License version
1851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * 2 along with this work; if not, write to the Free Software Foundation,
1951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
2151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * or visit www.oracle.com if you need additional information or have any
2351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * questions.
2451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
2551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipackage java.security.cert;
2751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
2851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.AccessController;
2951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.InvalidAlgorithmParameterException;
3051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.NoSuchAlgorithmException;
3151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.NoSuchProviderException;
3251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.PrivilegedAction;
3351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.Provider;
3451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.security.Security;
3551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport java.util.Collection;
3651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
3751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport sun.security.jca.*;
3851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskiimport sun.security.jca.GetInstance.Instance;
3951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
4051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski/**
4194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * A class for retrieving {@code Certificate}s and {@code CRL}s
4251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * from a repository.
4351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
4451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This class uses a provider-based architecture.
4594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * To create a {@code CertStore}, call one of the static
4694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * {@code getInstance} methods, passing in the type of
4794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * {@code CertStore} desired, any applicable initialization parameters
4851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * and optionally the name of the provider desired.
4951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
5094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * Once the {@code CertStore} has been created, it can be used to
5194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * retrieve {@code Certificate}s and {@code CRL}s by calling its
5251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@link #getCertificates(CertSelector selector) getCertificates} and
5351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * {@link #getCRLs(CRLSelector selector) getCRLs} methods.
5451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
5551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Unlike a {@link java.security.KeyStore KeyStore}, which provides access
5651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * to a cache of private keys and trusted certificates, a
5794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * {@code CertStore} is designed to provide access to a potentially
5851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * vast repository of untrusted certificates and CRLs. For example, an LDAP
5994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * implementation of {@code CertStore} provides access to certificates
6051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * and CRLs stored in one or more directories using the LDAP protocol and the
6151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * schema as defined in the RFC service attribute.
6251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
63444325bf794144dcdc90ab594232be2def307ca1Przemyslaw Szczepaniak * <p> Android provides the following <code>CertStore</code> types:
64444325bf794144dcdc90ab594232be2def307ca1Przemyslaw Szczepaniak * <table>
65a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *   <thead>
66a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *     <tr>
67a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *       <th>Algorithm</th>
68a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *       <th>Supported API Levels</th>
69a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *     </tr>
70a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *   </thead>
71a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *   <tbody>
72a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *     <tr>
73a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *       <td>Collection</td>
74a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *       <td>1+</td>
75a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *     </tr>
76a52aa9ffde23844fad4fd1980fdd129662afd0a4Adam Vartanian *   </tbody>
77444325bf794144dcdc90ab594232be2def307ca1Przemyslaw Szczepaniak * </table>
78444325bf794144dcdc90ab594232be2def307ca1Przemyslaw Szczepaniak *
7951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * This type is described in the <a href=
80309f9df28350e15445b9135e8b710fa2b34b5dc1Yi Kong * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#CertStore">
8151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * CertStore section</a> of the
8251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Java Cryptography Architecture Standard Algorithm Name Documentation.
8351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
8451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
8551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <b>Concurrent Access</b>
8651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
8794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * All public methods of {@code CertStore} objects must be thread-safe.
8851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * That is, multiple threads may concurrently invoke these methods on a
8994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * single {@code CertStore} object (or more than one) with no
9094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro * ill effects. This allows a {@code CertPathBuilder} to search for a
9151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * CRL while simultaneously searching for further certificates, for instance.
9251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * <p>
9351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * The static methods of this class are also guaranteed to be thread-safe.
9451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * Multiple threads may concurrently invoke the static methods defined in
9551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * this class with no ill effects.
9651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski *
9751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @since       1.4
9851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski * @author      Sean Mullan, Steve Hanna
9951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski */
10051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebskipublic class CertStore {
10151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /*
10251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Constant to lookup in the Security properties file to determine
10351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the default certstore type. In the Security properties file, the
10451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * default certstore type is given as:
10551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <pre>
10651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * certstore.type=LDAP
10751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * </pre>
10851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
10951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private static final String CERTSTORE_TYPE = "certstore.type";
11051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private CertStoreSpi storeSpi;
11151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private Provider provider;
11251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private String type;
11351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private CertStoreParameters params;
11451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
11551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
11694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Creates a {@code CertStore} object of the given type, and
11751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * encapsulates the given provider implementation (SPI object) in it.
11851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
11951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param storeSpi the provider implementation
12051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param provider the provider
12151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param type the type
12294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param params the initialization parameters (may be {@code null})
12351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
12451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    protected CertStore(CertStoreSpi storeSpi, Provider provider,
12551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                        String type, CertStoreParameters params) {
12651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        this.storeSpi = storeSpi;
12751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        this.provider = provider;
12851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        this.type = type;
12951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if (params != null)
13051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            this.params = (CertStoreParameters) params.clone();
13151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
13251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
13351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
13494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns a {@code Collection} of {@code Certificate}s that
13594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * match the specified selector. If no {@code Certificate}s
13694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * match the selector, an empty {@code Collection} will be returned.
13751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>
13894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * For some {@code CertStore} types, the resulting
13994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code Collection} may not contain <b>all</b> of the
14094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code Certificate}s that match the selector. For instance,
14194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * an LDAP {@code CertStore} may not search all entries in the
14251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * directory. Instead, it may just search entries that are likely to
14394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * contain the {@code Certificate}s it is looking for.
14451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>
14594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Some {@code CertStore} implementations (especially LDAP
14694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore}s) may throw a {@code CertStoreException}
14794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * unless a non-null {@code CertSelector} is provided that
14851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * includes specific criteria that can be used to find the certificates.
14951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Issuer and/or subject names are especially useful criteria.
15051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
15194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param selector A {@code CertSelector} used to select which
15294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *  {@code Certificate}s should be returned. Specify {@code null}
15394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *  to return all {@code Certificate}s (if supported).
15494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return A {@code Collection} of {@code Certificate}s that
15594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *         match the specified selector (never {@code null})
15651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws CertStoreException if an exception occurs
15751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
15851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final Collection<? extends Certificate> getCertificates
15951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            (CertSelector selector) throws CertStoreException {
16051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return storeSpi.engineGetCertificates(selector);
16151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
16251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
16351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
16494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns a {@code Collection} of {@code CRL}s that
16594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * match the specified selector. If no {@code CRL}s
16694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * match the selector, an empty {@code Collection} will be returned.
16751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>
16894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * For some {@code CertStore} types, the resulting
16994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code Collection} may not contain <b>all</b> of the
17094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CRL}s that match the selector. For instance,
17194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * an LDAP {@code CertStore} may not search all entries in the
17251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * directory. Instead, it may just search entries that are likely to
17394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * contain the {@code CRL}s it is looking for.
17451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p>
17594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Some {@code CertStore} implementations (especially LDAP
17694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore}s) may throw a {@code CertStoreException}
17794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * unless a non-null {@code CRLSelector} is provided that
17851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * includes specific criteria that can be used to find the CRLs.
17951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Issuer names and/or the certificate to be checked are especially useful.
18051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
18194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param selector A {@code CRLSelector} used to select which
18294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *  {@code CRL}s should be returned. Specify {@code null}
18394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *  to return all {@code CRL}s (if supported).
18494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return A {@code Collection} of {@code CRL}s that
18594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *         match the specified selector (never {@code null})
18651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws CertStoreException if an exception occurs
18751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
18851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final Collection<? extends CRL> getCRLs(CRLSelector selector)
18951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            throws CertStoreException {
19051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return storeSpi.engineGetCRLs(selector);
19151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
19251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
19351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
19494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns a {@code CertStore} object that implements the specified
19594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore} type and is initialized with the specified
19651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * parameters.
19751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
19851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p> This method traverses the list of registered security Providers,
19951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * starting with the most preferred Provider.
20051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * A new CertStore object encapsulating the
20151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * CertStoreSpi implementation from the first
20251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Provider that supports the specified type is returned.
20351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
20451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p> Note that the list of registered providers may be retrieved via
20551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the {@link Security#getProviders() Security.getProviders()} method.
20651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
20794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * <p>The {@code CertStore} that is returned is initialized with the
20894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * specified {@code CertStoreParameters}. The type of parameters
20994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * needed may vary between different types of {@code CertStore}s.
21094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Note that the specified {@code CertStoreParameters} object is
21151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * cloned.
21251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
21394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param type the name of the requested {@code CertStore} type.
21451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * See the CertStore section in the <a href=
215309f9df28350e15445b9135e8b710fa2b34b5dc1Yi Kong     * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#CertStore">
21651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
21751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * for information about standard types.
21851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
21994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param params the initialization parameters (may be {@code null}).
22051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
22194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return a {@code CertStore} object that implements the specified
22294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *          {@code CertStore} type.
22351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
22451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NoSuchAlgorithmException if no Provider supports a
22551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          CertStoreSpi implementation for the specified type.
22651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
22751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws InvalidAlgorithmParameterException if the specified
22851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          initialization parameters are inappropriate for this
22994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *          {@code CertStore}.
23051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
23151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see java.security.Provider
23251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
23351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static CertStore getInstance(String type, CertStoreParameters params)
23451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            throws InvalidAlgorithmParameterException,
23551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            NoSuchAlgorithmException {
23651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        try {
23751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            Instance instance = GetInstance.getInstance("CertStore",
23851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                CertStoreSpi.class, type, params);
23951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return new CertStore((CertStoreSpi)instance.impl,
24051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                instance.provider, type, params);
24151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        } catch (NoSuchAlgorithmException e) {
24251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return handleException(e);
24351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
24451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
24551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
24651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    private static CertStore handleException(NoSuchAlgorithmException e)
24751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            throws NoSuchAlgorithmException, InvalidAlgorithmParameterException {
24851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        Throwable cause = e.getCause();
24951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if (cause instanceof InvalidAlgorithmParameterException) {
25051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            throw (InvalidAlgorithmParameterException)cause;
25151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
25251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        throw e;
25351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
25451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
25551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
25694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns a {@code CertStore} object that implements the specified
25794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore} type.
25851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
25951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p> A new CertStore object encapsulating the
26051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * CertStoreSpi implementation from the specified provider
26151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * is returned.  The specified provider must be registered
26251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * in the security provider list.
26351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
26451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p> Note that the list of registered providers may be retrieved via
26551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * the {@link Security#getProviders() Security.getProviders()} method.
26651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
26794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * <p>The {@code CertStore} that is returned is initialized with the
26894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * specified {@code CertStoreParameters}. The type of parameters
26994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * needed may vary between different types of {@code CertStore}s.
27094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Note that the specified {@code CertStoreParameters} object is
27151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * cloned.
27251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
27394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param type the requested {@code CertStore} type.
27451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * See the CertStore section in the <a href=
275309f9df28350e15445b9135e8b710fa2b34b5dc1Yi Kong     * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#CertStore">
27651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
27751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * for information about standard types.
27851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
27994c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param params the initialization parameters (may be {@code null}).
28051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param provider the name of the provider.
28251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return a {@code CertStore} object that implements the
28451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          specified type.
28551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
28651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NoSuchAlgorithmException if a CertStoreSpi
28751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          implementation for the specified type is not
28851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          available from the specified provider.
28951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
29051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws InvalidAlgorithmParameterException if the specified
29151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          initialization parameters are inappropriate for this
29294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *          {@code CertStore}.
29351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
29451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws NoSuchProviderException if the specified provider is not
29551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          registered in the security provider list.
29651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
29794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @exception IllegalArgumentException if the {@code provider} is
29851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          null or empty.
29951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
30051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see java.security.Provider
30151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
30251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static CertStore getInstance(String type,
30351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            CertStoreParameters params, String provider)
30451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            throws InvalidAlgorithmParameterException,
30551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            NoSuchAlgorithmException, NoSuchProviderException {
30651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        try {
30751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            Instance instance = GetInstance.getInstance("CertStore",
30851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                CertStoreSpi.class, type, params, provider);
30951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return new CertStore((CertStoreSpi)instance.impl,
31051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                instance.provider, type, params);
31151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        } catch (NoSuchAlgorithmException e) {
31251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return handleException(e);
31351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
31451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
31551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
31651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
31794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns a {@code CertStore} object that implements the specified
31894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore} type.
31951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
32051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * <p> A new CertStore object encapsulating the
32151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * CertStoreSpi implementation from the specified Provider
32251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * object is returned.  Note that the specified Provider object
32351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * does not have to be registered in the provider list.
32451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
32594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * <p>The {@code CertStore} that is returned is initialized with the
32694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * specified {@code CertStoreParameters}. The type of parameters
32794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * needed may vary between different types of {@code CertStore}s.
32894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Note that the specified {@code CertStoreParameters} object is
32951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * cloned.
33051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
33194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param type the requested {@code CertStore} type.
33251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * See the CertStore section in the <a href=
333309f9df28350e15445b9135e8b710fa2b34b5dc1Yi Kong     * "{@docRoot}openjdk-redirect.html?v=8&path=/technotes/guides/security/StandardNames.html#CertStore">
33451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
33551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * for information about standard types.
33651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
33794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @param params the initialization parameters (may be {@code null}).
33851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
33951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @param provider the provider.
34051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
34194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return a {@code CertStore} object that implements the
34251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          specified type.
34351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
34451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @exception NoSuchAlgorithmException if a CertStoreSpi
34551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          implementation for the specified type is not available
34651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          from the specified Provider object.
34751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
34851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @throws InvalidAlgorithmParameterException if the specified
34951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          initialization parameters are inappropriate for this
35094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *          {@code CertStore}
35151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
35294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @exception IllegalArgumentException if the {@code provider} is
35351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *          null.
35451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
35551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * @see java.security.Provider
35651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
35751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public static CertStore getInstance(String type, CertStoreParameters params,
35851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            Provider provider) throws NoSuchAlgorithmException,
35951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            InvalidAlgorithmParameterException {
36051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        try {
36151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            Instance instance = GetInstance.getInstance("CertStore",
36251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                CertStoreSpi.class, type, params, provider);
36351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return new CertStore((CertStoreSpi)instance.impl,
36451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                instance.provider, type, params);
36551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        } catch (NoSuchAlgorithmException e) {
36651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            return handleException(e);
36751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
36851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
36951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
37051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
37194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns the parameters used to initialize this {@code CertStore}.
37294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Note that the {@code CertStoreParameters} object is cloned before
37351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * it is returned.
37451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
37594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return the parameters used to initialize this {@code CertStore}
37694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * (may be {@code null})
37751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
37851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final CertStoreParameters getCertStoreParameters() {
37951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return (params == null ? null : (CertStoreParameters) params.clone());
38051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
38151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
38251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
38394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns the type of this {@code CertStore}.
38451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
38594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return the type of this {@code CertStore}
38651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
38751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final String getType() {
38851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return this.type;
38951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
39051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
39151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
39294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns the provider of this {@code CertStore}.
39351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
39494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return the provider of this {@code CertStore}
39551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
39651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final Provider getProvider() {
39751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return this.provider;
39851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
39951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski
40051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    /**
40194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * Returns the default {@code CertStore} type as specified by the
40294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code certstore.type} security property, or the string
40394c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@literal "LDAP"} if no such property exists.
40494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     *
40594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * <p>The default {@code CertStore} type can be used by applications
40651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     * that do not want to use a hard-coded type when calling one of the
40794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code getInstance} methods, and want to provide a default
40894c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code CertStore} type in case a user does not specify its own.
40951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
41094c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * <p>The default {@code CertStore} type can be changed by setting
41194c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * the value of the {@code certstore.type} security property to the
41294c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * desired type.
41351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     *
41494c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @see java.security.Security security properties
41594c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * @return the default {@code CertStore} type as specified by the
41694c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@code certstore.type} security property, or the string
41794c24c5bb69f6dfec482f85f767ef0fc7dd98cbbSergio Giro     * {@literal "LDAP"} if no such property exists.
41851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski     */
41951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    public final static String getDefaultType() {
42051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        String cstype;
42151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        cstype = AccessController.doPrivileged(new PrivilegedAction<String>() {
42251b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            public String run() {
42351b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski                return Security.getProperty(CERTSTORE_TYPE);
42451b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            }
42551b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        });
42651b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        if (cstype == null) {
42751b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski            cstype = "LDAP";
42851b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        }
42951b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski        return cstype;
43051b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski    }
43151b1b6997fd3f980076b8081f7f1165ccc2a4008Piotr Jastrzebski}
432