jdk/src/java.base/share/classes/sun/security/provider/certpath/OCSPResponse.java
author ascarpino
Wed, 08 Feb 2017 12:08:28 -0800
changeset 43701 fe8c324ba97c
parent 41562 1e040ccac110
permissions -rw-r--r--
8160655: Fix denyAfter and usage types for security properties Reviewed-by: mullan, xuelei
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
     2
 * Copyright (c) 2003, 2017, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4673
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4673
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4673
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4673
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 4673
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.security.provider.certpath;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.security.*;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
    30
import java.security.cert.CertificateException;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
    31
import java.security.cert.CertificateParsingException;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.security.cert.CertPathValidatorException;
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
    33
import java.security.cert.CertPathValidatorException.BasicReason;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.security.cert.CRLReason;
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
    35
import java.security.cert.TrustAnchor;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.security.cert.X509Certificate;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    37
import java.util.ArrayList;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    38
import java.util.Arrays;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
    39
import java.util.Collections;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.util.Date;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.util.HashMap;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.util.List;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.util.Map;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
    44
import java.util.Set;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    45
import javax.security.auth.x500.X500Principal;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
    46
34687
d302ed125dc9 8144995: Move sun.misc.HexDumpEncoder to sun.security.util
chegar
parents: 32649
diff changeset
    47
import sun.security.util.HexDumpEncoder;
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
    48
