@Test(expectedExceptions = InvalidCmsSignatureException.class, expectedExceptionsMessageRegExp = "Invalid CMS signature. Signature does not contain SignerInformation element.") public void testVerifySignatureWithoutAnySignerInformationElement_ThrowsInvalidCmsSignatureException() throws Exception { Mockito.when(signatureStore.getSigners()).thenReturn(new ArrayList<SignerInformation>()); CMSSignatureVerifier verifier = new CMSSignatureVerifier(trustStore); verifier.verify(mockedSignature); }
@SuppressWarnings("unchecked") public void verify(CMSSignature signature) throws CryptoException { Store certStore = signature.getSignedDataCertificates(); SignerInformationStore signerInformationStore = signature.getSignerInformationStore(); Collection<SignerInformation> signerCollection = signerInformationStore.getSigners(); if (signerCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature does not contain SignerInformation element."); } if (signerCollection.size() != 1) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature contains multiple SignerInformation elements."); } SignerInformation signerInfo = signerCollection.iterator().next(); Collection certCollection = certStore.getMatches(signerInfo.getSID()); Iterator certIterator = certCollection.iterator(); if (certCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signer certificate collection is empty."); } X509CertificateHolder certHolder = (X509CertificateHolder) certIterator.next(); verifyCmsSignerInfo(signerInfo, certHolder); if(!trustStore.isTrusted(getCertificate(certHolder), certStore)) { throw new InvalidCmsSignatureException("Certificate that was used for signing isn't trusted"); } }
CMSSignatureVerifier { @SuppressWarnings("unchecked") public void verify(CMSSignature signature) throws CryptoException { Store certStore = signature.getSignedDataCertificates(); SignerInformationStore signerInformationStore = signature.getSignerInformationStore(); Collection<SignerInformation> signerCollection = signerInformationStore.getSigners(); if (signerCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature does not contain SignerInformation element."); } if (signerCollection.size() != 1) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature contains multiple SignerInformation elements."); } SignerInformation signerInfo = signerCollection.iterator().next(); Collection certCollection = certStore.getMatches(signerInfo.getSID()); Iterator certIterator = certCollection.iterator(); if (certCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signer certificate collection is empty."); } X509CertificateHolder certHolder = (X509CertificateHolder) certIterator.next(); verifyCmsSignerInfo(signerInfo, certHolder); if(!trustStore.isTrusted(getCertificate(certHolder), certStore)) { throw new InvalidCmsSignatureException("Certificate that was used for signing isn't trusted"); } } }
CMSSignatureVerifier { @SuppressWarnings("unchecked") public void verify(CMSSignature signature) throws CryptoException { Store certStore = signature.getSignedDataCertificates(); SignerInformationStore signerInformationStore = signature.getSignerInformationStore(); Collection<SignerInformation> signerCollection = signerInformationStore.getSigners(); if (signerCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature does not contain SignerInformation element."); } if (signerCollection.size() != 1) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature contains multiple SignerInformation elements."); } SignerInformation signerInfo = signerCollection.iterator().next(); Collection certCollection = certStore.getMatches(signerInfo.getSID()); Iterator certIterator = certCollection.iterator(); if (certCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signer certificate collection is empty."); } X509CertificateHolder certHolder = (X509CertificateHolder) certIterator.next(); verifyCmsSignerInfo(signerInfo, certHolder); if(!trustStore.isTrusted(getCertificate(certHolder), certStore)) { throw new InvalidCmsSignatureException("Certificate that was used for signing isn't trusted"); } } CMSSignatureVerifier(PKITrustStore trustStore); }
CMSSignatureVerifier { @SuppressWarnings("unchecked") public void verify(CMSSignature signature) throws CryptoException { Store certStore = signature.getSignedDataCertificates(); SignerInformationStore signerInformationStore = signature.getSignerInformationStore(); Collection<SignerInformation> signerCollection = signerInformationStore.getSigners(); if (signerCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature does not contain SignerInformation element."); } if (signerCollection.size() != 1) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature contains multiple SignerInformation elements."); } SignerInformation signerInfo = signerCollection.iterator().next(); Collection certCollection = certStore.getMatches(signerInfo.getSID()); Iterator certIterator = certCollection.iterator(); if (certCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signer certificate collection is empty."); } X509CertificateHolder certHolder = (X509CertificateHolder) certIterator.next(); verifyCmsSignerInfo(signerInfo, certHolder); if(!trustStore.isTrusted(getCertificate(certHolder), certStore)) { throw new InvalidCmsSignatureException("Certificate that was used for signing isn't trusted"); } } CMSSignatureVerifier(PKITrustStore trustStore); @SuppressWarnings("unchecked") void verify(CMSSignature signature); }
CMSSignatureVerifier { @SuppressWarnings("unchecked") public void verify(CMSSignature signature) throws CryptoException { Store certStore = signature.getSignedDataCertificates(); SignerInformationStore signerInformationStore = signature.getSignerInformationStore(); Collection<SignerInformation> signerCollection = signerInformationStore.getSigners(); if (signerCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature does not contain SignerInformation element."); } if (signerCollection.size() != 1) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signature contains multiple SignerInformation elements."); } SignerInformation signerInfo = signerCollection.iterator().next(); Collection certCollection = certStore.getMatches(signerInfo.getSID()); Iterator certIterator = certCollection.iterator(); if (certCollection.isEmpty()) { throw new InvalidCmsSignatureException("Invalid CMS signature. Signer certificate collection is empty."); } X509CertificateHolder certHolder = (X509CertificateHolder) certIterator.next(); verifyCmsSignerInfo(signerInfo, certHolder); if(!trustStore.isTrusted(getCertificate(certHolder), certStore)) { throw new InvalidCmsSignatureException("Certificate that was used for signing isn't trusted"); } } CMSSignatureVerifier(PKITrustStore trustStore); @SuppressWarnings("unchecked") void verify(CMSSignature signature);  }