jdk/src/java.base/share/classes/sun/security/validator/Validator.java
author martin
Tue, 15 Sep 2015 21:56:04 -0700
changeset 32649 2ee9017c7597
parent 32032 22badc53802f
child 39465 8c06651d9138
permissions -rw-r--r--
8136583: Core libraries should use blessed modifier order Summary: Run blessed-modifier-order script (see bug) Reviewed-by: psandoz, chegar, alanb, plevart
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
29901
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
     2
 * Copyright (c) 2002, 2015, 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: 2
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: 2
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: 2
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 2
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 sun.security.validator;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    30
import java.security.AlgorithmConstraints;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.security.KeyStore;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * Validator abstract base class. Concrete classes are instantiated by calling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * one of the getInstance() methods. All methods defined in this class
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * must be safe for concurrent use by multiple threads.<p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * The model is that a Validator instance is created specifying validation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * settings, such as trust anchors or PKIX parameters. Then one or more
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * paths are validated using those parameters. In some cases, additional
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * information can be provided per path validation. This is independent of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * the validation parameters and currently only used for TLS server validation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * Path validation is performed by calling one of the validate() methods. It
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * specifies a suggested path to be used for validation if available, or only
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * the end entity certificate otherwise. Optionally additional certificates can
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * be specified that the caller believes could be helpful. Implementations are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * free to make use of this information or validate the path using other means.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 * validate() also checks that the end entity certificate is suitable for the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * intended purpose as described below.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * <p>There are two orthogonal parameters to select the Validator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * implementation: type and variant. Type selects the validation algorithm.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * Currently supported are TYPE_SIMPLE and TYPE_PKIX. See SimpleValidator and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * PKIXValidator for details.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * Variant controls additional extension checks. Currently supported are
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * five variants:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * <ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <li>VAR_GENERIC (no additional checks),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * <li>VAR_TLS_CLIENT (TLS client specific checks)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * <li>VAR_TLS_SERVER (TLS server specific checks), and
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <li>VAR_CODE_SIGNING (code signing specific checks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <li>VAR_JCE_SIGNING (JCE code signing specific checks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * <li>VAR_TSA_SERVER (TSA server specific checks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * <li>VAR_PLUGIN_CODE_SIGNING (Plugin/WebStart code signing specific checks).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * </ul>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 * See EndEntityChecker for more information.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 * Examples:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *   // instantiate validator specifying type, variant, and trust anchors
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *   Validator validator = Validator.getInstance(Validator.TYPE_PKIX,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *                                               Validator.VAR_TLS_CLIENT,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *                                               trustedCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *   // validate one or more chains using the validator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *   validator.validate(chain); // throws CertificateException if failed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 * @see SimpleValidator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 * @see PKIXValidator
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 * @see EndEntityChecker
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 * @author Andreas Sterbenz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
public abstract class Validator {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
    89
    static final X509Certificate[] CHAIN0 = {};
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * Constant for a validator of type Simple.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
    95
    public static final String TYPE_SIMPLE = "Simple";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * Constant for a validator of type PKIX.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   101
    public static final String TYPE_PKIX = "PKIX";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     * Constant for a Generic variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   107
    public static final String VAR_GENERIC = "generic";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     * Constant for a Code Signing variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   113
    public static final String VAR_CODE_SIGNING = "code signing";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     * Constant for a JCE Code Signing variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   119
    public static final String VAR_JCE_SIGNING = "jce signing";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
     * Constant for a TLS Client variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   125
    public static final String VAR_TLS_CLIENT = "tls client";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
     * Constant for a TLS Server variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   131
    public static final String VAR_TLS_SERVER = "tls server";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * Constant for a TSA Server variant of a validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   137
    public static final String VAR_TSA_SERVER = "tsa server";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * Constant for a Code Signing variant of a validator for use by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * the J2SE Plugin/WebStart code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * @see #getInstance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   144
    public static final String VAR_PLUGIN_CODE_SIGNING = "plugin code signing";
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
29901
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   146
    private final String type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    final EndEntityChecker endEntityChecker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    final String variant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     * @see #setValidationDate
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
    volatile Date validationDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
    Validator(String type, String variant) {
29901
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   158
        this.type = type;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
        this.variant = variant;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
        endEntityChecker = EndEntityChecker.getInstance(type, variant);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
     * Get a new Validator instance using the trusted certificates from the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
     * specified KeyStore as trust anchors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
    public static Validator getInstance(String type, String variant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            KeyStore ks) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        return getInstance(type, variant, KeyStores.getTrustedCerts(ks));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
     * Get a new Validator instance using the Set of X509Certificates as trust
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
     * anchors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    public static Validator getInstance(String type, String variant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            Collection<X509Certificate> trustedCerts) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
        if (type.equals(TYPE_SIMPLE)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
            return new SimpleValidator(variant, trustedCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
        } else if (type.equals(TYPE_PKIX)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
            return new PKIXValidator(variant, trustedCerts);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
                ("Unknown validator type: " + type);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
     * Get a new Validator instance using the provided PKIXBuilderParameters.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
     * This method can only be used with the PKIX validator.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
    public static Validator getInstance(String type, String variant,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            PKIXBuilderParameters params) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
        if (type.equals(TYPE_PKIX) == false) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            throw new IllegalArgumentException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
                ("getInstance(PKIXBuilderParameters) can only be used "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
                + "with PKIX validator");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
        return new PKIXValidator(variant, params);
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
     * Validate the given certificate chain.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    public final X509Certificate[] validate(X509Certificate[] chain)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
            throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return validate(chain, null, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * Validate the given certificate chain. If otherCerts is non-null, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * a Collection of additional X509Certificates that could be helpful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * path building.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
    public final X509Certificate[] validate(X509Certificate[] chain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        Collection<X509Certificate> otherCerts) throws CertificateException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        return validate(chain, otherCerts, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     * Validate the given certificate chain. If otherCerts is non-null, it is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
     * a Collection of additional X509Certificates that could be helpful for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
     * path building.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
     * Parameter is an additional parameter with variant specific meaning.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
     * Currently, it is only defined for TLS_SERVER variant validators, where
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
     * it must be non null and the name of the TLS key exchange algorithm being
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * used (see JSSE X509TrustManager specification). In the future, it
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     * could be used to pass in a PKCS#7 object for code signing to check time
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * stamps.
30374
2abaf49910ea 8079478: some docs cleanup for sun.security
avstepan
parents: 29901
diff changeset
   231
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
     * @return a non-empty chain that was used to validate the path. The
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
     * end entity cert is at index 0, the trust anchor at index n-1.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
    public final X509Certificate[] validate(X509Certificate[] chain,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            Collection<X509Certificate> otherCerts, Object parameter)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
            throws CertificateException {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   238
        return validate(chain, otherCerts, Collections.emptyList(), null,
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   239
                parameter);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   240
    }
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   241
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   242
    /**
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   243
     * Validate the given certificate chain.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   244
     *
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   245
     * @param chain the target certificate chain
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   246
     * @param otherCerts a Collection of additional X509Certificates that
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   247
     *        could be helpful for path building (or null)
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   248
     * @param responseList a List of zero or more byte arrays, each
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   249
     *        one being a DER-encoded OCSP response (per RFC 6960).  Entries
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   250
     *        in the List must match the order of the certificates in the
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   251
     *        chain parameter.  It is possible that fewer responses may be
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   252
     *        in the list than are elements in {@code chain} and a missing
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   253
     *        response for a matching element in {@code chain} can be
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   254
     *        represented with a zero-length byte array.
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   255
     * @param constraints algorithm constraints for certification path
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   256
     *        processing
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   257
     * @param parameter an additional parameter with variant specific meaning.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   258
     *        Currently, it is only defined for TLS_SERVER variant validators,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   259
     *        where it must be non null and the name of the TLS key exchange
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   260
     *        algorithm being used (see JSSE X509TrustManager specification).
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   261
     *        In the future, it could be used to pass in a PKCS#7 object for
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   262
     *        code signing to check time stamps.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   263
     * @return a non-empty chain that was used to validate the path. The
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   264
     *        end entity cert is at index 0, the trust anchor at index n-1.
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   265
     */
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   266
    public final X509Certificate[] validate(X509Certificate[] chain,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   267
                Collection<X509Certificate> otherCerts,
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   268
                List<byte[]> responseList,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   269
                AlgorithmConstraints constraints,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   270
                Object parameter) throws CertificateException {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   271
        chain = engineValidate(chain, otherCerts, responseList, constraints,
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   272
                parameter);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   273
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
        // omit EE extension check if EE cert is also trust anchor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        if (chain.length > 1) {
29901
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   276
            // EndEntityChecker does not need to check unresolved critical
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   277
            // extensions when validating with a TYPE_PKIX Validator.
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   278
            // A TYPE_PKIX Validator will already have run checks on all
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   279
            // certs' extensions, including checks by any PKIXCertPathCheckers
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   280
            // included in the PKIXParameters, so the extra checks would be
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   281
            // redundant.
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   282
            boolean checkUnresolvedCritExts =
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   283
                    (type == TYPE_PKIX) ? false : true;
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   284
            endEntityChecker.check(chain[0], parameter,
7288f904fbe8 8076117: EndEntityChecker should not process custom extensions after PKIX validation
juh
parents: 25859
diff changeset
   285
                                   checkUnresolvedCritExts);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
        }
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        return chain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
    abstract X509Certificate[] engineValidate(X509Certificate[] chain,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   292
                Collection<X509Certificate> otherCerts,
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 30374
diff changeset
   293
                List<byte[]> responseList,
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   294
                AlgorithmConstraints constraints,
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   295
                Object parameter) throws CertificateException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
     * Returns an immutable Collection of the X509Certificates this instance
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
     * uses as trust anchors.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
    public abstract Collection<X509Certificate> getTrustedCertificates();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
     * Set the date to be used for subsequent validations. NOTE that
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
     * this is not a supported API, it is provided to simplify
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * writing tests only.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
     * @deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
    @Deprecated
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
    public void setValidationDate(Date validationDate) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        this.validationDate = validationDate;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
}