Example usage for org.bouncycastle.mail.smime.validator SignedMailValidator getSignerInformationStore

List of usage examples for org.bouncycastle.mail.smime.validator SignedMailValidator getSignerInformationStore

Introduction

In this page you can find the example usage for org.bouncycastle.mail.smime.validator SignedMailValidator getSignerInformationStore.

Prototype

public SignerInformationStore getSignerInformationStore() 

Source Link

Usage

From source file:gov.nih.nci.cacis.nav.ValidateSignedMail.java

License:BSD License

/**
 * Verifies signed MimeMessage, as per the supplied PKIXParameters
 * /* ww w  . j a  v a  2s .  c  om*/
 * @param msg - signed message
 * @param param - PKIXParameters
 * @throws MessagingException - error thrown, if any
 */
public void verifySignedMail(MimeMessage msg, PKIXParameters param) throws MessagingException {

    try {
        // validate signatures
        final SignedMailValidator validator = new SignedMailValidator(msg, param);

        // iterate over all signatures and print results
        final Iterator it = validator.getSignerInformationStore().getSigners().iterator();

        while (it.hasNext()) {
            final SignerInformation signer = (SignerInformation) it.next();
            final SignedMailValidator.ValidationResult result = validator.getValidationResult(signer);

            final boolean validSign = handleValidateResults(result);

            handleNotifications(result);

            final PKIXCertPathReviewer review = result.getCertPathReview();

            boolean validCertPath = true;
            if (review != null) {
                validCertPath = handleCertPathValidation(review);

                handleCertPathReviewNotifications(review);

                handleCertificateErrorsAndNotifications(review);
            }

            if (!validSign || !validCertPath) {
                throw new MessagingException("Validation of signed message failed!");
            }
        }
    } catch (SignedMailValidatorException e) {
        throw new MessagingException("Validation of signed message failed!", e);
    }

}