jdk/src/share/classes/sun/security/provider/certpath/OCSP.java
author mullan
Tue, 28 Aug 2012 08:43:17 -0400
changeset 13596 897dea1b4c1f
parent 12860 9ffbd4e43413
child 13800 2fd4a82efe9c
permissions -rw-r--r--
7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed Reviewed-by: xuelei
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
/*
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
     2
 * Copyright (c) 2009, 2012, 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.*;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    46
import sun.security.util.Debug;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    47
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
    48
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
    49
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
    50
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
    51
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
    52
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
    53
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
    54
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
 * 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
    57
 * 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
    58
 * 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
    59
 * 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
    60
 * 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
    61
 * associated certificate chain.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    62
 *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    63
 * @author Sean Mullan
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    64
 */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    65
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
    66
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    67
    static final ObjectIdentifier NONCE_EXTENSION_OID =
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    68
        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
    69
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    70
    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
    71
4044
b2b2ee2ca90c 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents: 3841
diff changeset
    72
    private static final int CONNECT_TIMEOUT = 15000; // 15 seconds
b2b2ee2ca90c 6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents: 3841
diff changeset
    73
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    74
    private OCSP() {}
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    75
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    76
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    77
     * 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
    78
     * 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
    79
     * 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
    80
     * 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
    81
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    82
     * @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
    83
     * @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
    84
     * @return the RevocationStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    85
     * @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
    86
     *    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
    87
     * @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
    88
     *    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
    89
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    90
    public static RevocationStatus check(X509Certificate cert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    91
                                         X509Certificate issuerCert)
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    92
        throws IOException, CertPathValidatorException {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    93
        CertId certId = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    94
        URI responderURI = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    95
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    96
            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
    97
            responderURI = getResponderURI(certImpl);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    98
            if (responderURI == null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
    99
                throw new CertPathValidatorException
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   100
                    ("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
   101
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   102
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   103
        } 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
   104
            throw new CertPathValidatorException
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   105
                ("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
   106
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   107
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   108
            responderURI, issuerCert, null, Collections.<Extension>emptyList());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   109
        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
   110
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   111
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   112
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   113
     * 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
   114
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   115
     * @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
   116
     * @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
   117
     * @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
   118
     * @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
   119
     * @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
   120
     *    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
   121
     * @return the RevocationStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   122
     * @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
   123
     *    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
   124
     * @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
   125
     *    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
   126
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   127
    public static RevocationStatus check(X509Certificate cert,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   128
                                         X509Certificate issuerCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   129
                                         URI responderURI,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   130
                                         X509Certificate responderCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   131
                                         Date date)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   132
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   133
    {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   134
        return check(cert, issuerCert, responderURI, responderCert, date,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   135
                     Collections.<Extension>emptyList());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   136
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   137
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   138
    // Called by com.sun.deploy.security.TrustDecider
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   139
    public static RevocationStatus check(X509Certificate cert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   140
                                         X509Certificate issuerCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   141
                                         URI responderURI,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   142
                                         X509Certificate responderCert,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   143
                                         Date date, List<Extension> extensions)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   144
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   145
    {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   146
        CertId certId = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   147
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   148
            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
   149
            certId = new CertId(issuerCert, certImpl.getSerialNumberObject());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   150
        } 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
   151
            throw new CertPathValidatorException
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   152
                ("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
   153
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   154
        OCSPResponse ocspResponse = check(Collections.singletonList(certId),
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   155
            responderURI, 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
   156
        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
   157
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   158
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   159
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   160
     * 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
   161
     *
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   162
     * @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
   163
     * @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
   164
     * @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
   165
     * @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
   166
     *    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
   167
     * @return the OCSPResponse
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   168
     * @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
   169
     *    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
   170
     * @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
   171
     *    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
   172
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   173
    static OCSPResponse check(List<CertId> certIds, URI responderURI,
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   174
                              X509Certificate responderCert, Date date,
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   175
                              List<Extension> extensions)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   176
        throws IOException, CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   177
    {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   178
        byte[] bytes = null;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   179
        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
   180
        try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   181
            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
   182
            bytes = request.encodeBytes();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   183
        } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   184
            throw new CertPathValidatorException
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   185
                ("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
   186
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   187
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   188
        InputStream in = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   189
        OutputStream out = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   190
        byte[] response = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   191
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   192
            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
   193
            if (debug != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   194
                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
   195
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   196
            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
   197
            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
   198
            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
   199
            con.setDoOutput(true);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   200
            con.setDoInput(true);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   201
            con.setRequestMethod("POST");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   202
            con.setRequestProperty
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   203
                ("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
   204
            con.setRequestProperty
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   205
                ("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
   206
            out = con.getOutputStream();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   207
            out.write(bytes);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   208
            out.flush();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   209
            // Check the response
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   210
            if (debug != null &&
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   211
                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
   212
                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
   213
                    + " - " + con.getResponseMessage());
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
            in = con.getInputStream();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   216
            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
   217
            if (contentLength == -1) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   218
                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
   219
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   220
            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
   221
            int total = 0;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   222
            while (total < contentLength) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   223
                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
   224
                if (count < 0)
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   225
                    break;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   226
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   227
                total += count;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   228
                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
   229
                    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
   230
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   231
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   232
            response = Arrays.copyOf(response, total);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   233
        } catch (IOException ioe) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   234
            throw new NetworkFailureException(ioe);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   235
        } finally {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   236
            if (in != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   237
                try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   238
                    in.close();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   239
                } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   240
                    throw ioe;
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
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   243
            if (out != null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   244
                try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   245
                    out.close();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   246
                } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   247
                    throw ioe;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   248
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   249
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   250
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   251
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   252
        OCSPResponse ocspResponse = null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   253
        try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   254
            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
   255
        } catch (IOException ioe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   256
            // response decoding exception
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   257
            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
   258
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   259
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   260
        // verify the response
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   261
        ocspResponse.verify(certIds, responderCert, date, request.getNonce());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   262
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   263
        return ocspResponse;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   264
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   265
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   266
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   267
     * 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
   268
     * 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
   269
     * not specified.
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
     * @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
   272
     * @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
   273
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   274
    // 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
   275
    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
   276
        try {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   277
            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
   278
        } catch (CertificateException ce) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   279
            // 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
   280
            return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   281
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   282
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   283
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   284
    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
   285
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   286
        // 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
   287
        AuthorityInfoAccessExtension aia =
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   288
            certImpl.getAuthorityInfoAccessExtension();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   289
        if (aia == null) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   290
            return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   291
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   292
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   293
        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
   294
        for (AccessDescription description : descriptions) {
10336
0bb1999251f8 7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents: 5506
diff changeset
   295
            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
   296
                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
   297
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   298
                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
   299
                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
   300
                    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
   301
                    return uri.getURI();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   302
                }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   303
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   304
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   305
        return null;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   306
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   307
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   308
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   309
     * 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
   310
     */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   311
    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
   312
        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
   313
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   314
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   315
         * 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
   316
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   317
        CertStatus getCertStatus();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   318
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   319
         * 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
   320
         * 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
   321
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   322
        Date getRevocationTime();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   323
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   324
         * 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
   325
         * 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
   326
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   327
        CRLReason getRevocationReason();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   328
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   329
        /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   330
         * 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
   331
         */
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   332
        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
   333
    }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   334
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   335
    static class NetworkFailureException extends CertPathValidatorException {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   336
        private static final long serialVersionUID = 0l;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   337
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   338
        private NetworkFailureException(IOException ioe) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   339
            super(ioe);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   340
        }
13596
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
   341
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
   342
        @Override
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
   343
        public CertPathValidatorException.Reason getReason() {
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
   344
            return BasicReason.UNDETERMINED_REVOCATION_STATUS;
897dea1b4c1f 7192896: Reason of CertPathValidatorException should be UNDETERMINED_REVOCATION_STATUS if OCSP request failed
mullan
parents: 12860
diff changeset
   345
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   346
    }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
diff changeset
   347
}