Search in sources :

Example 71 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.

the class PEMInputOutput method writeX509Aux.

public static void writeX509Aux(final Writer _out, final X509AuxCertificate cert) throws IOException {
    BufferedWriter out = makeBuffered(_out);
    final byte[] encoding;
    final int encLen;
    try {
        if (cert.aux == null) {
            encoding = cert.getEncoded();
            encLen = encoding.length;
        } else {
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] enc = cert.getEncoded();
            baos.write(enc, 0, enc.length);
            final X509Aux aux = cert.aux;
            ASN1EncodableVector a1 = new ASN1EncodableVector();
            if (aux.trust.size() > 0) {
                ASN1EncodableVector a2 = new ASN1EncodableVector();
                for (String trust : aux.trust) {
                    a2.add(new ASN1ObjectIdentifier(trust));
                }
                a1.add(new DLSequence(a2));
            }
            if (aux.reject.size() > 0) {
                ASN1EncodableVector a2 = new ASN1EncodableVector();
                for (String reject : aux.reject) {
                    a2.add(new ASN1ObjectIdentifier(reject));
                }
                a1.add(new DERTaggedObject(0, new DLSequence(a2)));
            }
            if (aux.alias != null) {
                a1.add(new DERUTF8String(aux.alias));
            }
            if (aux.keyid != null) {
                a1.add(new DEROctetString(aux.keyid));
            }
            if (aux.other.size() > 0) {
                ASN1EncodableVector a2 = new ASN1EncodableVector();
                for (ASN1Primitive other : aux.other) a2.add(other);
                a1.add(new DERTaggedObject(1, new DLSequence(a2)));
            }
            enc = new DLSequence(a1).getEncoded();
            baos.write(enc, 0, enc.length);
            encoding = baos.buffer();
            encLen = baos.size();
        }
    } catch (CertificateEncodingException e) {
        throw new IOException("problem with encoding object in write_X509_AUX", e);
    }
    out.write(BEF_G + PEM_STRING_X509_TRUSTED + AFT);
    out.newLine();
    writeEncoded(out, encoding, encLen);
    out.write(BEF_E + PEM_STRING_X509_TRUSTED + AFT);
    out.newLine();
    out.flush();
}
Also used : DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) CertificateEncodingException(java.security.cert.CertificateEncodingException) ByteArrayOutputStream(org.jruby.ext.openssl.util.ByteArrayOutputStream) ASN1OctetString(org.bouncycastle.asn1.ASN1OctetString) DERUTF8String(org.bouncycastle.asn1.DERUTF8String) DEROctetString(org.bouncycastle.asn1.DEROctetString) IOException(java.io.IOException) DEROctetString(org.bouncycastle.asn1.DEROctetString) BufferedWriter(java.io.BufferedWriter) DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Primitive(org.bouncycastle.asn1.ASN1Primitive) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 72 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.

the class X509ExtensionFactory method parseAuthorityKeyIdentifier.

private ASN1Sequence parseAuthorityKeyIdentifier(final ThreadContext context, final String valuex) {
    final ASN1EncodableVector vec = new ASN1EncodableVector();
    for (String value : valuex.split(",")) {
        // e.g. "keyid:always,issuer:always"
        if (value.startsWith("keyid:")) {
            // keyid:always
            ASN1Encodable publicKeyIdentifier = new DEROctetString(publicKeyIdentifier(context));
            vec.add(new DERTaggedObject(false, 0, publicKeyIdentifier));
        } else if (value.startsWith("issuer:")) {
            // issuer:always
            GeneralName issuerName = new GeneralName(authorityCertIssuer(context));
            vec.add(new DERTaggedObject(false, 1, new GeneralNames(issuerName)));
            BigInteger issuerSerial = getIssuerSerialNumber(context);
            if (issuerSerial != null) {
                vec.add(new DERTaggedObject(false, 2, new ASN1Integer(issuerSerial)));
            }
        }
    }
    return new DERSequence(vec);
}
Also used : GeneralNames(org.bouncycastle.asn1.x509.GeneralNames) BigInteger(java.math.BigInteger) RubyString(org.jruby.RubyString) GeneralName(org.bouncycastle.asn1.x509.GeneralName)

Example 73 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.

the class PKCS7 method asASN1.

public ASN1Encodable asASN1() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    ASN1ObjectIdentifier contentType;
    if (data == null) {
        // OpenSSL behavior
        contentType = new ASN1ObjectIdentifier(EMPTY_PKCS7_OID);
    } else {
        contentType = ASN1Registry.nid2obj(getType());
    }
    vector.add(contentType);
    if (data != null) {
        vector.add(new DERTaggedObject(0, data.asASN1()));
    }
    return new DLSequence(vector);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 74 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.

the class SignerInfoWithPkey method toASN1Object.

/**
 * Produce an object suitable for an ASN1OutputStream.
 * <pre>
 *  SignerInfo ::= SEQUENCE {
 *      version Version,
 *      issuerAndSerialNumber IssuerAndSerialNumber,
 *      digestAlgorithm DigestAlgorithmIdentifier,
 *      authenticatedAttributes [0] IMPLICIT Attributes OPTIONAL,
 *      digestEncryptionAlgorithm DigestEncryptionAlgorithmIdentifier,
 *      encryptedDigest EncryptedDigest,
 *      unauthenticatedAttributes [1] IMPLICIT Attributes OPTIONAL
 *  }
 *
 *  EncryptedDigest ::= OCTET STRING
 *
 *  DigestAlgorithmIdentifier ::= AlgorithmIdentifier
 *
 *  DigestEncryptionAlgorithmIdentifier ::= AlgorithmIdentifier
 * </pre>
 */
public ASN1Encodable toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(version);
    v.add(issuerAndSerialNumber);
    v.add(digAlgorithm);
    if (authenticatedAttributes != null) {
        v.add(new DERTaggedObject(false, 0, authenticatedAttributes));
    }
    v.add(digEncryptionAlgorithm);
    v.add(encryptedDigest);
    if (unauthenticatedAttributes != null) {
        v.add(new DERTaggedObject(false, 1, unauthenticatedAttributes));
    }
    return new DLSequence(v);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 75 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project jruby-openssl by jruby.

the class EncContent method asASN1.

public ASN1Encodable asASN1() {
    ASN1EncodableVector vector = new ASN1EncodableVector();
    vector.add(ASN1Registry.nid2obj(contentType).toASN1Primitive());
    vector.add(algorithm.toASN1Primitive());
    if (encData != null) {
        vector.add(new DERTaggedObject(false, 0, encData));
    }
    return new DLSequence(vector);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Aggregations

DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)73 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)42 DERSequence (org.bouncycastle.asn1.DERSequence)40 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)22 DEROctetString (org.bouncycastle.asn1.DEROctetString)21 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)18 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)16 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)16 DLSequence (org.bouncycastle.asn1.DLSequence)14 IOException (java.io.IOException)11 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)11 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)11 DERIA5String (org.bouncycastle.asn1.DERIA5String)10 GeneralName (org.bouncycastle.asn1.x509.GeneralName)10 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)9 BigInteger (java.math.BigInteger)7 DERPrintableString (org.bouncycastle.asn1.DERPrintableString)7 BERSequence (org.bouncycastle.asn1.BERSequence)6 DERGeneralizedTime (org.bouncycastle.asn1.DERGeneralizedTime)6 DERSet (org.bouncycastle.asn1.DERSet)6