| 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 javax.inject.Inject; |
| 27 |
|
import javax.inject.Named; |
| 28 |
|
import javax.inject.Singleton; |
| 29 |
|
|
| 30 |
|
import org.bouncycastle.cms.CMSException; |
| 31 |
|
import org.bouncycastle.cms.CMSSignedData; |
| 32 |
|
import org.bouncycastle.cms.SignerInformation; |
| 33 |
|
import org.bouncycastle.operator.DigestCalculatorProvider; |
| 34 |
|
import org.xwiki.component.annotation.Component; |
| 35 |
|
import org.xwiki.component.manager.ComponentManager; |
| 36 |
|
import org.xwiki.component.phase.Initializable; |
| 37 |
|
import org.xwiki.component.phase.InitializationException; |
| 38 |
|
import org.xwiki.crypto.DigestFactory; |
| 39 |
|
import org.xwiki.crypto.pkix.CertificateChainBuilder; |
| 40 |
|
import org.xwiki.crypto.pkix.CertificateFactory; |
| 41 |
|
import org.xwiki.crypto.pkix.CertificateProvider; |
| 42 |
|
import org.xwiki.crypto.pkix.params.CertifiedPublicKey; |
| 43 |
|
import org.xwiki.crypto.signer.CMSSignedDataVerifier; |
| 44 |
|
import org.xwiki.crypto.signer.internal.BcContentVerifierProviderBuilder; |
| 45 |
|
import org.xwiki.crypto.signer.param.CMSSignedDataVerified; |
| 46 |
|
|
| 47 |
|
|
| 48 |
|
@link |
| 49 |
|
|
| 50 |
|
@version |
| 51 |
|
@since |
| 52 |
|
|
| 53 |
|
@Component |
| 54 |
|
@Singleton |
| |
|
| 81.5% |
Uncovered Elements: 5 (27) |
Complexity: 10 |
Complexity Density: 0.59 |
|
| 55 |
|
public class DefaultCMSSignedDataVerifier implements CMSSignedDataVerifier, Initializable |
| 56 |
|
{ |
| 57 |
|
@Inject |
| 58 |
|
private DigestFactory digestProvider; |
| 59 |
|
|
| 60 |
|
@Inject |
| 61 |
|
private BcContentVerifierProviderBuilder contentVerifierProviderBuilder; |
| 62 |
|
|
| 63 |
|
@Inject |
| 64 |
|
@Named("X509") |
| 65 |
|
private CertificateFactory certFactory; |
| 66 |
|
|
| 67 |
|
@Inject |
| 68 |
|
@Named("X509") |
| 69 |
|
private CertificateChainBuilder chainBuilder; |
| 70 |
|
|
| 71 |
|
@Inject |
| 72 |
|
private ComponentManager manager; |
| 73 |
|
|
| |
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
| 74 |
7 |
@Override... |
| 75 |
|
public void initialize() throws InitializationException |
| 76 |
|
{ |
| 77 |
7 |
if (!(this.digestProvider instanceof DigestCalculatorProvider)) { |
| 78 |
0 |
throw new InitializationException("Incompatible DigestFactory for this signed data verifier."); |
| 79 |
|
} |
| 80 |
|
} |
| 81 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 82 |
1 |
@Override... |
| 83 |
|
public CMSSignedDataVerified verify(byte[] signature) throws GeneralSecurityException |
| 84 |
|
{ |
| 85 |
1 |
return verify(signature, null, (CertificateProvider) null); |
| 86 |
|
} |
| 87 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 88 |
1 |
@Override... |
| 89 |
|
public CMSSignedDataVerified verify(byte[] signature, Collection<CertifiedPublicKey> certificates) |
| 90 |
|
throws GeneralSecurityException |
| 91 |
|
{ |
| 92 |
1 |
return verify(signature, null, certificates); |
| 93 |
|
} |
| 94 |
|
|
| |
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 95 |
0 |
@Override... |
| 96 |
|
public CMSSignedDataVerified verify(byte[] signature, CertificateProvider certificateProvider) |
| 97 |
|
throws GeneralSecurityException |
| 98 |
|
{ |
| 99 |
0 |
return verify(signature, null, certificateProvider); |
| 100 |
|
} |
| 101 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 102 |
2 |
@Override... |
| 103 |
|
public CMSSignedDataVerified verify(byte[] signature, byte[] data) throws GeneralSecurityException |
| 104 |
|
{ |
| 105 |
2 |
return verify(signature, data, (CertificateProvider) null); |
| 106 |
|
} |
| 107 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 108 |
6 |
@Override... |
| 109 |
|
public CMSSignedDataVerified verify(byte[] signature, byte[] data, |
| 110 |
|
Collection<CertifiedPublicKey> certificates) throws GeneralSecurityException |
| 111 |
|
{ |
| 112 |
6 |
return verify(signature, data, BcStoreUtils.getCertificateProvider(this.manager, certificates)); |
| 113 |
|
} |
| 114 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 115 |
9 |
@Override... |
| 116 |
|
public CMSSignedDataVerified verify(byte[] signature, byte[] data, CertificateProvider certificateProvider) |
| 117 |
|
throws GeneralSecurityException |
| 118 |
|
{ |
| 119 |
9 |
CMSSignedData signedData = BcCMSUtils.getSignedData(signature, data); |
| 120 |
|
|
| 121 |
9 |
CertificateProvider provider = BcStoreUtils.getCertificateProvider(this.manager, signedData.getCertificates(), |
| 122 |
|
certificateProvider); |
| 123 |
|
|
| 124 |
9 |
return verify(signedData, provider); |
| 125 |
|
} |
| 126 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
| 127 |
9 |
private CMSSignedDataVerified verify(CMSSignedData signedData, CertificateProvider provider)... |
| 128 |
|
{ |
| 129 |
9 |
BcCMSSignedDataVerified verifiedData = BcCMSUtils.getCMSSignedDataVerified(signedData, this.certFactory); |
| 130 |
|
|
| 131 |
9 |
for (SignerInformation signer : BcCMSUtils.getSigners(signedData)) { |
| 132 |
9 |
CertifiedPublicKey certKey = BcStoreUtils.getCertificate(provider, signer, this.certFactory); |
| 133 |
|
|
| 134 |
9 |
try { |
| 135 |
9 |
verifiedData.addSignature( |
| 136 |
|
new BcCMSSignerVerifiedInformation(signer, |
| 137 |
|
BcCMSUtils.verify(signer, certKey, this.contentVerifierProviderBuilder, this.digestProvider), |
| 138 |
|
this.chainBuilder.build(certKey, provider))); |
| 139 |
|
} catch (CMSException e) { |
| 140 |
0 |
verifiedData.addSignature( |
| 141 |
|
new BcCMSSignerVerifiedInformation(signer, false, this.chainBuilder.build(certKey, provider))); |
| 142 |
|
} |
| 143 |
|
} |
| 144 |
|
|
| 145 |
9 |
return verifiedData; |
| 146 |
|
} |
| 147 |
|
} |