Search in sources :

Example 26 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier in project BiglyBT by BiglySoftware.

the class X509ExtensionsGenerator method addExtension.

/**
 * Add an extension with the given oid and the passed in value to be included
 * in the OCTET STRING associated with the extension.
 *
 * @param oid  OID for the extension.
 * @param critical  true if critical, false otherwise.
 * @param value the ASN.1 object to be included in the extension.
 */
public void addExtension(DERObjectIdentifier oid, boolean critical, DEREncodable value) {
    ByteArrayOutputStream bOut = new ByteArrayOutputStream();
    DEROutputStream dOut = new DEROutputStream(bOut);
    try {
        dOut.writeObject(value);
    } catch (IOException e) {
        throw new IllegalArgumentException("error encoding value: " + e);
    }
    this.addExtension(oid, critical, bOut.toByteArray());
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) DEROutputStream(org.gudy.bouncycastle.asn1.DEROutputStream)

Example 27 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier in project BiglyBT by BiglySoftware.

the class PKCS7SignedData method getEncoded.

/**
 * return the bytes for the PKCS7SignedData object.
 */
public byte[] getEncoded() {
    try {
        digest = sig.sign();
        // Create the set of Hash algorithms. I've assumed this is the
        // set of all hash agorithms used to created the digest in the
        // "signerInfo" structure. I may be wrong.
        // 
        ASN1EncodableVector v = new ASN1EncodableVector();
        for (Iterator i = digestalgos.iterator(); i.hasNext(); ) {
            AlgorithmIdentifier a = new AlgorithmIdentifier(new DERObjectIdentifier((String) i.next()), null);
            v.add(a);
        }
        DERSet algos = new DERSet(v);
        // Create the contentInfo. Empty, I didn't implement this bit
        // 
        DERSequence contentinfo = new DERSequence(new DERObjectIdentifier(ID_PKCS7_DATA));
        // Get all the certificates
        // 
        v = new ASN1EncodableVector();
        for (Iterator i = certs.iterator(); i.hasNext(); ) {
            DERInputStream tempstream = new DERInputStream(new ByteArrayInputStream(((X509Certificate) i.next()).getEncoded()));
            v.add(tempstream.readObject());
        }
        DERSet dercertificates = new DERSet(v);
        // Create signerinfo structure.
        // 
        ASN1EncodableVector signerinfo = new ASN1EncodableVector();
        // Add the signerInfo version
        // 
        signerinfo.add(new DERInteger(signerversion));
        IssuerAndSerialNumber isAnds = new IssuerAndSerialNumber(new X509Name((ASN1Sequence) getIssuer(signCert.getTBSCertificate())), new DERInteger(signCert.getSerialNumber()));
        signerinfo.add(isAnds);
        // Add the digestAlgorithm
        // 
        signerinfo.add(new AlgorithmIdentifier(new DERObjectIdentifier(digestAlgorithm), new DERNull()));
        // 
        // Add the digestEncryptionAlgorithm
        // 
        signerinfo.add(new AlgorithmIdentifier(new DERObjectIdentifier(digestEncryptionAlgorithm), new DERNull()));
        // 
        // Add the digest
        // 
        signerinfo.add(new DEROctetString(digest));
        // 
        // Finally build the body out of all the components above
        // 
        ASN1EncodableVector body = new ASN1EncodableVector();
        body.add(new DERInteger(version));
        body.add(algos);
        body.add(contentinfo);
        body.add(new DERTaggedObject(false, 0, dercertificates));
        if (crls.size() > 0) {
            v = new ASN1EncodableVector();
            for (Iterator i = crls.iterator(); i.hasNext(); ) {
                DERInputStream t = new DERInputStream(new ByteArrayInputStream((((X509CRL) i.next()).getEncoded())));
                v.add(t.readObject());
            }
            DERSet dercrls = new DERSet(v);
            body.add(new DERTaggedObject(false, 1, dercrls));
        }
        // Only allow one signerInfo
        // 
        body.add(new DERSet(new DERSequence(signerinfo)));
        // Now we have the body, wrap it in it's PKCS7Signed shell
        // and return it
        // 
        ASN1EncodableVector whole = new ASN1EncodableVector();
        whole.add(new DERObjectIdentifier(ID_PKCS7_SIGNED_DATA));
        whole.add(new DERTaggedObject(0, new DERSequence(body)));
        ByteArrayOutputStream bOut = new ByteArrayOutputStream();
        DEROutputStream dout = new DEROutputStream(bOut);
        dout.writeObject(new DERSequence(whole));
        dout.close();
        return bOut.toByteArray();
    } catch (Exception e) {
        throw new RuntimeException(e.toString());
    }
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) AlgorithmIdentifier(org.gudy.bouncycastle.asn1.x509.AlgorithmIdentifier) X509Name(org.gudy.bouncycastle.asn1.x509.X509Name) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 28 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier in project BiglyBT by BiglySoftware.