import sun.security.action.GetIntegerAction;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import sun.security.x509.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.security.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * This class is used to process an OCSP response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * The OCSP Response is defined
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * in RFC 2560 and the ASN.1 encoding is as follows:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 *  OCSPResponse ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 *      responseStatus         OCSPResponseStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 *      responseBytes          [0] EXPLICIT ResponseBytes OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 *   OCSPResponseStatus ::= ENUMERATED {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 *       successful            (0),  --Response has valid confirmations
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 *       malformedRequest      (1),  --Illegal confirmation request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 *       internalError         (2),  --Internal error in issuer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 *       tryLater              (3),  --Try again later
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *                                   --(4) is not used
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 *       sigRequired           (5),  --Must sign the request
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *       unauthorized          (6)   --Request unauthorized
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 *   }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
 *   ResponseBytes ::=       SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
 *       responseType   OBJECT IDENTIFIER,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
 *       response       OCTET STRING }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
 *   BasicOCSPResponse       ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
 *      tbsResponseData      ResponseData,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
 *      signatureAlgorithm   AlgorithmIdentifier,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
 *      signature            BIT STRING,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
 *      certs                [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
 *   The value for signature SHALL be computed on the hash of the DER
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
 *   encoding ResponseData.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
 *   ResponseData ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
 *      version              [0] EXPLICIT Version DEFAULT v1,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
 *      responderID              ResponderID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
 *      producedAt               GeneralizedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
 *      responses                SEQUENCE OF SingleResponse,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
 *      responseExtensions   [1] EXPLICIT Extensions OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
 *   ResponderID ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
 *      byName               [1] Name,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
 *      byKey                [2] KeyHash }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
 *   KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
 *   (excluding the tag and length fields)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
 *   SingleResponse ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
 *      certID                       CertID,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
 *      certStatus                   CertStatus,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
 *      thisUpdate                   GeneralizedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
 *      nextUpdate         [0]       EXPLICIT GeneralizedTime OPTIONAL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
 *      singleExtensions   [1]       EXPLICIT Extensions OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
 *   CertStatus ::= CHOICE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
 *       good        [0]     IMPLICIT NULL,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
 *       revoked     [1]     IMPLICIT RevokedInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
 *       unknown     [2]     IMPLICIT UnknownInfo }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
 *   RevokedInfo ::= SEQUENCE {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
 *       revocationTime              GeneralizedTime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
 *       revocationReason    [0]     EXPLICIT CRLReason OPTIONAL }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
 *   UnknownInfo ::= NULL -- this can be replaced with an enumeration
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
 * @author      Ram Marti
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   122
public final class OCSPResponse {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   124
    public enum ResponseStatus {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   125
        SUCCESSFUL,            // Response has valid confirmations
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   126
        MALFORMED_REQUEST,     // Illegal request
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   127
        INTERNAL_ERROR,        // Internal error in responder
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   128
        TRY_LATER,             // Try again later
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   129
        UNUSED,                // is not used
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   130
        SIG_REQUIRED,          // Must sign the request
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   131
        UNAUTHORIZED           // Request unauthorized
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   132
    };
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   133
    private static final ResponseStatus[] rsvalues = ResponseStatus.values();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   135
    private static final Debug debug = Debug.getInstance("certpath");
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   136
    private static final boolean dump = debug != null && Debug.isOn("ocsp");
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   137
    private static final ObjectIdentifier OCSP_BASIC_RESPONSE_OID =
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   138
        ObjectIdentifier.newInternal(new int[] { 1, 3, 6, 1, 5, 5, 7, 48, 1, 1});
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   139
    private static final int CERT_STATUS_GOOD = 0;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   140
    private static final int CERT_STATUS_REVOKED = 1;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   141
    private static final int CERT_STATUS_UNKNOWN = 2;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
    // ResponderID CHOICE tags
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    private static final int NAME_TAG = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static final int KEY_TAG = 2;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
    // Object identifier for the OCSPSigning key purpose
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
    private static final String KP_OCSP_SIGNING_OID = "1.3.6.1.5.5.7.3.9";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   150
    // Default maximum clock skew in milliseconds (15 minutes)
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   151
    // allowed when checking validity of OCSP responses
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   152
    private static final int DEFAULT_MAX_CLOCK_SKEW = 900000;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   153
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   154
    /**
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   155
     * Integer value indicating the maximum allowable clock skew,
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   156
     * in milliseconds, to be used for the OCSP check.
17044
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   157
     */
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   158
    private static final int MAX_CLOCK_SKEW = initializeClockSkew();
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   159
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   160
    /**
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   161
     * Initialize the maximum allowable clock skew by getting the OCSP
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   162
     * clock skew system property. If the property has not been set, or if its
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   163
     * value is negative, set the skew to the default.
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   164
     */
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   165
    private static int initializeClockSkew() {
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   166
        Integer tmp = java.security.AccessController.doPrivileged(
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   167
                new GetIntegerAction("com.sun.security.ocsp.clockSkew"));
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   168
        if (tmp == null || tmp < 0) {
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   169
            return DEFAULT_MAX_CLOCK_SKEW;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   170
        }
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   171
        // Convert to milliseconds, as the system property will be
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   172
        // specified in seconds
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   173
        return tmp * 1000;
c67bf062ca30 8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents: 13402
diff changeset
   174
    }
1567
58ef474069d7 6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents: 2
diff changeset
   175
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
    // an array of all of the CRLReasons (used in SingleResponse)
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   177
    private static final CRLReason[] values = CRLReason.values();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   179
    private final ResponseStatus responseStatus;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   180
    private final Map<CertId, SingleResponse> singleResponseMap;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   181
    private final AlgorithmId sigAlgId;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   182
    private final byte[] signature;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   183
    private final byte[] tbsResponseData;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   184
    private final byte[] responseNonce;
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   185
    private List<X509CertImpl> certs;
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   186
    private X509CertImpl signerCert = null;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   187
    private final ResponderId respId;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   188
    private Date producedAtDate = null;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   189
    private final Map<String, java.security.cert.Extension> responseExtensions;
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   190
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
     * Create an OCSP response from its ASN.1 DER encoding.
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   193
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   194
     * @param bytes The DER-encoded bytes for an OCSP response
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     */
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   196
    public OCSPResponse(byte[] bytes) throws IOException {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   197
        if (dump) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   198
            HexDumpEncoder hexEnc = new HexDumpEncoder();
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   199
            debug.println("OCSPResponse bytes...\n\n" +
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   200
                hexEnc.encode(bytes) + "\n");
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   201
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   202
        DerValue der = new DerValue(bytes);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   203
        if (der.tag != DerValue.tag_Sequence) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   204
            throw new IOException("Bad encoding in OCSP response: " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   205
                "expected ASN.1 SEQUENCE tag.");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   206
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   207
        DerInputStream derIn = der.getData();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   209
        // responseStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   210
        int status = derIn.getEnumerated();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   211
        if (status >= 0 && status < rsvalues.length) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   212
            responseStatus = rsvalues[status];
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   213
        } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   214
            // unspecified responseStatus
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   215
            throw new IOException("Unknown OCSPResponse status: " + status);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   216
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   217
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   218
            debug.println("OCSP response status: " + responseStatus);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   219
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   220
        if (responseStatus != ResponseStatus.SUCCESSFUL) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   221
            // no need to continue, responseBytes are not set.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   222
            singleResponseMap = Collections.emptyMap();
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   223
            certs = new ArrayList<X509CertImpl>();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   224
            sigAlgId = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   225
            signature = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   226
            tbsResponseData = null;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   227
            responseNonce = null;
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   228
            responseExtensions = Collections.emptyMap();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   229
            respId = null;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   230
            return;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   231
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   233
        // responseBytes
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   234
        der = derIn.getDerValue();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   235
        if (!der.isContextSpecific((byte)0)) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   236
            throw new IOException("Bad encoding in responseBytes element " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   237
                "of OCSP response: expected ASN.1 context specific tag 0.");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   238
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   239
        DerValue tmp = der.data.getDerValue();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   240
        if (tmp.tag != DerValue.tag_Sequence) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   241
            throw new IOException("Bad encoding in responseBytes element " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   242
                "of OCSP response: expected ASN.1 SEQUENCE tag.");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   243
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   245
        // responseType
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   246
        derIn = tmp.data;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   247
        ObjectIdentifier responseType = derIn.getOID();
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   248
        if (responseType.equals((Object)OCSP_BASIC_RESPONSE_OID)) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   249
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   250
                debug.println("OCSP response type: basic");
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   251
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   252
        } else {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   253
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   254
                debug.println("OCSP response type: " + responseType);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
            }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   256
            throw new IOException("Unsupported OCSP response type: " +
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   257
                                  responseType);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   258
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   260
        // BasicOCSPResponse
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   261
        DerInputStream basicOCSPResponse =
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   262
            new DerInputStream(derIn.getOctetString());
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   264
        DerValue[] seqTmp = basicOCSPResponse.getSequence(2);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   265
        if (seqTmp.length < 3) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   266
            throw new IOException("Unexpected BasicOCSPResponse value");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   267
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   269
        DerValue responseData = seqTmp[0];
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   270
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   271
        // Need the DER encoded ResponseData to verify the signature later
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   272
        tbsResponseData = seqTmp[0].toByteArray();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   274
        // tbsResponseData
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   275
        if (responseData.tag != DerValue.tag_Sequence) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   276
            throw new IOException("Bad encoding in tbsResponseData " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   277
                "element of OCSP response: expected ASN.1 SEQUENCE tag.");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   278
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   279
        DerInputStream seqDerIn = responseData.data;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   280
        DerValue seq = seqDerIn.getDerValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   282
        // version
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   283
        if (seq.isContextSpecific((byte)0)) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   284
            // seq[0] is version
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   285
            if (seq.isConstructed() && seq.isContextSpecific()) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   286
                //System.out.println ("version is available");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   287
                seq = seq.data.getDerValue();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   288
                int version = seq.getInteger();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   289
                if (seq.data.available() != 0) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   290
                    throw new IOException("Bad encoding in version " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   291
                        " element of OCSP response: bad format");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
                }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   293
                seq = seqDerIn.getDerValue();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   295
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   297
        // responderID
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   298
        respId = new ResponderId(seq.toByteArray());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   299
        if (debug != null) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   300
            debug.println("Responder ID: " + respId);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   301
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   303
        // producedAt
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   304
        seq = seqDerIn.getDerValue();
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   305
        producedAtDate = seq.getGeneralizedTime();
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   306
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   307
            debug.println("OCSP response produced at: " + producedAtDate);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   308
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   310
        // responses
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   311
        DerValue[] singleResponseDer = seqDerIn.getSequence(1);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   312
        singleResponseMap = new HashMap<>(singleResponseDer.length);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   313
        if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   314
            debug.println("OCSP number of SingleResponses: "
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   315
                          + singleResponseDer.length);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   316
        }
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   317
        for (DerValue srDer : singleResponseDer) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   318
            SingleResponse singleResponse = new SingleResponse(srDer);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   319
            singleResponseMap.put(singleResponse.getCertId(), singleResponse);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   320
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   322
        // responseExtensions
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   323
        Map<String, java.security.cert.Extension> tmpExtMap = new HashMap<>();
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   324
        if (seqDerIn.available() > 0) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   325
            seq = seqDerIn.getDerValue();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   326
            if (seq.isContextSpecific((byte)1)) {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   327
                tmpExtMap = parseExtensions(seq);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   329
        }
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   330
        responseExtensions = tmpExtMap;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   331
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   332
        // Attach the nonce value if found in the extension map
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   333
        Extension nonceExt = (Extension)tmpExtMap.get(
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   334
                PKIXExtensions.OCSPNonce_Id.toString());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   335
        responseNonce = (nonceExt != null) ?
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   336
                nonceExt.getExtensionValue() : null;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   337
        if (debug != null && responseNonce != null) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   338
            debug.println("Response nonce: " + Arrays.toString(responseNonce));
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   339
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   341
        // signatureAlgorithmId
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   342
        sigAlgId = AlgorithmId.parse(seqTmp[1]);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   343
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   344
        // signature
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   345
        signature = seqTmp[2].getBitString();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   347
        // if seq[3] is available , then it is a sequence of certificates
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   348
        if (seqTmp.length > 3) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   349
            // certs are available
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   350
            DerValue seqCert = seqTmp[3];
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   351
            if (!seqCert.isContextSpecific((byte)0)) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   352
                throw new IOException("Bad encoding in certs element of " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   353
                    "OCSP response: expected ASN.1 context specific tag 0.");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   354
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   355
            DerValue[] derCerts = seqCert.getData().getSequence(3);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   356
            certs = new ArrayList<X509CertImpl>(derCerts.length);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   357
            try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   358
                for (int i = 0; i < derCerts.length; i++) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   359
                    X509CertImpl cert =
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   360
                        new X509CertImpl(derCerts[i].toByteArray());
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   361
                    certs.add(cert);
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   362
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   363
                    if (debug != null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   364
                        debug.println("OCSP response cert #" + (i + 1) + ": " +
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   365
                            cert.getSubjectX500Principal());
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   366
                    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
                }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   368
            } catch (CertificateException ce) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   369
                throw new IOException("Bad encoding in X509 Certificate", ce);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   371
        } else {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   372
            certs = new ArrayList<X509CertImpl>();
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   373
        }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   374
    }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   375
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   376
    void verify(List<CertId> certIds, IssuerInfo issuerInfo,
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
   377
            X509Certificate responderCert, Date date, byte[] nonce,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
   378
            String variant)
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   379
        throws CertPathValidatorException
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   380
    {
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   381
        switch (responseStatus) {
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   382
            case SUCCESSFUL:
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   383
                break;
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   384
            case TRY_LATER:
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   385
            case INTERNAL_ERROR:
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   386
                throw new CertPathValidatorException(
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   387
                    "OCSP response error: " + responseStatus, null, null, -1,
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   388
                    BasicReason.UNDETERMINED_REVOCATION_STATUS);
19820
9ee1d7810f50 8023362: Don't allow soft-fail behavior if OCSP responder returns "unauthorized"
mullan
parents: 19045
diff changeset
   389
            case UNAUTHORIZED:
19045
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   390
            default:
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   391
                throw new CertPathValidatorException("OCSP response error: " +
bc9a25fff6c5 8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents: 17729
diff changeset
   392
                                                     responseStatus);
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   393
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   394
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   395
        // Check that the response includes a response for all of the
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   396
        // certs that were supplied in the request
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   397
        for (CertId certId : certIds) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   398
            SingleResponse sr = getSingleResponse(certId);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   399
            if (sr == null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   400
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   401
                    debug.println("No response found for CertId: " + certId);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   402
                }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   403
                throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   404
                    "OCSP response does not include a response for a " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   405
                    "certificate supplied in the OCSP request");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   406
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   407
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   408
                debug.println("Status of certificate (with serial number " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   409
                    certId.getSerialNumber() + ") is: " + sr.getCertStatus());
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   410
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   411
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   412
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   413
        // Locate the signer cert
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   414
        if (signerCert == null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   415
            // Add the Issuing CA cert and/or Trusted Responder cert to the list
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   416
            // of certs from the OCSP response
22063
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   417
            try {
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   418
                if (issuerInfo.getCertificate() != null) {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   419
                    certs.add(X509CertImpl.toImpl(issuerInfo.getCertificate()));
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   420
                }
22063
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   421
                if (responderCert != null) {
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   422
                    certs.add(X509CertImpl.toImpl(responderCert));
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   423
                }
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   424
            } catch (CertificateException ce) {
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   425
                throw new CertPathValidatorException(
e5cdd7bc3564 8029788: Certificate validation - java.lang.ClassCastException
vinnie
parents: 21819
diff changeset
   426
                    "Invalid issuer or trusted responder certificate", ce);
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   427
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   429
            if (respId.getType() == ResponderId.Type.BY_NAME) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   430
                X500Principal rName = respId.getResponderName();
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   431
                for (X509CertImpl cert : certs) {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   432
                    if (cert.getSubjectX500Principal().equals(rName)) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   433
                        signerCert = cert;
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   434
                        break;
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   435
                    }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   436
                }
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   437
            } else if (respId.getType() == ResponderId.Type.BY_KEY) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   438
                KeyIdentifier ridKeyId = respId.getKeyIdentifier();
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   439
                for (X509CertImpl cert : certs) {
22356
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   440
                    // Match responder's key identifier against the cert's SKID
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   441
                    // This will match if the SKID is encoded using the 160-bit
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   442
                    // SHA-1 hash method as defined in RFC 5280.
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   443
                    KeyIdentifier certKeyId = cert.getSubjectKeyId();
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   444
                    if (certKeyId != null && ridKeyId.equals(certKeyId)) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   445
                        signerCert = cert;
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   446
                        break;
22356
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   447
                    } else {
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   448
                        // The certificate does not have a SKID or may have
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   449
                        // been using a different algorithm (ex: see RFC 7093).
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   450
                        // Check if the responder's key identifier matches
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   451
                        // against a newly generated key identifier of the
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   452
                        // cert's public key using the 160-bit SHA-1 method.
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   453
                        try {
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   454
                            certKeyId = new KeyIdentifier(cert.getPublicKey());
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   455
                        } catch (IOException e) {
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   456
                            // ignore
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   457
                        }
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   458
                        if (ridKeyId.equals(certKeyId)) {
22356
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   459
                            signerCert = cert;
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   460
                            break;
dc568020e87e 8031825: OCSP client can't find responder cert if it uses a different subject key id algorithm than responderID
mullan
parents: 22063
diff changeset
   461
                        }
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   462
                    }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   463
                }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   464
            }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   465
        }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   466
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   467
        // Check whether the signer cert returned by the responder is trusted
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   468
        if (signerCert != null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   469
            // Check if the response is signed by the issuing CA
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   470
            if (signerCert.getSubjectX500Principal().equals(
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   471
                    issuerInfo.getName()) &&
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   472
                    signerCert.getPublicKey().equals(
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   473
                            issuerInfo.getPublicKey())) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   474
                if (debug != null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   475
                    debug.println("OCSP response is signed by the target's " +
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   476
                        "Issuing CA");
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   477
                }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   478
                // cert is trusted, now verify the signed response
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   480
            // Check if the response is signed by a trusted responder
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   481
            } else if (signerCert.equals(responderCert)) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   482
                if (debug != null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   483
                    debug.println("OCSP response is signed by a Trusted " +
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   484
                        "Responder");
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   485
                }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   486
                // cert is trusted, now verify the signed response
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   487
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   488
            // Check if the response is signed by an authorized responder
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   489
            } else if (signerCert.getIssuerX500Principal().equals(
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   490
                    issuerInfo.getName())) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   492
                // Check for the OCSPSigning key purpose
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   493
                try {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   494
                    List<String> keyPurposes = signerCert.getExtendedKeyUsage();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
                    if (keyPurposes == null ||
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
                        !keyPurposes.contains(KP_OCSP_SIGNING_OID)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
                        throw new CertPathValidatorException(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
                            "Responder's certificate not valid for signing " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                            "OCSP responses");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                    }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   501
                } catch (CertificateParsingException cpe) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   502
                    // assume cert is not valid for signing
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   503
                    throw new CertPathValidatorException(
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   504
                        "Responder's certificate not valid for signing " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   505
                        "OCSP responses", cpe);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   506
                }
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 1639
diff changeset
   507
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   508
                // Check algorithm constraints specified in security property
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   509
                // "jdk.certpath.disabledAlgorithms".
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   510
                AlgorithmChecker algChecker =
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
   511
                        new AlgorithmChecker(issuerInfo.getAnchor(), date,
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
   512
                                variant);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   513
                algChecker.init(false);
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   514
                algChecker.check(signerCert, Collections.<String>emptySet());
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   515
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   516
                // check the validity
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   517
                try {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   518
                    if (date == null) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   519
                        signerCert.checkValidity();
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 1639
diff changeset
   520
                    } else {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   521
                        signerCert.checkValidity(date);
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 1639
diff changeset
   522
                    }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   523
                } catch (CertificateException e) {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   524
                    throw new CertPathValidatorException(
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   525
                        "Responder's certificate not within the " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   526
                        "validity period", e);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   527
                }
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 1639
diff changeset
   528
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   529
                // check for revocation
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   530
                //
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   531
                // A CA may specify that an OCSP client can trust a
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   532
                // responder for the lifetime of the responder's
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   533
                // certificate. The CA does so by including the
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   534
                // extension id-pkix-ocsp-nocheck.
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   535
                //
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   536
                Extension noCheck =
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   537
                    signerCert.getExtension(PKIXExtensions.OCSPNoCheck_Id);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   538
                if (noCheck != null) {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   539
                    if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   540
                        debug.println("Responder's certificate includes " +
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   541
                            "the extension id-pkix-ocsp-nocheck.");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
                    }
