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.signer.internal.cms; |
22 |
|
|
23 |
|
import java.security.GeneralSecurityException; |
24 |
|
import java.util.Collection; |
25 |
|
|
26 |
|
import org.bouncycastle.cms.CMSException; |
27 |
|
import org.bouncycastle.cms.CMSProcessableByteArray; |
28 |
|
import org.bouncycastle.cms.CMSSignedData; |
29 |
|
import org.bouncycastle.cms.DefaultCMSSignatureAlgorithmNameGenerator; |
30 |
|
import org.bouncycastle.cms.SignerInformation; |
31 |
|
import org.bouncycastle.cms.SignerInformationVerifier; |
32 |
|
import org.bouncycastle.operator.DefaultSignatureAlgorithmIdentifierFinder; |
33 |
|
import org.bouncycastle.operator.DigestCalculatorProvider; |
34 |
|
import org.xwiki.crypto.DigestFactory; |
35 |
|
import org.xwiki.crypto.pkix.CertificateFactory; |
36 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
37 |
|
import org.xwiki.crypto.signer.internal.BcContentVerifierProviderBuilder; |
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
@since |
44 |
|
|
|
|
| 80% |
Uncovered Elements: 5 (25) |
Complexity: 9 |
Complexity Density: 0.64 |
|
45 |
|
public final class BcCMSUtils |
46 |
|
{ |
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
47 |
0 |
private BcCMSUtils()... |
48 |
|
{ |
49 |
|
|
50 |
|
} |
51 |
|
|
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@param |
56 |
|
@param |
57 |
|
@param |
58 |
|
@param |
59 |
|
@return |
60 |
|
@throws |
61 |
|
|
|
|
| 60% |
Uncovered Elements: 2 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
62 |
9 |
public static boolean verify(SignerInformation signer,... |
63 |
|
CertifiedPublicKey certKey, BcContentVerifierProviderBuilder contentVerifierProviderBuilder, |
64 |
|
DigestFactory digestProvider) throws CMSException |
65 |
|
{ |
66 |
9 |
if (certKey == null) { |
67 |
0 |
throw new CMSException("No certified key for proceeding to signature validation."); |
68 |
|
} |
69 |
|
|
70 |
9 |
return signer.verify( |
71 |
|
new SignerInformationVerifier( |
72 |
|
new DefaultCMSSignatureAlgorithmNameGenerator(), |
73 |
|
new DefaultSignatureAlgorithmIdentifierFinder(), |
74 |
|
contentVerifierProviderBuilder.build(certKey), |
75 |
|
(DigestCalculatorProvider) digestProvider)); |
76 |
|
} |
77 |
|
|
78 |
|
|
79 |
|
@link |
80 |
|
|
81 |
|
@param |
82 |
|
@param |
83 |
|
@return |
84 |
|
@throws |
85 |
|
|
|
|
| 88.9% |
Uncovered Elements: 1 (9) |
Complexity: 3 |
Complexity Density: 0.43 |
|
86 |
9 |
public static CMSSignedData getSignedData(byte[] signature, byte[] data) throws GeneralSecurityException... |
87 |
|
{ |
88 |
9 |
CMSSignedData signedData; |
89 |
9 |
try { |
90 |
9 |
if (data != null) { |
91 |
7 |
signedData = new CMSSignedData(new CMSProcessableByteArray(data), signature); |
92 |
|
} else { |
93 |
2 |
signedData = new CMSSignedData(signature); |
94 |
|
} |
95 |
|
} catch (CMSException e) { |
96 |
0 |
throw new GeneralSecurityException("Unable to decode signature", e); |
97 |
|
} |
98 |
9 |
return signedData; |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@link |
103 |
|
|
104 |
|
|
105 |
|
|
106 |
|
@param |
107 |
|
@param |
108 |
|
@return |
109 |
|
|
|
|
| 80% |
Uncovered Elements: 1 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
110 |
9 |
public static BcCMSSignedDataVerified getCMSSignedDataVerified(CMSSignedData signedData,... |
111 |
|
CertificateFactory factory) |
112 |
|
{ |
113 |
9 |
BcCMSSignedDataVerified verifiedData = new BcCMSSignedDataVerified(signedData.getSignedContentTypeOID(), |
114 |
9 |
(signedData.getSignedContent() != null ? (byte[]) signedData.getSignedContent().getContent() : null)); |
115 |
|
|
116 |
9 |
BcStoreUtils.addCertificatesToVerifiedData(signedData.getCertificates(), verifiedData, factory); |
117 |
9 |
return verifiedData; |
118 |
|
} |
119 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
120 |
9 |
@SuppressWarnings("unchecked")... |
121 |
|
static Collection<SignerInformation> getSigners(CMSSignedData signedData) |
122 |
|
{ |
123 |
9 |
return signedData.getSignerInfos().getSigners(); |
124 |
|
} |
125 |
|
} |