Search in sources :

Example 11 with TimeStampToken

use of org.bouncycastle.tsp.TimeStampToken in project pdfbox by apache.

the class CertInformationCollector method addTimestampCerts.

/**
 * Processes an embedded signed timestamp, that has been placed into a signature. The
 * certificates and its chain(s) will be processed the same way as the signature itself.
 *
 * @param signerInformation of the signature, to get unsigned attributes from it.
 * @throws IOException
 * @throws CertificateProccessingException
 */
private void addTimestampCerts(SignerInformation signerInformation) throws IOException, CertificateProccessingException {
    AttributeTable unsignedAttributes = signerInformation.getUnsignedAttributes();
    if (unsignedAttributes == null) {
        return;
    }
    Attribute tsAttribute = signerInformation.getUnsignedAttributes().get(PKCSObjectIdentifiers.id_aa_signatureTimeStampToken);
    if (tsAttribute.getAttrValues() instanceof DERSet) {
        DERSet tsSet = (DERSet) tsAttribute.getAttrValues();
        tsSet.getEncoded("DER");
        DERSequence tsSeq = (DERSequence) tsSet.getObjectAt(0);
        try {
            TimeStampToken tsToken = new TimeStampToken(new CMSSignedData(tsSeq.getEncoded("DER")));
            rootCertInfo.tsaCerts = new CertSignatureInformation();
            @SuppressWarnings("unchecked") Store<X509CertificateHolder> certificatesStore = tsToken.getCertificates();
            processSignerStore(certificatesStore, tsToken.toCMSSignedData(), rootCertInfo.tsaCerts);
        } catch (TSPException | CMSException e) {
            throw new IOException("Error parsing timestamp token", e);
        }
    }
}
Also used : Attribute(org.bouncycastle.asn1.cms.Attribute) AttributeTable(org.bouncycastle.asn1.cms.AttributeTable) IOException(java.io.IOException) DERSet(org.bouncycastle.asn1.DERSet) CMSSignedData(org.bouncycastle.cms.CMSSignedData) DERSequence(org.bouncycastle.asn1.DERSequence) X509CertificateHolder(org.bouncycastle.cert.X509CertificateHolder) TSPException(org.bouncycastle.tsp.TSPException) TimeStampToken(org.bouncycastle.tsp.TimeStampToken) CMSException(org.bouncycastle.cms.CMSException)

Aggregations

IOException (java.io.IOException)11 TimeStampToken (org.bouncycastle.tsp.TimeStampToken)11 TSPException (org.bouncycastle.tsp.TSPException)8 CMSException (org.bouncycastle.cms.CMSException)5 CMSSignedData (org.bouncycastle.cms.CMSSignedData)5 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)4 X509CertificateHolder (org.bouncycastle.cert.X509CertificateHolder)4 TimeStampResponse (org.bouncycastle.tsp.TimeStampResponse)4 CertificateCoreException (org.demoiselle.signer.core.exception.CertificateCoreException)4 BigInteger (java.math.BigInteger)3 MessageDigest (java.security.MessageDigest)3 X509Certificate (java.security.cert.X509Certificate)3 TimeStampRequest (org.bouncycastle.tsp.TimeStampRequest)3 TimeStampRequestGenerator (org.bouncycastle.tsp.TimeStampRequestGenerator)3 Timestamp (org.demoiselle.signer.timestamp.Timestamp)3 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)2 SecureRandom (java.security.SecureRandom)2 CertificateException (java.security.cert.CertificateException)2 ArrayList (java.util.ArrayList)2 PKIFailureInfo (org.bouncycastle.asn1.cmp.PKIFailureInfo)2