2281
34fd38495efa 6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents: 1639
diff changeset
   543
                } else {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   544
                    // we should do the revocation checking of the
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   545
                    // authorized responder in a future update.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   548
                // verify the signature
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   549
                try {
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   550
                    signerCert.verify(issuerInfo.getPublicKey());
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   551
                    if (debug != null) {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   552
                        debug.println("OCSP response is signed by an " +
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   553
                            "Authorized Responder");
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   554
                    }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   555
                    // cert is trusted, now verify the signed response
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   557
                } catch (GeneralSecurityException e) {
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   558
                    signerCert = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
            } else {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   561
                throw new CertPathValidatorException(
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   562
                    "Responder's certificate is not authorized to sign " +
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   563
                    "OCSP responses");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   564
            }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   565
        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   566
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   567
        // Confirm that the signed response was generated using the public
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   568
        // key from the trusted responder cert
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   569
        if (signerCert != null) {
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   570
            // Check algorithm constraints specified in security property
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   571
            // "jdk.certpath.disabledAlgorithms".
43701
fe8c324ba97c 8160655: Fix denyAfter and usage types for security properties
ascarpino
parents: 41562
diff changeset
   572
            AlgorithmChecker.check(signerCert.getPublicKey(), sigAlgId, variant);
7040
659824c2a550 6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents: 5506
diff changeset
   573
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   574
            if (!verifySignature(signerCert)) {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
                throw new CertPathValidatorException(
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   576
                    "Error verifying OCSP Response's signature");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   578
        } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   579
            // Need responder's cert in order to verify the signature
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   580
            throw new CertPathValidatorException(
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   581
                "Unable to verify OCSP Response's signature");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   582
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   583
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   584
        if (nonce != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   585
            if (responseNonce != null && !Arrays.equals(nonce, responseNonce)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   586
                throw new CertPathValidatorException("Nonces don't match");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   587
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   588
        }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   589
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   590
        // Check freshness of OCSPResponse
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   591
        long now = (date == null) ? System.currentTimeMillis() : date.getTime();
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   592
        Date nowPlusSkew = new Date(now + MAX_CLOCK_SKEW);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   593
        Date nowMinusSkew = new Date(now - MAX_CLOCK_SKEW);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   594
        for (SingleResponse sr : singleResponseMap.values()) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   595
            if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   596
                String until = "";
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   597
                if (sr.nextUpdate != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   598
                    until = " until " + sr.nextUpdate;
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   599
                }
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   600
                debug.println("OCSP response validity interval is from " +
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   601
                        sr.thisUpdate + until);
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   602
                debug.println("Checking validity of OCSP response on: " +
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   603
                        new Date(now));
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   604
            }
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   605
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   606
            // Check that the test date is within the validity interval:
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   607
            //   [ thisUpdate - MAX_CLOCK_SKEW,
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   608
            //     MAX(thisUpdate, nextUpdate) + MAX_CLOCK_SKEW ]
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   609
            if (nowPlusSkew.before(sr.thisUpdate) ||
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   610
                    nowMinusSkew.after(
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   611
                    sr.nextUpdate != null ? sr.nextUpdate : sr.thisUpdate))
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   612
            {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   613
                throw new CertPathValidatorException(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   614
                                      "Response is unreliable: its validity " +
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   615
                                      "interval is out-of-date");
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   616
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   620
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   621
     * Returns the OCSP ResponseStatus.
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   622
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   623
     * @return the {@code ResponseStatus} for this OCSP response
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   624
     */
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   625
    public ResponseStatus getResponseStatus() {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   626
        return responseStatus;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   627
    }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   628
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
     * Verify the signature of the OCSP response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
     */
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   632
    private boolean verifySignature(X509Certificate cert)
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   633
        throws CertPathValidatorException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
            Signature respSignature = Signature.getInstance(sigAlgId.getName());
17729
90a2bf654c4f 7174966: With OCSP enabled on Java 7 get error 'Wrong key usage' with Comodo certificate
vinnie
parents: 17044
diff changeset
   637
            respSignature.initVerify(cert.getPublicKey());
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   638
            respSignature.update(tbsResponseData);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   639
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   640
            if (respSignature.verify(signature)) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   641
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   642
                    debug.println("Verified signature of OCSP Response");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   643
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   644
                return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   645
90ce3da70b43 Initial load
duke
parents:
diff changeset
   646
            } else {
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   647
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   648
                    debug.println(
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   649
                        "Error verifying signature of OCSP Response");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   650
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   651
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   652
            }
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   653
        } catch (InvalidKeyException | NoSuchAlgorithmException |
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   654
                 SignatureException e)
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   655
        {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   656
            throw new CertPathValidatorException(e);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   657
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   658
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   659
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   660
    /**
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   661
     * Returns the SingleResponse of the specified CertId, or null if
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   662
     * there is no response for that CertId.
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   663
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   664
     * @param certId the {@code CertId} for a {@code SingleResponse} to be
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   665
     * searched for in the OCSP response.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   666
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   667
     * @return the {@code SingleResponse} for the provided {@code CertId},
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   668
     * or {@code null} if it is not found.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   669
     */
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   670
    public SingleResponse getSingleResponse(CertId certId) {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   671
        return singleResponseMap.get(certId);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   672
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   673
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   674
    /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   675
     * Return a set of all CertIds in this {@code OCSPResponse}
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   676
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   677
     * @return an unmodifiable set containing every {@code CertId} in this
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   678
     *      response.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   679
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   680
    public Set<CertId> getCertIds() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   681
        return Collections.unmodifiableSet(singleResponseMap.keySet());
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   682
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   683
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   684
    /*
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   685
     * Returns the certificate for the authority that signed the OCSP response.
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   686
     */
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   687
    X509Certificate getSignerCertificate() {
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   688
        return signerCert; // set in verify()
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   689
    }
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   690
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   691
    /**
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   692
     * Get the {@code ResponderId} from this {@code OCSPResponse}
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   693
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   694
     * @return the {@code ResponderId} from this response or {@code null}
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   695
     *      if no responder ID is in the body of the response (e.g. a
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   696
     *      response with a status other than SUCCESS.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   697
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   698
    public ResponderId getResponderId() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   699
        return respId;
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   700
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   701
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   702
    /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   703
     * Provide a String representation of an OCSPResponse
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   704
     *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   705
     * @return a human-readable representation of the OCSPResponse
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   706
     */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   707
    @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   708
    public String toString() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   709
        StringBuilder sb = new StringBuilder();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   710
        sb.append("OCSP Response:\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   711
        sb.append("Response Status: ").append(responseStatus).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   712
        sb.append("Responder ID: ").append(respId).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   713
        sb.append("Produced at: ").append(producedAtDate).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   714
        int count = singleResponseMap.size();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   715
        sb.append(count).append(count == 1 ?
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   716
                " response:\n" : " responses:\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   717
        for (SingleResponse sr : singleResponseMap.values()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   718
            sb.append(sr).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   719
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   720
        if (responseExtensions != null && responseExtensions.size() > 0) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   721
            count = responseExtensions.size();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   722
            sb.append(count).append(count == 1 ?
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   723
                    " extension:\n" : " extensions:\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   724
            for (String extId : responseExtensions.keySet()) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   725
                sb.append(responseExtensions.get(extId)).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   726
            }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   727
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   728
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   729
        return sb.toString();
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   730
    }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   731
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   732
    /**
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   733
     * Build a String-Extension map from DER encoded data.
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   734
     * @param derVal A {@code DerValue} object built from a SEQUENCE of
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   735
     *      extensions
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   736
     *
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   737
     * @return a {@code Map} using the OID in string form as the keys.  If no
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   738
     *      extensions are found or an empty SEQUENCE is passed in, then
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   739
     *      an empty {@code Map} will be returned.
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   740
     *
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   741
     * @throws IOException if any decoding errors occur.
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   742
     */
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   743
    private static Map<String, java.security.cert.Extension>
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   744
        parseExtensions(DerValue derVal) throws IOException {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   745
        DerValue[] extDer = derVal.data.getSequence(3);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   746
        Map<String, java.security.cert.Extension> extMap =
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   747
                new HashMap<>(extDer.length);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   748
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   749
        for (DerValue extDerVal : extDer) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   750
            Extension ext = new Extension(extDerVal);
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   751
            if (debug != null) {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   752
                debug.println("Extension: " + ext);
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   753
            }
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   754
            // We don't support any extensions yet. Therefore, if it
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   755
            // is critical we must throw an exception because we
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   756
            // don't know how to process it.
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   757
            if (ext.isCritical()) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   758
                throw new IOException("Unsupported OCSP critical extension: " +
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   759
                        ext.getExtensionId());
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   760
            }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   761
            extMap.put(ext.getId(), ext);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   762
        }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   763
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   764
        return extMap;
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   765
    }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   766
21819
8cd757e836d8 8015571: OCSP validation fails if ocsp.responderCertSubjectName is set
vinnie
parents: 19820
diff changeset
   767
    /*
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   768
     * A class representing a single OCSP response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   769
     */
32649
2ee9017c7597 8136583: Core libraries should use blessed modifier order
martin
parents: 32032
diff changeset
   770
    public static final class SingleResponse implements OCSP.RevocationStatus {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   771
        private final CertId certId;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   772
        private final CertStatus certStatus;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   773
        private final Date thisUpdate;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   774
        private final Date nextUpdate;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   775
        private final Date revocationTime;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   776
        private final CRLReason revocationReason;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   777
        private final Map<String, java.security.cert.Extension> singleExtensions;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   778
90ce3da70b43 Initial load
duke
parents:
diff changeset
   779
        private SingleResponse(DerValue der) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   780
            if (der.tag != DerValue.tag_Sequence) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   781
                throw new IOException("Bad ASN.1 encoding in SingleResponse");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   782
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   783
            DerInputStream tmp = der.data;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   784
90ce3da70b43 Initial load
duke
parents:
diff changeset
   785
            certId = new CertId(tmp.getDerValue().data);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   786
            DerValue derVal = tmp.getDerValue();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   787
            short tag = (byte)(derVal.tag & 0x1f);
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   788
            if (tag ==  CERT_STATUS_REVOKED) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   789
                certStatus = CertStatus.REVOKED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   790
                revocationTime = derVal.data.getGeneralizedTime();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   791
                if (derVal.data.available() != 0) {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   792
                    DerValue dv = derVal.data.getDerValue();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   793
                    tag = (byte)(dv.tag & 0x1f);
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   794
                    if (tag == 0) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   795
                        int reason = dv.data.getEnumerated();
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   796
                        // if reason out-of-range just leave as UNSPECIFIED
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   797
                        if (reason >= 0 && reason < values.length) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   798
                            revocationReason = values[reason];
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   799
                        } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   800
                            revocationReason = CRLReason.UNSPECIFIED;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   801
                        }
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   802
                    } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   803
                        revocationReason = CRLReason.UNSPECIFIED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   804
                    }
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   805
                } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   806
                    revocationReason = CRLReason.UNSPECIFIED;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   807
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   808
                // RevokedInfo
