jdk/src/share/classes/java/security/cert/CertificateFactory.java
author ohair
Wed, 06 Apr 2011 22:06:11 -0700
changeset 9035 1255eb81cc2f
parent 8152 94e5966bdf22
child 18156 edb590d448c5
permissions -rw-r--r--
7033660: Update copyright year to 2011 on any files changed in 2011 Reviewed-by: dholmes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
9035
1255eb81cc2f 7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents: 8152
diff changeset
     2
 * Copyright (c) 1998, 2011, Oracle and/or its affiliates. All rights reserved.
2
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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2589
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2589
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2589
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2589
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2589
diff changeset
    23
 * questions.
2
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
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    94
 * <p> Every implementation of the Java platform is required to support the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    95
 * following standard <code>CertificateFactory</code> type:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    96
 * <ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    97
 * <li><tt>X.509</tt></li>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    98
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    99
 * and the following standard <code>CertPath</code> encodings:
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   100
 * <ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   101
 * <li><tt>PKCS7</tt></li>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   102
 * <li><tt>PkiPath</tt></li>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   103
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   104
 * The type and encodings are described in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   105
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   106
 * CertificateFactory section</a> and the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   107
 * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathEncodings">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   108
 * CertPath Encodings section</a> of the
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   109
 * Java Cryptography Architecture Standard Algorithm Name Documentation.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   110
 * Consult the release documentation for your implementation to see if any
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   111
 * other types or encodings are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   112
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * @see Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * @see X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @see CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
public class CertificateFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    // The certificate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    // The provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
    private CertificateFactorySpi certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * Creates a CertificateFactory object of the given type, and encapsulates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param certFacSpi the provider implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     * @param type the certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    protected CertificateFactory(CertificateFactorySpi certFacSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
                                 Provider provider, String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.certFacSpi = certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * Returns a certificate factory object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * specified certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * CertificateFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     * @param type the name of the requested certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   167
     * See the CertificateFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   168
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   169
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * @exception CertificateException if no Provider supports a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     *          CertificateFactorySpi implementation for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
     *          specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    public static final CertificateFactory getInstance(String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                CertificateFactorySpi.class, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * CertificateFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * @param type the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   205
     * See the CertificateFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   206
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   207
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @exception CertificateException if a CertificateFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     *          implementation for the specified algorithm is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     *          available from the specified provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * @exception NoSuchProviderException if the specified provider is not
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *          registered in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * @exception IllegalArgumentException if the provider name is null
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     *          or empty.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            String provider) throws CertificateException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            NoSuchProviderException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
     * CertificateFactorySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     * @param type the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   249
     * See the CertificateFactory section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   250
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertificateFactory">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   251
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     * @return a certificate factory object for the specified type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * @exception CertificateException if a CertificateFactorySpi
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     *          implementation for the specified algorithm is not available
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *          from the specified Provider object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @exception IllegalArgumentException if the <code>provider</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *          null.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
            Provider provider) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * Returns the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     * @return the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
     * Returns the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
     * @return the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        return this.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
     * Generates a certificate object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
     * the data read from the input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * the returned certificate object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * factory implements X.509 certificates, the returned certificate object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * can be typecast to the <code>X509Certificate</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     * <p>In the case of a certificate factory for X.509 certificates, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
     * certificate provided in <code>inStream</code> must be DER-encoded and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
     * may be supplied in binary or printable (Base64) encoding. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
     * certificate is provided in Base64 encoding, it must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
     * the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
     * the end by -----END CERTIFICATE-----.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * method consumes one certificate and the read position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * input stream is positioned to the next available byte after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * the inherent end-of-certificate marker. If the data in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
     * does not contain an inherent end-of-certificate marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     * than EOF) and there is trailing data after the certificate is parsed, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <code>CertificateException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * @param inStream an input stream with the certificate data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * @return a certificate object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
    public final Certificate generateCertificate(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
        return certFacSpi.engineGenerateCertificate(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
     * Returns an iteration of the <code>CertPath</code> encodings supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     * by this certificate factory, with the default encoding first. See
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   345
     * the CertPath Encodings section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   346
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathEncodings">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   347
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   348
     * for information about standard encoding names and their formats.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
     * Attempts to modify the returned <code>Iterator</code> via its
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     * <code>remove</code> method result in an
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
     * <code>UnsupportedOperationException</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
     * @return an <code>Iterator</code> over the names of the supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
     *         <code>CertPath</code> encodings (as <code>String</code>s)
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 Iterator<String> getCertPathEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
        return(certFacSpi.engineGetCertPathEncodings());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
     * the data read from the <code>InputStream</code> inStream. The data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * is assumed to be in the default encoding. The name of the default
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
     * encoding is the first element of the <code>Iterator</code> returned by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
     * the {@link #getCertPathEncodings getCertPathEncodings} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     * @param inStream an <code>InputStream</code> containing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
     * @return a <code>CertPath</code> initialized with the data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
     *   <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @exception CertificateException if an exception occurs while decoding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
    public final CertPath generateCertPath(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
        return(certFacSpi.engineGenerateCertPath(inStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * the data read from the <code>InputStream</code> inStream. The data
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   384
     * is assumed to be in the specified encoding. See
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   385
     * the CertPath Encodings section in the <a href=
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   386
     * "{@docRoot}/../technotes/guides/security/StandardNames.html#CertPathEncodings">
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   387
     * Java Cryptography Architecture Standard Algorithm Name Documentation</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
     * for information about standard encoding names and their formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     * @param inStream an <code>InputStream</code> containing the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
     * @param encoding the encoding used for the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
     * @return a <code>CertPath</code> initialized with the data from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
     *   <code>InputStream</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
     * @exception CertificateException if an exception occurs while decoding or
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
     *   the encoding requested is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
    public final CertPath generateCertPath(InputStream inStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
        String encoding) throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
        return(certFacSpi.engineGenerateCertPath(inStream, encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     * Generates a <code>CertPath</code> object and initializes it with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
     * a <code>List</code> of <code>Certificate</code>s.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
     * The certificates supplied must be of a type supported by the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
     * <code>CertificateFactory</code>. They will be copied out of the supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
     * <code>List</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @param certificates a <code>List</code> of <code>Certificate</code>s
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     * @return a <code>CertPath</code> initialized with the supplied list of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
     *   certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
     * @exception CertificateException if an exception occurs
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    public final CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
        generateCertPath(List<? extends Certificate> certificates)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        return(certFacSpi.engineGenerateCertPath(certificates));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
     * Returns a (possibly empty) collection view of the certificates read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     * from the given input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     * factory implements X.509 certificates, the elements in the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
     * collection can be typecast to the <code>X509Certificate</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
     * <p>In the case of a certificate factory for X.509 certificates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
     * <code>inStream</code> may contain a sequence of DER-encoded certificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
     * in the formats described for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
     * {@link #generateCertificate(java.io.InputStream) generateCertificate}.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
     * In addition, <code>inStream</code> may contain a PKCS#7 certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
     * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * significant field being <i>certificates</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     * certificates to be downloaded at once. If no certificates are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * @param inStream the input stream with the certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * java.security.cert.Certificate objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
     * initialized with the data from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * @exception CertificateException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
    public final Collection<? extends Certificate> generateCertificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            (InputStream inStream) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
        return certFacSpi.engineGenerateCertificates(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * Generates a certificate revocation list (CRL) object and initializes it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     * with the data read from the input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * the returned CRL object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     * factory implements X.509 CRLs, the returned CRL object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
     * can be typecast to the <code>X509CRL</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
     * method consumes one CRL and the read position of the input stream
2589
af4853bc7e87 6827153: Miscellaneous typos in javadoc
martin
parents: 2
diff changeset
   481
     * is positioned to the next available byte after the inherent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * end-of-CRL marker. If the data in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
     * input stream does not contain an inherent end-of-CRL marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     * than EOF) and there is trailing data after the CRL is parsed, a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <code>CRLException</code> is thrown.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * @param inStream an input stream with the CRL data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * @return a CRL object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
    public final CRL generateCRL(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        throws CRLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        return certFacSpi.engineGenerateCRL(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
     * Returns a (possibly empty) collection view of the CRLs read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     * from the given input stream <code>inStream</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
     * factory implements X.509 CRLs, the elements in the returned
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     * collection can be typecast to the <code>X509CRL</code> class.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
     * <p>In the case of a certificate factory for X.509 CRLs,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
     * <code>inStream</code> may contain a sequence of DER-encoded CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
     * In addition, <code>inStream</code> may contain a PKCS#7 CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
     * set. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
     * significant field being <i>crls</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * CRLs to be downloaded at once. If no CRLs are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
     * @param inStream the input stream with the CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
     * java.security.cert.CRL objects initialized with the data from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * @exception CRLException on parsing errors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
    public final Collection<? extends CRL> generateCRLs(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        return certFacSpi.engineGenerateCRLs(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
}