Search in sources :

Example 61 with ContentInfo

use of com.github.zhenwei.pkix.util.asn1.cms.ContentInfo in project LinLong-Java by zhenwei1108.

the class CMSCompressedData method getContentStream.

public CMSTypedStream getContentStream(InputExpanderProvider expanderProvider) {
    ContentInfo content = comData.getEncapContentInfo();
    ASN1OctetString bytes = (ASN1OctetString) content.getContent();
    InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier());
    InputStream zIn = expander.getInputStream(bytes.getOctetStream());
    return new CMSTypedStream(content.getContentType(), zIn);
}
Also used : ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) InputStream(java.io.InputStream) InputExpander(com.github.zhenwei.pkix.operator.InputExpander)

Example 62 with ContentInfo

use of com.github.zhenwei.pkix.util.asn1.cms.ContentInfo in project LinLong-Java by zhenwei1108.

the class CMSCompressedData method getContent.

/**
 * Return the uncompressed content.
 *
 * @param expanderProvider a provider of expander algorithm implementations.
 * @return the uncompressed content
 * @throws CMSException if there is an exception un-compressing the data.
 */
public byte[] getContent(InputExpanderProvider expanderProvider) throws CMSException {
    ContentInfo content = comData.getEncapContentInfo();
    ASN1OctetString bytes = (ASN1OctetString) content.getContent();
    InputExpander expander = expanderProvider.get(comData.getCompressionAlgorithmIdentifier());
    InputStream zIn = expander.getInputStream(bytes.getOctetStream());
    try {
        return CMSUtils.streamToByteArray(zIn);
    } catch (IOException e) {
        throw new CMSException("exception reading compressed stream.", e);
    }
}
Also used : ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) InputStream(java.io.InputStream) InputExpander(com.github.zhenwei.pkix.operator.InputExpander) IOException(java.io.IOException)

Example 63 with ContentInfo

use of com.github.zhenwei.pkix.util.asn1.cms.ContentInfo in project LinLong-Java by zhenwei1108.

the class CMSAuthEnvelopedDataGenerator method doGenerate.

private CMSAuthEnvelopedData doGenerate(CMSTypedData content, OutputAEADEncryptor contentEncryptor) throws CMSException {
    ASN1EncodableVector recipientInfos = new ASN1EncodableVector();
    AlgorithmIdentifier encAlgId;
    ASN1OctetString encContent;
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    ASN1Set authenticatedAttrSet = null;
    try {
        OutputStream cOut = contentEncryptor.getOutputStream(bOut);
        content.write(cOut);
        if (authAttrsGenerator != null) {
            AttributeTable attrTable = authAttrsGenerator.getAttributes(Collections.EMPTY_MAP);
            authenticatedAttrSet = new DERSet(attrTable.toASN1EncodableVector());
            contentEncryptor.getAADStream().write(authenticatedAttrSet.getEncoded(ASN1Encoding.DER));
        }
        cOut.close();
    } catch (IOException e) {
        throw new CMSException("unable to process authenticated content: " + e.getMessage(), e);
    }
    byte[] encryptedContent = bOut.toByteArray();
    byte[] mac = contentEncryptor.getMAC();
    encAlgId = contentEncryptor.getAlgorithmIdentifier();
    encContent = new BEROctetString(encryptedContent);
    GenericKey encKey = contentEncryptor.getKey();
    for (Iterator it = recipientInfoGenerators.iterator(); it.hasNext(); ) {
        RecipientInfoGenerator recipient = (RecipientInfoGenerator) it.next();
        recipientInfos.add(recipient.generate(encKey));
    }
    EncryptedContentInfo eci = new EncryptedContentInfo(content.getContentType(), encAlgId, encContent);
    ASN1Set unprotectedAttrSet = null;
    if (unauthAttrsGenerator != null) {
        AttributeTable attrTable = unauthAttrsGenerator.getAttributes(Collections.EMPTY_MAP);
        unprotectedAttrSet = new DLSet(attrTable.toASN1EncodableVector());
    }
    ContentInfo contentInfo = new ContentInfo(CMSObjectIdentifiers.authEnvelopedData, new AuthEnvelopedData(originatorInfo, new DERSet(recipientInfos), eci, authenticatedAttrSet, new DEROctetString(mac), unprotectedAttrSet));
    return new CMSAuthEnvelopedData(contentInfo);
}
Also used : ASN1OctetString(com.github.zhenwei.core.asn1.ASN1OctetString) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) AuthEnvelopedData(com.github.zhenwei.pkix.util.asn1.cms.AuthEnvelopedData) AttributeTable(com.github.zhenwei.pkix.util.asn1.cms.AttributeTable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DERSet(com.github.zhenwei.core.asn1.DERSet) DEROctetString(com.github.zhenwei.core.asn1.DEROctetString) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) BEROctetString(com.github.zhenwei.core.asn1.BEROctetString) EncryptedContentInfo(com.github.zhenwei.pkix.util.asn1.cms.EncryptedContentInfo) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) Iterator(java.util.Iterator) DLSet(com.github.zhenwei.core.asn1.DLSet) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) GenericKey(com.github.zhenwei.pkix.operator.GenericKey) EncryptedContentInfo(com.github.zhenwei.pkix.util.asn1.cms.EncryptedContentInfo)

