Example usage for org.bouncycastle.asn1.tsp TSTInfo getInstance

List of usage examples for org.bouncycastle.asn1.tsp TSTInfo getInstance

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.tsp TSTInfo getInstance.

Prototype

public static TSTInfo getInstance(Object o) 

Source Link

Usage

From source file:de.rub.dez6a3.jpdfsigner.TimeStampToken.java

License:Open Source License

public TimeStampToken(CMSSignedData signedData) throws TSPException, IOException {
    this.tsToken = signedData;

    if (!this.tsToken.getSignedContentTypeOID().equals(PKCSObjectIdentifiers.id_ct_TSTInfo.getId())) {
        throw new TSPValidationException("ContentInfo object not for a time stamp.");
    }//from w w w . j a  v  a  2 s .  co  m

    Collection signers = tsToken.getSignerInfos().getSigners();

    if (signers.size() != 1) {
        throw new IllegalArgumentException("Time-stamp token signed by " + signers.size()
                + " signers, but it must contain just the TSA signature.");
    }

    tsaSignerInfo = (SignerInformation) signers.iterator().next();

    try {
        CMSProcessable content = tsToken.getSignedContent();
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();

        content.write(bOut);

        ASN1InputStream aIn = new ASN1InputStream(new ByteArrayInputStream(bOut.toByteArray()));

        this.tstInfo = new TimeStampTokenInfo(TSTInfo.getInstance(aIn.readObject()));

        Attribute attr = tsaSignerInfo.getSignedAttributes()
                .get(PKCSObjectIdentifiers.id_aa_signingCertificate);

        if (attr == null) {
            throw new TSPValidationException("no signing certificate attribute found, time stamp invalid.");
        }

        SigningCertificate signCert = SigningCertificate.getInstance(attr.getAttrValues().getObjectAt(0));

        this.certID = ESSCertID.getInstance(signCert.getCerts()[0]);
    } catch (CMSException e) {
        throw new TSPException(e.getMessage(), e.getUnderlyingException());
    }
}