jdk/src/java.base/share/classes/sun/security/provider/certpath/RevocationChecker.java
author mullan
Thu, 06 Apr 2017 16:21:05 -0400
changeset 44479 9669aa3c7bcb
parent 43701 fe8c324ba97c
permissions -rw-r--r--
8161973: PKIXRevocationChecker.getSoftFailExceptions() not working Reviewed-by: xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41974
diff changeset
     2
 * Copyright (c) 2012, 2017, Oracle and/or its affiliates. All rights reserved.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     4
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    10
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    15
 * accompanied this code).
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    16
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    20
 *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    23
 * questions.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    24
 */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    25
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    26
package sun.security.provider.certpath;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    27
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    28
import java.io.IOException;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    29
import java.math.BigInteger;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    30
import java.net.URI;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    31
import java.net.URISyntaxException;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    32
import java.security.AccessController;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    33
import java.security.InvalidAlgorithmParameterException;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    34
import java.security.NoSuchAlgorithmException;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    35
import java.security.PrivilegedAction;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    36
import java.security.PublicKey;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    37
import java.security.Security;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    38
import java.security.cert.CertPathValidatorException.BasicReason;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    39
import java.security.cert.Extension;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    40
import java.security.cert.*;
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
    41
import java.util.*;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    42
import javax.security.auth.x500.X500Principal;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    43
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    44
import static sun.security.provider.certpath.OCSP.*;
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
    45
