1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.crypto.pkix.internal.extension; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.util.ArrayList; |
24 |
|
import java.util.EnumSet; |
25 |
|
import java.util.Enumeration; |
26 |
|
import java.util.List; |
27 |
|
|
28 |
|
import org.bouncycastle.asn1.ASN1ObjectIdentifier; |
29 |
|
import org.bouncycastle.asn1.x509.AuthorityKeyIdentifier; |
30 |
|
import org.bouncycastle.asn1.x509.BasicConstraints; |
31 |
|
import org.bouncycastle.asn1.x509.ExtendedKeyUsage; |
32 |
|
import org.bouncycastle.asn1.x509.Extension; |
33 |
|
import org.bouncycastle.asn1.x509.Extensions; |
34 |
|
import org.bouncycastle.asn1.x509.GeneralNames; |
35 |
|
import org.bouncycastle.asn1.x509.SubjectKeyIdentifier; |
36 |
|
import org.bouncycastle.asn1.x509.X509Extension; |
37 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.ExtendedKeyUsages; |
38 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.KeyUsage; |
39 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509Extensions; |
40 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GeneralName; |
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
|
45 |
|
@version |
46 |
|
@since |
47 |
|
|
|
|
| 77.8% |
Uncovered Elements: 14 (63) |
Complexity: 23 |
Complexity Density: 0.68 |
|
48 |
|
public class BcX509Extensions implements X509Extensions |
49 |
|
{ |
50 |
|
private final Extensions extensions; |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
57 |
300 |
public BcX509Extensions(Extensions extensions)... |
58 |
|
{ |
59 |
300 |
this.extensions = extensions; |
60 |
|
} |
61 |
|
|
62 |
|
|
63 |
|
@return |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
14 |
public Extensions getExtensions()... |
66 |
|
{ |
67 |
14 |
return this.extensions; |
68 |
|
} |
69 |
|
|
|
|
| 0% |
Uncovered Elements: 6 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
70 |
0 |
@Override... |
71 |
|
public byte[] getExtensionValue(String oid) |
72 |
|
{ |
73 |
0 |
Extension ext = this.extensions.getExtension(new ASN1ObjectIdentifier(oid)); |
74 |
|
|
75 |
0 |
if (ext == null) { |
76 |
0 |
return null; |
77 |
|
} |
78 |
|
|
79 |
0 |
return ext.getExtnValue().getOctets(); |
80 |
|
} |
81 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
82 |
12 |
@Override... |
83 |
|
public boolean isCritical(String oid) |
84 |
|
{ |
85 |
12 |
Extension ext = this.extensions.getExtension(new ASN1ObjectIdentifier(oid)); |
86 |
|
|
87 |
12 |
return ext != null && ext.isCritical(); |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
90 |
1 |
@Override... |
91 |
|
public String[] getExtensionOID() |
92 |
|
{ |
93 |
1 |
List<String> oids = new ArrayList<String>(); |
94 |
|
|
95 |
1 |
@SuppressWarnings("unchecked") |
96 |
|
Enumeration<ASN1ObjectIdentifier> extOids = this.extensions.oids(); |
97 |
6 |
while (extOids.hasMoreElements()) { |
98 |
5 |
oids.add(extOids.nextElement().getId()); |
99 |
|
} |
100 |
|
|
101 |
1 |
return oids.toArray(new String[oids.size()]); |
102 |
|
} |
103 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
104 |
1 |
@Override... |
105 |
|
public String[] getCriticalExtensionOID() |
106 |
|
{ |
107 |
1 |
ASN1ObjectIdentifier[] asnoids = this.extensions.getCriticalExtensionOIDs(); |
108 |
1 |
return toStringArray(asnoids); |
109 |
|
} |
110 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
111 |
1 |
@Override... |
112 |
|
public String[] getNonCriticalExtensionOID() |
113 |
|
{ |
114 |
1 |
ASN1ObjectIdentifier[] asnoids = this.extensions.getNonCriticalExtensionOIDs(); |
115 |
1 |
return toStringArray(asnoids); |
116 |
|
} |
117 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 2 |
Complexity Density: 0.5 |
|
118 |
2 |
private String[] toStringArray(ASN1ObjectIdentifier[] asnoids)... |
119 |
|
{ |
120 |
2 |
String[] oids = new String[asnoids.length]; |
121 |
|
|
122 |
7 |
for (int i = 0; i < asnoids.length; i++) { |
123 |
5 |
oids[i] = asnoids[i].getId(); |
124 |
|
} |
125 |
|
|
126 |
2 |
return oids; |
127 |
|
} |
128 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
129 |
0 |
@Override... |
130 |
|
public byte[] getEncoded() throws IOException |
131 |
|
{ |
132 |
0 |
return this.extensions.getEncoded(); |
133 |
|
} |
134 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
135 |
30 |
@Override... |
136 |
|
public boolean hasCertificateAuthorityBasicConstraints() |
137 |
|
{ |
138 |
30 |
BasicConstraints bc = BasicConstraints.fromExtensions(this.extensions); |
139 |
|
|
140 |
30 |
return bc != null && bc.isCA(); |
141 |
|
} |
142 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
143 |
2 |
@Override... |
144 |
|
public int getBasicConstraintsPathLen() |
145 |
|
{ |
146 |
2 |
BasicConstraints bc = BasicConstraints.fromExtensions(this.extensions); |
147 |
|
|
148 |
2 |
return (bc != null) ? bc.getPathLenConstraint().intValue() : -1; |
149 |
|
} |
150 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
151 |
27 |
@Override... |
152 |
|
public EnumSet<KeyUsage> getKeyUsage() |
153 |
|
{ |
154 |
27 |
return BcExtensionUtils.getSetOfKeyUsage(org.bouncycastle.asn1.x509.KeyUsage.fromExtensions(this.extensions)); |
155 |
|
} |
156 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
157 |
4 |
@Override... |
158 |
|
public ExtendedKeyUsages getExtendedKeyUsage() |
159 |
|
{ |
160 |
4 |
return BcExtensionUtils.getExtendedKeyUsages(ExtendedKeyUsage.fromExtensions(this.extensions)); |
161 |
|
} |
162 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
163 |
44 |
@Override... |
164 |
|
public byte[] getAuthorityKeyIdentifier() |
165 |
|
{ |
166 |
44 |
AuthorityKeyIdentifier id = AuthorityKeyIdentifier.fromExtensions(this.extensions); |
167 |
44 |
return (id != null) ? id.getKeyIdentifier() : null; |
168 |
|
} |
169 |
|
|
|
|
| 75% |
Uncovered Elements: 1 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
170 |
220 |
@Override... |
171 |
|
public byte[] getSubjectKeyIdentifier() |
172 |
|
{ |
173 |
220 |
SubjectKeyIdentifier id = SubjectKeyIdentifier.fromExtensions(this.extensions); |
174 |
220 |
return (id != null) ? id.getKeyIdentifier() : null; |
175 |
|
} |
176 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
177 |
1 |
@Override... |
178 |
|
public List<X509GeneralName> getSubjectAltName() |
179 |
|
{ |
180 |
1 |
return BcExtensionUtils.getX509GeneralNames(GeneralNames.fromExtensions(this.extensions, |
181 |
|
X509Extension.subjectAlternativeName)); |
182 |
|
} |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
@Override... |
185 |
|
public List<X509GeneralName> getIssuerAltName() |
186 |
|
{ |
187 |
0 |
return BcExtensionUtils.getX509GeneralNames(GeneralNames.fromExtensions(this.extensions, |
188 |
|
X509Extension.issuerAlternativeName)); |
189 |
|
} |
190 |
|
} |