12860
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   809
                if (debug != null) {
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   810
                    debug.println("Revocation time: " + revocationTime);
9ffbd4e43413 6854712: Revocation checking enhancements (JEP-124)
mullan
parents: 10336
diff changeset
   811
                    debug.println("Revocation reason: " + revocationReason);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   812
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   813
            } else {
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   814
                revocationTime = null;
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   815
                revocationReason = null;
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   816
                if (tag == CERT_STATUS_GOOD) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   817
                    certStatus = CertStatus.GOOD;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   818
                } else if (tag == CERT_STATUS_UNKNOWN) {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   819
                    certStatus = CertStatus.UNKNOWN;
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   820
                } else {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   821
                    throw new IOException("Invalid certificate status");
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   822
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   823
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   824
90ce3da70b43 Initial load
duke
parents:
diff changeset
   825
            thisUpdate = tmp.getGeneralizedTime();
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   826
            if (debug != null) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   827
                debug.println("thisUpdate: " + thisUpdate);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   828
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   829
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   830
            // Parse optional fields like nextUpdate and singleExtensions
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   831
            Date tmpNextUpdate = null;
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   832
            Map<String, java.security.cert.Extension> tmpMap = null;
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   833
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   834
            // Check for the first optional item, it could be nextUpdate
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   835
            // [CONTEXT 0] or singleExtensions [CONTEXT 1]
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   836
            if (tmp.available() > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   837
                derVal = tmp.getDerValue();
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   838
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   839
                // nextUpdate processing
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   840
                if (derVal.isContextSpecific((byte)0)) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   841
                    tmpNextUpdate = derVal.data.getGeneralizedTime();
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   842
                    if (debug != null) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   843
                        debug.println("nextUpdate: " + tmpNextUpdate);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   844
                    }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   845
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   846
                    // If more data exists in the singleResponse, it
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   847
                    // can only be singleExtensions.  Get this DER value
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   848
                    // for processing in the next block
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   849
                    derVal = tmp.available() > 0 ? tmp.getDerValue() : null;
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   850
                }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   851
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   852
                // singleExtensions processing
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   853
                if (derVal != null) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   854
                    if (derVal.isContextSpecific((byte)1)) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   855
                        tmpMap = parseExtensions(derVal);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   856
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   857
                        // There should not be any other items in the
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   858
                        // singleResponse at this point.
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   859
                        if (tmp.available() > 0) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   860
                            throw new IOException(tmp.available() +
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   861
                                " bytes of additional data in singleResponse");
