jdk/src/share/classes/java/security/cert/CertificateFactory.java
author duke
Sat, 01 Dec 2007 00:00:00 +0000
changeset 2 90ce3da70b43
child 2589 af4853bc7e87
permissions -rw-r--r--
Initial load
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1998-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.security.cert;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.InputStream;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.util.Collection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.util.Iterator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * This class defines the functionality of a certificate factory, which is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * used to generate certificate, certification path (<code>CertPath</code>)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * and certificate revocation list (CRL) objects from their encodings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * <p>For encodings consisting of multiple certificates, use
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * <code>generateCertificates</code> when you want to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * parse a collection of possibly unrelated certificates. Otherwise,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * use <code>generateCertPath</code> when you want to generate
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * a <code>CertPath</code> (a certificate chain) and subsequently
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * validate it with a <code>CertPathValidator</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * <p>A certificate factory for X.509 must return certificates that are an
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * instance of <code>java.security.cert.X509Certificate</code>, and CRLs
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * that are an instance of <code>java.security.cert.X509CRL</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * <p>The following example reads a file with Base64 encoded certificates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * which are each bounded at the beginning by -----BEGIN CERTIFICATE-----, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * bounded at the end by -----END CERTIFICATE-----. We convert the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>FileInputStream</code> (which does not support <code>mark</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * and <code>reset</code>) to a <code>BufferedInputStream</code> (which
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * supports those methods), so that each call to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>generateCertificate</code> consumes only one certificate, and the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * read position of the input stream is positioned to the next certificate in
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * the file:<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * FileInputStream fis = new FileInputStream(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * BufferedInputStream bis = new BufferedInputStream(fis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * CertificateFactory cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 * while (bis.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *    Certificate cert = cf.generateCertificate(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *    System.out.println(cert.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 * <p>The following example parses a PKCS#7-formatted certificate reply stored
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * in a file and extracts all the certificates from it:<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * FileInputStream fis = new FileInputStream(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * CertificateFactory cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Collection c = cf.generateCertificates(fis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * Iterator i = c.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 * while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *    Certificate cert = (Certificate)i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *    System.out.println(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 * @see Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 * @see X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 * @see CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
public class CertificateFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
    // The certificate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
    // The provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    private CertificateFactorySpi certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
     * Creates a CertificateFactory object of the given type, and encapsulates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
     * the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @param certFacSpi the provider implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * @param type the certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    protected CertificateFactory(CertificateFactorySpi certFacSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                                 Provider provider, String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
        this.certFacSpi = certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * Returns a certificate factory object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * specified certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * CertificateFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param type the name of the requested certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     * "../../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * @exception CertificateException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     *          CertificateFactorySpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *          specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public static final CertificateFactory getInstance(String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                CertificateFactorySpi.class, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     * CertificateFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @param type the certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     * "../../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * @exception CertificateException if a CertificateFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @exception IllegalArgumentException if the provider name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     *          or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
            String provider) throws CertificateException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * CertificateFactorySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @param type the certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     * See Appendix A in the <a href=
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * "../../../../technotes/guides/security/crypto/CryptoSpec.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * Java Cryptography Architecture API Specification &amp; Reference </a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * @exception CertificateException if a CertificateFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
            Provider provider) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * Returns the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @return the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Returns the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     * @return the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        return this.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     * Generates a certificate object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
     * the data read from the input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
     * the returned certificate object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * factory implements X.509 certificates, the returned certificate object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     * can be typecast to the <code>X509Certificate</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * <p>In the case of a certificate factory for X.509 certificates, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     * certificate provided in <code>inStream</code> must be DER-encoded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
     * may be supplied in binary or printable (Base64) encoding. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * certificate is provided in Base64 encoding, it must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * the end by -----END CERTIFICATE-----.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * method consumes one certificate and the read position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * input stream is positioned to the next available byte after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * the inherent end-of-certificate marker. If the data in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * does not contain an inherent end-of-certificate marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * than EOF) and there is trailing data after the certificate is parsed, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * <code>CertificateException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * @param inStream an input stream with the certificate data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * @return a certificate object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
    public final Certificate generateCertificate(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
        return certFacSpi.engineGenerateCertificate(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * Returns an iteration of the <code>CertPath</code> encodings supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * by this certificate factory, with the default encoding first. See
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     * Appendix A in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * <a href="../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * Java Certification Path API Programmer's Guide</a> for information about
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * standard encoding names and their formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * Attempts to modify the returned <code>Iterator</code> via its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <code>remove</code> method result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * @return an <code>Iterator</code> over the names of the supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     *         <code>CertPath</code> encodings (as <code>String</code>s)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
    public final Iterator<String> getCertPathEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        return(certFacSpi.engineGetCertPathEncodings());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * the data read from the <code>InputStream</code> inStream. The data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * is assumed to be in the default encoding. The name of the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * encoding is the first element of the <code>Iterator</code> returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * the {@link #getCertPathEncodings getCertPathEncodings} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * @param inStream an <code>InputStream</code> containing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     * @return a <code>CertPath</code> initialized with the data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     *   <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     * @exception CertificateException if an exception occurs while decoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    public final CertPath generateCertPath(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
        return(certFacSpi.engineGenerateCertPath(inStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * the data read from the <code>InputStream</code> inStream. The data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * is assumed to be in the specified encoding. See Appendix A in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     * <a href="../../../../technotes/guides/security/certpath/CertPathProgGuide.html#AppA">
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * Java Certification Path API Programmer's Guide</a>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * for information about standard encoding names and their formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @param inStream an <code>InputStream</code> containing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @param encoding the encoding used for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * @return a <code>CertPath</code> initialized with the data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     *   <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     * @exception CertificateException if an exception occurs while decoding or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     *   the encoding requested is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
    public final CertPath generateCertPath(InputStream inStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
        String encoding) throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        return(certFacSpi.engineGenerateCertPath(inStream, encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
90ce3da70b43 Initial load
duke
parents:
diff changeset
   386
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * a <code>List</code> of <code>Certificate</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * The certificates supplied must be of a type supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * <code>CertificateFactory</code>. They will be copied out of the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * <code>List</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @param certificates a <code>List</code> of <code>Certificate</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     * @return a <code>CertPath</code> initialized with the supplied list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     *   certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     * @exception CertificateException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    public final CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        generateCertPath(List<? extends Certificate> certificates)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
        return(certFacSpi.engineGenerateCertPath(certificates));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * Returns a (possibly empty) collection view of the certificates read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * from the given input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * factory implements X.509 certificates, the elements in the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * collection can be typecast to the <code>X509Certificate</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
     * <p>In the case of a certificate factory for X.509 certificates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * <code>inStream</code> may contain a sequence of DER-encoded certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     * in the formats described for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
     * {@link #generateCertificate(java.io.InputStream) generateCertificate}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
     * In addition, <code>inStream</code> may contain a PKCS#7 certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * significant field being <i>certificates</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * certificates to be downloaded at once. If no certificates are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * @param inStream the input stream with the certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * java.security.cert.Certificate objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * initialized with the data from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    public final Collection<? extends Certificate> generateCertificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
            (InputStream inStream) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
        return certFacSpi.engineGenerateCertificates(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * Generates a certificate revocation list (CRL) object and initializes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * with the data read from the input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     * the returned CRL object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * factory implements X.509 CRLs, the returned CRL object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * can be typecast to the <code>X509CRL</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     * method consumes one CRL and the read position of the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * is positioned to the next available byte after the the inherent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * end-of-CRL marker. If the data in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * input stream does not contain an inherent end-of-CRL marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * than EOF) and there is trailing data after the CRL is parsed, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * <code>CRLException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * @param inStream an input stream with the CRL data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return a CRL object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public final CRL generateCRL(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
        throws CRLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
        return certFacSpi.engineGenerateCRL(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * Returns a (possibly empty) collection view of the CRLs read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * from the given input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * factory implements X.509 CRLs, the elements in the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * collection can be typecast to the <code>X509CRL</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * <p>In the case of a certificate factory for X.509 CRLs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * <code>inStream</code> may contain a sequence of DER-encoded CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * In addition, <code>inStream</code> may contain a PKCS#7 CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * set. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
     * significant field being <i>crls</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * CRLs to be downloaded at once. If no CRLs are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * @param inStream the input stream with the CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     * java.security.cert.CRL objects initialized with the data from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
    public final Collection<? extends CRL> generateCRLs(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
        return certFacSpi.engineGenerateCRLs(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
}