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; |
21 |
|
|
22 |
|
import java.io.IOException; |
23 |
|
import java.math.BigInteger; |
24 |
|
import java.util.Date; |
25 |
|
|
26 |
|
import org.bouncycastle.asn1.ASN1Integer; |
27 |
|
import org.bouncycastle.asn1.x509.TBSCertificate; |
28 |
|
import org.bouncycastle.asn1.x509.Time; |
29 |
|
import org.bouncycastle.asn1.x509.V3TBSCertificateGenerator; |
30 |
|
import org.xwiki.crypto.params.cipher.asymmetric.PublicKeyParameters; |
31 |
|
import org.xwiki.crypto.pkix.internal.extension.BcX509Extensions; |
32 |
|
import org.xwiki.crypto.pkix.internal.extension.DefaultX509ExtensionBuilder; |
33 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
34 |
|
import org.xwiki.crypto.pkix.params.PrincipalIndentifier; |
35 |
|
import org.xwiki.crypto.pkix.params.x509certificate.extension.X509Extensions; |
36 |
|
import org.xwiki.crypto.signer.Signer; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@version |
42 |
|
@since |
43 |
|
|
|
|
| 97.6% |
Uncovered Elements: 1 (42) |
Complexity: 14 |
Complexity Density: 0.54 |
|
44 |
|
public class BcX509v3TBSCertificateBuilder implements BcX509TBSCertificateBuilder |
45 |
|
{ |
46 |
|
private final V3TBSCertificateGenerator tbsGen = new V3TBSCertificateGenerator(); |
47 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
48 |
7 |
@Override... |
49 |
|
public BcX509TBSCertificateBuilder setSerialNumber(BigInteger serial) |
50 |
|
{ |
51 |
7 |
this.tbsGen.setSerialNumber(new ASN1Integer(serial)); |
52 |
7 |
return this; |
53 |
|
} |
54 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
55 |
7 |
@Override... |
56 |
|
public BcX509TBSCertificateBuilder setSubjectPublicKeyInfo(PublicKeyParameters subject) |
57 |
|
{ |
58 |
7 |
this.tbsGen.setSubjectPublicKeyInfo(BcUtils.getSubjectPublicKeyInfo(subject)); |
59 |
7 |
return this; |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
62 |
7 |
@Override... |
63 |
|
public BcX509TBSCertificateBuilder setIssuer(PrincipalIndentifier issuer) |
64 |
|
{ |
65 |
7 |
this.tbsGen.setIssuer(BcUtils.getX500Name(issuer)); |
66 |
7 |
return this; |
67 |
|
} |
68 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
69 |
7 |
@Override... |
70 |
|
public BcX509TBSCertificateBuilder setSubject(PrincipalIndentifier subject) |
71 |
|
{ |
72 |
7 |
this.tbsGen.setSubject(BcUtils.getX500Name(subject)); |
73 |
7 |
return this; |
74 |
|
} |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
76 |
7 |
@Override... |
77 |
|
public BcX509TBSCertificateBuilder setStartDate(Date time) |
78 |
|
{ |
79 |
7 |
this.tbsGen.setStartDate(new Time(time)); |
80 |
7 |
return this; |
81 |
|
} |
82 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
83 |
7 |
@Override... |
84 |
|
public BcX509TBSCertificateBuilder setEndDate(Date time) |
85 |
|
{ |
86 |
7 |
this.tbsGen.setEndDate(new Time(time)); |
87 |
7 |
return this; |
88 |
|
} |
89 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
90 |
7 |
@Override... |
91 |
|
public BcX509TBSCertificateBuilder setSignature(Signer signer) |
92 |
|
{ |
93 |
7 |
this.tbsGen.setSignature(BcUtils.getSignerAlgoritmIdentifier(signer)); |
94 |
7 |
return this; |
95 |
|
} |
96 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
97 |
7 |
@Override... |
98 |
|
public TBSCertificate build() |
99 |
|
{ |
100 |
7 |
return this.tbsGen.generateTBSCertificate(); |
101 |
|
} |
102 |
|
|
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
|
108 |
|
@param |
109 |
|
@param |
110 |
|
@return |
111 |
|
@throws |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (10) |
Complexity: 4 |
Complexity Density: 0.67 |
|
113 |
4 |
public BcX509v3TBSCertificateBuilder setExtensions(PublicKeyParameters subject,... |
114 |
|
X509Extensions extensions1, X509Extensions extensions2) throws IOException |
115 |
|
{ |
116 |
4 |
DefaultX509ExtensionBuilder extBuilder = new DefaultX509ExtensionBuilder(); |
117 |
|
|
118 |
4 |
if (extensions1 != null || extensions2 != null) { |
119 |
3 |
extBuilder.addAuthorityKeyIdentifier(subject) |
120 |
|
.addSubjectKeyIdentifier(subject) |
121 |
|
.addExtensions(extensions1) |
122 |
|
.addExtensions(extensions2); |
123 |
|
} |
124 |
|
|
125 |
4 |
if (!extBuilder.isEmpty()) |
126 |
|
{ |
127 |
3 |
this.tbsGen.setExtensions(((BcX509Extensions) extBuilder.build()).getExtensions()); |
128 |
|
} |
129 |
4 |
return this; |
130 |
|
} |
131 |
|
|
132 |
|
|
133 |
|
|
134 |
|
|
135 |
|
@param |
136 |
|
@param |
137 |
|
|
138 |
|
@param |
139 |
|
@param |
140 |
|
@return |
141 |
|
@throws |
142 |
|
|
|
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
143 |
3 |
public BcX509v3TBSCertificateBuilder setExtensions(CertifiedPublicKey issuer, PublicKeyParameters subject,... |
144 |
|
X509Extensions extensions1, X509Extensions extensions2) throws IOException |
145 |
|
{ |
146 |
3 |
DefaultX509ExtensionBuilder extBuilder = new DefaultX509ExtensionBuilder(); |
147 |
|
|
148 |
3 |
extBuilder.addAuthorityKeyIdentifier(issuer) |
149 |
|
.addSubjectKeyIdentifier(subject) |
150 |
|
.addExtensions(extensions1) |
151 |
|
.addExtensions(extensions2); |
152 |
|
|
153 |
3 |
if (!extBuilder.isEmpty()) |
154 |
|
{ |
155 |
3 |
this.tbsGen.setExtensions(((BcX509Extensions) extBuilder.build()).getExtensions()); |
156 |
|
} |
157 |
3 |
return this; |
158 |
|
} |
159 |
|
} |