Search in sources :

Example 31 with DLSequence

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

the class X509Attribute method toASN1.

ASN1Primitive toASN1(final ThreadContext context) {
    ASN1EncodableVector v1 = new ASN1EncodableVector();
    v1.add(getTypeID());
    if (value instanceof ASN1.Constructive) {
        v1.add(((ASN1.Constructive) value).toASN1(context));
    } else {
        ASN1EncodableVector v2 = new ASN1EncodableVector();
        v2.add(((ASN1.ASN1Data) value).toASN1(context));
        v1.add(new DERSet(v2));
    }
    return new DLSequence(v1);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1._ASN1(org.jruby.ext.openssl.ASN1._ASN1) DERSet(org.bouncycastle.asn1.DERSet)

Example 32 with DLSequence

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

the class X509Extension method toASN1Sequence.

ASN1Sequence toASN1Sequence() throws IOException {
    final ASN1EncodableVector vec = new ASN1EncodableVector();
    vec.add(getRealObjectID());
    if (critical)
        vec.add(DERBoolean.TRUE);
    vec.add(new DEROctetString(getRealValueEncoded()));
    return new DLSequence(vec);
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DEROctetString(org.bouncycastle.asn1.DEROctetString)

Example 33 with DLSequence

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

the class PKCS7 method sign.

/* c: PKCS7_sign
     *
     */
public static PKCS7 sign(X509AuxCertificate signcert, PrivateKey pkey, Collection<X509AuxCertificate> certs, BIO data, int flags) throws PKCS7Exception {
    PKCS7 p7 = new PKCS7();
    p7.setType(ASN1Registry.NID_pkcs7_signed);
    p7.contentNew(ASN1Registry.NID_pkcs7_data);
    SignerInfoWithPkey si = p7.addSignature(signcert, pkey, EVP.sha1());
    if ((flags & NOCERTS) == 0) {
        p7.addCertificate(signcert);
        if (certs != null) {
            for (X509AuxCertificate c : certs) {
                p7.addCertificate(c);
            }
        }
    }
    if ((flags & NOATTR) == 0) {
        si.addSignedAttribute(ASN1Registry.NID_pkcs9_contentType, OID_pkcs7_data);
        if ((flags & NOSMIMECAP) == 0) {
            ASN1EncodableVector smcap = new ASN1EncodableVector();
            smcap.add(new AlgorithmIdentifier(OID_des_ede3_cbc));
            smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_128)));
            smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_64)));
            smcap.add(new AlgorithmIdentifier(OID_rc2_cbc, new ASN1Integer(BI_40)));
            smcap.add(new AlgorithmIdentifier(OID_des_cbc));
            si.addSignedAttribute(ASN1Registry.NID_SMIMECapabilities, new DLSequence(smcap));
        }
    }
    if ((flags & STREAM) != 0) {
        return p7;
    }
    BIO p7bio = p7.dataInit(null);
    try {
        data.crlfCopy(p7bio, flags);
    } catch (IOException e) {
        throw new PKCS7Exception(F_PKCS7_SIGN, R_PKCS7_DATAFINAL_ERROR, e);
    }
    if ((flags & DETACHED) != 0) {
        p7.setDetached(1);
    }
    p7.dataFinal(p7bio);
    return p7;
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer) IOException(java.io.IOException) X509AuxCertificate(org.jruby.ext.openssl.x509store.X509AuxCertificate) AlgorithmIdentifier(org.bouncycastle.asn1.x509.AlgorithmIdentifier)

Example 34 with DLSequence

use of org.bouncycastle.asn1.DLSequence 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 35 with DLSequence

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

the class PKey method toDerDSAKey.

public static byte[] toDerDSAKey(DSAPublicKey pubKey, DSAPrivateKey privKey) throws IOException {
    if (pubKey != null && privKey == null) {
        return pubKey.getEncoded();
    }
    if (privKey != null && pubKey != null) {
        ASN1EncodableVector vec = new ASN1EncodableVector();
        final DSAParams params = privKey.getParams();
        vec.add(new ASN1Integer(BigInteger.ZERO));
        vec.add(new ASN1Integer(params.getP()));
        vec.add(new ASN1Integer(params.getQ()));
        vec.add(new ASN1Integer(params.getG()));
        vec.add(new ASN1Integer(pubKey.getY()));
        vec.add(new ASN1Integer(privKey.getX()));
        return new DLSequence(vec).getEncoded();
    }
    if (privKey == null) {
        throw new IllegalArgumentException("private key as well as public key are null");
    }
    return privKey.getEncoded();
}
Also used : DLSequence(org.bouncycastle.asn1.DLSequence) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DSAParams(java.security.interfaces.DSAParams) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Aggregations

DLSequence (org.bouncycastle.asn1.DLSequence)37 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)21 DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)14 IOException (java.io.IOException)13 ASN1Integer (org.bouncycastle.asn1.ASN1Integer)12 ASN1ObjectIdentifier (org.bouncycastle.asn1.ASN1ObjectIdentifier)9 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)9 DEROctetString (org.bouncycastle.asn1.DEROctetString)9 ASN1Sequence (org.bouncycastle.asn1.ASN1Sequence)8 ASN1Encodable (org.bouncycastle.asn1.ASN1Encodable)6 DERIA5String (org.bouncycastle.asn1.DERIA5String)6 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)6 BigInteger (java.math.BigInteger)5 Pair (android.util.Pair)3 BufferedWriter (java.io.BufferedWriter)3 ASN1OutputStream (org.bouncycastle.asn1.ASN1OutputStream)3 JRubyMethod (org.jruby.anno.JRubyMethod)3 ByteArrayOutputStream (org.jruby.ext.openssl.util.ByteArrayOutputStream)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ASN1InputStream (org.bouncycastle.asn1.ASN1InputStream)2