the class JDKX509CertificateFactory method readPKCS7Certificate.

/**
 * read in a BER encoded PKCS7 certificate.
 */
private Certificate readPKCS7Certificate(InputStream in) throws IOException {
    BERInputStream dIn = new BERInputStream(in);
    ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
    if (seq.size() > 1 && seq.getObjectAt(0) instanceof DERObjectIdentifier) {
        if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) {
            sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true));
            return new X509CertificateObject(X509CertificateStructure.getInstance(sData.getCertificates().getObjectAt(sDataObjectCount++)));
        }
    }
    return new X509CertificateObject(X509CertificateStructure.getInstance(seq));
}
Also used : SignedData(org.gudy.bouncycastle.asn1.pkcs.SignedData)

Example 29 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier in project BiglyBT by BiglySoftware.

the class JDKX509CertificateFactory method readDERCertificate.

private Certificate readDERCertificate(InputStream in) throws IOException {
    DERInputStream dIn = new DERInputStream(in);
    ASN1Sequence seq = (ASN1Sequence) dIn.readObject();
    if (seq.size() > 1 && seq.getObjectAt(0) instanceof DERObjectIdentifier) {
        if (seq.getObjectAt(0).equals(PKCSObjectIdentifiers.signedData)) {
            sData = new SignedData(ASN1Sequence.getInstance((ASN1TaggedObject) seq.getObjectAt(1), true));
            return new X509CertificateObject(X509CertificateStructure.getInstance(sData.getCertificates().getObjectAt(sDataObjectCount++)));
        }
    }
    return new X509CertificateObject(X509CertificateStructure.getInstance(seq));
}
Also used : SignedData(org.gudy.bouncycastle.asn1.pkcs.SignedData)

Example 30 with DERObjectIdentifier

use of org.gudy.bouncycastle.asn1.DERObjectIdentifier in project BiglyBT by BiglySoftware.

the class X509CRLEntryObject method toString.

public String toString() {
    StringBuilder buf = new StringBuilder();
    String nl = System.getProperty("line.separator");
    buf.append("      userCertificate: ").append(this.getSerialNumber()).append(nl);
    buf.append("       revocationDate: ").append(this.getRevocationDate()).append(nl);
    X509Extensions extensions = c.getExtensions();
    if (extensions != null) {
        Enumeration e = extensions.oids();
        if (e.hasMoreElements()) {
            buf.append("   crlEntryExtensions:").append(nl);
            while (e.hasMoreElements()) {
                DERObjectIdentifier oid = (DERObjectIdentifier) e.nextElement();
                X509Extension ext = extensions.getExtension(oid);
                buf.append(ext);
            }
        }
    }
    return buf.toString();
}
Also used : Enumeration(java.util.Enumeration) X509Extension(org.gudy.bouncycastle.asn1.x509.X509Extension) X509Extensions(org.gudy.bouncycastle.asn1.x509.X509Extensions) DERObjectIdentifier(org.gudy.bouncycastle.asn1.DERObjectIdentifier)

Aggregations

DERObjectIdentifier (org.bouncycastle.asn1.DERObjectIdentifier)48 IOException (java.io.IOException)28 Enumeration (java.util.Enumeration)23 HashSet (java.util.HashSet)19 ArrayList (java.util.ArrayList)17 Set (java.util.Set)17 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)17 List (java.util.List)16 X509Certificate (java.security.cert.X509Certificate)13 ByteArrayOutputStream (java.io.ByteArrayOutputStream)11 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)11 DEREncodable (org.bouncycastle.asn1.DEREncodable)11 DERObject (org.bouncycastle.asn1.DERObject)11 AlgorithmIdentifier (org.bouncycastle.asn1.x509.AlgorithmIdentifier)11 X509Extension (org.gudy.bouncycastle.asn1.x509.X509Extension)11 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 Iterator (java.util.Iterator)8 X962Parameters (org.bouncycastle.asn1.x9.X962Parameters)8 X9ECParameters (org.bouncycastle.asn1.x9.X9ECParameters)8 HashMap (java.util.HashMap)7