1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.script; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.math.BigInteger; |
24 |
|
import java.nio.charset.Charset; |
25 |
|
import java.security.GeneralSecurityException; |
26 |
|
import java.util.Collection; |
27 |
|
import java.util.Date; |
28 |
|
import java.util.EnumSet; |
29 |
|
import java.util.HashSet; |
30 |
|
import java.util.List; |
31 |
|
import java.util.Set; |
32 |
|
|
33 |
|
import javax.inject.Inject; |
34 |
|
import javax.inject.Named; |
35 |
|
import javax.inject.Provider; |
36 |
|
import javax.inject.Singleton; |
37 |
|
|
38 |
|
import org.xwiki.component.annotation.Component; |
39 |
|
import org.xwiki.crypto.KeyPairGenerator; |
40 |
|
import org.xwiki.crypto.params.cipher.asymmetric.AsymmetricKeyPair; |
41 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PrivateKeyParameters; |
42 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters; |
43 |
|
import org.xwiki.crypto.params.generator.asymmetric.RSAKeyGenerationParameters; |
44 |
|
import org.xwiki.crypto.pkix.CertificateChainBuilder; |
45 |
|
import org.xwiki.crypto.pkix.CertificateGeneratorFactory; |
46 |
|
import org.xwiki.crypto.pkix.CertificateProvider; |
47 |
|
import org.xwiki.crypto.pkix.CertifyingSigner; |
48 |
|
import org.xwiki.crypto.pkix.X509ExtensionBuilder; |
49 |
|
import org.xwiki.crypto.pkix.params.CertifiedKeyPair; |
50 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
51 |
|
import org.xwiki.crypto.pkix.params.x509certificate.DistinguishedName; |
52 |
|
import org.xwiki.crypto.pkix.params.x509certificate.X509CertificateGenerationParameters; |
53 |
|
import org.xwiki.crypto.pkix.params.x509certificate.X509CertificateParameters; |
54 |
|
import org.xwiki.crypto.pkix.params.x509certificate.X509CertifiedPublicKey; |
55 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.ExtendedKeyUsages; |
56 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.KeyUsage; |
57 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509DnsName; |
58 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GeneralName; |
59 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509IpAddress; |
60 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509Rfc822Name; |
61 |
|
import org.xwiki.crypto.signer.CMSSignedDataGenerator; |
62 |
|
import org.xwiki.crypto.signer.CMSSignedDataVerifier; |
63 |
|
import org.xwiki.crypto.signer.SignerFactory; |
64 |
|
import org.xwiki.crypto.signer.param.CMSSignedDataGeneratorParameters; |
65 |
|
import org.xwiki.crypto.signer.param.CMSSignedDataVerified; |
66 |
|
import org.xwiki.crypto.signer.param.CMSSignerInfo; |
67 |
|
import org.xwiki.script.service.ScriptService; |
68 |
|
import org.xwiki.stability.Unstable; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@version |
74 |
|
@since |
75 |
|
|
76 |
|
@Component |
77 |
|
@Named(CryptoScriptService.ROLEHINT + '.' + RSACryptoScriptService.ROLEHINT) |
78 |
|
@Singleton |
79 |
|
@Unstable |
|
|
| 0% |
Uncovered Elements: 118 (118) |
Complexity: 40 |
Complexity Density: 0.62 |
|
80 |
|
public class RSACryptoScriptService implements ScriptService |
81 |
|
{ |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
public static final String ROLEHINT = "rsa"; |
86 |
|
|
87 |
|
private static final Charset UTF8 = Charset.forName("UTF-8"); |
88 |
|
|
89 |
|
@Inject |
90 |
|
@Named("RSA") |
91 |
|
private KeyPairGenerator keyPairGenerator; |
92 |
|
|
93 |
|
@Inject |
94 |
|
@Named("SHA1withRSAEncryption") |
95 |
|
private SignerFactory signerFactory; |
96 |
|
|
97 |
|
@Inject |
98 |
|
private Provider<X509ExtensionBuilder> extensionBuilder; |
99 |
|
|
100 |
|
@Inject |
101 |
|
@Named("X509") |
102 |
|
private CertificateGeneratorFactory certificateGeneratorFactory; |
103 |
|
|
104 |
|
@Inject |
105 |
|
private CMSSignedDataGenerator cmsSignedDataGenerator; |
106 |
|
|
107 |
|
@Inject |
108 |
|
@Named("X509") |
109 |
|
private CertificateChainBuilder certificateChainBuilder; |
110 |
|
|
111 |
|
@Inject |
112 |
|
private CMSSignedDataVerifier cmsSignedDataVerifier; |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@value |
118 |
|
|
119 |
|
|
120 |
|
@value |
121 |
|
|
122 |
|
@return |
123 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
124 |
0 |
public AsymmetricKeyPair generateKeyPair()... |
125 |
|
{ |
126 |
0 |
return keyPairGenerator.generate(); |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@value |
136 |
|
|
137 |
|
@param |
138 |
|
@return |
139 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
140 |
0 |
public AsymmetricKeyPair generateKeyPair(int strength)... |
141 |
|
{ |
142 |
0 |
return keyPairGenerator.generate(new RSAKeyGenerationParameters(strength)); |
143 |
|
} |
144 |
|
|
145 |
|
|
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
|
@param |
152 |
|
@param |
153 |
|
@param |
154 |
|
|
155 |
|
@return |
156 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
0 |
public AsymmetricKeyPair generateKeyPair(int strength, BigInteger publicExponent, int certainty)... |
158 |
|
{ |
159 |
0 |
return keyPairGenerator.generate(new RSAKeyGenerationParameters(strength, publicExponent, certainty)); |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
@param |
166 |
|
@param |
167 |
|
@return |
168 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
169 |
0 |
public CertifiedKeyPair createCertifiedKeyPair(PrivateKeyParameters privateKey, CertifiedPublicKey certificate)... |
170 |
|
{ |
171 |
0 |
return new CertifiedKeyPair(privateKey, certificate); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@param |
178 |
|
@param |
179 |
|
@param |
180 |
|
@return |
181 |
|
@throws |
182 |
|
@throws |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
public CertifiedKeyPair issueRootCACertificate(AsymmetricKeyPair keyPair, String dn, int validity)... |
185 |
|
throws IOException, GeneralSecurityException |
186 |
|
{ |
187 |
0 |
return new CertifiedKeyPair( |
188 |
|
keyPair.getPrivate(), |
189 |
|
certificateGeneratorFactory.getInstance(signerFactory.getInstance(true, keyPair.getPrivate()), |
190 |
|
new X509CertificateGenerationParameters( |
191 |
|
validity, |
192 |
|
extensionBuilder.get().addBasicConstraints(true) |
193 |
|
.addKeyUsage(true, EnumSet.of(KeyUsage.keyCertSign, |
194 |
|
KeyUsage.cRLSign)) |
195 |
|
.build())) |
196 |
|
.generate(new DistinguishedName(dn), keyPair.getPublic(), |
197 |
|
new X509CertificateParameters()) |
198 |
|
); |
199 |
|
} |
200 |
|
|
201 |
|
|
202 |
|
|
203 |
|
|
204 |
|
@param |
205 |
|
@param |
206 |
|
@param |
207 |
|
@param |
208 |
|
@return |
209 |
|
@throws |
210 |
|
@throws |
211 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
212 |
0 |
public CertifiedKeyPair issueIntermediateCertificate(CertifiedKeyPair issuer, AsymmetricKeyPair keyPair,... |
213 |
|
String dn, int validity) |
214 |
|
throws IOException, GeneralSecurityException |
215 |
|
{ |
216 |
0 |
return new CertifiedKeyPair( |
217 |
|
keyPair.getPrivate(), |
218 |
|
issueIntermediateCertificate(issuer, keyPair.getPublic(), dn, validity) |
219 |
|
); |
220 |
|
} |
221 |
|
|
222 |
|
|
223 |
|
|
224 |
|
|
225 |
|
@param |
226 |
|
@param |
227 |
|
@param |
228 |
|
@param |
229 |
|
@param |
230 |
|
@return |
231 |
|
@throws |
232 |
|
@throws |
233 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
234 |
0 |
public CertifiedPublicKey issueIntermediateCertificate(PrivateKeyParameters privateKey, CertifiedPublicKey issuer,... |
235 |
|
PublicKeyParameters publicKey, String dn, int validity) |
236 |
|
throws IOException, GeneralSecurityException |
237 |
|
{ |
238 |
0 |
return issueIntermediateCertificate(new CertifiedKeyPair(privateKey, issuer), publicKey, dn, validity); |
239 |
|
} |
240 |
|
|
241 |
|
|
242 |
|
|
243 |
|
|
244 |
|
@param |
245 |
|
@param |
246 |
|
@param |
247 |
|
@param |
248 |
|
@return |
249 |
|
@throws |
250 |
|
@throws |
251 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
252 |
0 |
public CertifiedPublicKey issueIntermediateCertificate(CertifiedKeyPair issuer, PublicKeyParameters publicKey,... |
253 |
|
String dn, int validity) |
254 |
|
throws IOException, GeneralSecurityException |
255 |
|
{ |
256 |
0 |
return certificateGeneratorFactory.getInstance( |
257 |
|
CertifyingSigner.getInstance(true, issuer, signerFactory), |
258 |
|
new X509CertificateGenerationParameters( |
259 |
|
validity, |
260 |
|
extensionBuilder.get().addBasicConstraints(0) |
261 |
|
.addKeyUsage(EnumSet.of(KeyUsage.keyCertSign, |
262 |
|
KeyUsage.cRLSign)) |
263 |
|
.build())) |
264 |
|
.generate(new DistinguishedName(dn), publicKey, |
265 |
|
new X509CertificateParameters()); |
266 |
|
} |
267 |
|
|
268 |
|
|
269 |
|
|
270 |
|
|
271 |
|
@param |
272 |
|
@param |
273 |
|
@param |
274 |
|
@param |
275 |
|
@param |
276 |
|
@return |
277 |
|
@throws |
278 |
|
@throws |
279 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
280 |
0 |
public CertifiedKeyPair issueCertificate(CertifiedKeyPair issuer, AsymmetricKeyPair keyPair, String dn,... |
281 |
|
int validity, List<X509GeneralName> subjectAltName) throws IOException, GeneralSecurityException |
282 |
|
{ |
283 |
0 |
return new CertifiedKeyPair( |
284 |
|
keyPair.getPrivate(), |
285 |
|
issueCertificate(issuer, keyPair.getPublic(), dn, validity, subjectAltName) |
286 |
|
); |
287 |
|
} |
288 |
|
|
289 |
|
|
290 |
|
|
291 |
|
|
292 |
|
@param |
293 |
|
@param |
294 |
|
@param |
295 |
|
@param |
296 |
|
@param |
297 |
|
@param |
298 |
|
@return |
299 |
|
@throws |
300 |
|
@throws |
301 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
302 |
0 |
public CertifiedPublicKey issueCertificate(PrivateKeyParameters privateKey, CertifiedPublicKey issuer,... |
303 |
|
PublicKeyParameters publicKey, String dn, int validity, List<X509GeneralName> subjectAltName) |
304 |
|
throws IOException, GeneralSecurityException |
305 |
|
{ |
306 |
0 |
return issueCertificate(new CertifiedKeyPair(privateKey, issuer), publicKey, dn, validity, subjectAltName); |
307 |
|
} |
308 |
|
|
309 |
|
|
310 |
|
|
311 |
|
|
312 |
|
|
313 |
|
|
314 |
|
|
315 |
|
@param |
316 |
|
@param |
317 |
|
@param |
318 |
|
@param |
319 |
|
@param |
320 |
|
@return |
321 |
|
@throws |
322 |
|
@throws |
323 |
|
|
|
|
| 0% |
Uncovered Elements: 20 (20) |
Complexity: 5 |
Complexity Density: 0.36 |
|
324 |
0 |
public CertifiedPublicKey issueCertificate(CertifiedKeyPair issuer, PublicKeyParameters publicKey,... |
325 |
|
String dn, int validity, List<X509GeneralName> subjectAltName) throws IOException, GeneralSecurityException |
326 |
|
{ |
327 |
0 |
X509CertificateParameters params; |
328 |
0 |
X509ExtensionBuilder builder = extensionBuilder.get().addKeyUsage(EnumSet.of(KeyUsage.digitalSignature, |
329 |
|
KeyUsage.dataEncipherment)); |
330 |
|
|
331 |
0 |
if (subjectAltName != null) { |
332 |
0 |
params = new X509CertificateParameters( |
333 |
|
extensionBuilder.get().addSubjectAltName(false, subjectAltName.toArray(new X509GeneralName[]{})) |
334 |
|
.build()); |
335 |
0 |
Set<String> extUsage = new HashSet<String>(); |
336 |
0 |
for (X509GeneralName genName : subjectAltName) { |
337 |
0 |
if (genName instanceof X509Rfc822Name) { |
338 |
0 |
extUsage.add(ExtendedKeyUsages.EMAIL_PROTECTION); |
339 |
0 |
} else if (genName instanceof X509DnsName || genName instanceof X509IpAddress) { |
340 |
0 |
extUsage.add(ExtendedKeyUsages.SERVER_AUTH); |
341 |
0 |
extUsage.add(ExtendedKeyUsages.CLIENT_AUTH); |
342 |
|
} |
343 |
0 |
builder.addExtendedKeyUsage(false, new ExtendedKeyUsages(extUsage)); |
344 |
|
} |
345 |
|
} else { |
346 |
0 |
params = new X509CertificateParameters(); |
347 |
|
} |
348 |
|
|
349 |
|
|
350 |
0 |
return certificateGeneratorFactory.getInstance( |
351 |
|
CertifyingSigner.getInstance(true, issuer, signerFactory), |
352 |
|
new X509CertificateGenerationParameters(validity, builder.build())) |
353 |
|
.generate(new DistinguishedName(dn), publicKey, params); |
354 |
|
} |
355 |
|
|
356 |
|
|
357 |
|
|
358 |
|
|
359 |
|
|
360 |
|
@param |
361 |
|
@param |
362 |
|
@param |
363 |
|
@return |
364 |
|
@throws |
365 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
366 |
0 |
public byte[] cmsSign(byte[] data, CertifiedKeyPair keyPair, boolean embedContent)... |
367 |
|
throws GeneralSecurityException |
368 |
|
{ |
369 |
0 |
return cmsSign(data, keyPair, null, null, embedContent); |
370 |
|
} |
371 |
|
|
372 |
|
|
373 |
|
|
374 |
|
|
375 |
|
|
376 |
|
@param |
377 |
|
@param |
378 |
|
@param |
379 |
|
|
380 |
|
@param |
381 |
|
@return |
382 |
|
@throws |
383 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
384 |
0 |
public byte[] cmsSign(byte[] data, CertifiedKeyPair keyPair, CertificateProvider certificateProvider,... |
385 |
|
boolean embedContent) throws GeneralSecurityException |
386 |
|
{ |
387 |
0 |
return cmsSign(data, keyPair, certificateProvider, null, embedContent); |
388 |
|
} |
389 |
|
|
390 |
|
|
391 |
|
|
392 |
|
|
393 |
|
|
394 |
|
@param |
395 |
|
@param |
396 |
|
@param |
397 |
|
|
398 |
|
@param |
399 |
|
@param |
400 |
|
@return |
401 |
|
@throws |
402 |
|
|
|
|
| 0% |
Uncovered Elements: 29 (29) |
Complexity: 8 |
Complexity Density: 0.47 |
|
403 |
0 |
public byte[] cmsSign(byte[] data, CertifiedKeyPair keyPair, CertificateProvider certificateProvider,... |
404 |
|
CMSSignedDataVerified existingSignature, boolean embedContent) throws GeneralSecurityException |
405 |
|
{ |
406 |
0 |
CMSSignedDataGeneratorParameters parameters = new CMSSignedDataGeneratorParameters() |
407 |
|
.addSigner(CertifyingSigner.getInstance(true, keyPair, signerFactory)); |
408 |
|
|
409 |
0 |
if (existingSignature != null) { |
410 |
0 |
for (CMSSignerInfo existingSigner : existingSignature.getSignatures()) { |
411 |
0 |
parameters.addSignature(existingSigner); |
412 |
|
} |
413 |
|
} |
414 |
|
|
415 |
0 |
Set<CertifiedPublicKey> certs = new HashSet<CertifiedPublicKey>(); |
416 |
0 |
if (existingSignature != null && existingSignature.getCertificates() != null) { |
417 |
0 |
certs.addAll(existingSignature.getCertificates()); |
418 |
|
} |
419 |
|
|
420 |
0 |
if (certificateProvider != null) { |
421 |
0 |
if (existingSignature != null) { |
422 |
0 |
for (CMSSignerInfo existingSigner : existingSignature.getSignatures()) { |
423 |
0 |
if (existingSigner.getSubjectKeyIdentifier() != null) { |
424 |
0 |
addCertificateChain( |
425 |
|
certificateProvider.getCertificate(existingSigner.getSubjectKeyIdentifier()), |
426 |
|
certificateProvider, certs); |
427 |
|
} else { |
428 |
0 |
addCertificateChain( |
429 |
|
certificateProvider.getCertificate(existingSigner.getIssuer(), |
430 |
|
existingSigner.getSerialNumber()), |
431 |
|
certificateProvider, certs); |
432 |
|
} |
433 |
|
} |
434 |
|
} |
435 |
|
|
436 |
0 |
addCertificateChain(keyPair.getCertificate(), certificateProvider, certs); |
437 |
|
} |
438 |
|
|
439 |
0 |
if (!certs.isEmpty()) { |
440 |
0 |
parameters.addCertificates(certs); |
441 |
|
} |
442 |
|
|
443 |
0 |
return cmsSignedDataGenerator.generate(data, parameters, embedContent); |
444 |
|
} |
445 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
446 |
0 |
private void addCertificateChain(CertifiedPublicKey certificate, CertificateProvider certificateProvider,... |
447 |
|
Collection<CertifiedPublicKey> certs) |
448 |
|
{ |
449 |
0 |
Collection<CertifiedPublicKey> chain = certificateChainBuilder.build(certificate, certificateProvider); |
450 |
0 |
if (chain != null) { |
451 |
0 |
certs.addAll(chain); |
452 |
|
} |
453 |
|
} |
454 |
|
|
455 |
|
|
456 |
|
|
457 |
|
|
458 |
|
@param |
459 |
|
|
460 |
|
@return |
461 |
|
@throws |
462 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
463 |
0 |
public CMSSignedDataVerified cmsVerify(byte[] signature)... |
464 |
|
throws GeneralSecurityException |
465 |
|
{ |
466 |
0 |
return cmsSignedDataVerifier.verify(signature); |
467 |
|
} |
468 |
|
|
469 |
|
|
470 |
|
|
471 |
|
|
472 |
|
@param |
473 |
|
@param |
474 |
|
@return |
475 |
|
@throws |
476 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
477 |
0 |
public CMSSignedDataVerified cmsVerify(byte[] signature, byte[] data)... |
478 |
|
throws GeneralSecurityException |
479 |
|
{ |
480 |
0 |
return cmsSignedDataVerifier.verify(signature, data); |
481 |
|
} |
482 |
|
|
483 |
|
|
484 |
|
|
485 |
|
|
486 |
|
@param |
487 |
|
@param |
488 |
|
|
489 |
|
@return |
490 |
|
@throws |
491 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
492 |
0 |
public CMSSignedDataVerified cmsVerify(byte[] signature, CertificateProvider certificateProvider)... |
493 |
|
throws GeneralSecurityException |
494 |
|
{ |
495 |
0 |
return cmsSignedDataVerifier.verify(signature, certificateProvider); |
496 |
|
} |
497 |
|
|
498 |
|
|
499 |
|
|
500 |
|
|
501 |
|
@param |
502 |
|
@param |
503 |
|
@param |
504 |
|
|
505 |
|
@return |
506 |
|
@throws |
507 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
508 |
0 |
public CMSSignedDataVerified cmsVerify(byte[] signature, byte[] data, CertificateProvider certificateProvider)... |
509 |
|
throws GeneralSecurityException |
510 |
|
{ |
511 |
0 |
return cmsSignedDataVerifier.verify(signature, data, certificateProvider); |
512 |
|
} |
513 |
|
|
514 |
|
|
515 |
|
|
516 |
|
|
517 |
|
@param |
518 |
|
@return |
519 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
520 |
0 |
public boolean checkX509CertificateChainValidity(Collection<CertifiedPublicKey> chain)... |
521 |
|
{ |
522 |
0 |
return checkX509CertificateChainValidity(chain, null); |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
|
|
527 |
|
|
528 |
|
@param |
529 |
|
@param |
530 |
|
@return |
531 |
|
|
|
|
| 0% |
Uncovered Elements: 26 (26) |
Complexity: 8 |
Complexity Density: 0.57 |
|
532 |
0 |
public boolean checkX509CertificateChainValidity(Collection<CertifiedPublicKey> chain, Date date)... |
533 |
|
{ |
534 |
0 |
if (chain == null || chain.isEmpty()) { |
535 |
0 |
return false; |
536 |
|
} |
537 |
|
|
538 |
0 |
Date checkDate = (date != null) ? date : new Date(); |
539 |
0 |
boolean rootExpected = true; |
540 |
0 |
for (CertifiedPublicKey cert : chain) { |
541 |
0 |
if (!(cert instanceof X509CertifiedPublicKey)) { |
542 |
0 |
return false; |
543 |
|
} |
544 |
0 |
if (rootExpected) { |
545 |
0 |
if (!((X509CertifiedPublicKey) cert).isRootCA()) { |
546 |
0 |
return false; |
547 |
|
} |
548 |
0 |
rootExpected = false; |
549 |
|
} |
550 |
0 |
if (!((X509CertifiedPublicKey) cert).isValidOn(checkDate)) { |
551 |
0 |
return false; |
552 |
|
} |
553 |
|
} |
554 |
0 |
return true; |
555 |
|
} |
556 |
|
} |