Package org.bouncycastle.asn1.cms

Examples of org.bouncycastle.asn1.cms.SignedData


      }
  }
    }

    private void validate(CMSSignedData pkiMessage) {
  SignedData sd = SignedData.getInstance(pkiMessage.toASN1Structure()
    .getContent());
  LOGGER.debug("pkiMessage version: {}", sd.getVersion());
  LOGGER.debug("pkiMessage contentInfo contentType: {}", sd
    .getEncapContentInfo().getContentType());
    }
View Full Code Here


        certs.add(new DERTaggedObject(false, 2, new ASN1InputStream(AttrCertTest.attrCert).readObject()));

        ASN1EncodableVector crls = new ASN1EncodableVector();

        crls.add(new ASN1InputStream(CertPathTest.rootCrlBin).readObject());
        SignedData sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(certs), new DERSet(crls), new DERSet());

        ContentInfo info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");

        X509Certificate cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert == null || !areEqual(cert.getEncoded(), certs.get(0).getDERObject().getEncoded()))
        {
            fail("PKCS7 cert not read");
        }
        X509CRL crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
        if (crl == null || !areEqual(crl.getEncoded(), crls.get(0).getDERObject().getEncoded()))
        {
            fail("PKCS7 crl not read");
        }
        Collection col = cf.generateCertificates(new ByteArrayInputStream(info.getEncoded()));
        if (col.size() != 1 || !col.contains(cert))
        {
            fail("PKCS7 cert collection not right");
        }
        col = cf.generateCRLs(new ByteArrayInputStream(info.getEncoded()));
        if (col.size() != 1 || !col.contains(crl))
        {
            fail("PKCS7 crl collection not right");
        }

        // data with no certificates or CRLs

        sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(), new DERSet(), new DERSet());

        info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert != null)
        {
            fail("PKCS7 cert present");
        }
        crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
        if (crl != null)
        {
            fail("PKCS7 crl present");
        }

        // data with absent certificates and CRLS

        sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), null, null, new DERSet());

        info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert != null)
View Full Code Here

  }

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

  protected byte[] encapsulateContent(final byte[] data, final byte[] signature) throws IOException {
    ASN1InputStream inputStream = new ASN1InputStream(signature);
    DERSequence derSequence = (DERSequence) inputStream.readObject();
    ContentInfo signaturecontentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = new SignedData((ASN1Sequence) signaturecontentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BERConstructedOctetString(data));
    SignedData datasignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, datasignedData);
    return fullContentInfo.getDEREncoded();
  }
View Full Code Here

        else
        {
            encInfo = new ContentInfo(contentTypeOID, null);
        }

        SignedData  sd = new SignedData(
                                 new DERSet(digestAlgs),
                                 encInfo,
                                 certificates,
                                 certrevlist,
                                 new DERSet(signerInfos));
View Full Code Here

        }
       
        //
        // replace the CMS structure.
        //
        cms.signedData = new SignedData(signedData.signedData.getDigestAlgorithms(),
                                   signedData.signedData.getEncapContentInfo(),
                                   certs,
                                   crls,
                                   signedData.signedData.getSignerInfos());
       
View Full Code Here

  protected byte[] encapsulateContent(final byte[] data, final byte[] signature) throws IOException {
    ASN1InputStream inputStream = new ASN1InputStream(signature);
    DERSequence derSequence = (DERSequence) inputStream.readObject();
    ContentInfo signaturecontentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = new SignedData((ASN1Sequence) signaturecontentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BERConstructedOctetString(data));
    SignedData datasignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, datasignedData);
    return fullContentInfo.getDEREncoded();
  }
View Full Code Here

  }

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

        certs.add(new DERTaggedObject(false, 2, new ASN1InputStream(AttrCertTest.attrCert).readObject()));

        ASN1EncodableVector crls = new ASN1EncodableVector();

        crls.add(new ASN1InputStream(CertPathTest.rootCrlBin).readObject());
        SignedData sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(certs), new DERSet(crls), new DERSet());

        ContentInfo info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        CertificateFactory cf = CertificateFactory.getInstance("X.509", "BC");

        X509Certificate cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert == null || !areEqual(cert.getEncoded(), certs.get(0).getDERObject().getEncoded()))
        {
            fail("PKCS7 cert not read");
        }
        X509CRL crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
        if (crl == null || !areEqual(crl.getEncoded(), crls.get(0).getDERObject().getEncoded()))
        {
            fail("PKCS7 crl not read");
        }
        Collection col = cf.generateCertificates(new ByteArrayInputStream(info.getEncoded()));
        if (col.size() != 1 || !col.contains(cert))
        {
            fail("PKCS7 cert collection not right");
        }
        col = cf.generateCRLs(new ByteArrayInputStream(info.getEncoded()));
        if (col.size() != 1 || !col.contains(crl))
        {
            fail("PKCS7 crl collection not right");
        }

        // data with no certificates or CRLs

        sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), new DERSet(), new DERSet(), new DERSet());

        info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert != null)
        {
            fail("PKCS7 cert present");
        }
        crl = (X509CRL)cf.generateCRL(new ByteArrayInputStream(info.getEncoded()));
        if (crl != null)
        {
            fail("PKCS7 crl present");
        }

        // data with absent certificates and CRLS

        sigData = new SignedData(new DERSet(), new ContentInfo(CMSObjectIdentifiers.data, null), null, null, new DERSet());

        info = new ContentInfo(CMSObjectIdentifiers.signedData, sigData);

        cert = (X509Certificate)cf.generateCertificate(new ByteArrayInputStream(info.getEncoded()));
        if (cert != null)
View Full Code Here

  }

  public byte[] wrap(final byte[] data, final byte[] signature) throws IOException {
    DERSequence derSequence = (DERSequence) BouncyCastleProviderHelper.toASN1Primitive(signature);
    ContentInfo signatureContentInfo = new ContentInfo(derSequence);
    SignedData signatureSignedData = SignedData.getInstance(signatureContentInfo.getContent());
    ContentInfo dataContentInfo = new ContentInfo(CMSObjectIdentifiers.data, new BEROctetString(data));
    SignedData dataSignedData = new SignedData(signatureSignedData.getDigestAlgorithms(), dataContentInfo, signatureSignedData.getCertificates(), signatureSignedData.getCRLs(), signatureSignedData.getSignerInfos());
    ContentInfo fullContentInfo = new ContentInfo(PKCSObjectIdentifiers.signedData, dataSignedData);
    return fullContentInfo.getEncoded();
  }
View Full Code Here

TOP

Related Classes of org.bouncycastle.asn1.cms.SignedData

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.