31703
82c80ffb85f5 8075374: Responding to OCSP responses
vinnie
parents: 31426
diff changeset
   862
                        }
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   863
                    } else {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   864
                        // Unknown item in the singleResponse
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   865
                        throw new IOException("Unsupported singleResponse " +
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   866
                            "item, tag = " + String.format("%02X", derVal.tag));
29484
066390a3907d 8074064: OCSPResponse.SingleResponse objects do not parse singleExtensions
jnimeh
parents: 25859
diff changeset
   867
                    }
066390a3907d 8074064: OCSPResponse.SingleResponse objects do not parse singleExtensions
jnimeh
parents: 25859
diff changeset
   868
                }
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   869
            }
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   870
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   871
            nextUpdate = tmpNextUpdate;
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   872
            singleExtensions = (tmpMap != null) ? tmpMap :
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   873
                    Collections.emptyMap();
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   874
            if (debug != null) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   875
                for (java.security.cert.Extension ext :
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   876
                        singleExtensions.values()) {
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   877
                   debug.println("singleExtension: " + ext);
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   878
                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   879
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   880
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   881
90ce3da70b43 Initial load
duke
parents:
diff changeset
   882
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   883
         * Return the certificate's revocation status code
90ce3da70b43 Initial load
duke
parents:
diff changeset
   884
         */
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   885
        @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   886
        public CertStatus getCertStatus() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   887
            return certStatus;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   888
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   889
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   890
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   891
         * Get the Cert ID that this SingleResponse is for.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   892
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   893
         * @return the {@code CertId} for this {@code SingleResponse}
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   894
         */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   895
        public CertId getCertId() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   896
            return certId;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   897
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   898
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   899
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   900
         * Get the {@code thisUpdate} field from this {@code SingleResponse}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   901
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   902
         * @return a {@link Date} object containing the thisUpdate date
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   903
         */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   904
        public Date getThisUpdate() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   905
            return (thisUpdate != null ? (Date) thisUpdate.clone() : null);
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   906
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   907
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   908
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   909
         * Get the {@code nextUpdate} field from this {@code SingleResponse}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   910
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   911
         * @return a {@link Date} object containing the nexUpdate date or
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   912
         * {@code null} if a nextUpdate field is not present in the response.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   913
         */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   914
        public Date getNextUpdate() {
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   915
            return (nextUpdate != null ? (Date) nextUpdate.clone() : null);
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   916
        }
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   917
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   918
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   919
         * Get the {@code revocationTime} field from this
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   920
         * {@code SingleResponse}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   921
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   922
         * @return a {@link Date} object containing the revocationTime date or
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   923
         * {@code null} if the {@code SingleResponse} does not have a status
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   924
         * of {@code REVOKED}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   925
         */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   926
        @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   927
        public Date getRevocationTime() {
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   928
            return (revocationTime != null ? (Date) revocationTime.clone() :
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   929
                    null);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   930
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   931
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   932
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   933
         * Get the {@code revocationReason} field for the
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   934
         * {@code SingleResponse}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   935
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   936
         * @return a {@link CRLReason} containing the revocation reason, or
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   937
         * {@code null} if a revocation reason was not provided or the
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   938
         * response status is not {@code REVOKED}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   939
         */
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   940
        @Override
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   941
        public CRLReason getRevocationReason() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   942
            return revocationReason;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   943
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   944
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   945
        /**
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   946
         * Get the {@code singleExtensions} for this {@code SingleResponse}.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   947
         *
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   948
         * @return a {@link Map} of {@link Extension} objects, keyed by
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   949
         * their OID value in string form.
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   950
         */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   951
        @Override
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   952
        public Map<String, java.security.cert.Extension> getSingleExtensions() {
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   953
            return Collections.unmodifiableMap(singleExtensions);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   954
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   955
90ce3da70b43 Initial load
duke
parents:
diff changeset
   956
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   957
         * Construct a string representation of a single OCSP response.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   958
         */
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   959
        @Override public String toString() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   960
            StringBuilder sb = new StringBuilder();
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   961
            sb.append("SingleResponse:\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   962
            sb.append(certId);
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   963
            sb.append("\nCertStatus: ").append(certStatus).append("\n");
3841
6738c111d48f 6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents: 3314
diff changeset
   964
            if (certStatus == CertStatus.REVOKED) {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   965
                sb.append("revocationTime is ");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   966
                sb.append(revocationTime).append("\n");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   967
                sb.append("revocationReason is ");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   968
                sb.append(revocationReason).append("\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   969
            }
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   970
            sb.append("thisUpdate is ").append(thisUpdate).append("\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   971
            if (nextUpdate != null) {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   972
                sb.append("nextUpdate is ").append(nextUpdate).append("\n");
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   973
            }
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   974
            for (java.security.cert.Extension ext : singleExtensions.values()) {
32032
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   975
                sb.append("singleExtension: ");
22badc53802f 8046321: OCSP Stapling for TLS
jnimeh
parents: 31704
diff changeset
   976
                sb.append(ext.toString()).append("\n");
31704
4727673aaa92 8077546: Restore the change to OCSPResponse in the fix for JDK-8074064
vinnie
parents: 31703
diff changeset
   977
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   978
            return sb.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   979
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   980
    }
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   981
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   982
    /**
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   983
     * Helper class that allows consumers to pass in issuer information.  This
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   984
     * will always consist of the issuer's name and public key, but may also
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   985
     * contain a certificate if the originating data is in that form.  The
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   986
     * trust anchor for the certificate chain will be included for certpath
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   987
     * disabled algorithm checking.
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   988
     */
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   989
    static final class IssuerInfo {
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   990
        private final TrustAnchor anchor;
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   991
        private final X509Certificate certificate;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   992
        private final X500Principal name;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   993
        private final PublicKey pubKey;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   994
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   995
        IssuerInfo(TrustAnchor anchor) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   996
            this(anchor, (anchor != null) ? anchor.getTrustedCert() : null);
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   997
        }
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
   998
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
   999
        IssuerInfo(X509Certificate issuerCert) {
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1000
            this(null, issuerCert);
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1001
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1002
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1003
        IssuerInfo(TrustAnchor anchor, X509Certificate issuerCert) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1004
            if (anchor == null && issuerCert == null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1005
                throw new NullPointerException("TrustAnchor and issuerCert " +
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1006
                        "cannot be null");
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1007
            }
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1008
            this.anchor = anchor;
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1009
            if (issuerCert != null) {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1010
                name = issuerCert.getSubjectX500Principal();
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1011
                pubKey = issuerCert.getPublicKey();
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1012
                certificate = issuerCert;
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1013
            } else {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1014
                name = anchor.getCA();
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1015
                pubKey = anchor.getCAPublicKey();
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1016
                certificate = anchor.getTrustedCert();
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1017
            }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1018
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1019
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1020
        /**
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1021
         * Get the certificate in this IssuerInfo if present.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1022
         *
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1023
         * @return the {@code X509Certificate} used to create this IssuerInfo
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1024
         * object, or {@code null} if a certificate was not used in its
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1025
         * creation.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1026
         */
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1027
        X509Certificate getCertificate() {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1028
            return certificate;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1029
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1030
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1031
        /**
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1032
         * Get the name of this issuer.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1033
         *
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1034
         * @return an {@code X500Principal} corresponding to this issuer's
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1035
         * name.  If derived from an issuer's {@code X509Certificate} this
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1036
         * would be equivalent to the certificate subject name.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1037
         */
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1038
        X500Principal getName() {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1039
            return name;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1040
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1041
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1042
        /**
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1043
         * Get the public key for this issuer.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1044
         *
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1045
         * @return a {@code PublicKey} for this issuer.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1046
         */
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1047
        PublicKey getPublicKey() {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1048
            return pubKey;
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1049
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1050
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1051
        /**
41562
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1052
         * Get the TrustAnchor for the certificate chain.
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1053
         *
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1054
         * @return a {@code TrustAnchor}.
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1055
         */
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1056
        TrustAnchor getAnchor() {
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1057
            return anchor;
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1058
        }
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1059
1e040ccac110 8165274: SHA1 certpath constraint check fails with OCSP certificate
ascarpino
parents: 40946
diff changeset
  1060
        /**
40946
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1061
         * Create a string representation of this IssuerInfo.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1062
         *
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1063
         * @return a {@code String} form of this IssuerInfo object.
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1064
         */
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1065
        @Override
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1066
        public String toString() {
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1067
            StringBuilder sb = new StringBuilder();
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1068
            sb.append("Issuer Info:\n");
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1069
            sb.append("Name: ").append(name.toString()).append("\n");
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1070
            sb.append("Public Key:\n").append(pubKey.toString()).append("\n");
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1071
            return sb.toString();
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1072
        }
362ab0ff2d9a 8132926: PKIXParameters built with public key form of TrustAnchor causes NPE during cert path building/validation
jnimeh
parents: 34687
diff changeset
  1073
    }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
  1074
}