List<SMIMESignerInfo> result = new ArrayList<SMIMESignerInfo>(sigCol.size());
// I iterate over the signer collection
// checking if the signatures put
// on the message are valid.
for (int i=0;sigIterator.hasNext();i++) {
SignerInformation info = sigIterator.next();
// I get the signer's certificate
Collection certCollection = certs.getCertificates(info.getSID());
Iterator<X509Certificate> certIter = certCollection.iterator();
if (certIter.hasNext()) {
X509Certificate signerCert = certIter.next();
// The issuer's certifcate is searched in the list of trusted certificate.
CertPath path = verifyCertificate(signerCert, certs, keyStore);
try {
// if the signature is valid the SMIMESignedInfo is
// created using "true" as last argument. If it is
// invalid an exception is thrown by the "verify" method
// and the SMIMESignerInfo is created with "false".
//
// The second argument "path" is not null if the
// certificate can be trusted (it can be connected
// by a chain of trust to a trusted certificate), null
// otherwise.
if (info.verify(signerCert, "BC")) {
result.add(new SMIMESignerInfo(signerCert, path, true));
}
} catch (Exception e) {
result.add(new SMIMESignerInfo(signerCert,path, false));
}