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.security.SecureRandom; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Provider; |
27 |
|
import javax.inject.Singleton; |
28 |
|
|
29 |
|
import org.xwiki.component.annotation.Component; |
30 |
|
import org.xwiki.crypto.pkix.CertificateGenerator; |
31 |
|
import org.xwiki.crypto.pkix.CertificateGeneratorFactory; |
32 |
|
import org.xwiki.crypto.pkix.params.CertificateGenerationParameters; |
33 |
|
import org.xwiki.crypto.pkix.params.x509certificate.X509CertificateGenerationParameters; |
34 |
|
import org.xwiki.crypto.signer.Signer; |
35 |
|
import org.xwiki.crypto.signer.SignerFactory; |
36 |
|
|
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
@version |
41 |
|
@since |
42 |
|
|
43 |
|
@Component |
44 |
|
@Named("X509") |
45 |
|
@Singleton |
|
|
| 64.7% |
Uncovered Elements: 6 (17) |
Complexity: 5 |
Complexity Density: 0.42 |
|
46 |
|
public class BcX509CertificateGeneratorFactory implements CertificateGeneratorFactory |
47 |
|
{ |
48 |
|
|
49 |
|
@Inject |
50 |
|
private SignerFactory signerFactory; |
51 |
|
|
52 |
|
@Inject |
53 |
|
private Provider<SecureRandom> randomProvider; |
54 |
|
|
|
|
| 62.5% |
Uncovered Elements: 6 (16) |
Complexity: 5 |
Complexity Density: 0.42 |
|
55 |
10 |
@Override... |
56 |
|
public CertificateGenerator getInstance(Signer signer, CertificateGenerationParameters parameters) |
57 |
|
{ |
58 |
10 |
if (!(parameters instanceof X509CertificateGenerationParameters)) { |
59 |
0 |
throw new IllegalArgumentException("Invalid parameters for X.509 certificate: " |
60 |
|
+ parameters.getClass().getName()); |
61 |
|
} |
62 |
|
|
63 |
10 |
if (!signer.isForSigning()) { |
64 |
0 |
throw new IllegalArgumentException("Verifying signer used for signing certificates."); |
65 |
|
} |
66 |
|
|
67 |
10 |
X509CertificateGenerationParameters params = (X509CertificateGenerationParameters) parameters; |
68 |
|
|
69 |
10 |
switch (params.getX509Version()) { |
70 |
3 |
case V1: |
71 |
3 |
return new BcX509v1CertificateGenerator(signer, params, this.signerFactory, this.randomProvider.get()); |
72 |
7 |
case V3: |
73 |
7 |
return new BcX509v3CertificateGenerator(signer, params, this.signerFactory, this.randomProvider.get()); |
74 |
0 |
default: |
75 |
0 |
throw new IllegalArgumentException("Unknown X.509 certificate version: " + params.getX509Version()); |
76 |
|
} |
77 |
|
} |
78 |
|
} |