author | xuelei |
Mon, 01 Nov 2010 07:57:46 -0700 | |
changeset 7040 | 659824c2a550 |
parent 5506 | 202f599c92aa |
child 10336 | 0bb1999251f8 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
2 |
* Copyright (c) 2003, 2010, 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.math.BigInteger; |
|
30 |
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
|
31 |
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
|
32 |
import java.security.cert.CertificateParsingException; |
2 | 33 |
import java.security.cert.CertPathValidatorException; |
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 | 36 |
import java.security.cert.X509Certificate; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
37 |
import java.util.Collections; |
2 | 38 |
import java.util.Date; |
39 |
import java.util.HashMap; |
|
40 |
import java.util.List; |
|
41 |
import java.util.Map; |
|
42 |
import sun.misc.HexDumpEncoder; |
|
43 |
import sun.security.x509.*; |
|
44 |
import sun.security.util.*; |
|
45 |
||
46 |
/** |
|
47 |
* This class is used to process an OCSP response. |
|
48 |
* The OCSP Response is defined |
|
49 |
* in RFC 2560 and the ASN.1 encoding is as follows: |
|
50 |
* <pre> |
|
51 |
* |
|
52 |
* OCSPResponse ::= SEQUENCE { |
|
53 |
* responseStatus OCSPResponseStatus, |
|
54 |
* responseBytes [0] EXPLICIT ResponseBytes OPTIONAL } |
|
55 |
* |
|
56 |
* OCSPResponseStatus ::= ENUMERATED { |
|
57 |
* successful (0), --Response has valid confirmations |
|
58 |
* malformedRequest (1), --Illegal confirmation request |
|
59 |
* internalError (2), --Internal error in issuer |
|
60 |
* tryLater (3), --Try again later |
|
61 |
* --(4) is not used |
|
62 |
* sigRequired (5), --Must sign the request |
|
63 |
* unauthorized (6) --Request unauthorized |
|
64 |
* } |
|
65 |
* |
|
66 |
* ResponseBytes ::= SEQUENCE { |
|
67 |
* responseType OBJECT IDENTIFIER, |
|
68 |
* response OCTET STRING } |
|
69 |
* |
|
70 |
* BasicOCSPResponse ::= SEQUENCE { |
|
71 |
* tbsResponseData ResponseData, |
|
72 |
* signatureAlgorithm AlgorithmIdentifier, |
|
73 |
* signature BIT STRING, |
|
74 |
* certs [0] EXPLICIT SEQUENCE OF Certificate OPTIONAL } |
|
75 |
* |
|
76 |
* The value for signature SHALL be computed on the hash of the DER |
|
77 |
* encoding ResponseData. |
|
78 |
* |
|
79 |
* ResponseData ::= SEQUENCE { |
|
80 |
* version [0] EXPLICIT Version DEFAULT v1, |
|
81 |
* responderID ResponderID, |
|
82 |
* producedAt GeneralizedTime, |
|
83 |
* responses SEQUENCE OF SingleResponse, |
|
84 |
* responseExtensions [1] EXPLICIT Extensions OPTIONAL } |
|
85 |
* |
|
86 |
* ResponderID ::= CHOICE { |
|
87 |
* byName [1] Name, |
|
88 |
* byKey [2] KeyHash } |
|
89 |
* |
|
90 |
* KeyHash ::= OCTET STRING -- SHA-1 hash of responder's public key |
|
91 |
* (excluding the tag and length fields) |
|
92 |
* |
|
93 |
* SingleResponse ::= SEQUENCE { |
|
94 |
* certID CertID, |
|
95 |
* certStatus CertStatus, |
|
96 |
* thisUpdate GeneralizedTime, |
|
97 |
* nextUpdate [0] EXPLICIT GeneralizedTime OPTIONAL, |
|
98 |
* singleExtensions [1] EXPLICIT Extensions OPTIONAL } |
|
99 |
* |
|
100 |
* CertStatus ::= CHOICE { |
|
101 |
* good [0] IMPLICIT NULL, |
|
102 |
* revoked [1] IMPLICIT RevokedInfo, |
|
103 |
* unknown [2] IMPLICIT UnknownInfo } |
|
104 |
* |
|
105 |
* RevokedInfo ::= SEQUENCE { |
|
106 |
* revocationTime GeneralizedTime, |
|
107 |
* revocationReason [0] EXPLICIT CRLReason OPTIONAL } |
|
108 |
* |
|
109 |
* UnknownInfo ::= NULL -- this can be replaced with an enumeration |
|
110 |
* |
|
111 |
* </pre> |
|
112 |
* |
|
113 |
* @author Ram Marti |
|
114 |
*/ |
|
115 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
116 |
public final class OCSPResponse { |
2 | 117 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
118 |
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
|
119 |
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
|
120 |
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
|
121 |
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
|
122 |
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
|
123 |
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
|
124 |
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
|
125 |
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
|
126 |
}; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
127 |
private static ResponseStatus[] rsvalues = ResponseStatus.values(); |
2 | 128 |
|
129 |
private static final Debug DEBUG = Debug.getInstance("certpath"); |
|
130 |
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
|
131 |
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
|
132 |
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
|
133 |
private static final ObjectIdentifier OCSP_NONCE_EXTENSION_OID = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
134 |
ObjectIdentifier.newInternal(new int[] { 1, 3, 6, 1, 5, 5, 7, 48, 1, 2}); |
2 | 135 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
136 |
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
|
137 |
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
|
138 |
private static final int CERT_STATUS_UNKNOWN = 2; |
2 | 139 |
|
140 |
// ResponderID CHOICE tags |
|
141 |
private static final int NAME_TAG = 1; |
|
142 |
private static final int KEY_TAG = 2; |
|
143 |
||
144 |
// Object identifier for the OCSPSigning key purpose |
|
145 |
private static final String KP_OCSP_SIGNING_OID = "1.3.6.1.5.5.7.3.9"; |
|
146 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
147 |
private final ResponseStatus responseStatus; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
148 |
private final Map<CertId, SingleResponse> singleResponseMap; |
2 | 149 |
|
3314
1e9d33caef08
6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents:
2281
diff
changeset
|
150 |
// Maximum clock skew in milliseconds (15 minutes) allowed when checking |
1567
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
151 |
// validity of OCSP responses |
3314
1e9d33caef08
6787645: CRL validation code should permit some clock skew when checking validity of CRLs
mullan
parents:
2281
diff
changeset
|
152 |
private static final long MAX_CLOCK_SKEW = 900000; |
1567
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
153 |
|
2 | 154 |
// an array of all of the CRLReasons (used in SingleResponse) |
155 |
private static CRLReason[] values = CRLReason.values(); |
|
156 |
||
157 |
/* |
|
158 |
* Create an OCSP response from its ASN.1 DER encoding. |
|
159 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
160 |
OCSPResponse(byte[] bytes, Date dateCheckedAgainst, |
2 | 161 |
X509Certificate responderCert) |
162 |
throws IOException, CertPathValidatorException { |
|
163 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
164 |
// OCSPResponse |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
165 |
if (dump) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
166 |
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
|
167 |
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
|
168 |
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
|
169 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
170 |
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
|
171 |
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
|
172 |
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
|
173 |
"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
|
174 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
175 |
DerInputStream derIn = der.getData(); |
2 | 176 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
177 |
// responseStatus |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
178 |
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
|
179 |
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
|
180 |
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
|
181 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
182 |
// unspecified responseStatus |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
183 |
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
|
184 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
185 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
186 |
DEBUG.println("OCSP response status: " + responseStatus); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
187 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
188 |
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
|
189 |
// 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
|
190 |
singleResponseMap = Collections.emptyMap(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
191 |
return; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
192 |
} |
2 | 193 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
194 |
// responseBytes |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
195 |
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
|
196 |
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
|
197 |
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
|
198 |
"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
|
199 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
200 |
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
|
201 |
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
|
202 |
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
|
203 |
"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
|
204 |
} |
2 | 205 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
206 |
// responseType |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
207 |
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
|
208 |
ObjectIdentifier responseType = derIn.getOID(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
209 |
if (responseType.equals(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
|
210 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
211 |
DEBUG.println("OCSP response type: basic"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
212 |
} |
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 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
215 |
DEBUG.println("OCSP response type: " + responseType); |
2 | 216 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
217 |
throw new IOException("Unsupported OCSP response type: " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
218 |
responseType); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
219 |
} |
2 | 220 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
221 |
// BasicOCSPResponse |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
222 |
DerInputStream basicOCSPResponse = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
223 |
new DerInputStream(derIn.getOctetString()); |
2 | 224 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
225 |
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
|
226 |
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
|
227 |
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
|
228 |
} |
2 | 229 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
230 |
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
|
231 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
232 |
// Need the DER encoded ResponseData to verify the signature later |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
233 |
byte[] responseDataDer = seqTmp[0].toByteArray(); |
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 |
// tbsResponseData |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
236 |
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
|
237 |
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
|
238 |
"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
|
239 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
240 |
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
|
241 |
DerValue seq = seqDerIn.getDerValue(); |
2 | 242 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
243 |
// version |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
244 |
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
|
245 |
// 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
|
246 |
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
|
247 |
//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
|
248 |
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
|
249 |
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
|
250 |
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
|
251 |
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
|
252 |
" element of OCSP response: bad format"); |
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 |
seq = seqDerIn.getDerValue(); |
2 | 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 |
} |
2 | 257 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
258 |
// responderID |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
259 |
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
|
260 |
if (tag == NAME_TAG) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
261 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
262 |
X500Name responderName = new X500Name(seq.getData()); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
263 |
DEBUG.println("OCSP Responder name: " + responderName); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
264 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
265 |
} else if (tag == KEY_TAG) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
266 |
// Ignore, for now |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
267 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
268 |
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
|
269 |
"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
|
270 |
} |
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 |
// producedAt |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
273 |
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
|
274 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
275 |
Date producedAtDate = seq.getGeneralizedTime(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
276 |
DEBUG.println("OCSP response produced at: " + producedAtDate); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
277 |
} |
2 | 278 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
279 |
// responses |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
280 |
DerValue[] singleResponseDer = seqDerIn.getSequence(1); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
281 |
singleResponseMap |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
282 |
= new HashMap<CertId, SingleResponse>(singleResponseDer.length); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
283 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
284 |
DEBUG.println("OCSP number of SingleResponses: " |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
285 |
+ singleResponseDer.length); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
286 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
287 |
for (int i = 0; i < singleResponseDer.length; i++) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
288 |
SingleResponse singleResponse |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
289 |
= new SingleResponse(singleResponseDer[i]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
290 |
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
|
291 |
} |
2 | 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 |
// responseExtensions |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
294 |
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
|
295 |
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
|
296 |
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
|
297 |
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
|
298 |
for (int i = 0; i < responseExtDer.length; i++) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
299 |
Extension responseExtension |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
300 |
= new Extension(responseExtDer[i]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
301 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
302 |
DEBUG.println("OCSP extension: " + responseExtension); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
303 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
304 |
if (responseExtension.getExtensionId().equals( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
305 |
OCSP_NONCE_EXTENSION_OID)) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
306 |
/* |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
307 |
ocspNonce = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
308 |
responseExtension[i].getExtensionValue(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
309 |
*/ |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
310 |
} else if (responseExtension.isCritical()) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
311 |
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
|
312 |
"Unsupported OCSP critical extension: " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
313 |
responseExtension.getExtensionId()); |
2 | 314 |
} |
315 |
} |
|
316 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
317 |
} |
2 | 318 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
319 |
// signatureAlgorithmId |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
320 |
AlgorithmId sigAlgId = AlgorithmId.parse(seqTmp[1]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
321 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
322 |
// signature |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
323 |
byte[] signature = seqTmp[2].getBitString(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
324 |
X509CertImpl[] x509Certs = null; |
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 |
// 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
|
327 |
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
|
328 |
// 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
|
329 |
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
|
330 |
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
|
331 |
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
|
332 |
"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
|
333 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
334 |
DerValue[] certs = seqCert.getData().getSequence(3); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
335 |
x509Certs = new X509CertImpl[certs.length]; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
336 |
try { |
2 | 337 |
for (int i = 0; i < certs.length; i++) { |
338 |
x509Certs[i] = new X509CertImpl(certs[i].toByteArray()); |
|
339 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
340 |
} 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
|
341 |
throw new IOException("Bad encoding in X509 Certificate", ce); |
2 | 342 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
343 |
} |
2 | 344 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
345 |
// Check whether the cert returned by the responder is trusted |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
346 |
if (x509Certs != null && x509Certs[0] != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
347 |
X509CertImpl cert = x509Certs[0]; |
2 | 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 |
// First check if the cert matches the responder cert which |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
350 |
// 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
|
351 |
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
|
352 |
// cert is trusted, now verify the signed response |
2 | 353 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
354 |
// 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
|
355 |
// 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
|
356 |
} else if (cert.getIssuerX500Principal().equals( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
357 |
responderCert.getSubjectX500Principal())) { |
2 | 358 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
359 |
// 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
|
360 |
try { |
2 | 361 |
List<String> keyPurposes = cert.getExtendedKeyUsage(); |
362 |
if (keyPurposes == null || |
|
363 |
!keyPurposes.contains(KP_OCSP_SIGNING_OID)) { |
|
364 |
throw new CertPathValidatorException( |
|
365 |
"Responder's certificate not valid for signing " + |
|
366 |
"OCSP responses"); |
|
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 (CertificateParsingException cpe) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
369 |
// 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
|
370 |
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
|
371 |
"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
|
372 |
"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
|
373 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
374 |
|
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
375 |
// Check algorithm constraints specified in security property |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
376 |
// "jdk.certpath.disabledAlgorithms". |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
377 |
AlgorithmChecker algChecker = new AlgorithmChecker( |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
378 |
new TrustAnchor(responderCert, null)); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
379 |
algChecker.init(false); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
380 |
algChecker.check(cert, Collections.<String>emptySet()); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
381 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
382 |
// 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
|
383 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
384 |
if (dateCheckedAgainst == null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
385 |
cert.checkValidity(); |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
386 |
} else { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
387 |
cert.checkValidity(dateCheckedAgainst); |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
388 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
389 |
} 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
|
390 |
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
|
391 |
"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
|
392 |
"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
|
393 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
394 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
395 |
// 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
|
396 |
// |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
397 |
// 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
|
398 |
// 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
|
399 |
// 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
|
400 |
// 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
|
401 |
// |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
402 |
Extension noCheck = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
403 |
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
|
404 |
if (noCheck != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
405 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
406 |
DEBUG.println("Responder's certificate includes " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
407 |
"the extension id-pkix-ocsp-nocheck."); |
2 | 408 |
} |
2281
34fd38495efa
6798714: OCSPResponse class has to check the validity of signing certificate for OCSP response
xuelei
parents:
1639
diff
changeset
|
409 |
} else { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
410 |
// 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
|
411 |
// authorized responder in a future update. |
2 | 412 |
} |
413 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
414 |
// 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
|
415 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
416 |
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
|
417 |
responderCert = cert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
418 |
// cert is trusted, now verify the signed response |
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 |
} 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
|
421 |
responderCert = null; |
2 | 422 |
} |
423 |
} else { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
424 |
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
|
425 |
"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
|
426 |
"OCSP responses"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
427 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
428 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
429 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
430 |
// 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
|
431 |
// 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
|
432 |
if (responderCert != null) { |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
433 |
// Check algorithm constraints specified in security property |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
434 |
// "jdk.certpath.disabledAlgorithms". |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
435 |
AlgorithmChecker.check(responderCert.getPublicKey(), sigAlgId); |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
436 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
437 |
if (!verifyResponse(responseDataDer, responderCert, |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
438 |
sigAlgId, signature)) { |
2 | 439 |
throw new CertPathValidatorException( |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
440 |
"Error verifying OCSP Responder's signature"); |
2 | 441 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
442 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
443 |
// 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
|
444 |
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
|
445 |
"Unable to verify OCSP Responder's signature"); |
2 | 446 |
} |
447 |
} |
|
448 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
449 |
/** |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
450 |
* 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
|
451 |
*/ |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
452 |
ResponseStatus getResponseStatus() { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
453 |
return responseStatus; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
454 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
455 |
|
2 | 456 |
/* |
457 |
* Verify the signature of the OCSP response. |
|
458 |
* The responder's cert is implicitly trusted. |
|
459 |
*/ |
|
460 |
private boolean verifyResponse(byte[] responseData, 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
|
461 |
AlgorithmId sigAlgId, byte[] signBytes) |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
462 |
throws CertPathValidatorException { |
2 | 463 |
|
464 |
try { |
|
465 |
Signature respSignature = Signature.getInstance(sigAlgId.getName()); |
|
466 |
respSignature.initVerify(cert); |
|
467 |
respSignature.update(responseData); |
|
468 |
||
469 |
if (respSignature.verify(signBytes)) { |
|
470 |
if (DEBUG != null) { |
|
471 |
DEBUG.println("Verified signature of OCSP Responder"); |
|
472 |
} |
|
473 |
return true; |
|
474 |
||
475 |
} else { |
|
476 |
if (DEBUG != null) { |
|
477 |
DEBUG.println( |
|
478 |
"Error verifying signature of OCSP Responder"); |
|
479 |
} |
|
480 |
return false; |
|
481 |
} |
|
482 |
} catch (InvalidKeyException ike) { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
483 |
throw new CertPathValidatorException(ike); |
2 | 484 |
} catch (NoSuchAlgorithmException nsae) { |
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(nsae); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
486 |
} catch (SignatureException se) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
487 |
throw new CertPathValidatorException(se); |
2 | 488 |
} |
489 |
} |
|
490 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
491 |
/** |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
492 |
* 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
|
493 |
* there is no response for that CertId. |
2 | 494 |
*/ |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
495 |
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
|
496 |
return singleResponseMap.get(certId); |
2 | 497 |
} |
498 |
||
499 |
/* |
|
500 |
* A class representing a single OCSP response. |
|
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 |
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
|
503 |
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
|
504 |
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
|
505 |
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
|
506 |
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
|
507 |
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
|
508 |
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
|
509 |
private final Map<String, java.security.cert.Extension> singleExtensions; |
2 | 510 |
|
511 |
private SingleResponse(DerValue der) throws IOException { |
|
512 |
if (der.tag != DerValue.tag_Sequence) { |
|
513 |
throw new IOException("Bad ASN.1 encoding in SingleResponse"); |
|
514 |
} |
|
515 |
DerInputStream tmp = der.data; |
|
516 |
||
517 |
certId = new CertId(tmp.getDerValue().data); |
|
518 |
DerValue derVal = tmp.getDerValue(); |
|
519 |
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
|
520 |
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
|
521 |
certStatus = CertStatus.REVOKED; |
2 | 522 |
revocationTime = derVal.data.getGeneralizedTime(); |
523 |
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
|
524 |
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
|
525 |
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
|
526 |
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
|
527 |
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
|
528 |
// 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
|
529 |
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
|
530 |
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
|
531 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
532 |
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
|
533 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
534 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
535 |
revocationReason = CRLReason.UNSPECIFIED; |
2 | 536 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
537 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
538 |
revocationReason = CRLReason.UNSPECIFIED; |
2 | 539 |
} |
540 |
// RevokedInfo |
|
541 |
if (DEBUG != null) { |
|
542 |
DEBUG.println("Revocation time: " + revocationTime); |
|
543 |
DEBUG.println("Revocation reason: " + revocationReason); |
|
544 |
} |
|
545 |
} else { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
546 |
revocationTime = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
547 |
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
|
548 |
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
|
549 |
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
|
550 |
} 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
|
551 |
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
|
552 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
553 |
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
|
554 |
} |
2 | 555 |
} |
556 |
||
557 |
thisUpdate = tmp.getGeneralizedTime(); |
|
558 |
||
559 |
if (tmp.available() == 0) { |
|
560 |
// 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
|
561 |
nextUpdate = null; |
2 | 562 |
} else { |
563 |
derVal = tmp.getDerValue(); |
|
564 |
tag = (byte)(derVal.tag & 0x1f); |
|
565 |
if (tag == 0) { |
|
566 |
// next update |
|
567 |
nextUpdate = derVal.data.getGeneralizedTime(); |
|
568 |
||
569 |
if (tmp.available() == 0) { |
|
570 |
// we are done |
|
571 |
} else { |
|
572 |
derVal = tmp.getDerValue(); |
|
573 |
tag = (byte)(derVal.tag & 0x1f); |
|
574 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
575 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
576 |
nextUpdate = null; |
2 | 577 |
} |
578 |
} |
|
579 |
// singleExtensions |
|
580 |
if (tmp.available() > 0) { |
|
581 |
derVal = tmp.getDerValue(); |
|
582 |
if (derVal.isContextSpecific((byte)1)) { |
|
583 |
DerValue[] singleExtDer = derVal.data.getSequence(3); |
|
584 |
singleExtensions = |
|
585 |
new HashMap<String, java.security.cert.Extension> |
|
586 |
(singleExtDer.length); |
|
587 |
for (int i = 0; i < singleExtDer.length; i++) { |
|
588 |
Extension ext = new Extension(singleExtDer[i]); |
|
589 |
if (DEBUG != null) { |
|
590 |
DEBUG.println("OCSP single extension: " + ext); |
|
591 |
} |
|
4673
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
592 |
// 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
|
593 |
// 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
|
594 |
// 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
|
595 |
if (ext.isCritical()) { |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
596 |
throw new IOException( |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
597 |
"Unsupported OCSP critical extension: " + |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
598 |
ext.getExtensionId()); |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
599 |
} |
1536565aebcc
6915939: Exception should be thrown if OCSP SingleResponses contain unresolved critical extensions
mullan
parents:
4209
diff
changeset
|
600 |
singleExtensions.put(ext.getId(), ext); |
2 | 601 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
602 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
603 |
singleExtensions = Collections.emptyMap(); |
2 | 604 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
605 |
} else { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
606 |
singleExtensions = Collections.emptyMap(); |
2 | 607 |
} |
608 |
||
1567
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
609 |
long now = System.currentTimeMillis(); |
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
610 |
Date nowPlusSkew = new Date(now + MAX_CLOCK_SKEW); |
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
611 |
Date nowMinusSkew = new Date(now - MAX_CLOCK_SKEW); |
2 | 612 |
if (DEBUG != null) { |
613 |
String until = ""; |
|
614 |
if (nextUpdate != null) { |
|
615 |
until = " until " + nextUpdate; |
|
616 |
} |
|
617 |
DEBUG.println("Response's validity interval is from " + |
|
618 |
thisUpdate + until); |
|
619 |
} |
|
620 |
// Check that the test date is within the validity interval |
|
1567
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
621 |
if ((thisUpdate != null && nowPlusSkew.before(thisUpdate)) || |
58ef474069d7
6744888: OCSP validation code should permit some clock skew when checking validity of OCSP responses
mullan
parents:
2
diff
changeset
|
622 |
(nextUpdate != null && nowMinusSkew.after(nextUpdate))) { |
2 | 623 |
|
624 |
if (DEBUG != null) { |
|
625 |
DEBUG.println("Response is unreliable: its validity " + |
|
626 |
"interval is out-of-date"); |
|
627 |
} |
|
628 |
throw new IOException("Response is unreliable: its validity " + |
|
629 |
"interval is out-of-date"); |
|
630 |
} |
|
631 |
} |
|
632 |
||
633 |
/* |
|
634 |
* Return the certificate's revocation status code |
|
635 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
636 |
@Override public CertStatus getCertStatus() { |
2 | 637 |
return certStatus; |
638 |
} |
|
639 |
||
640 |
private CertId getCertId() { |
|
641 |
return certId; |
|
642 |
} |
|
643 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
644 |
@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
|
645 |
return (Date) revocationTime.clone(); |
2 | 646 |
} |
647 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
648 |
@Override public CRLReason getRevocationReason() { |
2 | 649 |
return revocationReason; |
650 |
} |
|
651 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
652 |
@Override |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3314
diff
changeset
|
653 |
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
|
654 |
return Collections.unmodifiableMap(singleExtensions); |
2 | 655 |
} |
656 |
||
657 |
/** |
|
658 |
* Construct a string representation of a single OCSP response. |
|
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 |
@Override public String toString() { |
2 | 661 |
StringBuilder sb = new StringBuilder(); |
662 |
sb.append("SingleResponse: \n"); |
|
663 |
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
|
664 |
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
|
665 |
if (certStatus == CertStatus.REVOKED) { |
2 | 666 |
sb.append("revocationTime is " + revocationTime + "\n"); |
667 |
sb.append("revocationReason is " + revocationReason + "\n"); |
|
668 |
} |
|
669 |
sb.append("thisUpdate is " + thisUpdate + "\n"); |
|
670 |
if (nextUpdate != null) { |
|
671 |
sb.append("nextUpdate is " + nextUpdate + "\n"); |
|
672 |
} |
|
673 |
return sb.toString(); |
|
674 |
} |
|
675 |
} |
|
676 |
} |