src/java.base/share/classes/java/security/cert/CertificateFactory.java
author jboes
Fri, 20 Sep 2019 11:07:52 +0100
changeset 58242 94bb65cb37d3
parent 47216 71c04702a3d5
permissions -rw-r--r--
8230648: Replace @exception tag with @throws in java.base Summary: Minor coding style update of javadoc tag in any file in java.base Reviewed-by: prappo, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
     2
 * Copyright (c) 1998, 2019, 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;
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
    32
import java.util.Objects;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.security.Provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.Security;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.security.NoSuchAlgorithmException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.NoSuchProviderException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import sun.security.jca.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import sun.security.jca.GetInstance.Instance;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * This class defines the functionality of a certificate factory, which is
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    43
 * used to generate certificate, certification path ({@code CertPath})
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * and certificate revocation list (CRL) objects from their encodings.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <p>For encodings consisting of multiple certificates, use
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    47
 * {@code generateCertificates} when you want to
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * parse a collection of possibly unrelated certificates. Otherwise,
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    49
 * use {@code generateCertPath} when you want to generate
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    50
 * a {@code CertPath} (a certificate chain) and subsequently
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    51
 * validate it with a {@code CertPathValidator}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>A certificate factory for X.509 must return certificates that are an
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    54
 * instance of {@code java.security.cert.X509Certificate}, and CRLs
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    55
 * that are an instance of {@code java.security.cert.X509CRL}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>The following example reads a file with Base64 encoded certificates,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * which are each bounded at the beginning by -----BEGIN CERTIFICATE-----, and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * bounded at the end by -----END CERTIFICATE-----. We convert the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    60
 * {@code FileInputStream} (which does not support {@code mark}
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    61
 * and {@code reset}) to a {@code BufferedInputStream} (which
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * supports those methods), so that each call to
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    63
 * {@code generateCertificate} consumes only one certificate, and the
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * read position of the input stream is positioned to the next certificate in
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18551
diff changeset
    65
 * the file:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
    67
 * <pre>{@code
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * FileInputStream fis = new FileInputStream(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * BufferedInputStream bis = new BufferedInputStream(fis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * CertificateFactory cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 * while (bis.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *    Certificate cert = cf.generateCertificate(bis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *    System.out.println(cert.toString());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 * }
18156
edb590d448c5 8016217: More javadoc warnings
alanb
parents: 9035
diff changeset
    77
 * }</pre>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * <p>The following example parses a PKCS#7-formatted certificate reply stored
21334
c60dfce46a77 8026982: javadoc errors in core libs
rriggs
parents: 18551
diff changeset
    80
 * in a file and extracts all the certificates from it:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * FileInputStream fis = new FileInputStream(filename);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 * CertificateFactory cf = CertificateFactory.getInstance("X.509");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * Collection c = cf.generateCertificates(fis);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 * Iterator i = c.iterator();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 * while (i.hasNext()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *    Certificate cert = (Certificate)i.next();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *    System.out.println(cert);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 * }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    93
 * <p> Every implementation of the Java platform is required to support the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    94
 * following standard {@code CertificateFactory} type:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    95
 * <ul>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    96
 * <li>{@code X.509}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    97
 * </ul>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
    98
 * and the following standard {@code CertPath} encodings:
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
    99
 * <ul>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   100
 * <li>{@code PKCS7}</li>
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   101
 * <li>{@code PkiPath}</li>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   102
 * </ul>
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   103
 * The type and encodings are described in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   104
 * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   105
 * CertificateFactory section</a> and the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   106
 * "{@docRoot}/../specs/security/standard-names.html#certpath-encodings">
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   107
 * CertPath Encodings section</a> of the
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   108
 * Java Security Standard Algorithm Names Specification.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   109
 * 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
   110
 * other types or encodings are supported.
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   111
 *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 * @author Hemma Prafullchandra
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 * @author Jan Luehe
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 * @author Sean Mullan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 * @see Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * @see X509Certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 * @see CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @see CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 * @see X509CRL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
public class CertificateFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    // The certificate type
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    private String type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    // The provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    private Provider provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    // The provider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
    private CertificateFactorySpi certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * Creates a CertificateFactory object of the given type, and encapsulates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * the given provider implementation (SPI object) in it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * @param certFacSpi the provider implementation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @param type the certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    protected CertificateFactory(CertificateFactorySpi certFacSpi,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
                                 Provider provider, String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        this.certFacSpi = certFacSpi;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        this.provider = provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        this.type = type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     * Returns a certificate factory object that implements the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * specified certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     * <p> This method traverses the list of registered security Providers,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * starting with the most preferred Provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     * A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * CertificateFactorySpi implementation from the first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * Provider that supports the specified type is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     *
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   165
     * @implNote
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   166
     * The JDK Reference Implementation additionally uses the
37348
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   167
     * {@code jdk.security.provider.preferred}
9ccec3170d5e 8152205: jdk.security.provider.preferred is ambiguously documented
ascarpino
parents: 33241
diff changeset
   168
     * {@link Security#getProperty(String) Security} property to determine
33241
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   169
     * the preferred provider order for the specified algorithm. This
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   170
     * may be different than the order of providers returned by
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   171
     * {@link Security#getProviders() Security.getProviders()}.
27eb2d6abda9 8133151: Preferred provider configuration for JCE
ascarpino
parents: 25859
diff changeset
   172
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * @param type the name of the requested certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   174
     * See the CertificateFactory section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   175
     * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   176
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   179
     * @return a certificate factory object for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   181
     * @throws CertificateException if no {@code Provider} supports a
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   182
     *         {@code CertificateFactorySpi} implementation for the
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   183
     *         specified type
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   184
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   185
     * @throws NullPointerException if {@code type} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
    public static final CertificateFactory getInstance(String type)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
            throws CertificateException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   191
        Objects.requireNonNull(type, "null type name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                CertificateFactorySpi.class, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     * CertificateFactorySpi implementation from the specified provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * is returned.  The specified provider must be registered
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     * in the security provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * <p> Note that the list of registered providers may be retrieved via
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the {@link Security#getProviders() Security.getProviders()} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * @param type the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   215
     * See the CertificateFactory section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   216
     * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   217
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @param provider the name of the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   222
     * @return a certificate factory object for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   224
     * @throws CertificateException if a {@code CertificateFactorySpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   225
     *         implementation for the specified algorithm is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   226
     *         available from the specified provider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   228
     * @throws IllegalArgumentException if the provider name is {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   229
     *         or empty
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   231
     * @throws NoSuchProviderException if the specified provider is not
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   232
     *         registered in the security provider list
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   233
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   234
     * @throws NullPointerException if {@code type} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
            String provider) throws CertificateException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
            NoSuchProviderException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   241
        Objects.requireNonNull(type, "null type name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * Returns a certificate factory object for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     * certificate type.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
     * <p> A new CertificateFactory object encapsulating the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
     * CertificateFactorySpi implementation from the specified Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * object is returned.  Note that the specified Provider object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * does not have to be registered in the provider list.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * @param type the certificate type.
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   262
     * See the CertificateFactory section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   263
     * "{@docRoot}/../specs/security/standard-names.html#certificatefactory-types">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   264
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * for information about standard certificate types.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * @param provider the provider.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   268
     * @return a certificate factory object for the specified type
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   270
     * @throws CertificateException if a {@code CertificateFactorySpi}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   271
     *         implementation for the specified algorithm is not available
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   272
     *         from the specified {@code Provider} object
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     *
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   274
     * @throws IllegalArgumentException if the {@code provider} is
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   275
     *         {@code null}
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   276
     *
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   277
     * @throws NullPointerException if {@code type} is {@code null}
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * @see java.security.Provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
    public static final CertificateFactory getInstance(String type,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
            Provider provider) throws CertificateException {
41826
b35ee9b35b09 4985694: Incomplete spec for most of the getInstances
wetmore
parents: 37348
diff changeset
   285
        Objects.requireNonNull(type, "null type name");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
            Instance instance = GetInstance.getInstance("CertificateFactory",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                CertificateFactorySpi.class, type, provider);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            return new CertificateFactory((CertificateFactorySpi)instance.impl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                instance.provider, type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        } catch (NoSuchAlgorithmException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            throw new CertificateException(type + " not found", e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
     * Returns the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * @return the provider of this certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public final Provider getProvider() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        return this.provider;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Returns the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     * @return the name of the certificate type associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
     * certificate factory.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
    public final String getType() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
        return this.type;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
     * Generates a certificate object and initializes it with
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   318
     * the data read from the input stream {@code inStream}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
     * the returned certificate object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
     * factory implements X.509 certificates, the returned certificate object
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   325
     * can be typecast to the {@code X509Certificate} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
     * <p>In the case of a certificate factory for X.509 certificates, the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   328
     * certificate provided in {@code inStream} must be DER-encoded and
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
     * may be supplied in binary or printable (Base64) encoding. If the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
     * certificate is provided in Base64 encoding, it must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
     * the beginning by -----BEGIN CERTIFICATE-----, and must be bounded at
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * the end by -----END CERTIFICATE-----.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * method consumes one certificate and the read position of the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     * input stream is positioned to the next available byte after
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
     * the inherent end-of-certificate marker. If the data in the input stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
     * does not contain an inherent end-of-certificate marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
     * than EOF) and there is trailing data after the certificate is parsed, a
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   343
     * {@code CertificateException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
     * @param inStream an input stream with the certificate data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
     * @return a certificate object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   350
     * @throws    CertificateException on parsing errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
    public final Certificate generateCertificate(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
        return certFacSpi.engineGenerateCertificate(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   359
     * Returns an iteration of the {@code CertPath} encodings supported
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
     * 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
   361
     * the CertPath Encodings section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   362
     * "{@docRoot}/../specs/security/standard-names.html#certpath-encodings">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   363
     * Java Security Standard Algorithm Names Specification</a>
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   364
     * for information about standard encoding names and their formats.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
     * <p>
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   366
     * Attempts to modify the returned {@code Iterator} via its
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   367
     * {@code remove} method result in an
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   368
     * {@code UnsupportedOperationException}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   370
     * @return an {@code Iterator} over the names of the supported
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   371
     *         {@code CertPath} encodings (as {@code String}s)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
    public final Iterator<String> getCertPathEncodings() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
        return(certFacSpi.engineGetCertPathEncodings());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   379
     * Generates a {@code CertPath} object and initializes it with
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   380
     * the data read from the {@code InputStream} inStream. The data
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
     * is assumed to be in the default encoding. The name of the default
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   382
     * encoding is the first element of the {@code Iterator} returned by
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
     * the {@link #getCertPathEncodings getCertPathEncodings} method.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   385
     * @param inStream an {@code InputStream} containing the data
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   386
     * @return a {@code CertPath} initialized with the data from the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   387
     *   {@code InputStream}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   388
     * @throws    CertificateException if an exception occurs while decoding
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
    public final CertPath generateCertPath(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
        return(certFacSpi.engineGenerateCertPath(inStream));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   398
     * Generates a {@code CertPath} object and initializes it with
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   399
     * the data read from the {@code InputStream} inStream. The data
8152
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   400
     * is assumed to be in the specified encoding. See
94e5966bdf22 5001004: Required Security Algorithms need to be defined
mullan
parents: 5506
diff changeset
   401
     * the CertPath Encodings section in the <a href=
45118
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   402
     * "{@docRoot}/../specs/security/standard-names.html#certpath-encodings">
e4258d800b54 8178278: Move Standard Algorithm Names document to specs directory
ihse
parents: 41826
diff changeset
   403
     * Java Security Standard Algorithm Names Specification</a>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
     * for information about standard encoding names and their formats.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   406
     * @param inStream an {@code InputStream} containing the data
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
     * @param encoding the encoding used for the data
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   408
     * @return a {@code CertPath} initialized with the data from the
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   409
     *   {@code InputStream}
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   410
     * @throws    CertificateException if an exception occurs while decoding or
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
     *   the encoding requested is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
    public final CertPath generateCertPath(InputStream inStream,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
        String encoding) throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
        return(certFacSpi.engineGenerateCertPath(inStream, encoding));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
    /**
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   421
     * Generates a {@code CertPath} object and initializes it with
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   422
     * a {@code List} of {@code Certificate}s.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
     * The certificates supplied must be of a type supported by the
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   425
     * {@code CertificateFactory}. They will be copied out of the supplied
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   426
     * {@code List} object.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
     *
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   428
     * @param certificates a {@code List} of {@code Certificate}s
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   429
     * @return a {@code CertPath} initialized with the supplied list of
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
     *   certificates
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   431
     * @throws    CertificateException if an exception occurs
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
    public final CertPath
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
        generateCertPath(List<? extends Certificate> certificates)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        throws CertificateException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
        return(certFacSpi.engineGenerateCertPath(certificates));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
     * Returns a (possibly empty) collection view of the certificates read
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   443
     * from the given input stream {@code inStream}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * <p>In order to take advantage of the specialized certificate format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     * certificate class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * factory implements X.509 certificates, the elements in the returned
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   450
     * collection can be typecast to the {@code X509Certificate} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
     * <p>In the case of a certificate factory for X.509 certificates,
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   453
     * {@code inStream} may contain a sequence of DER-encoded certificates
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
     * in the formats described for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
     * {@link #generateCertificate(java.io.InputStream) generateCertificate}.
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   456
     * In addition, {@code inStream} may contain a PKCS#7 certificate
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
     * chain. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
     * significant field being <i>certificates</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
     * certificates to be downloaded at once. If no certificates are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
     * @param inStream the input stream with the certificates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * java.security.cert.Certificate objects
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     * initialized with the data from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   474
     * @throws    CertificateException on parsing errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
    public final Collection<? extends Certificate> generateCertificates
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
            (InputStream inStream) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
        return certFacSpi.engineGenerateCertificates(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
     * Generates a certificate revocation list (CRL) object and initializes it
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   483
     * with the data read from the input stream {@code inStream}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
     * supported by this certificate factory,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
     * the returned CRL object can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * factory implements X.509 CRLs, the returned CRL object
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   490
     * can be typecast to the {@code X509CRL} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
     * consume the entire input stream. Otherwise, each call to this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
     * method consumes one CRL and the read position of the input stream
2589
af4853bc7e87 6827153: Miscellaneous typos in javadoc
martin
parents: 2
diff changeset
   497
     * is positioned to the next available byte after the inherent
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
     * end-of-CRL marker. If the data in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
     * input stream does not contain an inherent end-of-CRL marker (other
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
     * than EOF) and there is trailing data after the CRL is parsed, a
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   501
     * {@code CRLException} is thrown.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
     * @param inStream an input stream with the CRL data.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
     * @return a CRL object initialized with the data
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
     * from the input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   508
     * @throws    CRLException on parsing errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
    public final CRL generateCRL(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
        throws CRLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        return certFacSpi.engineGenerateCRL(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * Returns a (possibly empty) collection view of the CRLs read
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   518
     * from the given input stream {@code inStream}.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
     * <p>In order to take advantage of the specialized CRL format
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
     * supported by this certificate factory, each element in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
     * the returned collection view can be typecast to the corresponding
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
     * CRL class. For example, if this certificate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
     * factory implements X.509 CRLs, the elements in the returned
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   525
     * collection can be typecast to the {@code X509CRL} class.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
     * <p>In the case of a certificate factory for X.509 CRLs,
18551
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   528
     * {@code inStream} may contain a sequence of DER-encoded CRLs.
882a3948c6e6 8017325: Cleanup of the javadoc <code> tag in java.security.cert
juh
parents: 18156
diff changeset
   529
     * In addition, {@code inStream} may contain a PKCS#7 CRL
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
     * set. This is a PKCS#7 <i>SignedData</i> object, with the only
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
     * significant field being <i>crls</i>. In particular, the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
     * signature and the contents are ignored. This format allows multiple
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
     * CRLs to be downloaded at once. If no CRLs are present,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
     * an empty collection is returned.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
     * <p>Note that if the given input stream does not support
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
     * {@link java.io.InputStream#mark(int) mark} and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
     * {@link java.io.InputStream#reset() reset}, this method will
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
     * consume the entire input stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
     * @param inStream the input stream with the CRLs.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
     * @return a (possibly empty) collection view of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
     * java.security.cert.CRL objects initialized with the data from the input
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
     * stream.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
     *
58242
94bb65cb37d3 8230648: Replace @exception tag with @throws in java.base
jboes
parents: 47216
diff changeset
   547
     * @throws    CRLException on parsing errors.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    public final Collection<? extends CRL> generateCRLs(InputStream inStream)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            throws CRLException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        return certFacSpi.engineGenerateCRLs(inStream);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
}