author | xuelei |
Mon, 14 Feb 2011 13:31:13 -0800 | |
changeset 8395 | 29afb3ec47e2 |
parent 7040 | 659824c2a550 |
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.math.BigInteger; |
|
29 |
import java.util.*; |
|
30 |
import java.security.AccessController; |
|
31 |
import java.security.PrivilegedAction; |
|
32 |
import java.security.Security; |
|
33 |
import java.security.cert.*; |
|
1238
6d1f4b722acd
6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
715
diff
changeset
|
34 |
import java.security.cert.CertPathValidatorException.BasicReason; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
35 |
import java.net.URI; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
36 |
import java.net.URISyntaxException; |
2 | 37 |
import javax.security.auth.x500.X500Principal; |
38 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
39 |
import static sun.security.provider.certpath.OCSP.*; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
40 |
import sun.security.util.Debug; |
2 | 41 |
import sun.security.x509.*; |
42 |
||
43 |
/** |
|
44 |
* OCSPChecker is a <code>PKIXCertPathChecker</code> that uses the |
|
45 |
* Online Certificate Status Protocol (OCSP) as specified in RFC 2560 |
|
46 |
* <a href="http://www.ietf.org/rfc/rfc2560.txt"> |
|
47 |
* http://www.ietf.org/rfc/rfc2560.txt</a>. |
|
48 |
* |
|
49 |
* @author Ram Marti |
|
50 |
*/ |
|
51 |
class OCSPChecker extends PKIXCertPathChecker { |
|
52 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
53 |
static final String OCSP_ENABLE_PROP = "ocsp.enable"; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
54 |
static final String OCSP_URL_PROP = "ocsp.responderURL"; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
55 |
static final String OCSP_CERT_SUBJECT_PROP = |
2 | 56 |
"ocsp.responderCertSubjectName"; |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
57 |
static final String OCSP_CERT_ISSUER_PROP = "ocsp.responderCertIssuerName"; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
58 |
static final String OCSP_CERT_NUMBER_PROP = |
2 | 59 |
"ocsp.responderCertSerialNumber"; |
60 |
||
61 |
private static final String HEX_DIGITS = "0123456789ABCDEFabcdef"; |
|
62 |
private static final Debug DEBUG = Debug.getInstance("certpath"); |
|
63 |
private static final boolean dump = false; |
|
64 |
||
65 |
private int remainingCerts; |
|
66 |
||
67 |
private X509Certificate[] certs; |
|
68 |
||
69 |
private CertPath cp; |
|
70 |
||
71 |
private PKIXParameters pkixParams; |
|
72 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
73 |
private boolean onlyEECert = false; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
74 |
|
2 | 75 |
/** |
76 |
* Default Constructor |
|
77 |
* |
|
78 |
* @param certPath the X509 certification path |
|
79 |
* @param pkixParams the input PKIX parameter set |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
80 |
* @throws CertPathValidatorException if OCSPChecker can not be created |
2 | 81 |
*/ |
82 |
OCSPChecker(CertPath certPath, PKIXParameters pkixParams) |
|
83 |
throws CertPathValidatorException { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
84 |
this(certPath, pkixParams, false); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
85 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
86 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
87 |
OCSPChecker(CertPath certPath, PKIXParameters pkixParams, boolean onlyEECert) |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
88 |
throws CertPathValidatorException { |
2 | 89 |
|
90 |
this.cp = certPath; |
|
91 |
this.pkixParams = pkixParams; |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
92 |
this.onlyEECert = onlyEECert; |
2 | 93 |
List<? extends Certificate> tmp = cp.getCertificates(); |
94 |
certs = tmp.toArray(new X509Certificate[tmp.size()]); |
|
95 |
init(false); |
|
96 |
} |
|
97 |
||
98 |
/** |
|
99 |
* Initializes the internal state of the checker from parameters |
|
100 |
* specified in the constructor |
|
101 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
102 |
@Override |
2 | 103 |
public void init(boolean forward) throws CertPathValidatorException { |
104 |
if (!forward) { |
|
625
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
105 |
remainingCerts = certs.length + 1; |
2 | 106 |
} else { |
107 |
throw new CertPathValidatorException( |
|
108 |
"Forward checking not supported"); |
|
109 |
} |
|
110 |
} |
|
111 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
112 |
@Override public boolean isForwardCheckingSupported() { |
2 | 113 |
return false; |
114 |
} |
|
115 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
116 |
@Override public Set<String> getSupportedExtensions() { |
2 | 117 |
return Collections.<String>emptySet(); |
118 |
} |
|
119 |
||
120 |
/** |
|
121 |
* Sends an OCSPRequest for the certificate to the OCSP Server and |
|
122 |
* processes the response back from the OCSP Server. |
|
123 |
* |
|
124 |
* @param cert the Certificate |
|
125 |
* @param unresolvedCritExts the unresolved critical extensions |
|
126 |
* @exception CertPathValidatorException Exception is thrown if the |
|
127 |
* certificate has been revoked. |
|
128 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
129 |
@Override |
2 | 130 |
public void check(Certificate cert, Collection<String> unresolvedCritExts) |
131 |
throws CertPathValidatorException { |
|
132 |
||
625
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
133 |
// Decrement the certificate counter |
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
134 |
remainingCerts--; |
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
135 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
136 |
X509CertImpl currCertImpl = null; |
2 | 137 |
try { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
138 |
currCertImpl = X509CertImpl.toImpl((X509Certificate)cert); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
139 |
} catch (CertificateException ce) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
140 |
throw new CertPathValidatorException(ce); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
141 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
142 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
143 |
if (onlyEECert && currCertImpl.getBasicConstraints() != -1) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
144 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
145 |
DEBUG.println("Skipping revocation check, not end entity cert"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
146 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
147 |
return; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
148 |
} |
2 | 149 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
150 |
/* |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
151 |
* OCSP security property values, in the following order: |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
152 |
* 1. ocsp.responderURL |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
153 |
* 2. ocsp.responderCertSubjectName |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
154 |
* 3. ocsp.responderCertIssuerName |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
155 |
* 4. ocsp.responderCertSerialNumber |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
156 |
*/ |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
157 |
// should cache these properties to avoid calling every time? |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
158 |
String[] properties = getOCSPProperties(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
159 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
160 |
// Check whether OCSP is feasible before seeking cert information |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
161 |
URI uri = getOCSPServerURI(currCertImpl, properties[0]); |
625
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
162 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
163 |
// When responder's subject name is set then the issuer/serial |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
164 |
// properties are ignored |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
165 |
X500Principal responderSubjectName = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
166 |
X500Principal responderIssuerName = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
167 |
BigInteger responderSerialNumber = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
168 |
if (properties[1] != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
169 |
responderSubjectName = new X500Principal(properties[1]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
170 |
} else if (properties[2] != null && properties[3] != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
171 |
responderIssuerName = new X500Principal(properties[2]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
172 |
// remove colon or space separators |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
173 |
String value = stripOutSeparators(properties[3]); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
174 |
responderSerialNumber = new BigInteger(value, 16); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
175 |
} else if (properties[2] != null || properties[3] != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
176 |
throw new CertPathValidatorException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
177 |
"Must specify both ocsp.responderCertIssuerName and " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
178 |
"ocsp.responderCertSerialNumber properties"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
179 |
} |
2 | 180 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
181 |
// If the OCSP responder cert properties are set then the |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
182 |
// identified cert must be located in the trust anchors or |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
183 |
// in the cert stores. |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
184 |
boolean seekResponderCert = false; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
185 |
if (responderSubjectName != null || responderIssuerName != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
186 |
seekResponderCert = true; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
187 |
} |
625
ba0b63c29671
6383078: OCSP checking does not work on end-entity certificate
vinnie
parents:
2
diff
changeset
|
188 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
189 |
// Set the issuer certificate to the next cert in the chain |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
190 |
// (unless we're processing the final cert). |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
191 |
X509Certificate issuerCert = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
192 |
boolean seekIssuerCert = true; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
193 |
X509Certificate responderCert = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
194 |
if (remainingCerts < certs.length) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
195 |
issuerCert = certs[remainingCerts]; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
196 |
seekIssuerCert = false; // done |
2 | 197 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
198 |
// By default, the OCSP responder's cert is the same as the |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
199 |
// issuer of the cert being validated. |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
200 |
if (!seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
201 |
responderCert = issuerCert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
202 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
203 |
DEBUG.println("Responder's certificate is the same " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
204 |
"as the issuer of the certificate being validated"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
205 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
206 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
207 |
} |
2 | 208 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
209 |
// Check anchor certs for: |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
210 |
// - the issuer cert (of the cert being validated) |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
211 |
// - the OCSP responder's cert |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
212 |
if (seekIssuerCert || seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
213 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
214 |
if (DEBUG != null && seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
215 |
DEBUG.println("Searching trust anchors for responder's " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
216 |
"certificate"); |
2 | 217 |
} |
218 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
219 |
// Extract the anchor certs |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
220 |
Iterator<TrustAnchor> anchors |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
221 |
= pkixParams.getTrustAnchors().iterator(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
222 |
if (!anchors.hasNext()) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
223 |
throw new CertPathValidatorException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
224 |
"Must specify at least one trust anchor"); |
2 | 225 |
} |
226 |
||
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
227 |
X500Principal certIssuerName = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
228 |
currCertImpl.getIssuerX500Principal(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
229 |
while (anchors.hasNext() && (seekIssuerCert || seekResponderCert)) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
230 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
231 |
TrustAnchor anchor = anchors.next(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
232 |
X509Certificate anchorCert = anchor.getTrustedCert(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
233 |
X500Principal anchorSubjectName = |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
234 |
anchorCert.getSubjectX500Principal(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
235 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
236 |
if (dump) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
237 |
System.out.println("Issuer DN is " + certIssuerName); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
238 |
System.out.println("Subject DN is " + anchorSubjectName); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
239 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
240 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
241 |
// Check if anchor cert is the issuer cert |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
242 |
if (seekIssuerCert && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
243 |
certIssuerName.equals(anchorSubjectName)) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
244 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
245 |
issuerCert = anchorCert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
246 |
seekIssuerCert = false; // done |
2 | 247 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
248 |
// By default, the OCSP responder's cert is the same as |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
249 |
// the issuer of the cert being validated. |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
250 |
if (!seekResponderCert && responderCert == null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
251 |
responderCert = anchorCert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
252 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
253 |
DEBUG.println("Responder's certificate is the" + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
254 |
" same as the issuer of the certificate " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
255 |
"being validated"); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
256 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
257 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
258 |
} |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
259 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
260 |
// Check if anchor cert is the responder cert |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
261 |
if (seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
262 |
// Satisfy the responder subject name property only, or |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
263 |
// satisfy the responder issuer name and serial number |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
264 |
// properties only |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
265 |
if ((responderSubjectName != null && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
266 |
responderSubjectName.equals(anchorSubjectName)) || |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
267 |
(responderIssuerName != null && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
268 |
responderSerialNumber != null && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
269 |
responderIssuerName.equals( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
270 |
anchorCert.getIssuerX500Principal()) && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
271 |
responderSerialNumber.equals( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
272 |
anchorCert.getSerialNumber()))) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
273 |
|
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
274 |
responderCert = anchorCert; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
275 |
seekResponderCert = false; // done |
2 | 276 |
} |
277 |
} |
|
278 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
279 |
if (issuerCert == null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
280 |
throw new CertPathValidatorException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
281 |
"No trusted certificate for " + currCertImpl.getIssuerDN()); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
282 |
} |
2 | 283 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
284 |
// Check cert stores if responder cert has not yet been found |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
285 |
if (seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
286 |
if (DEBUG != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
287 |
DEBUG.println("Searching cert stores for responder's " + |
2 | 288 |
"certificate"); |
289 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
290 |
X509CertSelector filter = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
291 |
if (responderSubjectName != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
292 |
filter = new X509CertSelector(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
293 |
filter.setSubject(responderSubjectName); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
294 |
} else if (responderIssuerName != null && |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
295 |
responderSerialNumber != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
296 |
filter = new X509CertSelector(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
297 |
filter.setIssuer(responderIssuerName); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
298 |
filter.setSerialNumber(responderSerialNumber); |
2 | 299 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
300 |
if (filter != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
301 |
List<CertStore> certStores = pkixParams.getCertStores(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
302 |
for (CertStore certStore : certStores) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
303 |
Iterator i = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
304 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
305 |
i = certStore.getCertificates(filter).iterator(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
306 |
} catch (CertStoreException cse) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
307 |
// ignore and try next certStore |
2 | 308 |
if (DEBUG != null) { |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
309 |
DEBUG.println("CertStore exception:" + cse); |
2 | 310 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
311 |
continue; |
2 | 312 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
313 |
if (i.hasNext()) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
314 |
responderCert = (X509Certificate) i.next(); |
2 | 315 |
seekResponderCert = false; // done |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
316 |
break; |
2 | 317 |
} |
318 |
} |
|
319 |
} |
|
320 |
} |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
321 |
} |
2 | 322 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
323 |
// Could not find the certificate identified in the OCSP properties |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
324 |
if (seekResponderCert) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
325 |
throw new CertPathValidatorException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
326 |
"Cannot find the responder's certificate " + |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
327 |
"(set using the OCSP security properties)."); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
328 |
} |
2 | 329 |
|
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
330 |
// The algorithm constraints of the OCSP trusted responder certificate |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
331 |
// does not need to be checked in this code. The constraints will be |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
332 |
// checked when the responder's certificate is validated. |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
333 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
334 |
CertId certId = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
335 |
OCSPResponse response = null; |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
336 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
337 |
certId = new CertId |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
338 |
(issuerCert, currCertImpl.getSerialNumberObject()); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
339 |
response = OCSP.check(Collections.singletonList(certId), uri, |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
340 |
responderCert, pkixParams.getDate()); |
4044
b2b2ee2ca90c
6885667: CertPath/CertPathValidatorTest/bugs/bug6383078 fails on jdk6u18/b02, jdk7/pit/b73 and passes on b72.
mullan
parents:
3841
diff
changeset
|
341 |
} catch (Exception e) { |
4318
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
342 |
if (e instanceof CertPathValidatorException) { |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
343 |
throw (CertPathValidatorException) e; |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
344 |
} else { |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
345 |
// Wrap exceptions in CertPathValidatorException so that |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
346 |
// we can fallback to CRLs, if enabled. |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
347 |
throw new CertPathValidatorException(e); |
fdcb5ce9dc00
6894461: OCSP Checker should not wrap all Exception as "Unable to send OCSP request."(introduced by #6885667)
mullan
parents:
4211
diff
changeset
|
348 |
} |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
349 |
} |
2 | 350 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
351 |
RevocationStatus rs = (RevocationStatus) response.getSingleResponse(certId); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
352 |
RevocationStatus.CertStatus certStatus = rs.getCertStatus(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
353 |
if (certStatus == RevocationStatus.CertStatus.REVOKED) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
354 |
Throwable t = new CertificateRevokedException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
355 |
rs.getRevocationTime(), rs.getRevocationReason(), |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
356 |
responderCert.getSubjectX500Principal(), |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
357 |
rs.getSingleExtensions()); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
358 |
throw new CertPathValidatorException(t.getMessage(), t, |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
359 |
null, -1, BasicReason.REVOKED); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
360 |
} else if (certStatus == RevocationStatus.CertStatus.UNKNOWN) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
361 |
throw new CertPathValidatorException( |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
362 |
"Certificate's revocation status is unknown", null, cp, |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
363 |
remainingCerts, BasicReason.UNDETERMINED_REVOCATION_STATUS); |
2 | 364 |
} |
365 |
} |
|
366 |
||
367 |
/* |
|
368 |
* The OCSP security property values are in the following order: |
|
369 |
* 1. ocsp.responderURL |
|
370 |
* 2. ocsp.responderCertSubjectName |
|
371 |
* 3. ocsp.responderCertIssuerName |
|
372 |
* 4. ocsp.responderCertSerialNumber |
|
373 |
*/ |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
374 |
private static URI getOCSPServerURI(X509CertImpl currCertImpl, |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
375 |
String responderURL) throws CertPathValidatorException { |
2 | 376 |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
377 |
if (responderURL != null) { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
378 |
try { |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
379 |
return new URI(responderURL); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
380 |
} catch (URISyntaxException e) { |
2 | 381 |
throw new CertPathValidatorException(e); |
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
382 |
} |
2 | 383 |
} |
384 |
||
385 |
// Examine the certificate's AuthorityInfoAccess extension |
|
386 |
AuthorityInfoAccessExtension aia = |
|
387 |
currCertImpl.getAuthorityInfoAccessExtension(); |
|
388 |
if (aia == null) { |
|
389 |
throw new CertPathValidatorException( |
|
390 |
"Must specify the location of an OCSP Responder"); |
|
391 |
} |
|
392 |
||
393 |
List<AccessDescription> descriptions = aia.getAccessDescriptions(); |
|
394 |
for (AccessDescription description : descriptions) { |
|
395 |
if (description.getAccessMethod().equals( |
|
396 |
AccessDescription.Ad_OCSP_Id)) { |
|
397 |
||
398 |
GeneralName generalName = description.getAccessLocation(); |
|
399 |
if (generalName.getType() == GeneralNameInterface.NAME_URI) { |
|
3841
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
400 |
URIName uri = (URIName) generalName.getName(); |
6738c111d48f
6745437: Add option to only check revocation of end-entity certificate in a chain of certificates
mullan
parents:
3214
diff
changeset
|
401 |
return uri.getURI(); |
2 | 402 |
} |
403 |
} |
|
404 |
} |
|
405 |
||
406 |
throw new CertPathValidatorException( |
|
407 |
"Cannot find the location of the OCSP Responder"); |
|
408 |
} |
|
409 |
||
410 |
/* |
|
411 |
* Retrieves the values of the OCSP security properties. |
|
412 |
*/ |
|
413 |
private static String[] getOCSPProperties() { |
|
414 |
final String[] properties = new String[4]; |
|
415 |
||
416 |
AccessController.doPrivileged( |
|
417 |
new PrivilegedAction<Void>() { |
|
418 |
public Void run() { |
|
419 |
properties[0] = Security.getProperty(OCSP_URL_PROP); |
|
420 |
properties[1] = |
|
421 |
Security.getProperty(OCSP_CERT_SUBJECT_PROP); |
|
422 |
properties[2] = |
|
423 |
Security.getProperty(OCSP_CERT_ISSUER_PROP); |
|
424 |
properties[3] = |
|
425 |
Security.getProperty(OCSP_CERT_NUMBER_PROP); |
|
426 |
return null; |
|
427 |
} |
|
428 |
}); |
|
429 |
||
430 |
return properties; |
|
431 |
} |
|
432 |
||
433 |
/* |
|
434 |
* Removes any non-hexadecimal characters from a string. |
|
435 |
*/ |
|
436 |
private static String stripOutSeparators(String value) { |
|
437 |
char[] chars = value.toCharArray(); |
|
438 |
StringBuilder hexNumber = new StringBuilder(); |
|
439 |
for (int i = 0; i < chars.length; i++) { |
|
440 |
if (HEX_DIGITS.indexOf(chars[i]) != -1) { |
|
441 |
hexNumber.append(chars[i]); |
|
442 |
} |
|
443 |
} |
|
444 |
return hexNumber.toString(); |
|
445 |
} |
|
446 |
} |