1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
|
21 |
|
package org.xwiki.crypto.pkix.internal; |
22 |
|
|
23 |
|
import java.math.BigInteger; |
24 |
|
import java.util.ArrayList; |
25 |
|
import java.util.Collection; |
26 |
|
|
27 |
|
import javax.inject.Inject; |
28 |
|
import javax.inject.Named; |
29 |
|
|
30 |
|
import org.bouncycastle.cert.AttributeCertificateHolder; |
31 |
|
import org.bouncycastle.cert.X509CertificateHolder; |
32 |
|
import org.bouncycastle.cms.SignerId; |
33 |
|
import org.bouncycastle.util.Selector; |
34 |
|
import org.bouncycastle.util.Store; |
35 |
|
import org.xwiki.component.annotation.Component; |
36 |
|
import org.xwiki.component.annotation.InstantiationStrategy; |
37 |
|
import org.xwiki.component.descriptor.ComponentInstantiationStrategy; |
38 |
|
import org.xwiki.crypto.pkix.CertificateFactory; |
39 |
|
import org.xwiki.crypto.pkix.CertificateProvider; |
40 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
41 |
|
import org.xwiki.crypto.pkix.params.PrincipalIndentifier; |
42 |
|
|
43 |
|
|
44 |
|
@link@link |
45 |
|
|
46 |
|
@version |
47 |
|
@since |
48 |
|
|
49 |
|
@Component |
50 |
|
@Named("BCStoreX509") |
51 |
|
@InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP) |
|
|
| 84.6% |
Uncovered Elements: 4 (26) |
Complexity: 10 |
Complexity Density: 0.62 |
|
52 |
|
public class BcStoreX509CertificateProvider implements CertificateProvider |
53 |
|
{ |
54 |
|
@Inject |
55 |
|
@Named("X509") |
56 |
|
private CertificateFactory factory; |
57 |
|
|
58 |
|
private Store store; |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
|
63 |
|
@param |
64 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
65 |
19 |
public void setStore(Store store)... |
66 |
|
{ |
67 |
19 |
this.store = store; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
@return |
75 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 2 |
Complexity Density: 0.67 |
|
76 |
49 |
public X509CertificateHolder getCertificate(Selector selector)... |
77 |
|
{ |
78 |
49 |
try { |
79 |
49 |
return (X509CertificateHolder) this.store.getMatches(selector).iterator().next(); |
80 |
|
} catch (Throwable t) { |
81 |
19 |
return null; |
82 |
|
} |
83 |
|
} |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
85 |
35 |
@Override... |
86 |
|
public CertifiedPublicKey getCertificate(byte[] keyIdentifier) |
87 |
|
{ |
88 |
35 |
return BcUtils.convertCertificate(this.factory, getCertificate(new SignerId(keyIdentifier))); |
89 |
|
} |
90 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
91 |
11 |
@Override... |
92 |
|
public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial) |
93 |
|
{ |
94 |
11 |
return BcUtils.convertCertificate(this.factory, |
95 |
|
getCertificate(new SignerId(BcUtils.getX500Name(issuer), serial))); |
96 |
|
} |
97 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
98 |
0 |
@Override... |
99 |
|
public CertifiedPublicKey getCertificate(PrincipalIndentifier issuer, BigInteger serial, byte[] keyIdentifier) |
100 |
|
{ |
101 |
0 |
return BcUtils.convertCertificate(this.factory, |
102 |
|
getCertificate(new SignerId(BcUtils.getX500Name(issuer), serial, keyIdentifier))); |
103 |
|
} |
104 |
|
|
|
|
| 84.6% |
Uncovered Elements: 2 (13) |
Complexity: 4 |
Complexity Density: 0.44 |
|
105 |
3 |
@Override... |
106 |
|
public Collection<CertifiedPublicKey> getCertificate(PrincipalIndentifier subject) |
107 |
|
{ |
108 |
3 |
AttributeCertificateHolder selector = new AttributeCertificateHolder(BcUtils.getX500Name(subject)); |
109 |
|
|
110 |
3 |
try { |
111 |
3 |
Collection<?> matches = this.store.getMatches(selector); |
112 |
2 |
Collection<CertifiedPublicKey> result = new ArrayList<CertifiedPublicKey>(matches.size()); |
113 |
2 |
for (Object holder : matches) { |
114 |
2 |
if (holder instanceof X509CertificateHolder) { |
115 |
2 |
result.add(BcUtils.convertCertificate(this.factory, (X509CertificateHolder) holder)); |
116 |
|
} |
117 |
|
} |
118 |
2 |
return (!result.isEmpty()) ? result : null; |
119 |
|
} catch (Throwable t) { |
120 |
1 |
return null; |
121 |
|
} |
122 |
|
} |
123 |
|
} |