jdk/src/share/classes/sun/security/provider/certpath/OCSP.java
author mullan
Mon, 17 Feb 2014 11:36:40 -0500
changeset 22977 f8f315760941
parent 21819 8cd757e836d8
permissions -rw-r--r--
8025708: Certificate Path Building problem with AKI serial number Reviewed-by: xuelei, juh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     1
/*
17043
ebd5b78aebe4 8011313: OCSP timeout set to wrong value if com.sun.security.ocsp.timeout not defined
mullan
parents: 16044
diff changeset
     2
 * Copyright (c) 2009, 2013, Oracle and/or its affiliates. All rights reserved.
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     4
 *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4044
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4044
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    10
 *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    15
 * accompanied this code).
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    16
 *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4044
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4044
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4044
diff changeset
    23
 * questions.
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    24
 */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    25
package sun.security.provider.certpath;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    26
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    27
import java.io.InputStream;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    28
import java.io.IOException;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    29
import java.io.OutputStream;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    30
import java.net.URI;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    31
import java.net.URL;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    32
import java.net.HttpURLConnection;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    33
import java.security.cert.CertificateException;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    34
import java.security.cert.CertPathValidatorException;
13596
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
    35
import java.security.cert.CertPathValidatorException.BasicReason;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    36
import java.security.cert.CRLReason;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    37
import java.security.cert.Extension;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    38
import java.security.cert.X509Certificate;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    39
import java.util.Arrays;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    40
import java.util.Collections;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    41
import java.util.Date;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    42
import java.util.List;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    43
import java.util.Map;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    44
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    45
import static sun.security.provider.certpath.OCSPResponse.*;
14701
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    46
import sun.security.action.GetIntegerAction;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    47
import sun.security.util.Debug;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    48
import sun.security.util.ObjectIdentifier;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    49
import sun.security.x509.AccessDescription;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    50
import sun.security.x509.AuthorityInfoAccessExtension;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    51
import sun.security.x509.GeneralName;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    52
import sun.security.x509.GeneralNameInterface;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    53
import sun.security.x509.URIName;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    54
import sun.security.x509.X509CertImpl;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    55
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    56
/**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    57
 * This is a class that checks the revocation status of a certificate(s) using
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    58
 * OCSP. It is not a PKIXCertPathChecker and therefore can be used outside of
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    59
 * the CertPathValidator framework. It is useful when you want to
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    60
 * just check the revocation status of a certificate, and you don't want to
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    61
 * incur the overhead of validating all of the certificates in the
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    62
 * associated certificate chain.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    63
 *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    64
 * @author Sean Mullan
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    65
 */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    66
