blob: f91b3a81dca573f1fb38873e96cacbb2148d1b56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
package org.bouncycastle.cert.path;
import org.bouncycastle.cert.X509CertificateHolder;
public class CertPath
{
private final X509CertificateHolder[] certificates;
public CertPath(X509CertificateHolder[] certificates)
{
this.certificates = copyArray(certificates);
}
public X509CertificateHolder[] getCertificates()
{
return copyArray(certificates);
}
public CertPathValidationResult validate(CertPathValidation[] ruleSet)
{
CertPathValidationContext context = new CertPathValidationContext(CertPathUtils.getCriticalExtensionsOIDs(certificates));
for (int i = 0; i != ruleSet.length; i++)
{
for (int j = certificates.length - 1; j >= 0; j--)
{
try
{
context.setIsEndEntity(j == 0);
ruleSet[i].validate(context, certificates[j]);
}
catch (CertPathValidationException e)
{ // TODO: introduce object to hold (i and e)
return new CertPathValidationResult(context, j, i, e);
}
}
}
return new CertPathValidationResult(context);
}
public CertPathValidationResult evaluate(CertPathValidation[] ruleSet)
{
CertPathValidationContext context = new CertPathValidationContext(CertPathUtils.getCriticalExtensionsOIDs(certificates));
CertPathValidationResultBuilder builder = new CertPathValidationResultBuilder();
for (int i = 0; i != ruleSet.length; i++)
{
for (int j = certificates.length - 1; j >= 0; j--)
{
try
{
context.setIsEndEntity(j == 0);
ruleSet[i].validate(context, certificates[j]);
}
catch (CertPathValidationException e)
{
builder.addException(e);
}
}
}
return builder.build();
}
private X509CertificateHolder[] copyArray(X509CertificateHolder[] array)
{
X509CertificateHolder[] rv = new X509CertificateHolder[array.length];
System.arraycopy(array, 0, rv, 0, rv.length);
return rv;
}
public int length()
{
return certificates.length;
}
}
|