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.util.EnumSet; |
23 |
|
|
24 |
|
import org.bouncycastle.asn1.x509.BasicConstraints; |
25 |
|
import org.bouncycastle.asn1.x509.Extension; |
26 |
|
import org.bouncycastle.cert.bc.BcX509ExtensionUtils; |
27 |
|
import org.xwiki.component.annotation.Component; |
28 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
29 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
30 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters; |
31 |
|
import org.xwiki.crypto.pkix.X509ExtensionBuilder; |
32 |
|
import org.xwiki.crypto.pkix.internal.BcUtils; |
33 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
34 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.ExtendedKeyUsages; |
35 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.KeyUsage; |
36 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509GeneralName; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
44 |
|
@Component |
45 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 62.5% |
Uncovered Elements: 18 (48) |
Complexity: 19 |
Complexity Density: 0.79 |
|
46 |
|
public class DefaultX509ExtensionBuilder extends AbstractBcX509ExtensionBuilder |
47 |
|
{ |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
48 |
3 |
@Override... |
49 |
|
public X509ExtensionBuilder addBasicConstraints(boolean isCertificateAuthority) |
50 |
|
{ |
51 |
3 |
return addExtension(Extension.basicConstraints, true, new BasicConstraints(isCertificateAuthority)); |
52 |
|
} |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
54 |
1 |
@Override... |
55 |
|
public X509ExtensionBuilder addBasicConstraints(int pathLen) |
56 |
|
{ |
57 |
1 |
return addExtension(Extension.basicConstraints, true, new BasicConstraints(pathLen)); |
58 |
|
} |
59 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
60 |
3 |
@Override... |
61 |
|
public X509ExtensionBuilder addKeyUsage(EnumSet<KeyUsage> usages) |
62 |
|
{ |
63 |
3 |
return addKeyUsage(true, usages); |
64 |
|
} |
65 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
66 |
6 |
@Override... |
67 |
|
public X509ExtensionBuilder addKeyUsage(boolean critical, EnumSet<KeyUsage> usages) |
68 |
|
{ |
69 |
6 |
if (usages == null || usages.isEmpty()) { |
70 |
0 |
return this; |
71 |
|
} |
72 |
|
|
73 |
6 |
return addExtension(Extension.keyUsage, critical, BcExtensionUtils.getKeyUsage(usages)); |
74 |
|
} |
75 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 3 |
Complexity Density: 1 |
|
76 |
2 |
@Override... |
77 |
|
public X509ExtensionBuilder addExtendedKeyUsage(boolean critical, ExtendedKeyUsages usages) |
78 |
|
{ |
79 |
2 |
if (usages == null || usages.isEmpty()) { |
80 |
0 |
return this; |
81 |
|
} |
82 |
|
|
83 |
2 |
return addExtension(Extension.extendedKeyUsage, critical, |
84 |
|
BcExtensionUtils.getExtendedKeyUsage(usages.getAll())); |
85 |
|
} |
86 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
87 |
3 |
@Override... |
88 |
|
public X509ExtensionBuilder addAuthorityKeyIdentifier(CertifiedPublicKey issuer) |
89 |
|
{ |
90 |
3 |
if (issuer == null) { |
91 |
0 |
return this; |
92 |
|
} |
93 |
|
|
94 |
3 |
return addExtension(Extension.authorityKeyIdentifier, false, |
95 |
|
new BcX509ExtensionUtils().createAuthorityKeyIdentifier(BcUtils.getX509CertificateHolder(issuer))); |
96 |
|
} |
97 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
98 |
3 |
@Override... |
99 |
|
public X509ExtensionBuilder addAuthorityKeyIdentifier(PublicKeyParameters subject) |
100 |
|
{ |
101 |
3 |
if (subject == null) { |
102 |
0 |
return this; |
103 |
|
} |
104 |
|
|
105 |
3 |
return addExtension(Extension.authorityKeyIdentifier, false, |
106 |
|
new BcX509ExtensionUtils().createAuthorityKeyIdentifier(BcUtils.getSubjectPublicKeyInfo(subject))); |
107 |
|
} |
108 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
109 |
6 |
@Override... |
110 |
|
public X509ExtensionBuilder addSubjectKeyIdentifier(PublicKeyParameters subject) |
111 |
|
{ |
112 |
6 |
if (subject == null) { |
113 |
0 |
return this; |
114 |
|
} |
115 |
|
|
116 |
6 |
return addExtension(Extension.subjectKeyIdentifier, false, |
117 |
|
new BcX509ExtensionUtils().createSubjectKeyIdentifier(BcUtils.getSubjectPublicKeyInfo(subject))); |
118 |
|
} |
119 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
120 |
2 |
@Override... |
121 |
|
public X509ExtensionBuilder addSubjectAltName(boolean critical, X509GeneralName[] names) |
122 |
|
{ |
123 |
2 |
if (names == null) { |
124 |
0 |
return this; |
125 |
|
} |
126 |
|
|
127 |
2 |
return addExtension(Extension.subjectAlternativeName, false, BcExtensionUtils.getGeneralNames(names)); |
128 |
|
} |
129 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
130 |
0 |
@Override... |
131 |
|
public X509ExtensionBuilder addIssuerAltName(X509GeneralName[] names) |
132 |
|
{ |
133 |
0 |
if (names == null) { |
134 |
0 |
return this; |
135 |
|
} |
136 |
|
|
137 |
0 |
return addExtension(Extension.issuerAlternativeName, false, BcExtensionUtils.getGeneralNames(names)); |
138 |
|
} |
139 |
|
} |