author | vinnie |
Wed, 29 May 2013 14:57:51 +0100 | |
changeset 17729 | 90a2bf654c4f |
parent 17044 | c67bf062ca30 |
child 19045 | bc9a25fff6c5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
17044
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
2 |
* Copyright (c) 2003, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.provider.certpath; |
|
27 |
||
28 |
import java.io.*; |
|
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 | 32 |
import java.security.cert.CertPathValidatorException; |
33 |
import java.security.cert.CRLReason; |
|
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
34 |
import java.security.cert.TrustAnchor; |
2 | 35 |
import java.security.cert.X509Certificate; |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
36 |
import java.util.ArrayList; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
37 |
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
|
38 |
import java.util.Collections; |
2 | 39 |
import java.util.Date; |
40 |
import java.util.HashMap; |
|
41 |
import java.util.List; |
|
42 |
import java.util.Map; |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
43 |
import javax.security.auth.x500.X500Principal; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
44 |
|
2 | 45 |
import sun.misc.HexDumpEncoder; |
17044
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
46 |
import sun.security.action.GetIntegerAction; |
2 | 47 |
import sun.security.x509.*; |
48 |
import sun.security.util.*; |
|
49 |
||
50 |
/** |
|
51 |
* This class is used to process an OCSP response. |
|
52 |
* The OCSP Response is defined |
|
53 |
* in RFC 2560 and the ASN.1 encoding is as follows: |
|
54 |
* <pre> |
|
55 |
* |
|
56 |
* OCSPResponse ::= SEQUENCE { |
|
57 |
* responseStatus OCSPResponseStatus, |
|
58 |
* responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } |
|
59 |
* |
|
60 |
* OCSPResponseStatus ::= ENUMERATED { |
|
61 |
* successful (0), --Response has valid confirmations |
|
62 |
* malformedRequest (1), --Illegal confirmation request |
|
63 |
* internalError (2), --Internal error in issuer |
|
64 |
* tryLater (3), --Try again later |
|
65 |
* --(4) is not used |
|
66 |
* sigRequired (5), --Must sign the request |
|
67 |
* unauthorized (6) --Request unauthorized |
|
68 |
* } |
|
69 |
* |
|
70 |
* ResponseBytes ::= SEQUENCE { |
|
71 |
* responseType OBJECT IDENTIFIER, |
|
72 |
* response OCTET STRING } |
|
73 |
* |
|
74 |
* BasicOCSPResponse ::= SEQUENCE { |
|
75 |
* tbsResponseData ResponseData, |
|
76 |
* signatureAlgorithm AlgorithmIdentifier, |
|
77 |
* signature BIT STRING, |
|
78 |
* certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } |
|
79 |
* |
|
80 |
* The value for signature SHALL be computed on the hash of the DER |
|
81 |
* encoding ResponseData. |
|
82 |
* |
|
83 |
* ResponseData ::= SEQUENCE { |
|
84 |
* version [0] EXPLICIT Version DEFAULT v1, |
|
85 |
* responderID ResponderID, |
|
86 |
* producedAt GeneralizedTime, |
|
87 |
* responses SEQUENCE OF SingleResponse, |
|
88 |
* responseExtensions [1] EXPLICIT Extensions OPTIONAL } |
|
89 |
* |
|
90 |
* ResponderID ::= CHOICE { |
|
91 |
* byName [1] Name, |
|
92 |
* byKey [2] KeyHash } |
|
93 |
* |
|
94 |
* KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key |
|
95 |
* (excluding the tag and length fields) |
|
96 |
* |
|
97 |
* SingleResponse ::= SEQUENCE { |
|
98 |
* certID CertID, |
|
99 |
* certStatus CertStatus, |
|
100 |
* thisUpdate GeneralizedTime, |
|
101 |
* nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, |
|
102 |
* singleExtensions [1] EXPLICIT Extensions OPTIONAL } |
|
103 |
* |
|
104 |
* CertStatus ::= CHOICE { |
|
105 |
* good [0] IMPLICIT NULL, |
|
106 |
* revoked [1] IMPLICIT RevokedInfo, |
|
107 |
* unknown [2] IMPLICIT UnknownInfo } |
|
108 |
* |
|
109 |
* RevokedInfo ::= SEQUENCE { |
|
110 |
* revocationTime GeneralizedTime, |
|
111 |
* revocationReason [0] EXPLICIT CRLReason OPTIONAL } |
|
112 |
* |
|
113 |
* UnknownInfo ::= NULL -- this can be replaced with an enumeration |
|
114 |
* |
|
115 |
* </pre> |
|
116 |
* |
|
117 |
* @author Ram Marti |
|
118 |
*/ |
|
119 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
120 |
public final class OCSPResponse { |
2 | 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 enum ResponseStatus { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
123 |
SUCCESSFUL, // Response has valid confirmations |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
124 |
MALFORMED_REQUEST, // Illegal confirmation request |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
125 |
INTERNAL_ERROR, // Internal error in issuer |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
126 |
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
|
127 |
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
|
128 |
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
|
129 |
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
|
130 |
}; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
131 |
private static ResponseStatus[] rsvalues = ResponseStatus.values(); |
2 | 132 |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
133 |
private static final Debug debug = Debug.getInstance("certpath"); |
2 | 134 |
private static final boolean dump = false; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
135 |
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
|
136 |
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
|
137 |
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
|
138 |
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
|
139 |
private static final int CERT_STATUS_UNKNOWN = 2; |
2 | 140 |
|
141 |
// ResponderID CHOICE tags |
|
142 |
private static final int NAME_TAG = 1; |
|
143 |
private static final int KEY_TAG = 2; |
|
144 |
||
145 |
// Object identifier for the OCSPSigning key purpose |
|
146 |
private static final String KP_OCSP_SIGNING_OID = "1.3.6.1.5.5.7.3.9"; |
|
147 |
||
17044
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
148 |
// 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
|
149 |
// 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
|
150 |
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
|
151 |
|
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
152 |
/** |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
153 |
* Integer value indicating the maximum allowable clock skew, in seconds, |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
154 |
* to be used for the OCSP check. |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
155 |
*/ |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
156 |
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
|
157 |
|
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
158 |
/** |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
159 |
* 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
|
160 |
* 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
|
161 |
* 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
|
162 |
*/ |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
163 |
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
|
164 |
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
|
165 |
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
|
166 |
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
|
167 |
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
|
168 |
} |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
169 |
// 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
|
170 |
// specified in seconds |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
171 |
return tmp * 1000; |
c67bf062ca30
8013228: Create new system properties to control allowable OCSP clock skew and CRL connection timeout
mullan
parents:
13402
diff
changeset
|
172 |
} |
1567
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
173 |
|
2 | 174 |
// an array of all of the CRLReasons (used in SingleResponse) |
175 |
private static CRLReason[] values = CRLReason.values(); |
|
176 |
||
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
177 |
private final ResponseStatus responseStatus; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
178 |
private final Map<CertId, SingleResponse> singleResponseMap; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
179 |
private final List<X509CertImpl> certs; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
180 |
private final AlgorithmId sigAlgId; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
181 |
private final byte[] signature; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
182 |
private final byte[] tbsResponseData; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
183 |
private final byte[] responseNonce; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
184 |
|
2 | 185 |
/* |
186 |
* Create an OCSP response from its ASN.1 DER encoding. |
|
187 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
188 |
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
|
189 |
if (dump) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
190 |
HexDumpEncoder hexEnc = new HexDumpEncoder(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
191 |
System.out.println("OCSPResponse bytes are..."); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
192 |
System.out.println(hexEnc.encode(bytes)); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
193 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
194 |
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
|
195 |
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
|
196 |
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
|
197 |
"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
|
198 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
199 |
DerInputStream derIn = der.getData(); |
2 | 200 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
201 |
// responseStatus |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
202 |
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
|
203 |
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
|
204 |
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
|
205 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
206 |
// unspecified responseStatus |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
207 |
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
|
208 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
209 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
210 |
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
|
211 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
212 |
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
|
213 |
// 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
|
214 |
singleResponseMap = Collections.emptyMap(); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
215 |
certs = Collections.<X509CertImpl>emptyList(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
216 |
sigAlgId = null; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
217 |
signature = null; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
218 |
tbsResponseData = null; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
219 |
responseNonce = null; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
220 |
return; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
221 |
} |
2 | 222 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
223 |
// responseBytes |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
224 |
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
|
225 |
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
|
226 |
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
|
227 |
"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
|
228 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
229 |
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
|
230 |
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
|
231 |
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
|
232 |
"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
|
233 |
} |
2 | 234 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
235 |
// responseType |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
236 |
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
|
237 |
ObjectIdentifier responseType = derIn.getOID(); |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
7040
diff
changeset
|
238 |
if (responseType.equals((Object)OCSP_BASIC_RESPONSE_OID)) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
239 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
240 |
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
|
241 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
242 |
} else { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
243 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
244 |
debug.println("OCSP response type: " + responseType); |
2 | 245 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
246 |
throw new IOException("Unsupported OCSP response type: " + |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
247 |
responseType); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
248 |
} |
2 | 249 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
250 |
// BasicOCSPResponse |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
251 |
DerInputStream basicOCSPResponse = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
252 |
new DerInputStream(derIn.getOctetString()); |
2 | 253 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
254 |
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
|
255 |
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
|
256 |
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
|
257 |
} |
2 | 258 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
259 |
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
|
260 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
261 |
// Need the DER encoded ResponseData to verify the signature later |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
262 |
tbsResponseData = seqTmp[0].toByteArray(); |
2 | 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 |
// tbsResponseData |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
265 |
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
|
266 |
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
|
267 |
"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
|
268 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
269 |
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
|
270 |
DerValue seq = seqDerIn.getDerValue(); |
2 | 271 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
272 |
// version |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
273 |
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
|
274 |
// 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
|
275 |
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
|
276 |
//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
|
277 |
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
|
278 |
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
|
279 |
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
|
280 |
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
|
281 |
" element of OCSP response: bad format"); |
2 | 282 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
283 |
seq = seqDerIn.getDerValue(); |
2 | 284 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
285 |
} |
2 | 286 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
287 |
// responderID |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
288 |
short tag = (byte)(seq.tag & 0x1f); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
289 |
if (tag == NAME_TAG) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
290 |
if (debug != null) { |
13402
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
291 |
X500Principal responderName = |
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
292 |
new X500Principal(seq.getData().toByteArray()); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
293 |
debug.println("OCSP Responder name: " + responderName); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
294 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
295 |
} else if (tag == KEY_TAG) { |
13402
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
296 |
if (debug != null) { |
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
297 |
byte[] responderKey = seq.getData().getOctetString(); |
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
298 |
debug.println("OCSP Responder key: " + |
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
299 |
Debug.toString(responderKey)); |
794d9fb379d2
7179715: OCSP revocation checking fails if the signer certificate is identified using the key ID
mullan
parents:
12860
diff
changeset
|
300 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
301 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
302 |
throw new IOException("Bad encoding in responderID element of " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
303 |
"OCSP response: expected ASN.1 context specific tag 0 or 1"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
304 |
} |
2 | 305 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
306 |
// producedAt |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
307 |
seq = seqDerIn.getDerValue(); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
308 |
if (debug != null) { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
309 |
Date producedAtDate = seq.getGeneralizedTime(); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
310 |
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
|
311 |
} |
2 | 312 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
313 |
// responses |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
314 |
DerValue[] singleResponseDer = seqDerIn.getSequence(1); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
315 |
singleResponseMap = new HashMap<>(singleResponseDer.length); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
316 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
317 |
debug.println("OCSP number of SingleResponses: " |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
318 |
+ 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
|
319 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
320 |
for (int i = 0; i < singleResponseDer.length; i++) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
321 |
SingleResponse singleResponse = |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
322 |
new SingleResponse(singleResponseDer[i]); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
323 |
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
|
324 |
} |
2 | 325 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
326 |
// responseExtensions |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
327 |
byte[] nonce = null; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
328 |
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
|
329 |
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
|
330 |
if (seq.isContextSpecific((byte)1)) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
331 |
DerValue[] responseExtDer = seq.data.getSequence(3); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
332 |
for (int i = 0; i < responseExtDer.length; i++) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
333 |
Extension ext = new Extension(responseExtDer[i]); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
334 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
335 |
debug.println("OCSP extension: " + ext); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
336 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
337 |
// Only the NONCE extension is recognized |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
338 |
if (ext.getExtensionId().equals((Object) |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
339 |
OCSP.NONCE_EXTENSION_OID)) |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
340 |
{ |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
341 |
nonce = ext.getExtensionValue(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
342 |
} else if (ext.isCritical()) { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
343 |
throw new IOException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
344 |
"Unsupported OCSP critical extension: " + |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
345 |
ext.getExtensionId()); |
2 | 346 |
} |
347 |
} |
|
348 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
349 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
350 |
responseNonce = nonce; |
2 | 351 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
352 |
// signatureAlgorithmId |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
353 |
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
|
354 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
355 |
// signature |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
356 |
signature = seqTmp[2].getBitString(); |
2 | 357 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
358 |
// 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
|
359 |
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
|
360 |
// 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
|
361 |
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
|
362 |
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
|
363 |
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
|
364 |
"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
|
365 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
366 |
DerValue[] derCerts = seqCert.getData().getSequence(3); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
367 |
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
|
368 |
try { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
369 |
for (int i = 0; i < derCerts.length; i++) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
370 |
certs.add(new X509CertImpl(derCerts[i].toByteArray())); |
2 | 371 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
372 |
} 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
|
373 |
throw new IOException("Bad encoding in X509 Certificate", ce); |
2 | 374 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
375 |
} else { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
376 |
certs = Collections.<X509CertImpl>emptyList(); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
377 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
378 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
379 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
380 |
void verify(List<CertId> certIds, X509Certificate responderCert, |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
381 |
Date date, byte[] nonce) |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
382 |
throws CertPathValidatorException |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
383 |
{ |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
384 |
if (responseStatus != ResponseStatus.SUCCESSFUL) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
385 |
throw new CertPathValidatorException |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
386 |
("OCSP response error: " + responseStatus); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
387 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
388 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
389 |
// Check that the response includes a response for all of the |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
390 |
// certs that were supplied in the request |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
391 |
for (CertId certId : certIds) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
392 |
SingleResponse sr = getSingleResponse(certId); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
393 |
if (sr == null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
394 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
395 |
debug.println("No response found for CertId: " + certId); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
396 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
397 |
throw new CertPathValidatorException( |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
398 |
"OCSP response does not include a response for a " + |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
399 |
"certificate supplied in the OCSP request"); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
400 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
401 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
402 |
debug.println("Status of certificate (with serial number " + |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
403 |
certId.getSerialNumber() + ") is: " + sr.getCertStatus()); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
404 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
405 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
406 |
|
2 | 407 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
408 |
// Check whether the cert returned by the responder is trusted |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
409 |
if (!certs.isEmpty()) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
410 |
X509CertImpl cert = certs.get(0); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
411 |
// First check if the cert matches the expected responder cert |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
412 |
if (cert.equals(responderCert)) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
413 |
// cert is trusted, now verify the signed response |
2 | 414 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
415 |
// Next check if the cert was issued by the responder cert |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
416 |
// which was set locally. |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
417 |
} else if (cert.getIssuerX500Principal().equals( |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
418 |
responderCert.getSubjectX500Principal())) { |
2 | 419 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
420 |
// 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
|
421 |
try { |
2 | 422 |
List<String> keyPurposes = cert.getExtendedKeyUsage(); |
423 |
if (keyPurposes == null || |
|
424 |
!keyPurposes.contains(KP_OCSP_SIGNING_OID)) { |
|
425 |
throw new CertPathValidatorException( |
|
426 |
"Responder's certificate not valid for signing " + |
|
427 |
"OCSP responses"); |
|
428 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
429 |
} 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
|
430 |
// 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
|
431 |
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
|
432 |
"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
|
433 |
"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
|
434 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
435 |
|
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
436 |
// Check algorithm constraints specified in security property |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
437 |
// "jdk.certpath.disabledAlgorithms". |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
438 |
AlgorithmChecker algChecker = new AlgorithmChecker( |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
439 |
new TrustAnchor(responderCert, null)); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
440 |
algChecker.init(false); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
441 |
algChecker.check(cert, Collections.<String>emptySet()); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
442 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
443 |
// 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
|
444 |
try { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
445 |
if (date == null) { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
446 |
cert.checkValidity(); |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
447 |
} else { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
448 |
cert.checkValidity(date); |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
449 |
} |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
450 |
} 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
|
451 |
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
|
452 |
"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
|
453 |
"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
|
454 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
455 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
456 |
// 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
|
457 |
// |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
458 |
// 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
|
459 |
// 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
|
460 |
// 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
|
461 |
// 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
|
462 |
// |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
463 |
Extension noCheck = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
464 |
cert.getExtension(PKIXExtensions.OCSPNoCheck_Id); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
465 |
if (noCheck != null) { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
466 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
467 |
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
|
468 |
"the extension id-pkix-ocsp-nocheck."); |
2 | 469 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
470 |
} else { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
471 |
// 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
|
472 |
// authorized responder in a future update. |
2 | 473 |
} |
474 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
475 |
// 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
|
476 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
477 |
cert.verify(responderCert.getPublicKey()); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
478 |
responderCert = cert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
479 |
// cert is trusted, now verify the signed response |
2 | 480 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
481 |
} catch (GeneralSecurityException e) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
482 |
responderCert = null; |
2 | 483 |
} |
484 |
} else { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
485 |
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
|
486 |
"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
|
487 |
"OCSP responses"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
488 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
489 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
490 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
491 |
// 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
|
492 |
// key from the trusted responder cert |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
493 |
if (responderCert != null) { |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
494 |
// Check algorithm constraints specified in security property |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
495 |
// "jdk.certpath.disabledAlgorithms". |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
496 |
AlgorithmChecker.check(responderCert.getPublicKey(), sigAlgId); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
497 |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
498 |
if (!verifySignature(responderCert)) { |
2 | 499 |
throw new CertPathValidatorException( |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
500 |
"Error verifying OCSP Response's signature"); |
2 | 501 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
502 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
503 |
// 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
|
504 |
throw new CertPathValidatorException( |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
505 |
"Unable to verify OCSP Response's signature"); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
506 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
507 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
508 |
// Check freshness of OCSPResponse |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
509 |
if (nonce != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
510 |
if (responseNonce != null && !Arrays.equals(nonce, responseNonce)) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
511 |
throw new CertPathValidatorException("Nonces don't match"); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
512 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
513 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
514 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
515 |
long now = (date == null) ? System.currentTimeMillis() : date.getTime(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
516 |
Date nowPlusSkew = new Date(now + MAX_CLOCK_SKEW); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
517 |
Date nowMinusSkew = new Date(now - MAX_CLOCK_SKEW); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
518 |
for (SingleResponse sr : singleResponseMap.values()) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
519 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
520 |
String until = ""; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
521 |
if (sr.nextUpdate != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
522 |
until = " until " + sr.nextUpdate; |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
523 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
524 |
debug.println("Response's validity interval is from " + |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
525 |
sr.thisUpdate + until); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
526 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
527 |
|
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
528 |
// Check that the test date is within the validity interval |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
529 |
if ((sr.thisUpdate != null && nowPlusSkew.before(sr.thisUpdate)) || |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
530 |
(sr.nextUpdate != null && nowMinusSkew.after(sr.nextUpdate))) |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
531 |
{ |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
532 |
throw new CertPathValidatorException( |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
533 |
"Response is unreliable: its validity " + |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
534 |
"interval is out-of-date"); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
535 |
} |
2 | 536 |
} |
537 |
} |
|
538 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
539 |
/** |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
540 |
* Returns the OCSP ResponseStatus. |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
541 |
*/ |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
542 |
ResponseStatus getResponseStatus() { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
543 |
return responseStatus; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
544 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
545 |
|
2 | 546 |
/* |
547 |
* Verify the signature of the OCSP response. |
|
548 |
* The responder's cert is implicitly trusted. |
|
549 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
550 |
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
|
551 |
throws CertPathValidatorException { |
2 | 552 |
|
553 |
try { |
|
554 |
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
|
555 |
respSignature.initVerify(cert.getPublicKey()); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
556 |
respSignature.update(tbsResponseData); |
2 | 557 |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
558 |
if (respSignature.verify(signature)) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
559 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
560 |
debug.println("Verified signature of OCSP Response"); |
2 | 561 |
} |
562 |
return true; |
|
563 |
||
564 |
} else { |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
565 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
566 |
debug.println( |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
567 |
"Error verifying signature of OCSP Response"); |
2 | 568 |
} |
569 |
return false; |
|
570 |
} |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
571 |
} catch (InvalidKeyException | NoSuchAlgorithmException | |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
572 |
SignatureException e) |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
573 |
{ |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
574 |
throw new CertPathValidatorException(e); |
2 | 575 |
} |
576 |
} |
|
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 |
/** |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
579 |
* 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
|
580 |
* there is no response for that CertId. |
2 | 581 |
*/ |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
582 |
SingleResponse getSingleResponse(CertId certId) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
583 |
return singleResponseMap.get(certId); |
2 | 584 |
} |
585 |
||
586 |
/* |
|
587 |
* A class representing a single OCSP response. |
|
588 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
589 |
final static class SingleResponse implements OCSP.RevocationStatus { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
590 |
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
|
591 |
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
|
592 |
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
|
593 |
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
|
594 |
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
|
595 |
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
|
596 |
private final Map<String, java.security.cert.Extension> singleExtensions; |
2 | 597 |
|
598 |
private SingleResponse(DerValue der) throws IOException { |
|
599 |
if (der.tag != DerValue.tag_Sequence) { |
|
600 |
throw new IOException("Bad ASN.1 encoding in SingleResponse"); |
|
601 |
} |
|
602 |
DerInputStream tmp = der.data; |
|
603 |
||
604 |
certId = new CertId(tmp.getDerValue().data); |
|
605 |
DerValue derVal = tmp.getDerValue(); |
|
606 |
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
|
607 |
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
|
608 |
certStatus = CertStatus.REVOKED; |
2 | 609 |
revocationTime = derVal.data.getGeneralizedTime(); |
610 |
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
|
611 |
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
|
612 |
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
|
613 |
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
|
614 |
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
|
615 |
// 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
|
616 |
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
|
617 |
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
|
618 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
619 |
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
|
620 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
621 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
622 |
revocationReason = CRLReason.UNSPECIFIED; |
2 | 623 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
624 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
625 |
revocationReason = CRLReason.UNSPECIFIED; |
2 | 626 |
} |
627 |
// RevokedInfo |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
628 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
629 |
debug.println("Revocation time: " + revocationTime); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
630 |
debug.println("Revocation reason: " + revocationReason); |
2 | 631 |
} |
632 |
} else { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
633 |
revocationTime = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
634 |
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
|
635 |
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
|
636 |
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
|
637 |
} 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
|
638 |
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
|
639 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
640 |
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
|
641 |
} |
2 | 642 |
} |
643 |
||
644 |
thisUpdate = tmp.getGeneralizedTime(); |
|
645 |
||
646 |
if (tmp.available() == 0) { |
|
647 |
// we are done |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
648 |
nextUpdate = null; |
2 | 649 |
} else { |
650 |
derVal = tmp.getDerValue(); |
|
651 |
tag = (byte)(derVal.tag & 0x1f); |
|
652 |
if (tag == 0) { |
|
653 |
// next update |
|
654 |
nextUpdate = derVal.data.getGeneralizedTime(); |
|
655 |
||
656 |
if (tmp.available() == 0) { |
|
657 |
// we are done |
|
658 |
} else { |
|
659 |
derVal = tmp.getDerValue(); |
|
660 |
tag = (byte)(derVal.tag & 0x1f); |
|
661 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
662 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
663 |
nextUpdate = null; |
2 | 664 |
} |
665 |
} |
|
666 |
// singleExtensions |
|
667 |
if (tmp.available() > 0) { |
|
668 |
derVal = tmp.getDerValue(); |
|
669 |
if (derVal.isContextSpecific((byte)1)) { |
|
670 |
DerValue[] singleExtDer = derVal.data.getSequence(3); |
|
671 |
singleExtensions = |
|
672 |
new HashMap<String, java.security.cert.Extension> |
|
673 |
(singleExtDer.length); |
|
674 |
for (int i = 0; i < singleExtDer.length; i++) { |
|
675 |
Extension ext = new Extension(singleExtDer[i]); |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
676 |
if (debug != null) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10336
diff
changeset
|
677 |
debug.println("OCSP single extension: " + ext); |
2 | 678 |
} |
4673
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
679 |
// We don't support any extensions yet. Therefore, if it |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
680 |
// is critical we must throw an exception because we |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
681 |
// don't know how to process it. |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
682 |
if (ext.isCritical()) { |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
683 |
throw new IOException( |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
684 |
"Unsupported OCSP critical extension: " + |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
685 |
ext.getExtensionId()); |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
686 |
} |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
687 |
singleExtensions.put(ext.getId(), ext); |
2 | 688 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
689 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
690 |
singleExtensions = Collections.emptyMap(); |
2 | 691 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
692 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
693 |
singleExtensions = Collections.emptyMap(); |
2 | 694 |
} |
695 |
} |
|
696 |
||
697 |
/* |
|
698 |
* Return the certificate's revocation status code |
|
699 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
700 |
@Override public CertStatus getCertStatus() { |
2 | 701 |
return certStatus; |
702 |
} |
|
703 |
||
704 |
private CertId getCertId() { |
|
705 |
return certId; |
|
706 |
} |
|
707 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
708 |
@Override public Date getRevocationTime() { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
709 |
return (Date) revocationTime.clone(); |
2 | 710 |
} |
711 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
712 |
@Override public CRLReason getRevocationReason() { |
2 | 713 |
return revocationReason; |
714 |
} |
|
715 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
716 |
@Override |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
717 |
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
|
718 |
return Collections.unmodifiableMap(singleExtensions); |
2 | 719 |
} |
720 |
||
721 |
/** |
|
722 |
* Construct a string representation of a single OCSP response. |
|
723 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
724 |
@Override public String toString() { |
2 | 725 |
StringBuilder sb = new StringBuilder(); |
726 |
sb.append("SingleResponse: \n"); |
|
727 |
sb.append(certId); |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
728 |
sb.append("\nCertStatus: "+ certStatus + "\n"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
729 |
if (certStatus == CertStatus.REVOKED) { |
2 | 730 |
sb.append("revocationTime is " + revocationTime + "\n"); |
731 |
sb.append("revocationReason is " + revocationReason + "\n"); |
|
732 |
} |
|
733 |
sb.append("thisUpdate is " + thisUpdate + "\n"); |
|
734 |
if (nextUpdate != null) { |
|
735 |
sb.append("nextUpdate is " + nextUpdate + "\n"); |
|
736 |
} |
|
737 |
return sb.toString(); |
|
738 |
} |
|
739 |
} |
|
740 |
} |