author | xuelei |
Tue, 18 Aug 2009 20:47:13 -0700 | |
changeset 4190 | 227655c2ff8c |
parent 3225 | 023603ebeb1f |
child 4209 | e2e5a973b879 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
2 |
* Copyright 2000-2009 Sun Microsystems, Inc. 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 |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
|
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 |
* |
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.security.provider.certpath; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.util.*; |
|
30 |
||
31 |
import java.security.GeneralSecurityException; |
|
32 |
import java.security.InvalidKeyException; |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
33 |
import java.security.cert.Certificate; |
2 | 34 |
import java.security.cert.CertificateException; |
35 |
import java.security.cert.CertPathValidatorException; |
|
1238
6d1f4b722acd
6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
792
diff
changeset
|
36 |
import java.security.cert.PKIXReason; |
2 | 37 |
import java.security.cert.CertStore; |
38 |
import java.security.cert.CertStoreException; |
|
39 |
import java.security.cert.PKIXBuilderParameters; |
|
40 |
import java.security.cert.PKIXCertPathChecker; |
|
41 |
import java.security.cert.TrustAnchor; |
|
42 |
import java.security.cert.X509Certificate; |
|
43 |
import java.security.cert.X509CertSelector; |
|
44 |
import javax.security.auth.x500.X500Principal; |
|
45 |
||
46 |
import sun.security.util.Debug; |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
47 |
import sun.security.util.DerOutputStream; |
2 | 48 |
import sun.security.x509.AccessDescription; |
49 |
import sun.security.x509.AuthorityInfoAccessExtension; |
|
50 |
import sun.security.x509.PKIXExtensions; |
|
51 |
import sun.security.x509.PolicyMappingsExtension; |
|
52 |
import sun.security.x509.X500Name; |
|
53 |
import sun.security.x509.X509CertImpl; |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
54 |
import sun.security.x509.X509CRLImpl; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
55 |
import sun.security.x509.AuthorityKeyIdentifierExtension; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
56 |
import sun.security.x509.KeyIdentifier; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
57 |
import sun.security.x509.SubjectKeyIdentifierExtension; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
58 |
import sun.security.x509.SerialNumber; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
59 |
import sun.security.x509.GeneralNames; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
60 |
import sun.security.x509.GeneralName; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
61 |
import sun.security.x509.GeneralNameInterface; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
62 |
import java.math.BigInteger; |
2 | 63 |
|
64 |
/** |
|
65 |
* This class represents a forward builder, which is able to retrieve |
|
66 |
* matching certificates from CertStores and verify a particular certificate |
|
67 |
* against a ForwardState. |
|
68 |
* |
|
69 |
* @since 1.4 |
|
70 |
* @author Yassir Elley |
|
71 |
* @author Sean Mullan |
|
72 |
*/ |
|
73 |
class ForwardBuilder extends Builder { |
|
74 |
||
75 |
private static final Debug debug = Debug.getInstance("certpath"); |
|
76 |
private final Set<X509Certificate> trustedCerts; |
|
77 |
private final Set<X500Principal> trustedSubjectDNs; |
|
78 |
private final Set<TrustAnchor> trustAnchors; |
|
79 |
private X509CertSelector eeSelector; |
|
80 |
private X509CertSelector caSelector; |
|
81 |
private X509CertSelector caTargetSelector; |
|
82 |
TrustAnchor trustAnchor; |
|
83 |
private Comparator<X509Certificate> comparator; |
|
84 |
private boolean searchAllCertStores = true; |
|
85 |
||
86 |
/** |
|
87 |
* Initialize the builder with the input parameters. |
|
88 |
* |
|
89 |
* @param params the parameter set used to build a certification path |
|
90 |
*/ |
|
91 |
ForwardBuilder(PKIXBuilderParameters buildParams, |
|
92 |
X500Principal targetSubjectDN, boolean searchAllCertStores) |
|
93 |
{ |
|
94 |
super(buildParams, targetSubjectDN); |
|
95 |
||
96 |
// populate sets of trusted certificates and subject DNs |
|
97 |
trustAnchors = buildParams.getTrustAnchors(); |
|
98 |
trustedCerts = new HashSet<X509Certificate>(trustAnchors.size()); |
|
99 |
trustedSubjectDNs = new HashSet<X500Principal>(trustAnchors.size()); |
|
100 |
for (TrustAnchor anchor : trustAnchors) { |
|
101 |
X509Certificate trustedCert = anchor.getTrustedCert(); |
|
102 |
if (trustedCert != null) { |
|
103 |
trustedCerts.add(trustedCert); |
|
104 |
trustedSubjectDNs.add(trustedCert.getSubjectX500Principal()); |
|
105 |
} else { |
|
106 |
trustedSubjectDNs.add(anchor.getCA()); |
|
107 |
} |
|
108 |
} |
|
109 |
comparator = new PKIXCertComparator(trustedSubjectDNs); |
|
110 |
this.searchAllCertStores = searchAllCertStores; |
|
111 |
} |
|
112 |
||
113 |
/** |
|
114 |
* Retrieves all certs from the specified CertStores that satisfy the |
|
115 |
* requirements specified in the parameters and the current |
|
116 |
* PKIX state (name constraints, policy constraints, etc). |
|
117 |
* |
|
118 |
* @param currentState the current state. |
|
119 |
* Must be an instance of <code>ForwardState</code> |
|
120 |
* @param certStores list of CertStores |
|
121 |
*/ |
|
122 |
Collection<X509Certificate> getMatchingCerts |
|
123 |
(State currentState, List<CertStore> certStores) |
|
124 |
throws CertStoreException, CertificateException, IOException |
|
125 |
{ |
|
126 |
if (debug != null) { |
|
127 |
debug.println("ForwardBuilder.getMatchingCerts()..."); |
|
128 |
} |
|
129 |
||
130 |
ForwardState currState = (ForwardState) currentState; |
|
131 |
||
132 |
/* |
|
133 |
* We store certs in a Set because we don't want duplicates. |
|
134 |
* As each cert is added, it is sorted based on the PKIXCertComparator |
|
135 |
* algorithm. |
|
136 |
*/ |
|
137 |
Set<X509Certificate> certs = new TreeSet<X509Certificate>(comparator); |
|
138 |
||
139 |
/* |
|
140 |
* Only look for EE certs if search has just started. |
|
141 |
*/ |
|
142 |
if (currState.isInitial()) { |
|
143 |
getMatchingEECerts(currState, certStores, certs); |
|
144 |
} |
|
145 |
getMatchingCACerts(currState, certStores, certs); |
|
146 |
||
147 |
return certs; |
|
148 |
} |
|
149 |
||
150 |
/* |
|
151 |
* Retrieves all end-entity certificates which satisfy constraints |
|
152 |
* and requirements specified in the parameters and PKIX state. |
|
153 |
*/ |
|
154 |
private void getMatchingEECerts(ForwardState currentState, |
|
155 |
List<CertStore> certStores, Collection<X509Certificate> eeCerts) |
|
156 |
throws IOException { |
|
157 |
||
158 |
if (debug != null) { |
|
159 |
debug.println("ForwardBuilder.getMatchingEECerts()..."); |
|
160 |
} |
|
161 |
/* |
|
162 |
* Compose a certificate matching rule to filter out |
|
163 |
* certs which don't satisfy constraints |
|
164 |
* |
|
165 |
* First, retrieve clone of current target cert constraints, |
|
166 |
* and then add more selection criteria based on current validation |
|
167 |
* state. Since selector never changes, cache local copy & reuse. |
|
168 |
*/ |
|
169 |
if (eeSelector == null) { |
|
170 |
eeSelector = (X509CertSelector) targetCertConstraints.clone(); |
|
171 |
||
172 |
/* |
|
173 |
* Match on certificate validity date |
|
174 |
*/ |
|
175 |
eeSelector.setCertificateValid(date); |
|
176 |
||
177 |
/* |
|
178 |
* Policy processing optimizations |
|
179 |
*/ |
|
180 |
if (buildParams.isExplicitPolicyRequired()) { |
|
181 |
eeSelector.setPolicy(getMatchingPolicies()); |
|
182 |
} |
|
183 |
/* |
|
184 |
* Require EE certs |
|
185 |
*/ |
|
186 |
eeSelector.setBasicConstraints(-2); |
|
187 |
} |
|
188 |
||
189 |
/* Retrieve matching EE certs from CertStores */ |
|
190 |
addMatchingCerts(eeSelector, certStores, eeCerts, searchAllCertStores); |
|
191 |
} |
|
192 |
||
193 |
/** |
|
194 |
* Retrieves all CA certificates which satisfy constraints |
|
195 |
* and requirements specified in the parameters and PKIX state. |
|
196 |
*/ |
|
197 |
private void getMatchingCACerts(ForwardState currentState, |
|
198 |
List<CertStore> certStores, Collection<X509Certificate> caCerts) |
|
199 |
throws IOException { |
|
200 |
||
201 |
if (debug != null) { |
|
202 |
debug.println("ForwardBuilder.getMatchingCACerts()..."); |
|
203 |
} |
|
204 |
int initialSize = caCerts.size(); |
|
205 |
||
206 |
/* |
|
207 |
* Compose a CertSelector to filter out |
|
208 |
* certs which do not satisfy requirements. |
|
209 |
*/ |
|
210 |
X509CertSelector sel = null; |
|
211 |
||
212 |
if (currentState.isInitial()) { |
|
792
214933bde360
6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents:
2
diff
changeset
|
213 |
if (targetCertConstraints.getBasicConstraints() == -2) { |
214933bde360
6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents:
2
diff
changeset
|
214 |
// no need to continue: this means we never can match a CA cert |
214933bde360
6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents:
2
diff
changeset
|
215 |
return; |
214933bde360
6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents:
2
diff
changeset
|
216 |
} |
214933bde360
6714842: CertPathBuilder returns incorrect CertPath for BasicConstraints in builderParams
mullan
parents:
2
diff
changeset
|
217 |
|
2 | 218 |
/* This means a CA is the target, so match on same stuff as |
219 |
* getMatchingEECerts |
|
220 |
*/ |
|
221 |
if (debug != null) { |
|
222 |
debug.println("ForwardBuilder.getMatchingCACerts(): ca is target"); |
|
223 |
} |
|
224 |
||
225 |
if (caTargetSelector == null) { |
|
226 |
caTargetSelector = (X509CertSelector) |
|
227 |
targetCertConstraints.clone(); |
|
228 |
||
229 |
/* |
|
230 |
* Match on certificate validity date |
|
231 |
*/ |
|
232 |
caTargetSelector.setCertificateValid(date); |
|
233 |
||
234 |
/* |
|
235 |
* Policy processing optimizations |
|
236 |
*/ |
|
237 |
if (buildParams.isExplicitPolicyRequired()) |
|
238 |
caTargetSelector.setPolicy(getMatchingPolicies()); |
|
239 |
} |
|
240 |
||
241 |
/* |
|
242 |
* Require CA certs with a pathLenConstraint that allows |
|
243 |
* at least as many CA certs that have already been traversed |
|
244 |
*/ |
|
245 |
caTargetSelector.setBasicConstraints(currentState.traversedCACerts); |
|
246 |
sel = caTargetSelector; |
|
247 |
||
248 |
} else { |
|
249 |
||
250 |
if (caSelector == null) { |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
251 |
caSelector = new AdaptableX509CertSelector(); |
2 | 252 |
|
253 |
/* |
|
254 |
* Match on certificate validity date. |
|
255 |
*/ |
|
256 |
caSelector.setCertificateValid(date); |
|
257 |
||
258 |
/* |
|
259 |
* Policy processing optimizations |
|
260 |
*/ |
|
261 |
if (buildParams.isExplicitPolicyRequired()) |
|
262 |
caSelector.setPolicy(getMatchingPolicies()); |
|
263 |
} |
|
264 |
||
265 |
/* |
|
266 |
* Match on subject (issuer of previous cert) |
|
267 |
*/ |
|
268 |
caSelector.setSubject(currentState.issuerDN); |
|
269 |
||
270 |
/* |
|
271 |
* Match on subjectNamesTraversed (both DNs and AltNames) |
|
272 |
* (checks that current cert's name constraints permit it |
|
273 |
* to certify all the DNs and AltNames that have been traversed) |
|
274 |
*/ |
|
275 |
CertPathHelper.setPathToNames |
|
276 |
(caSelector, currentState.subjectNamesTraversed); |
|
277 |
||
278 |
/* |
|
279 |
* Require CA certs with a pathLenConstraint that allows |
|
280 |
* at least as many CA certs that have already been traversed |
|
281 |
*/ |
|
282 |
caSelector.setBasicConstraints(currentState.traversedCACerts); |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
283 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
284 |
/* |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
285 |
* Facilitate certification path construction with authority |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
286 |
* key identifier and subject key identifier. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
287 |
*/ |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
288 |
AuthorityKeyIdentifierExtension akidext = |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
289 |
currentState.cert.getAuthorityKeyIdentifierExtension(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
290 |
if (akidext != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
291 |
KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
292 |
if (akid != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
293 |
DerOutputStream derout = new DerOutputStream(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
294 |
derout.putOctetString(akid.getIdentifier()); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
295 |
caSelector.setSubjectKeyIdentifier(derout.toByteArray()); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
296 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
297 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
298 |
SerialNumber asn = |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
299 |
(SerialNumber)akidext.get(akidext.SERIAL_NUMBER); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
300 |
if (asn != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
301 |
caSelector.setSerialNumber(asn.getNumber()); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
302 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
303 |
// the subject criterion was set previously. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
304 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
305 |
|
2 | 306 |
sel = caSelector; |
307 |
} |
|
308 |
||
309 |
/* |
|
310 |
* Check if any of the trusted certs could be a match. |
|
311 |
* Since we are not validating the trusted cert, we can't |
|
312 |
* re-use the selector we've built up (sel) - we need |
|
313 |
* to use a new selector (trustedSel) |
|
314 |
*/ |
|
315 |
X509CertSelector trustedSel = null; |
|
316 |
if (currentState.isInitial()) { |
|
317 |
trustedSel = targetCertConstraints; |
|
318 |
} else { |
|
319 |
trustedSel = new X509CertSelector(); |
|
320 |
trustedSel.setSubject(currentState.issuerDN); |
|
321 |
} |
|
322 |
||
323 |
boolean foundMatchingCert = false; |
|
324 |
for (X509Certificate trustedCert : trustedCerts) { |
|
325 |
if (trustedSel.match(trustedCert)) { |
|
326 |
if (debug != null) { |
|
327 |
debug.println("ForwardBuilder.getMatchingCACerts: " |
|
328 |
+ "found matching trust anchor"); |
|
329 |
} |
|
330 |
if (caCerts.add(trustedCert) && !searchAllCertStores) { |
|
331 |
return; |
|
332 |
} |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
||
337 |
/* |
|
338 |
* If we have already traversed as many CA certs as the maxPathLength |
|
339 |
* will allow us to, then we don't bother looking through these |
|
340 |
* certificate pairs. If maxPathLength has a value of -1, this |
|
341 |
* means it is unconstrained, so we always look through the |
|
342 |
* certificate pairs. |
|
343 |
*/ |
|
344 |
if (currentState.isInitial() || |
|
345 |
(buildParams.getMaxPathLength() == -1) || |
|
346 |
(buildParams.getMaxPathLength() > currentState.traversedCACerts)) |
|
347 |
{ |
|
348 |
if (addMatchingCerts(sel, certStores, caCerts, searchAllCertStores) |
|
349 |
&& !searchAllCertStores) { |
|
350 |
return; |
|
351 |
} |
|
352 |
} |
|
353 |
||
354 |
if (!currentState.isInitial() && Builder.USE_AIA) { |
|
355 |
// check for AuthorityInformationAccess extension |
|
356 |
AuthorityInfoAccessExtension aiaExt = |
|
357 |
currentState.cert.getAuthorityInfoAccessExtension(); |
|
358 |
if (aiaExt != null) { |
|
359 |
getCerts(aiaExt, caCerts); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
if (debug != null) { |
|
364 |
int numCerts = caCerts.size() - initialSize; |
|
365 |
debug.println("ForwardBuilder.getMatchingCACerts: found " + |
|
366 |
numCerts + " CA certs"); |
|
367 |
} |
|
368 |
} |
|
369 |
||
370 |
/** |
|
371 |
* Download Certificates from the given AIA and add them to the |
|
372 |
* specified Collection. |
|
373 |
*/ |
|
374 |
private boolean getCerts(AuthorityInfoAccessExtension aiaExt, |
|
375 |
Collection<X509Certificate> certs) { |
|
376 |
if (Builder.USE_AIA == false) { |
|
377 |
return false; |
|
378 |
} |
|
379 |
List<AccessDescription> adList = aiaExt.getAccessDescriptions(); |
|
380 |
if (adList == null || adList.isEmpty()) { |
|
381 |
return false; |
|
382 |
} |
|
383 |
||
384 |
boolean add = false; |
|
385 |
for (AccessDescription ad : adList) { |
|
386 |
CertStore cs = URICertStore.getInstance(ad); |
|
387 |
try { |
|
388 |
if (certs.addAll((Collection<X509Certificate>) |
|
389 |
cs.getCertificates(caSelector))) { |
|
390 |
add = true; |
|
391 |
if (!searchAllCertStores) { |
|
392 |
return true; |
|
393 |
} |
|
394 |
} |
|
395 |
} catch (CertStoreException cse) { |
|
396 |
if (debug != null) { |
|
397 |
debug.println("exception getting certs from CertStore:"); |
|
398 |
cse.printStackTrace(); |
|
399 |
} |
|
400 |
continue; |
|
401 |
} |
|
402 |
} |
|
403 |
return add; |
|
404 |
} |
|
405 |
||
406 |
/** |
|
407 |
* This inner class compares 2 PKIX certificates according to which |
|
408 |
* should be tried first when building a path from the target. |
|
409 |
* The preference order is as follows: |
|
410 |
* |
|
411 |
* Given trusted certificate(s): |
|
412 |
* Subject:ou=D,ou=C,o=B,c=A |
|
413 |
* |
|
414 |
* Preference order for current cert: |
|
415 |
* |
|
416 |
* 1) Issuer matches a trusted subject |
|
417 |
* Issuer: ou=D,ou=C,o=B,c=A |
|
418 |
* |
|
419 |
* 2) Issuer is a descendant of a trusted subject (in order of |
|
420 |
* number of links to the trusted subject) |
|
421 |
* a) Issuer: ou=E,ou=D,ou=C,o=B,c=A [links=1] |
|
422 |
* b) Issuer: ou=F,ou=E,ou=D,ou=C,ou=B,c=A [links=2] |
|
423 |
* |
|
424 |
* 3) Issuer is an ancestor of a trusted subject (in order of number of |
|
425 |
* links to the trusted subject) |
|
426 |
* a) Issuer: ou=C,o=B,c=A [links=1] |
|
427 |
* b) Issuer: o=B,c=A [links=2] |
|
428 |
* |
|
429 |
* 4) Issuer is in the same namespace as a trusted subject (in order of |
|
430 |
* number of links to the trusted subject) |
|
431 |
* a) Issuer: ou=G,ou=C,o=B,c=A [links=2] |
|
432 |
* b) Issuer: ou=H,o=B,c=A [links=3] |
|
433 |
* |
|
434 |
* 5) Issuer is an ancestor of certificate subject (in order of number |
|
435 |
* of links to the certificate subject) |
|
436 |
* a) Issuer: ou=K,o=J,c=A |
|
437 |
* Subject: ou=L,ou=K,o=J,c=A |
|
438 |
* b) Issuer: o=J,c=A |
|
439 |
* Subject: ou=L,ou=K,0=J,c=A |
|
440 |
* |
|
441 |
* 6) Any other certificates |
|
442 |
*/ |
|
443 |
static class PKIXCertComparator implements Comparator<X509Certificate> { |
|
444 |
||
445 |
final static String METHOD_NME = "PKIXCertComparator.compare()"; |
|
446 |
||
447 |
private final Set<X500Principal> trustedSubjectDNs; |
|
448 |
||
449 |
PKIXCertComparator(Set<X500Principal> trustedSubjectDNs) { |
|
450 |
this.trustedSubjectDNs = trustedSubjectDNs; |
|
451 |
} |
|
452 |
||
453 |
/** |
|
454 |
* @param oCert1 First X509Certificate to be compared |
|
455 |
* @param oCert2 Second X509Certificate to be compared |
|
456 |
* @return -1 if oCert1 is preferable to oCert2, or |
|
457 |
* if oCert1 and oCert2 are equally preferable (in this |
|
458 |
* case it doesn't matter which is preferable, but we don't |
|
459 |
* return 0 because the comparator would behave strangely |
|
460 |
* when used in a SortedSet). |
|
461 |
* 1 if oCert2 is preferable to oCert1 |
|
462 |
* 0 if oCert1.equals(oCert2). We only return 0 if the |
|
463 |
* certs are equal so that this comparator behaves |
|
464 |
* correctly when used in a SortedSet. |
|
465 |
* @throws ClassCastException if either argument is not of type |
|
466 |
* X509Certificate |
|
467 |
*/ |
|
468 |
public int compare(X509Certificate oCert1, X509Certificate oCert2) { |
|
469 |
||
470 |
// if certs are the same, return 0 |
|
471 |
if (oCert1.equals(oCert2)) return 0; |
|
472 |
||
473 |
X500Principal cIssuer1 = oCert1.getIssuerX500Principal(); |
|
474 |
X500Principal cIssuer2 = oCert2.getIssuerX500Principal(); |
|
475 |
X500Name cIssuer1Name = X500Name.asX500Name(cIssuer1); |
|
476 |
X500Name cIssuer2Name = X500Name.asX500Name(cIssuer2); |
|
477 |
||
478 |
if (debug != null) { |
|
479 |
debug.println(METHOD_NME + " o1 Issuer: " + cIssuer1); |
|
480 |
debug.println(METHOD_NME + " o2 Issuer: " + cIssuer2); |
|
481 |
} |
|
482 |
||
483 |
/* If one cert's issuer matches a trusted subject, then it is |
|
484 |
* preferable. |
|
485 |
*/ |
|
486 |
if (debug != null) { |
|
487 |
debug.println(METHOD_NME + " MATCH TRUSTED SUBJECT TEST..."); |
|
488 |
} |
|
489 |
||
490 |
boolean m1 = trustedSubjectDNs.contains(cIssuer1); |
|
491 |
boolean m2 = trustedSubjectDNs.contains(cIssuer2); |
|
492 |
if (debug != null) { |
|
493 |
debug.println(METHOD_NME + " m1: " + m1); |
|
494 |
debug.println(METHOD_NME + " m2: " + m2); |
|
495 |
} |
|
496 |
if (m1 && m2) { |
|
497 |
return -1; |
|
498 |
} else if (m1) { |
|
499 |
return -1; |
|
500 |
} else if (m2) { |
|
501 |
return 1; |
|
502 |
} |
|
503 |
||
504 |
/* If one cert's issuer is a naming descendant of a trusted subject, |
|
505 |
* then it is preferable, in order of increasing naming distance. |
|
506 |
*/ |
|
507 |
if (debug != null) { |
|
508 |
debug.println(METHOD_NME + " NAMING DESCENDANT TEST..."); |
|
509 |
} |
|
510 |
for (X500Principal tSubject : trustedSubjectDNs) { |
|
511 |
X500Name tSubjectName = X500Name.asX500Name(tSubject); |
|
512 |
int distanceTto1 = |
|
513 |
Builder.distance(tSubjectName, cIssuer1Name, -1); |
|
514 |
int distanceTto2 = |
|
515 |
Builder.distance(tSubjectName, cIssuer2Name, -1); |
|
516 |
if (debug != null) { |
|
517 |
debug.println(METHOD_NME +" distanceTto1: " + distanceTto1); |
|
518 |
debug.println(METHOD_NME +" distanceTto2: " + distanceTto2); |
|
519 |
} |
|
520 |
if (distanceTto1 > 0 || distanceTto2 > 0) { |
|
521 |
if (distanceTto1 == distanceTto2) { |
|
522 |
return -1; |
|
523 |
} else if (distanceTto1 > 0 && distanceTto2 <= 0) { |
|
524 |
return -1; |
|
525 |
} else if (distanceTto1 <= 0 && distanceTto2 > 0) { |
|
526 |
return 1; |
|
527 |
} else if (distanceTto1 < distanceTto2) { |
|
528 |
return -1; |
|
529 |
} else { // distanceTto1 > distanceTto2 |
|
530 |
return 1; |
|
531 |
} |
|
532 |
} |
|
533 |
} |
|
534 |
||
535 |
/* If one cert's issuer is a naming ancestor of a trusted subject, |
|
536 |
* then it is preferable, in order of increasing naming distance. |
|
537 |
*/ |
|
538 |
if (debug != null) { |
|
539 |
debug.println(METHOD_NME + " NAMING ANCESTOR TEST..."); |
|
540 |
} |
|
541 |
for (X500Principal tSubject : trustedSubjectDNs) { |
|
542 |
X500Name tSubjectName = X500Name.asX500Name(tSubject); |
|
543 |
||
544 |
int distanceTto1 = Builder.distance |
|
545 |
(tSubjectName, cIssuer1Name, Integer.MAX_VALUE); |
|
546 |
int distanceTto2 = Builder.distance |
|
547 |
(tSubjectName, cIssuer2Name, Integer.MAX_VALUE); |
|
548 |
if (debug != null) { |
|
549 |
debug.println(METHOD_NME +" distanceTto1: " + distanceTto1); |
|
550 |
debug.println(METHOD_NME +" distanceTto2: " + distanceTto2); |
|
551 |
} |
|
552 |
if (distanceTto1 < 0 || distanceTto2 < 0) { |
|
553 |
if (distanceTto1 == distanceTto2) { |
|
554 |
return -1; |
|
555 |
} else if (distanceTto1 < 0 && distanceTto2 >= 0) { |
|
556 |
return -1; |
|
557 |
} else if (distanceTto1 >= 0 && distanceTto2 < 0) { |
|
558 |
return 1; |
|
559 |
} else if (distanceTto1 > distanceTto2) { |
|
560 |
return -1; |
|
561 |
} else { |
|
562 |
return 1; |
|
563 |
} |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
/* If one cert's issuer is in the same namespace as a trusted |
|
568 |
* subject, then it is preferable, in order of increasing naming |
|
569 |
* distance. |
|
570 |
*/ |
|
571 |
if (debug != null) { |
|
572 |
debug.println(METHOD_NME +" SAME NAMESPACE AS TRUSTED TEST..."); |
|
573 |
} |
|
574 |
for (X500Principal tSubject : trustedSubjectDNs) { |
|
575 |
X500Name tSubjectName = X500Name.asX500Name(tSubject); |
|
576 |
X500Name tAo1 = tSubjectName.commonAncestor(cIssuer1Name); |
|
577 |
X500Name tAo2 = tSubjectName.commonAncestor(cIssuer2Name); |
|
578 |
if (debug != null) { |
|
579 |
debug.println(METHOD_NME +" tAo1: " + String.valueOf(tAo1)); |
|
580 |
debug.println(METHOD_NME +" tAo2: " + String.valueOf(tAo2)); |
|
581 |
} |
|
582 |
if (tAo1 != null || tAo2 != null) { |
|
583 |
if (tAo1 != null && tAo2 != null) { |
|
584 |
int hopsTto1 = Builder.hops |
|
585 |
(tSubjectName, cIssuer1Name, Integer.MAX_VALUE); |
|
586 |
int hopsTto2 = Builder.hops |
|
587 |
(tSubjectName, cIssuer2Name, Integer.MAX_VALUE); |
|
588 |
if (debug != null) { |
|
589 |
debug.println(METHOD_NME +" hopsTto1: " + hopsTto1); |
|
590 |
debug.println(METHOD_NME +" hopsTto2: " + hopsTto2); |
|
591 |
} |
|
592 |
if (hopsTto1 == hopsTto2) { |
|
593 |
} else if (hopsTto1 > hopsTto2) { |
|
594 |
return 1; |
|
595 |
} else { // hopsTto1 < hopsTto2 |
|
596 |
return -1; |
|
597 |
} |
|
598 |
} else if (tAo1 == null) { |
|
599 |
return 1; |
|
600 |
} else { |
|
601 |
return -1; |
|
602 |
} |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
||
607 |
/* If one cert's issuer is an ancestor of that cert's subject, |
|
608 |
* then it is preferable, in order of increasing naming distance. |
|
609 |
*/ |
|
610 |
if (debug != null) { |
|
611 |
debug.println(METHOD_NME+" CERT ISSUER/SUBJECT COMPARISON TEST..."); |
|
612 |
} |
|
613 |
X500Principal cSubject1 = oCert1.getSubjectX500Principal(); |
|
614 |
X500Principal cSubject2 = oCert2.getSubjectX500Principal(); |
|
615 |
X500Name cSubject1Name = X500Name.asX500Name(cSubject1); |
|
616 |
X500Name cSubject2Name = X500Name.asX500Name(cSubject2); |
|
617 |
||
618 |
if (debug != null) { |
|
619 |
debug.println(METHOD_NME + " o1 Subject: " + cSubject1); |
|
620 |
debug.println(METHOD_NME + " o2 Subject: " + cSubject2); |
|
621 |
} |
|
622 |
int distanceStoI1 = Builder.distance |
|
623 |
(cSubject1Name, cIssuer1Name, Integer.MAX_VALUE); |
|
624 |
int distanceStoI2 = Builder.distance |
|
625 |
(cSubject2Name, cIssuer2Name, Integer.MAX_VALUE); |
|
626 |
if (debug != null) { |
|
627 |
debug.println(METHOD_NME + " distanceStoI1: " + distanceStoI1); |
|
628 |
debug.println(METHOD_NME + " distanceStoI2: " + distanceStoI2); |
|
629 |
} |
|
630 |
if (distanceStoI2 > distanceStoI1) { |
|
631 |
return -1; |
|
632 |
} else if (distanceStoI2 < distanceStoI1) { |
|
633 |
return 1; |
|
634 |
} |
|
635 |
||
636 |
/* Otherwise, certs are equally preferable. |
|
637 |
*/ |
|
638 |
if (debug != null) { |
|
639 |
debug.println(METHOD_NME + " no tests matched; RETURN 0"); |
|
640 |
} |
|
641 |
return -1; |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
/** |
|
646 |
* Verifies a matching certificate. |
|
647 |
* |
|
648 |
* This method executes the validation steps in the PKIX path |
|
649 |
* validation algorithm <draft-ietf-pkix-new-part1-08.txt> which were |
|
650 |
* not satisfied by the selection criteria used by getCertificates() |
|
651 |
* to find the certs and only the steps that can be executed in a |
|
652 |
* forward direction (target to trust anchor). Those steps that can |
|
653 |
* only be executed in a reverse direction are deferred until the |
|
654 |
* complete path has been built. |
|
655 |
* |
|
656 |
* Trust anchor certs are not validated, but are used to verify the |
|
657 |
* signature and revocation status of the previous cert. |
|
658 |
* |
|
659 |
* If the last certificate is being verified (the one whose subject |
|
660 |
* matches the target subject, then steps in 6.1.4 of the PKIX |
|
661 |
* Certification Path Validation algorithm are NOT executed, |
|
662 |
* regardless of whether or not the last cert is an end-entity |
|
663 |
* cert or not. This allows callers to certify CA certs as |
|
664 |
* well as EE certs. |
|
665 |
* |
|
666 |
* @param cert the certificate to be verified |
|
667 |
* @param currentState the current state against which the cert is verified |
|
668 |
* @param certPathList the certPathList generated thus far |
|
669 |
*/ |
|
670 |
void verifyCert(X509Certificate cert, State currentState, |
|
671 |
List<X509Certificate> certPathList) throws GeneralSecurityException |
|
672 |
{ |
|
673 |
if (debug != null) { |
|
674 |
debug.println("ForwardBuilder.verifyCert(SN: " |
|
675 |
+ Debug.toHexString(cert.getSerialNumber()) |
|
676 |
+ "\n Issuer: " + cert.getIssuerX500Principal() + ")" |
|
677 |
+ "\n Subject: " + cert.getSubjectX500Principal() + ")"); |
|
678 |
} |
|
679 |
||
680 |
ForwardState currState = (ForwardState) currentState; |
|
681 |
||
682 |
/* |
|
683 |
* check for looping - abort a loop if |
|
684 |
* ((we encounter the same certificate twice) AND |
|
685 |
* ((policyMappingInhibited = true) OR (no policy mapping |
|
686 |
* extensions can be found between the occurences of the same |
|
687 |
* certificate))) |
|
688 |
*/ |
|
689 |
if (certPathList != null) { |
|
690 |
boolean policyMappingFound = false; |
|
691 |
for (X509Certificate cpListCert : certPathList) { |
|
692 |
X509CertImpl cpListCertImpl = X509CertImpl.toImpl(cpListCert); |
|
693 |
PolicyMappingsExtension policyMappingsExt |
|
694 |
= cpListCertImpl.getPolicyMappingsExtension(); |
|
695 |
if (policyMappingsExt != null) { |
|
696 |
policyMappingFound = true; |
|
697 |
} |
|
698 |
if (debug != null) { |
|
699 |
debug.println("policyMappingFound = " + policyMappingFound); |
|
700 |
} |
|
701 |
if (cert.equals(cpListCert)) { |
|
702 |
if ((buildParams.isPolicyMappingInhibited()) || |
|
703 |
(!policyMappingFound)) { |
|
704 |
if (debug != null) { |
|
705 |
debug.println("loop detected!!"); |
|
706 |
} |
|
707 |
throw new CertPathValidatorException("loop detected"); |
|
708 |
} |
|
709 |
} |
|
710 |
} |
|
711 |
} |
|
712 |
||
713 |
/* check if trusted cert */ |
|
714 |
boolean isTrustedCert = trustedCerts.contains(cert); |
|
715 |
||
716 |
/* we don't perform any validation of the trusted cert */ |
|
717 |
if (!isTrustedCert) { |
|
718 |
/* |
|
4190 | 719 |
* check that the signature algorithm is not disabled. |
720 |
*/ |
|
721 |
AlgorithmChecker.check(cert); |
|
722 |
||
723 |
/* |
|
2 | 724 |
* Check CRITICAL private extensions for user checkers that |
725 |
* support forward checking (forwardCheckers) and remove |
|
726 |
* ones we know how to check. |
|
727 |
*/ |
|
728 |
Set<String> unresCritExts = cert.getCriticalExtensionOIDs(); |
|
729 |
if (unresCritExts == null) { |
|
730 |
unresCritExts = Collections.<String>emptySet(); |
|
731 |
} |
|
732 |
for (PKIXCertPathChecker checker : currState.forwardCheckers) { |
|
733 |
checker.check(cert, unresCritExts); |
|
734 |
} |
|
735 |
||
736 |
/* |
|
737 |
* Remove extensions from user checkers that don't support |
|
738 |
* forward checking. After this step, we will have removed |
|
739 |
* all extensions that all user checkers are capable of |
|
740 |
* processing. |
|
741 |
*/ |
|
742 |
for (PKIXCertPathChecker checker : buildParams.getCertPathCheckers()) { |
|
743 |
if (!checker.isForwardCheckingSupported()) { |
|
744 |
Set<String> supportedExts = checker.getSupportedExtensions(); |
|
745 |
if (supportedExts != null) { |
|
746 |
unresCritExts.removeAll(supportedExts); |
|
747 |
} |
|
748 |
} |
|
749 |
} |
|
750 |
||
751 |
/* |
|
752 |
* Look at the remaining extensions and remove any ones we know how |
|
753 |
* to check. If there are any left, throw an exception! |
|
754 |
*/ |
|
755 |
if (!unresCritExts.isEmpty()) { |
|
756 |
unresCritExts.remove( |
|
757 |
PKIXExtensions.BasicConstraints_Id.toString()); |
|
758 |
unresCritExts.remove( |
|
759 |
PKIXExtensions.NameConstraints_Id.toString()); |
|
760 |
unresCritExts.remove( |
|
761 |
PKIXExtensions.CertificatePolicies_Id.toString()); |
|
762 |
unresCritExts.remove( |
|
763 |
PKIXExtensions.PolicyMappings_Id.toString()); |
|
764 |
unresCritExts.remove( |
|
765 |
PKIXExtensions.PolicyConstraints_Id.toString()); |
|
766 |
unresCritExts.remove( |
|
767 |
PKIXExtensions.InhibitAnyPolicy_Id.toString()); |
|
768 |
unresCritExts.remove( |
|
769 |
PKIXExtensions.SubjectAlternativeName_Id.toString()); |
|
770 |
unresCritExts.remove(PKIXExtensions.KeyUsage_Id.toString()); |
|
771 |
unresCritExts.remove( |
|
772 |
PKIXExtensions.ExtendedKeyUsage_Id.toString()); |
|
773 |
||
774 |
if (!unresCritExts.isEmpty()) |
|
1238
6d1f4b722acd
6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
792
diff
changeset
|
775 |
throw new CertPathValidatorException |
6d1f4b722acd
6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
792
diff
changeset
|
776 |
("Unrecognized critical extension(s)", null, null, -1, |
6d1f4b722acd
6465942: Add problem identification facility to the CertPathValidator framework
mullan
parents:
792
diff
changeset
|
777 |
PKIXReason.UNRECOGNIZED_CRIT_EXT); |
2 | 778 |
} |
779 |
} |
|
780 |
||
781 |
/* |
|
782 |
* if this is the target certificate (init=true), then we are |
|
783 |
* not able to do any more verification, so just return |
|
784 |
*/ |
|
785 |
if (currState.isInitial()) { |
|
786 |
return; |
|
787 |
} |
|
788 |
||
789 |
/* we don't perform any validation of the trusted cert */ |
|
790 |
if (!isTrustedCert) { |
|
791 |
/* Make sure this is a CA cert */ |
|
792 |
if (cert.getBasicConstraints() == -1) { |
|
793 |
throw new CertificateException("cert is NOT a CA cert"); |
|
794 |
} |
|
795 |
||
796 |
/* |
|
797 |
* Check keyUsage extension |
|
798 |
*/ |
|
799 |
KeyChecker.verifyCAKeyUsage(cert); |
|
800 |
} |
|
801 |
||
802 |
/* |
|
803 |
* the following checks are performed even when the cert |
|
804 |
* is a trusted cert, since we are only extracting the |
|
805 |
* subjectDN, and publicKey from the cert |
|
806 |
* in order to verify a previous cert |
|
807 |
*/ |
|
808 |
||
809 |
/* |
|
810 |
* Check revocation for the previous cert |
|
811 |
*/ |
|
812 |
if (buildParams.isRevocationEnabled()) { |
|
813 |
||
814 |
// first off, see if this cert can authorize revocation... |
|
815 |
if (CrlRevocationChecker.certCanSignCrl(cert)) { |
|
816 |
// And then check to be sure no key requiring key parameters |
|
817 |
// has been encountered |
|
818 |
if (!currState.keyParamsNeeded()) |
|
819 |
// If all that checks out, we can check the |
|
820 |
// revocation status of the cert. Otherwise, |
|
821 |
// we'll just wait until the end. |
|
822 |
currState.crlChecker.check(currState.cert, |
|
823 |
cert.getPublicKey(), |
|
824 |
true); |
|
825 |
} |
|
826 |
} |
|
827 |
||
828 |
/* |
|
829 |
* Check signature only if no key requiring key parameters has been |
|
830 |
* encountered. |
|
831 |
*/ |
|
832 |
if (!currState.keyParamsNeeded()) { |
|
833 |
(currState.cert).verify(cert.getPublicKey(), |
|
834 |
buildParams.getSigProvider()); |
|
835 |
} |
|
836 |
} |
|
837 |
||
838 |
/** |
|
839 |
* Verifies whether the input certificate completes the path. |
|
840 |
* Checks the cert against each trust anchor that was specified, in order, |
|
841 |
* and returns true as soon as it finds a valid anchor. |
|
842 |
* Returns true if the cert matches a trust anchor specified as a |
|
843 |
* certificate or if the cert verifies with a trust anchor that |
|
844 |
* was specified as a trusted {pubkey, caname} pair. Returns false if none |
|
845 |
* of the trust anchors are valid for this cert. |
|
846 |
* |
|
847 |
* @param cert the certificate to test |
|
848 |
* @return a boolean value indicating whether the cert completes the path. |
|
849 |
*/ |
|
850 |
boolean isPathCompleted(X509Certificate cert) { |
|
851 |
for (TrustAnchor anchor : trustAnchors) { |
|
852 |
if (anchor.getTrustedCert() != null) { |
|
853 |
if (cert.equals(anchor.getTrustedCert())) { |
|
854 |
this.trustAnchor = anchor; |
|
855 |
return true; |
|
856 |
} else { |
|
857 |
continue; |
|
858 |
} |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
859 |
} else { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
860 |
X500Principal principal = anchor.getCA(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
861 |
java.security.PublicKey publicKey = anchor.getCAPublicKey(); |
2 | 862 |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
863 |
if (principal != null && publicKey != null && |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
864 |
principal.equals(cert.getSubjectX500Principal())) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
865 |
if (publicKey.equals(cert.getPublicKey())) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
866 |
// the cert itself is a trust anchor |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
867 |
this.trustAnchor = anchor; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
868 |
return true; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
869 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
870 |
// else, it is a self-issued certificate of the anchor |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
871 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
872 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
873 |
// Check subject/issuer name chaining |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
874 |
if (principal == null || |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
875 |
!principal.equals(cert.getIssuerX500Principal())) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
876 |
continue; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
877 |
} |
2 | 878 |
} |
879 |
||
880 |
/* Check revocation if it is enabled */ |
|
881 |
if (buildParams.isRevocationEnabled()) { |
|
882 |
try { |
|
883 |
CrlRevocationChecker crlChecker = |
|
884 |
new CrlRevocationChecker(anchor, buildParams); |
|
885 |
crlChecker.check(cert, anchor.getCAPublicKey(), true); |
|
886 |
} catch (CertPathValidatorException cpve) { |
|
887 |
if (debug != null) { |
|
888 |
debug.println("ForwardBuilder.isPathCompleted() cpve"); |
|
889 |
cpve.printStackTrace(); |
|
890 |
} |
|
891 |
continue; |
|
892 |
} |
|
893 |
} |
|
894 |
||
895 |
/* |
|
896 |
* Check signature |
|
897 |
*/ |
|
898 |
try { |
|
899 |
// NOTE: the DSA public key in the buildParams may lack |
|
900 |
// parameters, yet there is no key to inherit the parameters |
|
901 |
// from. This is probably such a rare case that it is not worth |
|
902 |
// trying to detect the situation earlier. |
|
903 |
cert.verify(anchor.getCAPublicKey(), |
|
904 |
buildParams.getSigProvider()); |
|
905 |
} catch (InvalidKeyException ike) { |
|
906 |
if (debug != null) { |
|
907 |
debug.println("ForwardBuilder.isPathCompleted() invalid " |
|
908 |
+ "DSA key found"); |
|
909 |
} |
|
910 |
continue; |
|
911 |
} catch (Exception e){ |
|
912 |
if (debug != null) { |
|
913 |
debug.println("ForwardBuilder.isPathCompleted() " + |
|
914 |
"unexpected exception"); |
|
915 |
e.printStackTrace(); |
|
916 |
} |
|
917 |
continue; |
|
918 |
} |
|
919 |
||
920 |
this.trustAnchor = anchor; |
|
921 |
return true; |
|
922 |
} |
|
923 |
||
924 |
return false; |
|
925 |
} |
|
926 |
||
927 |
/** Adds the certificate to the certPathList |
|
928 |
* |
|
929 |
* @param cert the certificate to be added |
|
930 |
* @param certPathList the certification path list |
|
931 |
*/ |
|
932 |
void addCertToPath(X509Certificate cert, |
|
933 |
LinkedList<X509Certificate> certPathList) { |
|
934 |
certPathList.addFirst(cert); |
|
935 |
} |
|
936 |
||
937 |
/** Removes final certificate from the certPathList |
|
938 |
* |
|
939 |
* @param certPathList the certification path list |
|
940 |
*/ |
|
941 |
void removeFinalCertFromPath(LinkedList<X509Certificate> certPathList) { |
|
942 |
certPathList.removeFirst(); |
|
943 |
} |
|
3225
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
944 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
945 |
/** Verifies whether a CRL is issued by a certain certificate |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
946 |
* |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
947 |
* @param cert the certificate |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
948 |
* @param crl the CRL to be verified |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
949 |
* @param provider the name of the signature provider |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
950 |
*/ |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
951 |
static boolean issues(X509CertImpl cert, X509CRLImpl crl, String provider) |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
952 |
throws IOException { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
953 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
954 |
boolean kidmatched = false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
955 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
956 |
// check certificate's key usage |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
957 |
boolean[] usages = cert.getKeyUsage(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
958 |
if (usages != null && !usages[6]) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
959 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
960 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
961 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
962 |
// check certificate's SKID and CRL's AKID |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
963 |
AuthorityKeyIdentifierExtension akidext = crl.getAuthKeyIdExtension(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
964 |
if (akidext != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
965 |
// the highest priority, matching KID |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
966 |
KeyIdentifier akid = (KeyIdentifier)akidext.get(akidext.KEY_ID); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
967 |
if (akid != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
968 |
SubjectKeyIdentifierExtension skidext = |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
969 |
cert.getSubjectKeyIdentifierExtension(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
970 |
if (skidext != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
971 |
KeyIdentifier skid = |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
972 |
(KeyIdentifier)skidext.get(skidext.KEY_ID); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
973 |
if (!akid.equals(skid)) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
974 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
975 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
976 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
977 |
kidmatched = true; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
978 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
979 |
// conservatively, in case of X509 V1 certificate, |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
980 |
// does return false here if no SKID extension. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
981 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
982 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
983 |
// the medium priority, matching issuer name/serial number |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
984 |
SerialNumber asn = (SerialNumber)akidext.get(akidext.SERIAL_NUMBER); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
985 |
GeneralNames anames = (GeneralNames)akidext.get(akidext.AUTH_NAME); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
986 |
if (asn != null && anames != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
987 |
X500Name subject = (X500Name)cert.getSubjectDN(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
988 |
BigInteger serial = cert.getSerialNumber(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
989 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
990 |
if (serial != null && subject != null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
991 |
if (serial.equals(asn.getNumber())) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
992 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
993 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
994 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
995 |
for (GeneralName name : anames.names()) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
996 |
GeneralNameInterface gni = name.getName(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
997 |
if (subject.equals(gni)) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
998 |
return true; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
999 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1000 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1001 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1002 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1003 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1004 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1005 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1006 |
if (kidmatched) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1007 |
return true; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1008 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1009 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1010 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1011 |
// the last priority, verify the CRL signature with the cert. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1012 |
X500Principal crlIssuer = crl.getIssuerX500Principal(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1013 |
X500Principal certSubject = cert.getSubjectX500Principal(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1014 |
if (certSubject != null && certSubject.equals(crlIssuer)) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1015 |
try { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1016 |
crl.verify(cert.getPublicKey(), provider); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1017 |
return true; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1018 |
} catch (Exception e) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1019 |
// ignore all exceptions. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1020 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1021 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1022 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1023 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1024 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1025 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1026 |
/** |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1027 |
* An adaptable X509 certificate selector for forward certification path |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1028 |
* building. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1029 |
*/ |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1030 |
private static class AdaptableX509CertSelector extends X509CertSelector { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1031 |
public AdaptableX509CertSelector() { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1032 |
super(); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1033 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1034 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1035 |
/** |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1036 |
* Decides whether a <code>Certificate</code> should be selected. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1037 |
* |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1038 |
* For the purpose of compatibility, when a certificate is of |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1039 |
* version 1 and version 2, or the certificate does not include |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1040 |
* a subject key identifier extension, the selection criterion |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1041 |
* of subjectKeyIdentifier will be disabled. |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1042 |
* |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1043 |
* @Override |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1044 |
*/ |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1045 |
public boolean match(Certificate cert) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1046 |
if (!(cert instanceof X509Certificate)) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1047 |
return false; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1048 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1049 |
X509Certificate xcert = (X509Certificate)cert; |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1050 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1051 |
if (xcert.getVersion() < 3 || |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1052 |
xcert.getExtensionValue("2.5.29.14") == null) { |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1053 |
// disable the subjectKeyIdentifier criterion |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1054 |
setSubjectKeyIdentifier(null); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1055 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1056 |
|
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1057 |
return super.match(cert); |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1058 |
} |
023603ebeb1f
6852744: PIT b61: PKI test suite fails because self signed certificates are beingrejected
xuelei
parents:
1238
diff
changeset
|
1059 |
} |
2 | 1060 |
} |