jdk/src/java.base/share/classes/sun/security/provider/certpath/PKIXCertPathValidator.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 39465 8c06651d9138
child 44158 49deb8a1ed3f
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
     2
 * Copyright (c) 2000, 2017, 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: 4209
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: 4209
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: 4209
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4209
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4209
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.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    28
import java.io.IOException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.InvalidAlgorithmParameterException;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    30
import java.security.cert.*;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    31
import java.util.*;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    32
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    33
import sun.security.provider.certpath.PKIX.ValidatorParams;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    34
import sun.security.x509.X509CertImpl;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import sun.security.util.Debug;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * This class implements the PKIX validation algorithm for certification
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * paths consisting exclusively of <code>X509Certificates</code>. It uses
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * the specified input parameter set (which must be a
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    41
 * <code>PKIXParameters</code> object).
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * @since       1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * @author      Yassir Elley
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    46
public final class PKIXCertPathValidator extends CertPathValidatorSpi {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    private static final Debug debug = Debug.getInstance("certpath");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
     * Default constructor.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
    public PKIXCertPathValidator() {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    55
    @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    56
    public CertPathChecker engineGetRevocationChecker() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    57
        return new RevocationChecker();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    58
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    59
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
     * Validates a certification path consisting exclusively of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
     * <code>X509Certificate</code>s using the PKIX validation algorithm,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
     * which uses the specified input parameter set.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
     * The input parameter set must be a <code>PKIXParameters</code> object.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
     * @param cp the X509 certification path
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    67
     * @param params the input PKIX parameter set
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
     * @return the result
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    69
     * @throws CertPathValidatorException if cert path does not validate.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    70
     * @throws InvalidAlgorithmParameterException if the specified
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    71
     *         parameters are inappropriate for this CertPathValidator
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    73
    @Override
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    public CertPathValidatorResult engineValidate(CertPath cp,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    75
                                                  CertPathParameters params)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
        throws CertPathValidatorException, InvalidAlgorithmParameterException
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    78
        ValidatorParams valParams = PKIX.checkParams(cp, params);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    79
        return validate(valParams);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    80
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    81
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    82
    private static PKIXCertPathValidatorResult validate(ValidatorParams params)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    83
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    84
    {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        if (debug != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
            debug.println("PKIXCertPathValidator.engineValidate()...");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        // Retrieve the first certificate in the certpath
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        // (to be used later in pre-screening)
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    90
        AdaptableX509CertSelector selector = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    91
        List<X509Certificate> certList = params.certificates();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (!certList.isEmpty()) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    93
            selector = new AdaptableX509CertSelector();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    94
            X509Certificate firstCert = certList.get(0);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    95
            // check trusted certificate's subject
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    96
            selector.setSubject(firstCert.getIssuerX500Principal());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    97
            /*
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    98
             * Facilitate certification path construction with authority
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    99
             * key identifier and subject key identifier.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   100
             */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   101
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   102
                X509CertImpl firstCertImpl = X509CertImpl.toImpl(firstCert);
22977
f8f315760941 8025708: Certificate Path Building problem with AKI serial number
mullan
parents: 19045
diff changeset
   103
                selector.setSkiAndSerialNumber(
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   104
                            firstCertImpl.getAuthorityKeyIdentifierExtension());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   105
            } catch (CertificateException | IOException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   106
                // ignore
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   107
            }
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
        CertPathValidatorException lastException = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
        // We iterate through the set of trust anchors until we find
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        // one that works at which time we stop iterating
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   114
        for (TrustAnchor anchor : params.trustAnchors()) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
            X509Certificate trustedCert = anchor.getTrustedCert();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            if (trustedCert != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
                // if this trust anchor is not worth trying,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
                // we move on to the next one
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   119
                if (selector != null && !selector.match(trustedCert)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   120
                    if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   121
                        debug.println("NO - don't try this trustedCert");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   122
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
                    continue;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                if (debug != null) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   127
                    debug.println("YES - try this trustedCert");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
                    debug.println("anchor.getTrustedCert()."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
                        + "getSubjectX500Principal() = "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
                        + trustedCert.getSubjectX500Principal());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
                if (debug != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
                    debug.println("PKIXCertPathValidator.engineValidate(): "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                        + "anchor.getTrustedCert() == null");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   140
                return validate(anchor, params);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            } catch (CertPathValidatorException cpe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
                // remember this exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
                lastException = cpe;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        // could not find a trust anchor that verified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
        // (a) if we did a validation and it failed, use that exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
        if (lastException != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            throw lastException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
        // (b) otherwise, generate new exception
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
        throw new CertPathValidatorException
1238
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 2
diff changeset
   154
            ("Path does not chain with any of the trust anchors",
6d1f4b722acd 6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents: 2
diff changeset
   155
             null, null, -1, PKIXReason.NO_TRUST_ANCHOR);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   158
    private static PKIXCertPathValidatorResult validate(TrustAnchor anchor,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   159
                                                        ValidatorParams params)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   160
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   161
    {
31688
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   162
        // check if anchor is untrusted
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   163
        UntrustedChecker untrustedChecker = new UntrustedChecker();
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   164
        X509Certificate anchorCert = anchor.getTrustedCert();
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   165
        if (anchorCert != null) {
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   166
            untrustedChecker.check(anchorCert);
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   167
        }
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   168
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   169
        int certPathLen = params.certificates().size();
8163
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
   170
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   171
        // create PKIXCertPathCheckers
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   172
        List<PKIXCertPathChecker> certPathCheckers = new ArrayList<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   173
        // add standard checkers that we will be using
31688
42c9b194a469 8073894: Getting to the root of certificate chains
mullan
parents: 25859
diff changeset
   174
        certPathCheckers.add(untrustedChecker);
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   175
        if (params.timestamp() == null) {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   176
            certPathCheckers.add(new AlgorithmChecker(anchor, params.date(), null));
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   177
        } else {
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   178
            certPathCheckers.add(new AlgorithmChecker(null,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 39465
diff changeset
   179
                    params.timestamp(), params.variant()));
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   180
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   181
        certPathCheckers.add(new KeyChecker(certPathLen,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   182
                                            params.targetCertConstraints()));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   183
        certPathCheckers.add(new ConstraintsChecker(certPathLen));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   184
        PolicyNodeImpl rootNode =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   185
            new PolicyNodeImpl(null, PolicyChecker.ANY_POLICY, null, false,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   186
                               Collections.singleton(PolicyChecker.ANY_POLICY),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   187
                               false);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   188
        PolicyChecker pc = new PolicyChecker(params.initialPolicies(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   189
                                             certPathLen,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   190
                                             params.explicitPolicyRequired(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   191
                                             params.policyMappingInhibited(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   192
                                             params.anyPolicyInhibited(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   193
                                             params.policyQualifiersRejected(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   194
                                             rootNode);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   195
        certPathCheckers.add(pc);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   196
        // default value for date is current time
39465
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   197
        BasicChecker bc;
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   198
        if (params.timestamp() == null) {
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   199
            bc = new BasicChecker(anchor, params.date(), params.sigProvider(),
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   200
                    false);
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   201
        } else {
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   202
            bc = new BasicChecker(anchor, params.timestamp().getTimestamp(),
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   203
                    params.sigProvider(), false);
8c06651d9138 8154015: Apply algorithm constraints to timestamped code
ascarpino
parents: 38576
diff changeset
   204
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   205
        certPathCheckers.add(bc);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   207
        boolean revCheckerAdded = false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   208
        List<PKIXCertPathChecker> checkers = params.certPathCheckers();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   209
        for (PKIXCertPathChecker checker : checkers) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   210
            if (checker instanceof PKIXRevocationChecker) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   211
                if (revCheckerAdded) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   212
                    throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   213
                        "Only one PKIXRevocationChecker can be specified");
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   214
                }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   215
                revCheckerAdded = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   216
                // if it's our own, initialize it
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   217
                if (checker instanceof RevocationChecker) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   218
                    ((RevocationChecker)checker).init(anchor, params);
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 12861
diff changeset
   219
                }
8163
d9bcc1208691 7011497: new CertPathValidatorException.BasicReason enum constant for constrained algorithm
xuelei
parents: 7040
diff changeset
   220
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   222
        // only add a RevocationChecker if revocation is enabled and
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   223
        // a PKIXRevocationChecker has not already been added
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   224
        if (params.revocationEnabled() && !revCheckerAdded) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   225
            certPathCheckers.add(new RevocationChecker(anchor, params));
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   227
        // add user-specified checkers
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   228
        certPathCheckers.addAll(checkers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   230
        PKIXMasterCertPathValidator.validate(params.certPath(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   231
                                             params.certificates(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   232
                                             certPathCheckers);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   234
        return new PKIXCertPathValidatorResult(anchor, pc.getPolicyTree(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   235
                                               bc.getPublicKey());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
}