Example 64 with ContentInfo

use of com.github.zhenwei.pkix.util.asn1.cms.ContentInfo in project LinLong-Java by zhenwei1108.

the class CMSTimeStampedData method addTimeStamp.

/**
 * Return a new timeStampedData object with the additional token attached.
 *
 * @throws CMSException
 */
public CMSTimeStampedData addTimeStamp(TimeStampToken token) throws CMSException {
    TimeStampAndCRL[] timeStamps = util.getTimeStamps();
    TimeStampAndCRL[] newTimeStamps = new TimeStampAndCRL[timeStamps.length + 1];
    System.arraycopy(timeStamps, 0, newTimeStamps, 0, timeStamps.length);
    newTimeStamps[timeStamps.length] = new TimeStampAndCRL(token.toCMSSignedData().toASN1Structure());
    return new CMSTimeStampedData(new ContentInfo(CMSObjectIdentifiers.timestampedData, new TimeStampedData(timeStampedData.getDataUri(), timeStampedData.getMetaData(), timeStampedData.getContent(), new Evidence(new TimeStampTokenEvidence(newTimeStamps)))));
}
Also used : TimeStampTokenEvidence(com.github.zhenwei.pkix.util.asn1.cms.TimeStampTokenEvidence) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) TimeStampedData(com.github.zhenwei.pkix.util.asn1.cms.TimeStampedData) TimeStampTokenEvidence(com.github.zhenwei.pkix.util.asn1.cms.TimeStampTokenEvidence) Evidence(com.github.zhenwei.pkix.util.asn1.cms.Evidence) TimeStampAndCRL(com.github.zhenwei.pkix.util.asn1.cms.TimeStampAndCRL)

Example 65 with ContentInfo

use of com.github.zhenwei.pkix.util.asn1.cms.ContentInfo in project LinLong-Java by zhenwei1108.

the class PKIArchiveControl method getEnvelopedData.

/**
 * Return the enveloped data structure contained in this control.
 *
 * @return a CMSEnvelopedData object.
 */
public CMSEnvelopedData getEnvelopedData() throws CRMFException {
    try {
        EncryptedKey encKey = EncryptedKey.getInstance(pkiArchiveOptions.getValue());
        EnvelopedData data = EnvelopedData.getInstance(encKey.getValue());
        return new CMSEnvelopedData(new ContentInfo(CMSObjectIdentifiers.envelopedData, data));
    } catch (CMSException e) {
        throw new CRMFException("CMS parsing error: " + e.getMessage(), e.getCause());
    } catch (Exception e) {
        throw new CRMFException("CRMF parsing error: " + e.getMessage(), e);
    }
}
Also used : CMSEnvelopedData(com.github.zhenwei.pkix.cms.CMSEnvelopedData) EncryptedKey(com.github.zhenwei.pkix.util.asn1.crmf.EncryptedKey) ContentInfo(com.github.zhenwei.pkix.util.asn1.cms.ContentInfo) CMSEnvelopedData(com.github.zhenwei.pkix.cms.CMSEnvelopedData) EnvelopedData(com.github.zhenwei.pkix.util.asn1.cms.EnvelopedData) CMSException(com.github.zhenwei.pkix.cms.CMSException) CMSException(com.github.zhenwei.pkix.cms.CMSException)

Aggregations

ContentInfo (org.bouncycastle.asn1.cms.ContentInfo)60 IOException (java.io.IOException)28 CMSSignedData (org.bouncycastle.cms.CMSSignedData)22 ContentInfo (com.github.zhenwei.pkix.util.asn1.cms.ContentInfo)18 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)15 OutputStream (java.io.OutputStream)12 X509Certificate (java.security.cert.X509Certificate)12 ArrayList (java.util.ArrayList)12 SignedData (org.bouncycastle.asn1.cms.SignedData)12 Iterator (java.util.Iterator)11 ASN1Set (org.bouncycastle.asn1.ASN1Set)11 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)10 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)10 ASN1OctetString (com.github.zhenwei.core.asn1.ASN1OctetString)9 ByteArrayInputStream (java.io.ByteArrayInputStream)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)9 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)9 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)9 DERSet (org.bouncycastle.asn1.DERSet)9