author | mullan |
Mon, 17 Feb 2014 11:36:40 -0500 | |
changeset 22977 | f8f315760941 |
parent 19045 | bc9a25fff6c5 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
19045
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
2 |
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.security.provider.certpath; |
|
27 |
||
28 |
import java.io.IOException; |
|
29 |
import java.security.PublicKey; |
|
30 |
import java.security.cert.CertificateException; |
|
31 |
import java.security.cert.CertPathValidatorException; |
|
32 |
import java.security.cert.PKIXCertPathChecker; |
|
19045
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
33 |
import java.security.cert.PKIXRevocationChecker; |
2 | 34 |
import java.security.cert.TrustAnchor; |
35 |
import java.security.cert.X509Certificate; |
|
36 |
import java.util.ArrayList; |
|
37 |
import java.util.HashSet; |
|
38 |
import java.util.List; |
|
39 |
import java.util.ListIterator; |
|
40 |
import java.util.Set; |
|
41 |
import javax.security.auth.x500.X500Principal; |
|
42 |
||
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
43 |
import sun.security.provider.certpath.PKIX.BuilderParams; |
2 | 44 |
import sun.security.util.Debug; |
45 |
import sun.security.x509.NameConstraintsExtension; |
|
46 |
import sun.security.x509.SubjectKeyIdentifierExtension; |
|
47 |
import sun.security.x509.X509CertImpl; |
|
48 |
||
49 |
/** |
|
50 |
* A specification of a reverse PKIX validation state |
|
51 |
* which is initialized by each build and updated each time a |
|
52 |
* certificate is added to the current path. |
|
53 |
* @since 1.4 |
|
54 |
* @author Sean Mullan |
|
55 |
* @author Yassir Elley |
|
56 |
*/ |
|
57 |
||
58 |
class ReverseState implements State { |
|
59 |
||
60 |
private static final Debug debug = Debug.getInstance("certpath"); |
|
61 |
||
62 |
/* The subject DN of the last cert in the path */ |
|
63 |
X500Principal subjectDN; |
|
64 |
||
65 |
/* The subject public key of the last cert */ |
|
66 |
PublicKey pubKey; |
|
67 |
||
68 |
/* The subject key identifier extension (if any) of the last cert */ |
|
69 |
SubjectKeyIdentifierExtension subjKeyId; |
|
70 |
||
71 |
/* The PKIX constrained/excluded subtrees state variable */ |
|
72 |
NameConstraintsExtension nc; |
|
73 |
||
74 |
/* The PKIX explicit policy, policy mapping, and inhibit_any-policy |
|
75 |
state variables */ |
|
76 |
int explicitPolicy; |
|
77 |
int policyMapping; |
|
78 |
int inhibitAnyPolicy; |
|
79 |
int certIndex; |
|
80 |
PolicyNodeImpl rootNode; |
|
81 |
||
82 |
/* The number of remaining CA certs which may follow in the path. |
|
83 |
* -1: previous cert was an EE cert |
|
84 |
* 0: only EE certs may follow. |
|
85 |
* >0 and <Integer.MAX_VALUE:no more than this number of CA certs may follow |
|
86 |
* Integer.MAX_VALUE: unlimited |
|
87 |
*/ |
|
88 |
int remainingCACerts; |
|
89 |
||
90 |
/* The list of user-defined checkers retrieved from the PKIXParameters |
|
91 |
* instance */ |
|
92 |
ArrayList<PKIXCertPathChecker> userCheckers; |
|
93 |
||
94 |
/* Flag indicating if state is initial (path is just starting) */ |
|
95 |
private boolean init = true; |
|
96 |
||
97 |
/* the checker used for revocation status */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
98 |
RevocationChecker revChecker; |
2 | 99 |
|
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
100 |
/* the algorithm checker */ |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
101 |
AlgorithmChecker algorithmChecker; |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
102 |
|
11900 | 103 |
/* the untrusted certificates checker */ |
104 |
UntrustedChecker untrustedChecker; |
|
105 |
||
2 | 106 |
/* the trust anchor used to validate the path */ |
107 |
TrustAnchor trustAnchor; |
|
108 |
||
109 |
/* Flag indicating if current cert can vouch for the CRL for |
|
110 |
* the next cert |
|
111 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
112 |
boolean crlSign = true; |
2 | 113 |
|
114 |
/** |
|
115 |
* Returns a boolean flag indicating if the state is initial |
|
116 |
* (just starting) |
|
117 |
* |
|
118 |
* @return boolean flag indicating if the state is initial (just starting) |
|
119 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
120 |
@Override |
2 | 121 |
public boolean isInitial() { |
122 |
return init; |
|
123 |
} |
|
124 |
||
125 |
/** |
|
126 |
* Display state for debugging purposes |
|
127 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
128 |
@Override |
2 | 129 |
public String toString() { |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
130 |
StringBuilder sb = new StringBuilder(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
131 |
sb.append("State ["); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
132 |
sb.append("\n subjectDN of last cert: ").append(subjectDN); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
133 |
sb.append("\n subjectKeyIdentifier: ").append |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
134 |
(String.valueOf(subjKeyId)); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
135 |
sb.append("\n nameConstraints: ").append(String.valueOf(nc)); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
136 |
sb.append("\n certIndex: ").append(certIndex); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
137 |
sb.append("\n explicitPolicy: ").append(explicitPolicy); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
138 |
sb.append("\n policyMapping: ").append(policyMapping); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
139 |
sb.append("\n inhibitAnyPolicy: ").append(inhibitAnyPolicy); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
140 |
sb.append("\n rootNode: ").append(rootNode); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
141 |
sb.append("\n remainingCACerts: ").append(remainingCACerts); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
142 |
sb.append("\n crlSign: ").append(crlSign); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
143 |
sb.append("\n init: ").append(init); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
144 |
sb.append("\n]\n"); |
2 | 145 |
return sb.toString(); |
146 |
} |
|
147 |
||
148 |
/** |
|
149 |
* Initialize the state. |
|
150 |
* |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
151 |
* @param buildParams builder parameters |
2 | 152 |
*/ |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
153 |
public void initState(BuilderParams buildParams) |
2 | 154 |
throws CertPathValidatorException |
155 |
{ |
|
156 |
/* |
|
157 |
* Initialize number of remainingCACerts. |
|
158 |
* Note that -1 maxPathLen implies unlimited. |
|
159 |
* 0 implies only an EE cert is acceptable. |
|
160 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
161 |
int maxPathLen = buildParams.maxPathLength(); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
162 |
remainingCACerts = (maxPathLen == -1) ? Integer.MAX_VALUE |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
163 |
: maxPathLen; |
2 | 164 |
|
165 |
/* Initialize explicit policy state variable */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
166 |
if (buildParams.explicitPolicyRequired()) { |
2 | 167 |
explicitPolicy = 0; |
168 |
} else { |
|
169 |
// unconstrained if maxPathLen is -1, |
|
170 |
// otherwise, we want to initialize this to the value of the |
|
171 |
// longest possible path + 1 (i.e. maxpathlen + finalcert + 1) |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
172 |
explicitPolicy = (maxPathLen == -1) ? maxPathLen : maxPathLen + 2; |
2 | 173 |
} |
174 |
||
175 |
/* Initialize policy mapping state variable */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
176 |
if (buildParams.policyMappingInhibited()) { |
2 | 177 |
policyMapping = 0; |
178 |
} else { |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
179 |
policyMapping = (maxPathLen == -1) ? maxPathLen : maxPathLen + 2; |
2 | 180 |
} |
181 |
||
182 |
/* Initialize inhibit any policy state variable */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
183 |
if (buildParams.anyPolicyInhibited()) { |
2 | 184 |
inhibitAnyPolicy = 0; |
185 |
} else { |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
186 |
inhibitAnyPolicy = (maxPathLen == -1) ? maxPathLen : maxPathLen + 2; |
2 | 187 |
} |
188 |
||
189 |
/* Initialize certIndex */ |
|
190 |
certIndex = 1; |
|
191 |
||
192 |
/* Initialize policy tree */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
193 |
Set<String> initExpPolSet = new HashSet<>(1); |
2 | 194 |
initExpPolSet.add(PolicyChecker.ANY_POLICY); |
195 |
||
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
196 |
rootNode = new PolicyNodeImpl(null, PolicyChecker.ANY_POLICY, null, |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
197 |
false, initExpPolSet, false); |
2 | 198 |
|
199 |
/* |
|
200 |
* Initialize each user-defined checker |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
201 |
* Shallow copy the checkers |
2 | 202 |
*/ |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
203 |
userCheckers = new ArrayList<>(buildParams.certPathCheckers()); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
204 |
/* initialize each checker (just in case) */ |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
205 |
for (PKIXCertPathChecker checker : userCheckers) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
206 |
checker.init(false); |
2 | 207 |
} |
208 |
||
209 |
/* Start by trusting the cert to sign CRLs */ |
|
210 |
crlSign = true; |
|
211 |
||
212 |
init = true; |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* Update the state with the specified trust anchor. |
|
217 |
* |
|
218 |
* @param anchor the most-trusted CA |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
219 |
* @param buildParams builder parameters |
2 | 220 |
*/ |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
221 |
public void updateState(TrustAnchor anchor, BuilderParams buildParams) |
2 | 222 |
throws CertificateException, IOException, CertPathValidatorException |
223 |
{ |
|
224 |
trustAnchor = anchor; |
|
225 |
X509Certificate trustedCert = anchor.getTrustedCert(); |
|
226 |
if (trustedCert != null) { |
|
227 |
updateState(trustedCert); |
|
228 |
} else { |
|
229 |
X500Principal caName = anchor.getCA(); |
|
230 |
updateState(anchor.getCAPublicKey(), caName); |
|
231 |
} |
|
232 |
||
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
233 |
// The user specified AlgorithmChecker and RevocationChecker may not be |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
234 |
// able to set the trust anchor until now. |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
235 |
boolean revCheckerAdded = false; |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
236 |
for (PKIXCertPathChecker checker : userCheckers) { |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
237 |
if (checker instanceof AlgorithmChecker) { |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
238 |
((AlgorithmChecker)checker).trySetTrustAnchor(anchor); |
19045
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
239 |
} else if (checker instanceof PKIXRevocationChecker) { |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
240 |
if (revCheckerAdded) { |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
241 |
throw new CertPathValidatorException( |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
242 |
"Only one PKIXRevocationChecker can be specified"); |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
243 |
} |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
244 |
// if it's our own, initialize it |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
245 |
if (checker instanceof RevocationChecker) { |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
246 |
((RevocationChecker)checker).init(anchor, buildParams); |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
247 |
} |
bc9a25fff6c5
8010748: Add PKIXRevocationChecker NO_FALLBACK option and improve SOFT_FAIL option
mullan
parents:
13806
diff
changeset
|
248 |
((PKIXRevocationChecker)checker).init(false); |
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
249 |
revCheckerAdded = true; |
7040
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
250 |
} |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
251 |
} |
659824c2a550
6792180: Enhance to reject weak algorithms or conform to crypto recommendations
xuelei
parents:
5506
diff
changeset
|
252 |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
253 |
// only create a RevocationChecker if revocation is enabled and |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
254 |
// a PKIXRevocationChecker has not already been added |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
255 |
if (buildParams.revocationEnabled() && !revCheckerAdded) { |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
256 |
revChecker = new RevocationChecker(anchor, buildParams); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
257 |
revChecker.init(false); |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
258 |
} |
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
259 |
|
2 | 260 |
init = false; |
261 |
} |
|
262 |
||
263 |
/** |
|
264 |
* Update the state. This method is used when the most-trusted CA is |
|
265 |
* a trusted public-key and caName, instead of a trusted cert. |
|
266 |
* |
|
267 |
* @param pubKey the public key of the trusted CA |
|
268 |
* @param subjectDN the subject distinguished name of the trusted CA |
|
269 |
*/ |
|
270 |
private void updateState(PublicKey pubKey, X500Principal subjectDN) { |
|
271 |
||
272 |
/* update subject DN */ |
|
273 |
this.subjectDN = subjectDN; |
|
274 |
||
275 |
/* update subject public key */ |
|
276 |
this.pubKey = pubKey; |
|
277 |
} |
|
278 |
||
279 |
/** |
|
280 |
* Update the state with the next certificate added to the path. |
|
281 |
* |
|
282 |
* @param cert the certificate which is used to update the state |
|
283 |
*/ |
|
284 |
public void updateState(X509Certificate cert) |
|
285 |
throws CertificateException, IOException, CertPathValidatorException { |
|
286 |
||
287 |
if (cert == null) { |
|
288 |
return; |
|
289 |
} |
|
290 |
||
291 |
/* update subject DN */ |
|
292 |
subjectDN = cert.getSubjectX500Principal(); |
|
293 |
||
294 |
/* check for key needing to inherit alg parameters */ |
|
295 |
X509CertImpl icert = X509CertImpl.toImpl(cert); |
|
296 |
PublicKey newKey = cert.getPublicKey(); |
|
13806
b18118646a65
7195409: CertPath/CertPathValidatorTest/KeyParamsInheritanceTest fails with NullPointerException
mullan
parents:
12861
diff
changeset
|
297 |
if (PKIX.isDSAPublicKeyWithoutParams(newKey)) { |
2 | 298 |
newKey = BasicChecker.makeInheritedParamsKey(newKey, pubKey); |
299 |
} |
|
300 |
||
301 |
/* update subject public key */ |
|
302 |
pubKey = newKey; |
|
303 |
||
304 |
/* |
|
305 |
* if this is a trusted cert (init == true), then we |
|
306 |
* don't update any of the remaining fields |
|
307 |
*/ |
|
308 |
if (init) { |
|
309 |
init = false; |
|
310 |
return; |
|
311 |
} |
|
312 |
||
313 |
/* update subject key identifier */ |
|
314 |
subjKeyId = icert.getSubjectKeyIdentifierExtension(); |
|
315 |
||
316 |
/* update crlSign */ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
317 |
crlSign = RevocationChecker.certCanSignCrl(cert); |
2 | 318 |
|
319 |
/* update current name constraints */ |
|
320 |
if (nc != null) { |
|
321 |
nc.merge(icert.getNameConstraintsExtension()); |
|
322 |
} else { |
|
323 |
nc = icert.getNameConstraintsExtension(); |
|
324 |
if (nc != null) { |
|
325 |
// Make sure we do a clone here, because we're probably |
|
326 |
// going to modify this object later and we don't want to |
|
327 |
// be sharing it with a Certificate object! |
|
328 |
nc = (NameConstraintsExtension) nc.clone(); |
|
329 |
} |
|
330 |
} |
|
331 |
||
332 |
/* update policy state variables */ |
|
333 |
explicitPolicy = |
|
334 |
PolicyChecker.mergeExplicitPolicy(explicitPolicy, icert, false); |
|
335 |
policyMapping = |
|
336 |
PolicyChecker.mergePolicyMapping(policyMapping, icert); |
|
337 |
inhibitAnyPolicy = |
|
338 |
PolicyChecker.mergeInhibitAnyPolicy(inhibitAnyPolicy, icert); |
|
339 |
certIndex++; |
|
340 |
||
341 |
/* |
|
342 |
* Update remaining CA certs |
|
343 |
*/ |
|
344 |
remainingCACerts = |
|
345 |
ConstraintsChecker.mergeBasicConstraints(cert, remainingCACerts); |
|
346 |
||
347 |
init = false; |
|
348 |
} |
|
349 |
||
350 |
/** |
|
351 |
* Returns a boolean flag indicating if a key lacking necessary key |
|
352 |
* algorithm parameters has been encountered. |
|
353 |
* |
|
354 |
* @return boolean flag indicating if key lacking parameters encountered. |
|
355 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
356 |
@Override |
2 | 357 |
public boolean keyParamsNeeded() { |
358 |
/* when building in reverse, we immediately get parameters needed |
|
359 |
* or else throw an exception |
|
360 |
*/ |
|
361 |
return false; |
|
362 |
} |
|
363 |
||
364 |
/* |
|
365 |
* Clone current state. The state is cloned as each cert is |
|
366 |
* added to the path. This is necessary if backtracking occurs, |
|
367 |
* and a prior state needs to be restored. |
|
368 |
* |
|
369 |
* Note that this is a SMART clone. Not all fields are fully copied, |
|
370 |
* because some of them (e.g., subjKeyId) will |
|
371 |
* not have their contents modified by subsequent calls to updateState. |
|
372 |
*/ |
|
12860
9ffbd4e43413
6854712: Revocation checking enhancements (JEP-124)
mullan
parents:
10419
diff
changeset
|
373 |
@Override |
10336
0bb1999251f8
7064075: Security libraries don't build with javac -Xlint:all,-deprecation -Werror
jjg
parents:
7040
diff
changeset
|
374 |
@SuppressWarnings("unchecked") // Safe casts assuming clone() works correctly |
2 | 375 |
public Object clone() { |
376 |
try { |
|
377 |
ReverseState clonedState = (ReverseState) super.clone(); |
|
378 |
||
379 |
/* clone checkers, if cloneable */ |
|
380 |
clonedState.userCheckers = |
|
381 |
(ArrayList<PKIXCertPathChecker>)userCheckers.clone(); |
|
382 |
ListIterator<PKIXCertPathChecker> li = |
|
383 |
clonedState.userCheckers.listIterator(); |
|
384 |
while (li.hasNext()) { |
|
385 |
PKIXCertPathChecker checker = li.next(); |
|
386 |
if (checker instanceof Cloneable) { |
|
387 |
li.set((PKIXCertPathChecker)checker.clone()); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
/* make copy of name constraints */ |
|
392 |
if (nc != null) { |
|
393 |
clonedState.nc = (NameConstraintsExtension) nc.clone(); |
|
394 |
} |
|
395 |
||
396 |
/* make copy of policy tree */ |
|
397 |
if (rootNode != null) { |
|
398 |
clonedState.rootNode = rootNode.copyTree(); |
|
399 |
} |
|
400 |
||
401 |
return clonedState; |
|
402 |
} catch (CloneNotSupportedException e) { |
|
10419
12c063b39232
7084245: Update usages of InternalError to use exception chaining
sherman
parents:
10336
diff
changeset
|
403 |
throw new InternalError(e.toString(), e); |
2 | 404 |
} |
405 |
} |
|
406 |
} |