public final class OCSP {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    67
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    68
    static final ObjectIdentifier NONCE_EXTENSION_OID =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    69
        ObjectIdentifier.newInternal(new int[]{ 1, 3, 6, 1, 5, 5, 7, 48, 1, 2});
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    70
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    71
    private static final Debug debug = Debug.getInstance("certpath");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    72
14701
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    73
    private static final int DEFAULT_CONNECT_TIMEOUT = 15000;
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    74
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    75
    /**
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    76
     * Integer value indicating the timeout length, in seconds, to be
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    77
     * used for the OCSP check. A timeout of zero is interpreted as
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    78
     * an infinite timeout.
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    79
     */
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    80
    private static final int CONNECT_TIMEOUT = initializeTimeout();
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    81
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    82
    /**
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    83
     * Initialize the timeout length by getting the OCSP timeout
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    84
     * system property. If the property has not been set, or if its
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    85
     * value is negative, set the timeout length to the default.
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    86
     */
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    87
    private static int initializeTimeout() {
17043
ebd5b78aebe4 8011313: OCSP timeout set to wrong value if com.sun.security.ocsp.timeout not defined
mullan
parents: 16044
diff changeset
    88
        Integer tmp = java.security.AccessController.doPrivileged(
ebd5b78aebe4 8011313: OCSP timeout set to wrong value if com.sun.security.ocsp.timeout not defined
mullan
parents: 16044
diff changeset
    89
                new GetIntegerAction("com.sun.security.ocsp.timeout"));
ebd5b78aebe4 8011313: OCSP timeout set to wrong value if com.sun.security.ocsp.timeout not defined
mullan
parents: 16044
diff changeset
    90
        if (tmp == null || tmp < 0) {
16044
85f90a877d17 8006853: OCSP timeout set to wrong value if com.sun.security.ocsp.timeout < 0
juh
parents: 14701
diff changeset
    91
            return DEFAULT_CONNECT_TIMEOUT;
14701
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    92
        }
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    93
        // Convert to milliseconds, as the system property will be
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    94
        // specified in seconds
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    95
        return tmp * 1000;
0c0578b802b1 7199143: RFE: OCSP revocation checker should provide possibility to specify connection timeout
mullan
parents: 13800
diff changeset
    96
    }
4044
b2b2ee2ca90c 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents: 3841
diff changeset
    97
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    98
    private OCSP() {}
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    99
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   100
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   101
     * Obtains the revocation status of a certificate using OCSP using the most
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   102
     * common defaults. The OCSP responder URI is retrieved from the
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   103
     * certificate's AIA extension. The OCSP responder certificate is assumed
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   104
     * to be the issuer's certificate (or issued by the issuer CA).
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   105
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   106
     * @param cert the certificate to be checked
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   107
     * @param issuerCert the issuer certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   108
     * @return the RevocationStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   109
     * @throws IOException if there is an exception connecting to or
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   110
     *    communicating with the OCSP responder
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   111
     * @throws CertPathValidatorException if an exception occurs while
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   112
     *    encoding the OCSP Request or validating the OCSP Response
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   113
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   114
    public static RevocationStatus check(X509Certificate cert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   115
                                         X509Certificate issuerCert)
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   116
        throws IOException, CertPathValidatorException {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   117
        CertId certId = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   118
        URI responderURI = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   119
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   120
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   121
            responderURI = getResponderURI(certImpl);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   122
            if (responderURI == null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   123
                throw new CertPathValidatorException
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   124
                    ("No OCSP Responder URI in certificate");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   125
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   126
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   127
        } catch (CertificateException | IOException e) {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   128
            throw new CertPathValidatorException
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   129
                ("Exception while encoding OCSPRequest", e);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   130
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   131
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   132
            responderURI, issuerCert, null, null,
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   133
            Collections.<Extension>emptyList());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   134
        return (RevocationStatus)ocspResponse.getSingleResponse(certId);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   135
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   136
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   137
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   138
     * Obtains the revocation status of a certificate using OCSP.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   139
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   140
     * @param cert the certificate to be checked
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   141
     * @param issuerCert the issuer certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   142
     * @param responderURI the URI of the OCSP responder
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   143
     * @param responderCert the OCSP responder's certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   144
     * @param date the time the validity of the OCSP responder's certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   145
     *    should be checked against. If null, the current time is used.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   146
     * @return the RevocationStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   147
     * @throws IOException if there is an exception connecting to or
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   148
     *    communicating with the OCSP responder
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   149
     * @throws CertPathValidatorException if an exception occurs while
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   150
     *    encoding the OCSP Request or validating the OCSP Response
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   151
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   152
    public static RevocationStatus check(X509Certificate cert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   153
                                         X509Certificate issuerCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   154
                                         URI responderURI,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   155
                                         X509Certificate responderCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   156
                                         Date date)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   157
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   158
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   159
        return check(cert, issuerCert, responderURI, responderCert, date,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   160
                     Collections.<Extension>emptyList());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   161
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   162
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   163
    // Called by com.sun.deploy.security.TrustDecider
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   164
    public static RevocationStatus check(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   165
                                         X509Certificate issuerCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   166
                                         URI responderURI,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   167
                                         X509Certificate responderCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   168
                                         Date date, List<Extension> extensions)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   169
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   170
    {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   171
        CertId certId = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   172
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   173
            X509CertImpl certImpl = X509CertImpl.toImpl(cert);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   174
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   175
        } catch (CertificateException | IOException e) {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   176
            throw new CertPathValidatorException
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   177
                ("Exception while encoding OCSPRequest", e);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   178
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   179
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   180
            responderURI, issuerCert, responderCert, date, extensions);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   181
        return (RevocationStatus) ocspResponse.getSingleResponse(certId);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   182
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   183
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   184
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   185
     * Checks the revocation status of a list of certificates using OCSP.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   186
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   187
     * @param certs the CertIds to be checked
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   188
     * @param responderURI the URI of the OCSP responder
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   189
     * @param issuerCert the issuer's certificate
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   190
     * @param responderCert the OCSP responder's certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   191
     * @param date the time the validity of the OCSP responder's certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   192
     *    should be checked against. If null, the current time is used.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   193
     * @return the OCSPResponse
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   194
     * @throws IOException if there is an exception connecting to or
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   195
     *    communicating with the OCSP responder
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   196
     * @throws CertPathValidatorException if an exception occurs while
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   197
     *    encoding the OCSP Request or validating the OCSP Response
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   198
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   199
    static OCSPResponse check(List<CertId> certIds, URI responderURI,
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   200
                              X509Certificate issuerCert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   201
                              X509Certificate responderCert, Date date,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   202
                              List<Extension> extensions)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   203
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   204
    {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   205
        byte[] bytes = null;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   206
        OCSPRequest request = null;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   207
        try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   208
            request = new OCSPRequest(certIds, extensions);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   209
            bytes = request.encodeBytes();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   210
        } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   211
            throw new CertPathValidatorException
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   212
                ("Exception while encoding OCSPRequest", ioe);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   213
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   214
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   215
        InputStream in = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   216
        OutputStream out = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   217
        byte[] response = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   218
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   219
            URL url = responderURI.toURL();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   220
            if (debug != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   221
                debug.println("connecting to OCSP service at: " + url);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   222
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   223
            HttpURLConnection con = (HttpURLConnection)url.openConnection();
4044
b2b2ee2ca90c 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents: 3841
diff changeset
   224
            con.setConnectTimeout(CONNECT_TIMEOUT);
b2b2ee2ca90c 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents: 3841
diff changeset
   225
            con.setReadTimeout(CONNECT_TIMEOUT);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   226
            con.setDoOutput(true);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   227
            con.setDoInput(true);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   228
            con.setRequestMethod("POST");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   229
            con.setRequestProperty
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   230
                ("Content-type", "application/ocsp-request");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   231
            con.setRequestProperty
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   232
                ("Content-length", String.valueOf(bytes.length));
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   233
            out = con.getOutputStream();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   234
            out.write(bytes);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   235
            out.flush();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   236
            // Check the response
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   237
            if (debug != null &&
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   238
                con.getResponseCode() != HttpURLConnection.HTTP_OK) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   239
                debug.println("Received HTTP error: " + con.getResponseCode()
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   240
                    + " - " + con.getResponseMessage());
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   241
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   242
            in = con.getInputStream();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   243
            int contentLength = con.getContentLength();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   244
            if (contentLength == -1) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   245
                contentLength = Integer.MAX_VALUE;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   246
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   247
            response = new byte[contentLength > 2048 ? 2048 : contentLength];
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   248
            int total = 0;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   249
            while (total < contentLength) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   250
                int count = in.read(response, total, response.length - total);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   251
                if (count < 0)
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   252
                    break;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   253
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   254
                total += count;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   255
                if (total >= response.length && total < contentLength) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   256
                    response = Arrays.copyOf(response, total * 2);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   257
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   258
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   259
            response = Arrays.copyOf(response, total);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   260
        } catch (IOException ioe) {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17043
diff changeset
   261
            throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17043
diff changeset
   262
                "Unable to determine revocation status due to network error",
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17043
diff changeset
   263
                ioe, null, -1, BasicReason.UNDETERMINED_REVOCATION_STATUS);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   264
        } finally {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   265
            if (in != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   266
                try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   267
                    in.close();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   268
                } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   269
                    throw ioe;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   270
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   271
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   272
            if (out != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   273
                try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   274
                    out.close();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   275
                } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   276
                    throw ioe;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   277
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   278
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   279
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   280
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   281
        OCSPResponse ocspResponse = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   282
        try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   283
            ocspResponse = new OCSPResponse(response);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   284
        } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   285
            // response decoding exception
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   286
            throw new CertPathValidatorException(ioe);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   287
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   288
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   289
        // verify the response
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   290
        ocspResponse.verify(certIds, issuerCert, responderCert, date,
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19045
diff changeset
   291
            request.getNonce());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   292
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   293
        return ocspResponse;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   294
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   295
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   296
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   297
     * Returns the URI of the OCSP Responder as specified in the
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   298
     * certificate's Authority Information Access extension, or null if
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   299
     * not specified.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   300
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   301
     * @param cert the certificate
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   302
     * @return the URI of the OCSP Responder, or null if not specified
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   303
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   304
    // Called by com.sun.deploy.security.TrustDecider
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   305
    public static URI getResponderURI(X509Certificate cert) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   306
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   307
            return getResponderURI(X509CertImpl.toImpl(cert));
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   308
        } catch (CertificateException ce) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   309
            // treat this case as if the cert had no extension
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   310
            return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   311
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   312
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   313
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   314
    static URI getResponderURI(X509CertImpl certImpl) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   315
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   316
        // Examine the certificate's AuthorityInfoAccess extension
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   317
        AuthorityInfoAccessExtension aia =
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   318
            certImpl.getAuthorityInfoAccessExtension();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   319
        if (aia == null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   320
            return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   321
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   322
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   323
        List<AccessDescription> descriptions = aia.getAccessDescriptions();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   324
        for (AccessDescription description : descriptions) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   325
            if (description.getAccessMethod().equals((Object)
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   326
                AccessDescription.Ad_OCSP_Id)) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   327
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   328
                GeneralName generalName = description.getAccessLocation();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   329
                if (generalName.getType() == GeneralNameInterface.NAME_URI) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   330
                    URIName uri = (URIName) generalName.getName();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   331
                    return uri.getURI();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   332
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   333
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   334
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   335
        return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   336
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   337
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   338
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   339
     * The Revocation Status of a certificate.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   340
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   341
    public static interface RevocationStatus {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   342
        public enum CertStatus { GOOD, REVOKED, UNKNOWN };
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   343
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   344
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   345
         * Returns the revocation status.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   346
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   347
        CertStatus getCertStatus();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   348
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   349
         * Returns the time when the certificate was revoked, or null
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   350
         * if it has not been revoked.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   351
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   352
        Date getRevocationTime();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   353
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   354
         * Returns the reason the certificate was revoked, or null if it
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   355
         * has not been revoked.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   356
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   357
        CRLReason getRevocationReason();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   358
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   359
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   360
         * Returns a Map of additional extensions.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   361
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   362
        Map<String, Extension> getSingleExtensions();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   363
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   364
}