import static sun.security.provider.certpath.PKIX.*;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    46
import sun.security.x509.*;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    47
import static sun.security.x509.PKIXExtensions.*;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    48
import sun.security.util.Debug;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    49
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    50
class RevocationChecker extends PKIXRevocationChecker {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    51
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    52
    private static final Debug debug = Debug.getInstance("certpath");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    53
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    54
    private TrustAnchor anchor;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    55
    private ValidatorParams params;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    56
    private boolean onlyEE;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    57
    private boolean softFail;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    58
    private boolean crlDP;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    59
    private URI responderURI;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    60
    private X509Certificate responderCert;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    61
    private List<CertStore> certStores;
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 13806
diff changeset
    62
    private Map<X509Certificate, byte[]> ocspResponses;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    63
    private List<Extension> ocspExtensions;
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
    64
    private final boolean legacy;
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
    65
    private LinkedList<CertPathValidatorException> softFailExceptions =
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
    66
        new LinkedList<>();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    67
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    68
    // state variables
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
    69
    private OCSPResponse.IssuerInfo issuerInfo;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    70
    private PublicKey prevPubKey;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    71
    private boolean crlSignFlag;
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
    72
    private int certIndex;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    73
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
    74
    private enum Mode { PREFER_OCSP, PREFER_CRLS, ONLY_CRLS, ONLY_OCSP };
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    75
    private Mode mode = Mode.PREFER_OCSP;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    76
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    77
    private static class RevocationProperties {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    78
        boolean onlyEE;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    79
        boolean ocspEnabled;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    80
        boolean crlDPEnabled;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    81
        String ocspUrl;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    82
        String ocspSubject;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    83
        String ocspIssuer;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    84
        String ocspSerial;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    85
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    86
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    87
    RevocationChecker() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    88
        legacy = false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    89
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    90
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    91
    RevocationChecker(TrustAnchor anchor, ValidatorParams params)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    92
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    93
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    94
        legacy = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    95
        init(anchor, params);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    96
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    97
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    98
    void init(TrustAnchor anchor, ValidatorParams params)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
    99
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   100
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   101
        RevocationProperties rp = getRevocationProperties();
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   102
        URI uri = getOcspResponder();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   103
        responderURI = (uri == null) ? toURI(rp.ocspUrl) : uri;
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   104
        X509Certificate cert = getOcspResponderCert();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   105
        responderCert = (cert == null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   106
                        ? getResponderCert(rp, params.trustAnchors(),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   107
                                           params.certStores())
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   108
                        : cert;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   109
        Set<Option> options = getOptions();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   110
        for (Option option : options) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   111
            switch (option) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   112
            case ONLY_END_ENTITY:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   113
            case PREFER_CRLS:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   114
            case SOFT_FAIL:
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   115
            case NO_FALLBACK:
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   116
                break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   117
            default:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   118
                throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   119
                    "Unrecognized revocation parameter option: " + option);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   120
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   121
        }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   122
        softFail = options.contains(Option.SOFT_FAIL);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   123
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   124
        // set mode, only end entity flag
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   125
        if (legacy) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   126
            mode = (rp.ocspEnabled) ? Mode.PREFER_OCSP : Mode.ONLY_CRLS;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   127
            onlyEE = rp.onlyEE;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   128
        } else {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   129
            if (options.contains(Option.NO_FALLBACK)) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   130
                if (options.contains(Option.PREFER_CRLS)) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   131
                    mode = Mode.ONLY_CRLS;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   132
                } else {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   133
                    mode = Mode.ONLY_OCSP;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   134
                }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   135
            } else if (options.contains(Option.PREFER_CRLS)) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   136
                mode = Mode.PREFER_CRLS;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   137
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   138
            onlyEE = options.contains(Option.ONLY_END_ENTITY);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   139
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   140
        if (legacy) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   141
            crlDP = rp.crlDPEnabled;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   142
        } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   143
            crlDP = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   144
        }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   145
        ocspResponses = getOcspResponses();
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   146
        ocspExtensions = getOcspExtensions();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   147
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   148
        this.anchor = anchor;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   149
        this.params = params;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   150
        this.certStores = new ArrayList<>(params.certStores());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   151
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   152
            this.certStores.add(CertStore.getInstance("Collection",
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   153
                new CollectionCertStoreParameters(params.certificates())));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   154
        } catch (InvalidAlgorithmParameterException |
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   155
                 NoSuchAlgorithmException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   156
            // should never occur but not necessarily fatal, so log it,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   157
            // ignore and continue
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   158
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   159
                debug.println("RevocationChecker: " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   160
                              "error creating Collection CertStore: " + e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   161
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   162
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   163
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   164
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   165
    private static URI toURI(String uriString)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   166
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   167
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   168
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   169
            if (uriString != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   170
                return new URI(uriString);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   171
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   172
            return null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   173
        } catch (URISyntaxException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   174
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   175
                "cannot parse ocsp.responderURL property", e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   176
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   177
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   178
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   179
    private static RevocationProperties getRevocationProperties() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   180
        return AccessController.doPrivileged(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   181
            new PrivilegedAction<RevocationProperties>() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   182
                public RevocationProperties run() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   183
                    RevocationProperties rp = new RevocationProperties();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   184
                    String onlyEE = Security.getProperty(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   185
                        "com.sun.security.onlyCheckRevocationOfEECert");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   186
                    rp.onlyEE = onlyEE != null
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   187
                                && onlyEE.equalsIgnoreCase("true");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   188
                    String ocspEnabled = Security.getProperty("ocsp.enable");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   189
                    rp.ocspEnabled = ocspEnabled != null
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   190
                                     && ocspEnabled.equalsIgnoreCase("true");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   191
                    rp.ocspUrl = Security.getProperty("ocsp.responderURL");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   192
                    rp.ocspSubject
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   193
                        = Security.getProperty("ocsp.responderCertSubjectName");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   194
                    rp.ocspIssuer
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   195
                        = Security.getProperty("ocsp.responderCertIssuerName");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   196
                    rp.ocspSerial
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   197
                        = Security.getProperty("ocsp.responderCertSerialNumber");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   198
                    rp.crlDPEnabled
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   199
                        = Boolean.getBoolean("com.sun.security.enableCRLDP");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   200
                    return rp;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   201
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   202
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   203
        );
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   204
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   205
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   206
    private static X509Certificate getResponderCert(RevocationProperties rp,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   207
                                                    Set<TrustAnchor> anchors,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   208
                                                    List<CertStore> stores)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   209
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   210
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   211
        if (rp.ocspSubject != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   212
            return getResponderCert(rp.ocspSubject, anchors, stores);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   213
        } else if (rp.ocspIssuer != null && rp.ocspSerial != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   214
            return getResponderCert(rp.ocspIssuer, rp.ocspSerial,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   215
                                    anchors, stores);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   216
        } else if (rp.ocspIssuer != null || rp.ocspSerial != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   217
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   218
                "Must specify both ocsp.responderCertIssuerName and " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   219
                "ocsp.responderCertSerialNumber properties");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   220
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   221
        return null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   222
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   223
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   224
    private static X509Certificate getResponderCert(String subject,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   225
                                                    Set<TrustAnchor> anchors,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   226
                                                    List<CertStore> stores)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   227
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   228
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   229
        X509CertSelector sel = new X509CertSelector();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   230
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   231
            sel.setSubject(new X500Principal(subject));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   232
        } catch (IllegalArgumentException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   233
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   234
                "cannot parse ocsp.responderCertSubjectName property", e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   235
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   236
        return getResponderCert(sel, anchors, stores);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   237
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   238
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   239
    private static X509Certificate getResponderCert(String issuer,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   240
                                                    String serial,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   241
                                                    Set<TrustAnchor> anchors,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   242
                                                    List<CertStore> stores)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   243
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   244
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   245
        X509CertSelector sel = new X509CertSelector();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   246
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   247
            sel.setIssuer(new X500Principal(issuer));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   248
        } catch (IllegalArgumentException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   249
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   250
                "cannot parse ocsp.responderCertIssuerName property", e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   251
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   252
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   253
            sel.setSerialNumber(new BigInteger(stripOutSeparators(serial), 16));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   254
        } catch (NumberFormatException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   255
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   256
                "cannot parse ocsp.responderCertSerialNumber property", e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   257
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   258
        return getResponderCert(sel, anchors, stores);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   259
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   260
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   261
    private static X509Certificate getResponderCert(X509CertSelector sel,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   262
                                                    Set<TrustAnchor> anchors,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   263
                                                    List<CertStore> stores)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   264
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   265
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   266
        // first check TrustAnchors
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   267
        for (TrustAnchor anchor : anchors) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   268
            X509Certificate cert = anchor.getTrustedCert();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   269
            if (cert == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   270
                continue;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   271
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   272
            if (sel.match(cert)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   273
                return cert;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   274
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   275
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   276
        // now check CertStores
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   277
        for (CertStore store : stores) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   278
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   279
                Collection<? extends Certificate> certs =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   280
                    store.getCertificates(sel);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   281
                if (!certs.isEmpty()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   282
                    return (X509Certificate)certs.iterator().next();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   283
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   284
            } catch (CertStoreException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   285
                // ignore and try next CertStore
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   286
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   287
                    debug.println("CertStore exception:" + e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   288
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   289
                continue;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   290
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   291
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   292
        throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   293
            "Cannot find the responder's certificate " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   294
            "(set using the OCSP security properties).");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   295
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   296
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   297
    @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   298
    public void init(boolean forward) throws CertPathValidatorException {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   299
        if (forward) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   300
            throw new
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   301
                CertPathValidatorException("forward checking not supported");
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   302
        }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   303
        if (anchor != null) {
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   304
            issuerInfo = new OCSPResponse.IssuerInfo(anchor);
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   305
            prevPubKey = issuerInfo.getPublicKey();
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   306
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   307
        }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   308
        crlSignFlag = true;
21329
c8ed09765b9a 8025287: NPE in api/java_security/cert/PKIXRevocationChecker/GeneralTests_GeneralTests
juh
parents: 19046
diff changeset
   309
        if (params != null && params.certPath() != null) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   310
            certIndex = params.certPath().getCertificates().size() - 1;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   311
        } else {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   312
            certIndex = -1;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   313
        }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   314
        softFailExceptions.clear();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   315
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   316
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   317
    @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   318
    public boolean isForwardCheckingSupported() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   319
        return false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   320
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   321
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   322
    @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   323
    public Set<String> getSupportedExtensions() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   324
        return null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   325
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   326
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   327
    @Override
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   328
    public List<CertPathValidatorException> getSoftFailExceptions() {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   329
        return Collections.unmodifiableList(softFailExceptions);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   330
    }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   331
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   332
    @Override
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   333
    public void check(Certificate cert, Collection<String> unresolvedCritExts)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   334
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   335
    {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   336
        check((X509Certificate)cert, unresolvedCritExts,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   337
              prevPubKey, crlSignFlag);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   338
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   339
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   340
    private void check(X509Certificate xcert,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   341
                       Collection<String> unresolvedCritExts,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   342
                       PublicKey pubKey, boolean crlSignFlag)
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   343
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   344
    {
29264
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   345
        if (debug != null) {
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   346
            debug.println("RevocationChecker.check: checking cert" +
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   347
                "\n  SN: " + Debug.toHexString(xcert.getSerialNumber()) +
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   348
                "\n  Subject: " + xcert.getSubjectX500Principal() +
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   349
                "\n  Issuer: " + xcert.getIssuerX500Principal());
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   350
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   351
        try {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   352
            if (onlyEE && xcert.getBasicConstraints() != -1) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   353
                if (debug != null) {
29264
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   354
                    debug.println("Skipping revocation check; cert is not " +
5172066a2da6 8054037: Improve tracing for java.security.debug=certpath
juh
parents: 26967
diff changeset
   355
                                  "an end entity cert");
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   356
                }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   357
                return;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   358
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   359
            switch (mode) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   360
                case PREFER_OCSP:
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   361
                case ONLY_OCSP:
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   362
                    checkOCSP(xcert, unresolvedCritExts);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   363
                    break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   364
                case PREFER_CRLS:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   365
                case ONLY_CRLS:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   366
                    checkCRLs(xcert, unresolvedCritExts, null,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   367
                              pubKey, crlSignFlag);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   368
                    break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   369
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   370
        } catch (CertPathValidatorException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   371
            if (e.getReason() == BasicReason.REVOKED) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   372
                throw e;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   373
            }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   374
            boolean eSoftFail = isSoftFailException(e);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   375
            if (eSoftFail) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   376
                if (mode == Mode.ONLY_OCSP || mode == Mode.ONLY_CRLS) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   377
                    return;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   378
                }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   379
            } else {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   380
                if (mode == Mode.ONLY_OCSP || mode == Mode.ONLY_CRLS) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   381
                    throw e;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   382
                }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   383
            }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   384
            CertPathValidatorException cause = e;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   385
            // Otherwise, failover
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   386
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   387
                debug.println("RevocationChecker.check() " + e.getMessage());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   388
                debug.println("RevocationChecker.check() preparing to failover");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   389
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   390
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   391
                switch (mode) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   392
                    case PREFER_OCSP:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   393
                        checkCRLs(xcert, unresolvedCritExts, null,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   394
                                  pubKey, crlSignFlag);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   395
                        break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   396
                    case PREFER_CRLS:
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   397
                        checkOCSP(xcert, unresolvedCritExts);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   398
                        break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   399
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   400
            } catch (CertPathValidatorException x) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   401
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   402
                    debug.println("RevocationChecker.check() failover failed");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   403
                    debug.println("RevocationChecker.check() " + x.getMessage());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   404
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   405
                if (x.getReason() == BasicReason.REVOKED) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   406
                    throw x;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   407
                }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   408
                if (!isSoftFailException(x)) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   409
                    cause.addSuppressed(x);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   410
                    throw cause;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   411
                } else {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   412
                    // only pass if both exceptions were soft failures
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   413
                    if (!eSoftFail) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   414
                        throw cause;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   415
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   416
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   417
            }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   418
        } finally {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   419
            updateState(xcert);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   420
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   421
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   422
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   423
    private boolean isSoftFailException(CertPathValidatorException e) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   424
        if (softFail &&
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   425
            e.getReason() == BasicReason.UNDETERMINED_REVOCATION_STATUS)
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   426
        {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   427
            // recreate exception with correct index
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   428
            CertPathValidatorException e2 = new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   429
                e.getMessage(), e.getCause(), params.certPath(), certIndex,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   430
                e.getReason());
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   431
            softFailExceptions.addFirst(e2);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   432
            return true;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   433
        }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   434
        return false;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   435
    }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   436
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   437
    private void updateState(X509Certificate cert)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   438
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   439
    {
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   440
        issuerInfo = new OCSPResponse.IssuerInfo(anchor, cert);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   441
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   442
        // Make new public key if parameters are missing
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   443
        PublicKey pubKey = cert.getPublicKey();
13806
b18118646a65 7195409: CertPath/CertPathValidatorTest/KeyParamsInheritanceTest fails with NullPointerException
mullan
parents: 13800
diff changeset
   444
        if (PKIX.isDSAPublicKeyWithoutParams(pubKey)) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   445
            // pubKey needs to inherit DSA parameters from prev key
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   446
            pubKey = BasicChecker.makeInheritedParamsKey(pubKey, prevPubKey);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   447
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   448
        prevPubKey = pubKey;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   449
        crlSignFlag = certCanSignCrl(cert);
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   450
        if (certIndex > 0) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   451
            certIndex--;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   452
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   453
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   454
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   455
    // Maximum clock skew in milliseconds (15 minutes) allowed when checking
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   456
    // validity of CRLs
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   457
    private static final long MAX_CLOCK_SKEW = 900000;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   458
    private void checkCRLs(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   459
                           Collection<String> unresolvedCritExts,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   460
                           Set<X509Certificate> stackedCerts,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   461
                           PublicKey pubKey, boolean signFlag)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   462
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   463
    {
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
   464
        checkCRLs(cert, pubKey, null, signFlag, true,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   465
                  stackedCerts, params.trustAnchors());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   466
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   467
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   468
    static boolean isCausedByNetworkIssue(String type, CertStoreException cse) {
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   469
        boolean result;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   470
        Throwable t = cse.getCause();
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   471
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   472
        switch (type) {
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   473
            case "LDAP":
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   474
                if (t != null) {
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   475
                    // These two exception classes are inside java.naming module
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   476
                    String cn = t.getClass().getName();
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   477
                    result = (cn.equals("javax.naming.ServiceUnavailableException") ||
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   478
                        cn.equals("javax.naming.CommunicationException"));
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   479
                } else {
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   480
                    result = false;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   481
                }
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   482
                break;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   483
            case "SSLServer":
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   484
                result = (t != null && t instanceof IOException);
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   485
                break;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   486
            case "URI":
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   487
                result = (t != null && t instanceof IOException);
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   488
                break;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   489
            default:
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   490
                // we don't know about any other remote CertStore types
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   491
                return false;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   492
        }
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   493
        return result;
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   494
    }
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   495
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   496
    private void checkCRLs(X509Certificate cert, PublicKey prevKey,
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
   497
                           X509Certificate prevCert, boolean signFlag,
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
   498
                           boolean allowSeparateKey,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   499
                           Set<X509Certificate> stackedCerts,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   500
                           Set<TrustAnchor> anchors)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   501
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   502
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   503
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   504
            debug.println("RevocationChecker.checkCRLs()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   505
                          " ---checking revocation status ...");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   506
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   507
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   508
        // Reject circular dependencies - RFC 5280 is not explicit on how
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   509
        // to handle this, but does suggest that they can be a security
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   510
        // risk and can create unresolvable dependencies
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   511
        if (stackedCerts != null && stackedCerts.contains(cert)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   512
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   513
                debug.println("RevocationChecker.checkCRLs()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   514
                              " circular dependency");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   515
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   516
            throw new CertPathValidatorException
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   517
                 ("Could not determine revocation status", null, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   518
                  BasicReason.UNDETERMINED_REVOCATION_STATUS);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   519
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   520
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   521
        Set<X509CRL> possibleCRLs = new HashSet<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   522
        Set<X509CRL> approvedCRLs = new HashSet<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   523
        X509CRLSelector sel = new X509CRLSelector();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   524
        sel.setCertificateChecking(cert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   525
        CertPathHelper.setDateAndTime(sel, params.date(), MAX_CLOCK_SKEW);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   526
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   527
        // First, check user-specified CertStores
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   528
        CertPathValidatorException networkFailureException = null;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   529
        for (CertStore store : certStores) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   530
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   531
                for (CRL crl : store.getCRLs(sel)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   532
                    possibleCRLs.add((X509CRL)crl);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   533
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   534
            } catch (CertStoreException e) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   535
                if (debug != null) {
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   536
                    debug.println("RevocationChecker.checkCRLs() " +
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   537
                                  "CertStoreException: " + e.getMessage());
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   538
                }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   539
                if (networkFailureException == null &&
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   540
                    isCausedByNetworkIssue(store.getType(),e)) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   541
                    // save this exception, we may need to throw it later
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   542
                    networkFailureException = new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   543
                        "Unable to determine revocation status due to " +
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   544
                        "network error", e, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   545
                        BasicReason.UNDETERMINED_REVOCATION_STATUS);
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   546
                }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   547
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   548
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   549
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   550
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   551
            debug.println("RevocationChecker.checkCRLs() " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   552
                          "possible crls.size() = " + possibleCRLs.size());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   553
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   554
        boolean[] reasonsMask = new boolean[9];
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   555
        if (!possibleCRLs.isEmpty()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   556
            // Now that we have a list of possible CRLs, see which ones can
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   557
            // be approved
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   558
            approvedCRLs.addAll(verifyPossibleCRLs(possibleCRLs, cert, prevKey,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   559
                                                   signFlag, reasonsMask,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   560
                                                   anchors));
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   561
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   562
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   563
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   564
            debug.println("RevocationChecker.checkCRLs() " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   565
                          "approved crls.size() = " + approvedCRLs.size());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   566
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   567
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   568
        // make sure that we have at least one CRL that _could_ cover
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   569
        // the certificate in question and all reasons are covered
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   570
        if (!approvedCRLs.isEmpty() &&
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   571
            Arrays.equals(reasonsMask, ALL_REASONS))
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   572
        {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   573
            checkApprovedCRLs(cert, approvedCRLs);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   574
        } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   575
            // Check Distribution Points
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   576
            // all CRLs returned by the DP Fetcher have also been verified
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   577
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   578
                if (crlDP) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   579
                    approvedCRLs.addAll(DistributionPointFetcher.getCRLs(
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
   580
                                        sel, signFlag, prevKey, prevCert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   581
                                        params.sigProvider(), certStores,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41974
diff changeset
   582
                                        reasonsMask, anchors, null, params.variant()));
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   583
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   584
            } catch (CertStoreException e) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   585
                if (e instanceof CertStoreTypeException) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   586
                    CertStoreTypeException cste = (CertStoreTypeException)e;
30506
1998a5644f50 8038084: CertStore needs a way to add new CertStore types
valeriep
parents: 29264
diff changeset
   587
                    if (isCausedByNetworkIssue(cste.getType(), e)) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   588
                        throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   589
                            "Unable to determine revocation status due to " +
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   590
                            "network error", e, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   591
                            BasicReason.UNDETERMINED_REVOCATION_STATUS);
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   592
                    }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   593
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   594
                throw new CertPathValidatorException(e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   595
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   596
            if (!approvedCRLs.isEmpty() &&
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   597
                Arrays.equals(reasonsMask, ALL_REASONS))
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   598
            {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   599
                checkApprovedCRLs(cert, approvedCRLs);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   600
            } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   601
                if (allowSeparateKey) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   602
                    try {
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   603
                        verifyWithSeparateSigningKey(cert, prevKey, signFlag,
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   604
                                                     stackedCerts);
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   605
                        return;
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   606
                    } catch (CertPathValidatorException cpve) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   607
                        if (networkFailureException != null) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   608
                            // if a network issue previously prevented us from
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   609
                            // retrieving a CRL from one of the user-specified
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   610
                            // CertStores, throw it now so it can be handled
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   611
                            // appropriately
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   612
                            throw networkFailureException;
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   613
                        }
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   614
                        throw cpve;
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   615
                    }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   616
                } else {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   617
                    if (networkFailureException != null) {
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   618
                        // if a network issue previously prevented us from
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   619
                        // retrieving a CRL from one of the user-specified
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   620
                        // CertStores, throw it now so it can be handled
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   621
                        // appropriately
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   622
                        throw networkFailureException;
13800
2fd4a82efe9c 7176627: CertPath/jep124/PreferCRL_SoftFail test fails (Could not determine revocation status)
mullan
parents: 12860
diff changeset
   623
                    }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   624
                    throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   625
                        "Could not determine revocation status", null, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   626
                        BasicReason.UNDETERMINED_REVOCATION_STATUS);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   627
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   628
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   629
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   630
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   631
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   632
    private void checkApprovedCRLs(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   633
                                   Set<X509CRL> approvedCRLs)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   634
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   635
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   636
        // See if the cert is in the set of approved crls.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   637
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   638
            BigInteger sn = cert.getSerialNumber();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   639
            debug.println("RevocationChecker.checkApprovedCRLs() " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   640
                          "starting the final sweep...");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   641
            debug.println("RevocationChecker.checkApprovedCRLs()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   642
                          " cert SN: " + sn.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   643
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   644
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   645
        CRLReason reasonCode = CRLReason.UNSPECIFIED;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   646
        X509CRLEntryImpl entry = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   647
        for (X509CRL crl : approvedCRLs) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   648
            X509CRLEntry e = crl.getRevokedCertificate(cert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   649
            if (e != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   650
                try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   651
                    entry = X509CRLEntryImpl.toImpl(e);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   652
                } catch (CRLException ce) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   653
                    throw new CertPathValidatorException(ce);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   654
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   655
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   656
                    debug.println("RevocationChecker.checkApprovedCRLs()"
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   657
                        + " CRL entry: " + entry.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   658
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   659
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   660
                /*
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   661
                 * Abort CRL validation and throw exception if there are any
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   662
                 * unrecognized critical CRL entry extensions (see section
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   663
                 * 5.3 of RFC 5280).
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   664
                 */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   665
                Set<String> unresCritExts = entry.getCriticalExtensionOIDs();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   666
                if (unresCritExts != null && !unresCritExts.isEmpty()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   667
                    /* remove any that we will process */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   668
                    unresCritExts.remove(ReasonCode_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   669
                    unresCritExts.remove(CertificateIssuer_Id.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   670
                    if (!unresCritExts.isEmpty()) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   671
                        throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   672
                            "Unrecognized critical extension(s) in revoked " +
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   673
                            "CRL entry");
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   674
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   675
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   676
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   677
                reasonCode = entry.getRevocationReason();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   678
                if (reasonCode == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   679
                    reasonCode = CRLReason.UNSPECIFIED;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   680
                }
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   681
                Date revocationDate = entry.getRevocationDate();
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   682
                if (revocationDate.before(params.date())) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   683
                    Throwable t = new CertificateRevokedException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   684
                        revocationDate, reasonCode,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   685
                        crl.getIssuerX500Principal(), entry.getExtensions());
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   686
                    throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   687
                        t.getMessage(), t, null, -1, BasicReason.REVOKED);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   688
                }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   689
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   690
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   691
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   692
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   693
    private void checkOCSP(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   694
                           Collection<String> unresolvedCritExts)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   695
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   696
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   697
        X509CertImpl currCert = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   698
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   699
            currCert = X509CertImpl.toImpl(cert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   700
        } catch (CertificateException ce) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   701
            throw new CertPathValidatorException(ce);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   702
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   703
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   704
        // The algorithm constraints of the OCSP trusted responder certificate
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   705
        // does not need to be checked in this code. The constraints will be
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   706
        // checked when the responder's certificate is validated.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   707
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   708
        OCSPResponse response = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   709
        CertId certId = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   710
        try {
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   711
            certId = new CertId(issuerInfo.getName(), issuerInfo.getPublicKey(),
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   712
                    currCert.getSerialNumberObject());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   713
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 13806
diff changeset
   714
            // check if there is a cached OCSP response available
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 13806
diff changeset
   715
            byte[] responseBytes = ocspResponses.get(cert);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   716
            if (responseBytes != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   717
                if (debug != null) {
14402
424f3f23f1da 7171570: JEP 124 Potential API Changes
mullan
parents: 13806
diff changeset
   718
                    debug.println("Found cached OCSP response");
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   719
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   720
                response = new OCSPResponse(responseBytes);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   721
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   722
                // verify the response
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   723
                byte[] nonce = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   724
                for (Extension ext : ocspExtensions) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   725
                    if (ext.getId().equals("1.3.6.1.5.5.7.48.1.2")) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   726
                        nonce = ext.getValue();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   727
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   728
                }
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 37781
diff changeset
   729
                response.verify(Collections.singletonList(certId), issuerInfo,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41974
diff changeset
   730
                        responderCert, params.date(), nonce, params.variant());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   731
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   732
            } else {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   733
                URI responderURI = (this.responderURI != null)
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   734
                                   ? this.responderURI
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   735
                                   : OCSP.getResponderURI(currCert);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   736
                if (responderURI == null) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   737
                    throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   738
                        "Certificate does not specify OCSP responder", null,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   739
                        null, -1);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   740
                }
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   741
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   742
                response = OCSP.check(Collections.singletonList(certId),
41974
28d3463c20b0 8168931: Few OCSP related test failed with "Response is unreliable: its validity interval is out-of-date"
ascarpino
parents: 41562
diff changeset
   743
                        responderURI, issuerInfo, responderCert, null,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41974
diff changeset
   744
                        ocspExtensions, params.variant());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   745
            }
18823
6c67701507df 8019627: RuntimeException gets obscured during OCSP cert revocation checking
vinnie
parents: 18587
diff changeset
   746
        } catch (IOException e) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   747
            throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   748
                "Unable to determine revocation status due to network error",
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   749
                e, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   750
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   751
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   752
        RevocationStatus rs =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   753
            (RevocationStatus)response.getSingleResponse(certId);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   754
        RevocationStatus.CertStatus certStatus = rs.getCertStatus();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   755
        if (certStatus == RevocationStatus.CertStatus.REVOKED) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   756
            Date revocationTime = rs.getRevocationTime();
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   757
            if (revocationTime.before(params.date())) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   758
                Throwable t = new CertificateRevokedException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   759
                    revocationTime, rs.getRevocationReason(),
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 21329
diff changeset
   760
                    response.getSignerCertificate().getSubjectX500Principal(),
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   761
                    rs.getSingleExtensions());
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   762
                throw new CertPathValidatorException(t.getMessage(), t, null,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   763
                                                     -1, BasicReason.REVOKED);
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   764
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   765
        } else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   766
            throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   767
                "Certificate's revocation status is unknown", null,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   768
                params.certPath(), -1,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   769
                BasicReason.UNDETERMINED_REVOCATION_STATUS);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   770
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   771
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   772
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   773
    /*
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   774
     * Removes any non-hexadecimal characters from a string.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   775
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   776
    private static final String HEX_DIGITS = "0123456789ABCDEFabcdef";
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   777
    private static String stripOutSeparators(String value) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   778
        char[] chars = value.toCharArray();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   779
        StringBuilder hexNumber = new StringBuilder();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   780
        for (int i = 0; i < chars.length; i++) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   781
            if (HEX_DIGITS.indexOf(chars[i]) != -1) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   782
                hexNumber.append(chars[i]);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   783
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   784
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   785
        return hexNumber.toString();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   786
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   787
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   788
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   789
     * Checks that a cert can be used to verify a CRL.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   790
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   791
     * @param cert an X509Certificate to check
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   792
     * @return a boolean specifying if the cert is allowed to vouch for the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   793
     *         validity of a CRL
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   794
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   795
    static boolean certCanSignCrl(X509Certificate cert) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   796
        // if the cert doesn't include the key usage ext, or
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   797
        // the key usage ext asserts cRLSigning, return true,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   798
        // otherwise return false.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   799
        boolean[] keyUsage = cert.getKeyUsage();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   800
        if (keyUsage != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   801
            return keyUsage[6];
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   802
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   803
        return false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   804
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   805
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   806
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   807
     * Internal method that verifies a set of possible_crls,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   808
     * and sees if each is approved, based on the cert.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   809
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   810
     * @param crls a set of possible CRLs to test for acceptability
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   811
     * @param cert the certificate whose revocation status is being checked
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   812
     * @param signFlag <code>true</code> if prevKey was trusted to sign CRLs
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   813
     * @param prevKey the public key of the issuer of cert
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   814
     * @param reasonsMask the reason code mask
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   815
     * @param trustAnchors a <code>Set</code> of <code>TrustAnchor</code>s>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   816
     * @return a collection of approved crls (or an empty collection)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   817
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   818
    private static final boolean[] ALL_REASONS =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   819
        {true, true, true, true, true, true, true, true, true};
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   820
    private Collection<X509CRL> verifyPossibleCRLs(Set<X509CRL> crls,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   821
                                                   X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   822
                                                   PublicKey prevKey,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   823
                                                   boolean signFlag,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   824
                                                   boolean[] reasonsMask,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   825
                                                   Set<TrustAnchor> anchors)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   826
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   827
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   828
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   829
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   830
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   831
                debug.println("RevocationChecker.verifyPossibleCRLs: " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   832
                              "Checking CRLDPs for "
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   833
                              + certImpl.getSubjectX500Principal());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   834
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   835
            CRLDistributionPointsExtension ext =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   836
                certImpl.getCRLDistributionPointsExtension();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   837
            List<DistributionPoint> points = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   838
            if (ext == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   839
                // assume a DP with reasons and CRLIssuer fields omitted
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   840
                // and a DP name of the cert issuer.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   841
                // TODO add issuerAltName too
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   842
                X500Name certIssuer = (X500Name)certImpl.getIssuerDN();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   843
                DistributionPoint point = new DistributionPoint(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   844
                     new GeneralNames().add(new GeneralName(certIssuer)),
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   845
                     null, null);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   846
                points = Collections.singletonList(point);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   847
            } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   848
                points = ext.get(CRLDistributionPointsExtension.POINTS);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   849
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   850
            Set<X509CRL> results = new HashSet<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   851
            for (DistributionPoint point : points) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   852
                for (X509CRL crl : crls) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   853
                    if (DistributionPointFetcher.verifyCRL(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   854
                            certImpl, point, crl, reasonsMask, signFlag,
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
   855
                            prevKey, null, params.sigProvider(), anchors,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41974
diff changeset
   856
                            certStores, params.date(), params.variant()))
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   857
                    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   858
                        results.add(crl);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   859
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   860
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   861
                if (Arrays.equals(reasonsMask, ALL_REASONS))
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   862
                    break;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   863
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   864
            return results;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   865
        } catch (CertificateException | CRLException | IOException e) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   866
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   867
                debug.println("Exception while verifying CRL: "+e.getMessage());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   868
                e.printStackTrace();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   869
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   870
            return Collections.emptySet();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   871
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   872
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   873
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   874
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   875
     * We have a cert whose revocation status couldn't be verified by
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   876
     * a CRL issued by the cert that issued the CRL. See if we can
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   877
     * find a valid CRL issued by a separate key that can verify the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   878
     * revocation status of this certificate.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   879
     * <p>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   880
     * Note that this does not provide support for indirect CRLs,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   881
     * only CRLs signed with a different key (but the same issuer
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   882
     * name) as the certificate being checked.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   883
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   884
     * @param currCert the <code>X509Certificate</code> to be checked
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   885
     * @param prevKey the <code>PublicKey</code> that failed
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   886
     * @param signFlag <code>true</code> if that key was trusted to sign CRLs
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   887
     * @param stackedCerts a <code>Set</code> of <code>X509Certificate</code>s>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   888
     *                     whose revocation status depends on the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   889
     *                     non-revoked status of this cert. To avoid
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   890
     *                     circular dependencies, we assume they're
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   891
     *                     revoked while checking the revocation
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   892
     *                     status of this cert.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   893
     * @throws CertPathValidatorException if the cert's revocation status
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   894
     *         cannot be verified successfully with another key
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   895
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   896
    private void verifyWithSeparateSigningKey(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   897
                                              PublicKey prevKey,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   898
                                              boolean signFlag,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   899
                                              Set<X509Certificate> stackedCerts)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   900
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   901
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   902
        String msg = "revocation status";
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   903
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   904
            debug.println(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   905
                "RevocationChecker.verifyWithSeparateSigningKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   906
                " ---checking " + msg + "...");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   907
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   908
26967
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   909
        // Reject circular dependencies - RFC 5280 is not explicit on how
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   910
        // to handle this, but does suggest that they can be a security
c182469301ee 8037550: Update RFC references in javadoc to RFC 5280
juh
parents: 25859
diff changeset
   911
        // risk and can create unresolvable dependencies
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   912
        if ((stackedCerts != null) && stackedCerts.contains(cert)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   913
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   914
                debug.println(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   915
                    "RevocationChecker.verifyWithSeparateSigningKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   916
                    " circular dependency");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   917
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   918
            throw new CertPathValidatorException
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   919
                ("Could not determine revocation status", null, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 16492
diff changeset
   920
                 BasicReason.UNDETERMINED_REVOCATION_STATUS);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   921
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   922
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   923
        // Try to find another key that might be able to sign
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   924
        // CRLs vouching for this cert.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   925
        // If prevKey wasn't trusted, maybe we just didn't have the right
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   926
        // path to it. Don't rule that key out.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   927
        if (!signFlag) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   928
            buildToNewKey(cert, null, stackedCerts);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   929
        } else {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   930
            buildToNewKey(cert, prevKey, stackedCerts);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   931
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   932
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   933
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   934
    /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   935
     * Tries to find a CertPath that establishes a key that can be
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   936
     * used to verify the revocation status of a given certificate.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   937
     * Ignores keys that have previously been tried. Throws a
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   938
     * CertPathValidatorException if no such key could be found.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   939
     *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   940
     * @param currCert the <code>X509Certificate</code> to be checked
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   941
     * @param prevKey the <code>PublicKey</code> of the certificate whose key
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   942
     *    cannot be used to vouch for the CRL and should be ignored
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   943
     * @param stackedCerts a <code>Set</code> of <code>X509Certificate</code>s>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   944
     *                     whose revocation status depends on the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   945
     *                     establishment of this path.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   946
     * @throws CertPathValidatorException on failure
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   947
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   948
    private static final boolean [] CRL_SIGN_USAGE =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   949
        { false, false, false, false, false, false, true };
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   950
    private void buildToNewKey(X509Certificate currCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   951
                               PublicKey prevKey,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   952
                               Set<X509Certificate> stackedCerts)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   953
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   954
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   955
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   956
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   957
            debug.println("RevocationChecker.buildToNewKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   958
                          " starting work");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   959
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   960
        Set<PublicKey> badKeys = new HashSet<>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   961
        if (prevKey != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   962
            badKeys.add(prevKey);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   963
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   964
        X509CertSelector certSel = new RejectKeySelector(badKeys);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   965
        certSel.setSubject(currCert.getIssuerX500Principal());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   966
        certSel.setKeyUsage(CRL_SIGN_USAGE);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   967
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   968
        Set<TrustAnchor> newAnchors = anchor == null ?
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   969
                                      params.trustAnchors() :
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   970
                                      Collections.singleton(anchor);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   971
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   972
        PKIXBuilderParameters builderParams;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   973
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   974
            builderParams = new PKIXBuilderParameters(newAnchors, certSel);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   975
        } catch (InvalidAlgorithmParameterException iape) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   976
            throw new RuntimeException(iape); // should never occur
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   977
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   978
        builderParams.setInitialPolicies(params.initialPolicies());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   979
        builderParams.setCertStores(certStores);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   980
        builderParams.setExplicitPolicyRequired
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   981
            (params.explicitPolicyRequired());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   982
        builderParams.setPolicyMappingInhibited
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   983
            (params.policyMappingInhibited());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   984
        builderParams.setAnyPolicyInhibited(params.anyPolicyInhibited());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   985
        // Policy qualifiers must be rejected, since we don't have
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   986
        // any way to convey them back to the application.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   987
        // That's the default, so no need to write code.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   988
        builderParams.setDate(params.date());
44479
9669aa3c7bcb 8161973: PKIXRevocationChecker.getSoftFailExceptions() not working
mullan
parents: 43701
diff changeset
   989
        builderParams.setCertPathCheckers(params.certPathCheckers());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   990
        builderParams.setSigProvider(params.sigProvider());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   991
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   992
        // Skip revocation during this build to detect circular
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   993
        // references. But check revocation afterwards, using the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   994
        // key (or any other that works).
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   995
        builderParams.setRevocationEnabled(false);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   996
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   997
        // check for AuthorityInformationAccess extension
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   998
        if (Builder.USE_AIA == true) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
   999
            X509CertImpl currCertImpl = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1000
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1001
                currCertImpl = X509CertImpl.toImpl(currCert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1002
            } catch (CertificateException ce) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1003
                // ignore but log it
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1004
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1005
                    debug.println("RevocationChecker.buildToNewKey: " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1006
                                  "error decoding cert: " + ce);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1007
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1008
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1009
            AuthorityInfoAccessExtension aiaExt = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1010
            if (currCertImpl != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1011
                aiaExt = currCertImpl.getAuthorityInfoAccessExtension();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1012
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1013
            if (aiaExt != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1014
                List<AccessDescription> adList = aiaExt.getAccessDescriptions();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1015
                if (adList != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1016
                    for (AccessDescription ad : adList) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1017
                        CertStore cs = URICertStore.getInstance(ad);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1018
                        if (cs != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1019
                            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1020
                                debug.println("adding AIAext CertStore");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1021
                            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1022
                            builderParams.addCertStore(cs);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1023
                        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1024
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1025
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1026
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1027
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1028
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1029
        CertPathBuilder builder = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1030
        try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1031
            builder = CertPathBuilder.getInstance("PKIX");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1032
        } catch (NoSuchAlgorithmException nsae) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1033
            throw new CertPathValidatorException(nsae);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1034
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1035
        while (true) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1036
            try {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1037
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1038
                    debug.println("RevocationChecker.buildToNewKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1039
                                  " about to try build ...");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1040
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1041
                PKIXCertPathBuilderResult cpbr =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1042
                    (PKIXCertPathBuilderResult)builder.build(builderParams);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1043
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1044
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1045
                    debug.println("RevocationChecker.buildToNewKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1046
                                  " about to check revocation ...");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1047
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1048
                // Now check revocation of all certs in path, assuming that
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1049
                // the stackedCerts are revoked.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1050
                if (stackedCerts == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1051
                    stackedCerts = new HashSet<X509Certificate>();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1052
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1053
                stackedCerts.add(currCert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1054
                TrustAnchor ta = cpbr.getTrustAnchor();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1055
                PublicKey prevKey2 = ta.getCAPublicKey();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1056
                if (prevKey2 == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1057
                    prevKey2 = ta.getTrustedCert().getPublicKey();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1058
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1059
                boolean signFlag = true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1060
                List<? extends Certificate> cpList =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1061
                    cpbr.getCertPath().getCertificates();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1062
                try {
33290
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1063
                    for (int i = cpList.size() - 1; i >= 0; i--) {
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1064
                        X509Certificate cert = (X509Certificate) cpList.get(i);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1065
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1066
                        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1067
                            debug.println("RevocationChecker.buildToNewKey()"
33290
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1068
                                    + " index " + i + " checking "
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1069
                                    + cert);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1070
                        }
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
  1071
                        checkCRLs(cert, prevKey2, null, signFlag, true,
33290
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1072
                                stackedCerts, newAnchors);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1073
                        signFlag = certCanSignCrl(cert);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1074
                        prevKey2 = cert.getPublicKey();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1075
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1076
                } catch (CertPathValidatorException cpve) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1077
                    // ignore it and try to get another key
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1078
                    badKeys.add(cpbr.getPublicKey());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1079
                    continue;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1080
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1081
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1082
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1083
                    debug.println("RevocationChecker.buildToNewKey()" +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1084
                                  " got key " + cpbr.getPublicKey());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1085
                }
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
  1086
                // Now check revocation on the current cert using that key and
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
  1087
                // the corresponding certificate.
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1088
                // If it doesn't check out, try to find a different key.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1089
                // And if we can't find a key, then return false.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1090
                PublicKey newKey = cpbr.getPublicKey();
33290
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1091
                X509Certificate newCert = cpList.isEmpty() ?
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1092
                    null : (X509Certificate) cpList.get(0);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1093
                try {
33290
f035b59aaf61 8081744: Clear out list corner case
juh
parents: 30506
diff changeset
  1094
                    checkCRLs(currCert, newKey, newCert,
22107
3e6b0718041e 8007967: Infinite loop can happen in sun.security.provider.certpath.SunCertPathBuilder.depthFirstSearchForward()
juh
parents: 21819
diff changeset
  1095
                              true, false, null, params.trustAnchors());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1096
                    // If that passed, the cert is OK!
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1097
                    return;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1098
                } catch (CertPathValidatorException cpve) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1099
                    // If it is revoked, rethrow exception
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1100
                    if (cpve.getReason() == BasicReason.REVOKED) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1101
                        throw cpve;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1102
                    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1103
                    // Otherwise, ignore the exception and
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1104
                    // try to get another key.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1105
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1106
                badKeys.add(newKey);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1107
            } catch (InvalidAlgorithmParameterException iape) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1108
                throw new CertPathValidatorException(iape);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1109
            } catch (CertPathBuilderException cpbe) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1110
                throw new CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1111
                    ("Could not determine revocation status", null, null,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1112
                     -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1113
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1114
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1115
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1116
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1117
    /*
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1118
     * This inner class extends the X509CertSelector to add an additional
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1119
     * check to make sure the subject public key isn't on a particular list.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1120
     * This class is used by buildToNewKey() to make sure the builder doesn't
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1121
     * end up with a CertPath to a public key that has already been rejected.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1122
     */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1123
    private static class RejectKeySelector extends X509CertSelector {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1124
        private final Set<PublicKey> badKeySet;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1125
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1126
        /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1127
         * Creates a new <code>RejectKeySelector</code>.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1128
         *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1129
         * @param badPublicKeys a <code>Set</code> of
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1130
         *                      <code>PublicKey</code>s that
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1131
         *                      should be rejected (or <code>null</code>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1132
         *                      if no such check should be done)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1133
         */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1134
        RejectKeySelector(Set<PublicKey> badPublicKeys) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1135
            this.badKeySet = badPublicKeys;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1136
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1137
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1138
        /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1139
         * Decides whether a <code>Certificate</code> should be selected.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1140
         *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1141
         * @param cert the <code>Certificate</code> to be checked
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1142
         * @return <code>true</code> if the <code>Certificate</code> should be
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1143
         *         selected, <code>false</code> otherwise
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1144
         */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1145
        @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1146
        public boolean match(Certificate cert) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1147
            if (!super.match(cert))
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1148
                return(false);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1149
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1150
            if (badKeySet.contains(cert.getPublicKey())) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1151
                if (debug != null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1152
                    debug.println("RejectKeySelector.match: bad key");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1153
                return false;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1154
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1155
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1156
            if (debug != null)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1157
                debug.println("RejectKeySelector.match: returning true");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1158
            return true;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1159
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1160
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1161
        /**
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1162
         * Return a printable representation of the <code>CertSelector</code>.
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1163
         *
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1164
         * @return a <code>String</code> describing the contents of the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1165
         *         <code>CertSelector</code>
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1166
         */
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1167
        @Override
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1168
        public String toString() {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1169
            StringBuilder sb = new StringBuilder();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1170
            sb.append("RejectKeySelector: [\n");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1171
            sb.append(super.toString());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1172
            sb.append(badKeySet);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1173
            sb.append("]");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1174
            return sb.toString();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1175
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1176
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
diff changeset
  1177
}