Search in sources :

Example 31 with BERSequence

use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.

the class CMSSignedData method replaceSigners.

/**
 * Replace the SignerInformation store associated with this CMSSignedData object with the new one
 * passed in. You would probably only want to do this if you wanted to change the unsigned
 * attributes associated with a signer, or perhaps delete one.
 *
 * @param signedData             the signed data object to be used as a base.
 * @param signerInformationStore the new signer information store to use.
 * @return a new signed data object.
 */
public static CMSSignedData replaceSigners(CMSSignedData signedData, SignerInformationStore signerInformationStore) {
    // 
    // copy
    // 
    CMSSignedData cms = new CMSSignedData(signedData);
    // 
    // replace the store
    // 
    cms.signerInfoStore = signerInformationStore;
    // 
    // replace the signers in the SignedData object
    // 
    Set<AlgorithmIdentifier> digestAlgs = new HashSet<AlgorithmIdentifier>();
    ASN1EncodableVector vec = new ASN1EncodableVector();
    Iterator it = signerInformationStore.getSigners().iterator();
    while (it.hasNext()) {
        SignerInformation signer = (SignerInformation) it.next();
        CMSUtils.addDigestAlgs(digestAlgs, signer, dgstAlgFinder);
        vec.add(signer.toASN1Structure());
    }
    ASN1Set digests = CMSUtils.convertToBERSet(digestAlgs);
    ASN1Set signers = new DLSet(vec);
    ASN1Sequence sD = (ASN1Sequence) signedData.signedData.toASN1Primitive();
    vec = new ASN1EncodableVector();
    // 
    // signers are the last item in the sequence.
    // 
    // version
    vec.add(sD.getObjectAt(0));
    vec.add(digests);
    for (int i = 2; i != sD.size() - 1; i++) {
        vec.add(sD.getObjectAt(i));
    }
    vec.add(signers);
    cms.signedData = SignedData.getInstance(new BERSequence(vec));
    // 
    // replace the contentInfo with the new one
    // 
    cms.contentInfo = new ContentInfo(cms.contentInfo.getContentType(), cms.signedData);
    return cms;
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) AlgorithmIdentifier(com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier) ASN1Sequence(com.github.zhenwei.core.asn1.ASN1Sequence) ASN1Set(com.github.zhenwei.core.asn1.ASN1Set) 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) HashSet(java.util.HashSet)

Example 32 with BERSequence

use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.

the class AuthEnvelopedData method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(7);
    v.add(version);
    if (originatorInfo != null) {
        v.add(new DERTaggedObject(false, 0, originatorInfo));
    }
    v.add(recipientInfos);
    v.add(authEncryptedContentInfo);
    // "authAttrs optionally contains the authenticated attributes."
    if (authAttrs != null) {
        // "AuthAttributes MUST be DER encoded, even if the rest of the
        // AuthEnvelopedData structure is BER encoded."
        v.add(new DERTaggedObject(false, 1, authAttrs));
    }
    v.add(mac);
    // "unauthAttrs optionally contains the unauthenticated attributes."
    if (unauthAttrs != null) {
        v.add(new DERTaggedObject(false, 2, unauthAttrs));
    }
    return new BERSequence(v);
}
Also used : DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Example 33 with BERSequence

use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.

the class ContentInfo method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(2);
    v.add(contentType);
    if (content != null) {
        v.add(new BERTaggedObject(0, content));
    }
    return new BERSequence(v);
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) BERTaggedObject(com.github.zhenwei.core.asn1.BERTaggedObject)

Example 34 with BERSequence

use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.

the class EncryptedData method toASN1Primitive.

/**
 * @return a basic ASN.1 object representation.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(3);
    v.add(version);
    v.add(encryptedContentInfo);
    if (unprotectedAttrs != null) {
        v.add(new BERTaggedObject(false, 1, unprotectedAttrs));
    }
    return new BERSequence(v);
}
Also used : BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector) BERTaggedObject(com.github.zhenwei.core.asn1.BERTaggedObject)

Example 35 with BERSequence

use of com.github.zhenwei.core.asn1.BERSequence in project LinLong-Java by zhenwei1108.

the class EnvelopedData method toASN1Primitive.

/**
 * Produce an object suitable for an ASN1OutputStream.
 */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector(5);
    v.add(version);
    if (originatorInfo != null) {
        v.add(new DERTaggedObject(false, 0, originatorInfo));
    }
    v.add(recipientInfos);
    v.add(encryptedContentInfo);
    if (unprotectedAttrs != null) {
        v.add(new DERTaggedObject(false, 1, unprotectedAttrs));
    }
    return new BERSequence(v);
}
Also used : DERTaggedObject(com.github.zhenwei.core.asn1.DERTaggedObject) BERSequence(com.github.zhenwei.core.asn1.BERSequence) ASN1EncodableVector(com.github.zhenwei.core.asn1.ASN1EncodableVector)

Aggregations

BERSequence (org.bouncycastle.asn1.BERSequence)21 BERSequence (com.github.zhenwei.core.asn1.BERSequence)18 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)18 ASN1EncodableVector (com.github.zhenwei.core.asn1.ASN1EncodableVector)17 BERTaggedObject (org.bouncycastle.asn1.BERTaggedObject)11 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)7 BERTaggedObject (com.github.zhenwei.core.asn1.BERTaggedObject)6 DERTaggedObject (com.github.zhenwei.core.asn1.DERTaggedObject)6 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)6 ASN1Set (org.bouncycastle.asn1.ASN1Set)6 HashSet (java.util.HashSet)5 Iterator (java.util.Iterator)5 ASN1Set (com.github.zhenwei.core.asn1.ASN1Set)4 Enumeration (java.util.Enumeration)4 ASN1Integer (com.github.zhenwei.core.asn1.ASN1Integer)3 ASN1Sequence (com.github.zhenwei.core.asn1.ASN1Sequence)3 AlgorithmIdentifier (com.github.zhenwei.core.asn1.x509.AlgorithmIdentifier)3 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)3 BERApplicationSpecific (org.bouncycastle.asn1.BERApplicationSpecific)3 BERConstructedOctetString (org.bouncycastle.asn1.BERConstructedOctetString)3