Search in sources :

Example 21 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project XobotOS by xamarin.

the class V3TBSCertificateGenerator method generateTBSCertificate.

public TBSCertificateStructure generateTBSCertificate() {
    if ((serialNumber == null) || (signature == null) || (issuer == null) || (startDate == null) || (endDate == null) || (subject == null && !altNamePresentAndCritical) || (subjectPublicKeyInfo == null)) {
        throw new IllegalStateException("not all mandatory fields set in V3 TBScertificate generator");
    }
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(version);
    v.add(serialNumber);
    v.add(signature);
    v.add(issuer);
    //
    // before and after dates
    //
    ASN1EncodableVector validity = new ASN1EncodableVector();
    validity.add(startDate);
    validity.add(endDate);
    v.add(new DERSequence(validity));
    if (subject != null) {
        v.add(subject);
    } else {
        v.add(new DERSequence());
    }
    v.add(subjectPublicKeyInfo);
    if (issuerUniqueID != null) {
        v.add(new DERTaggedObject(false, 1, issuerUniqueID));
    }
    if (subjectUniqueID != null) {
        v.add(new DERTaggedObject(false, 2, subjectUniqueID));
    }
    if (extensions != null) {
        v.add(new DERTaggedObject(3, extensions));
    }
    return new TBSCertificateStructure(new DERSequence(v));
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 22 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project wildfly by wildfly.

the class KerberosTestUtils method generateSpnegoTokenInit.

/**
     * Generates SPNEGO init token with given initial ticket and supported mechanisms.
     *
     * @param ticket initial ticket for the preferred (the first) mechanism.
     * @param supMechOids object identifiers (OIDs) of supported mechanisms for the SPNEGO.
     * @return ASN.1 encoded SPNEGO init token
     */
public static byte[] generateSpnegoTokenInit(byte[] ticket, String... supMechOids) throws IOException {
    DEROctetString ticketForPreferredMech = new DEROctetString(ticket);
    ASN1EncodableVector mechSeq = new ASN1EncodableVector();
    for (String mech : supMechOids) {
        mechSeq.add(new ASN1ObjectIdentifier(mech));
    }
    DERTaggedObject taggedMechTypes = new DERTaggedObject(0, new DERSequence(mechSeq));
    DERTaggedObject taggedMechToken = new DERTaggedObject(2, ticketForPreferredMech);
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(taggedMechTypes);
    v.add(taggedMechToken);
    DERSequence seqNegTokenInit = new DERSequence(v);
    DERTaggedObject taggedSpnego = new DERTaggedObject(0, seqNegTokenInit);
    ASN1EncodableVector appVec = new ASN1EncodableVector();
    appVec.add(new ASN1ObjectIdentifier(OID_SPNEGO));
    appVec.add(taggedSpnego);
    DERApplicationSpecific app = new DERApplicationSpecific(0, appVec);
    return app.getEncoded();
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERApplicationSpecific(org.bouncycastle.asn1.DERApplicationSpecific) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) DEROctetString(org.bouncycastle.asn1.DEROctetString) DEROctetString(org.bouncycastle.asn1.DEROctetString) ASN1ObjectIdentifier(org.bouncycastle.asn1.ASN1ObjectIdentifier)

Example 23 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project robovm by robovm.

the class CMSSignedGenerator method addAttributeCertificates.

// BEGIN android-removed
// /**
//  * Add a single instance of otherRevocationData to the CRL set to be included with the generated SignedData message.
//  *
//  * @param otherRevocationInfoFormat the OID specifying the format of the otherRevocationInfo data.
//  * @param otherRevocationInfo the otherRevocationInfo ASN.1 structure.
//  */
// public void addOtherRevocationInfo(
//     ASN1ObjectIdentifier   otherRevocationInfoFormat,
//     ASN1Encodable          otherRevocationInfo)
// {
//     crls.add(new DERTaggedObject(false, 1, new OtherRevocationInfoFormat(otherRevocationInfoFormat, otherRevocationInfo)));
// }
//
// /**
//  * Add a Store of otherRevocationData to the CRL set to be included with the generated SignedData message.
//  *
//  * @param otherRevocationInfoFormat the OID specifying the format of the otherRevocationInfo data.
//  * @param otherRevocationInfos a Store of otherRevocationInfo data to add.
//  */
// public void addOtherRevocationInfo(
//     ASN1ObjectIdentifier   otherRevocationInfoFormat,
//     Store                  otherRevocationInfos)
// {
//     crls.addAll(CMSUtils.getOthersFromStore(otherRevocationInfoFormat, otherRevocationInfos));
// }
// END android-removed
/**
     * Add the attribute certificates contained in the passed in store to the
     * generator.
     *
     * @param store a store of Version 2 attribute certificates
     * @throws CMSException if an error occurse processing the store.
     * @deprecated use basic Store method
     */
public void addAttributeCertificates(X509Store store) throws CMSException {
    try {
        for (Iterator it = store.getMatches(null).iterator(); it.hasNext(); ) {
            X509AttributeCertificate attrCert = (X509AttributeCertificate) it.next();
            certs.add(new DERTaggedObject(false, 2, AttributeCertificate.getInstance(ASN1Primitive.fromByteArray(attrCert.getEncoded()))));
        }
    } catch (IllegalArgumentException e) {
        throw new CMSException("error processing attribute certs", e);
    } catch (IOException e) {
        throw new CMSException("error processing attribute certs", e);
    }
}
Also used : DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) Iterator(java.util.Iterator) X509AttributeCertificate(org.bouncycastle.x509.X509AttributeCertificate) IOException(java.io.IOException)

Example 24 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project robovm by robovm.

the class CertBag method toASN1Primitive.

public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(certId);
    v.add(new DERTaggedObject(0, certValue));
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector)

Example 25 with DERTaggedObject

use of org.bouncycastle.asn1.DERTaggedObject in project robovm by robovm.

the class PrivateKeyInfo method toASN1Primitive.

/**
     * write out an RSA private key with its associated information
     * as described in PKCS8.
     * <pre>
     *      PrivateKeyInfo ::= SEQUENCE {
     *                              version Version,
     *                              privateKeyAlgorithm AlgorithmIdentifier {{PrivateKeyAlgorithms}},
     *                              privateKey PrivateKey,
     *                              attributes [0] IMPLICIT Attributes OPTIONAL 
     *                          }
     *      Version ::= INTEGER {v1(0)} (v1,...)
     *
     *      PrivateKey ::= OCTET STRING
     *
     *      Attributes ::= SET OF Attribute
     * </pre>
     */
public ASN1Primitive toASN1Primitive() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new ASN1Integer(0));
    v.add(algId);
    v.add(privKey);
    if (attributes != null) {
        v.add(new DERTaggedObject(false, 0, attributes));
    }
    return new DERSequence(v);
}
Also used : DERSequence(org.bouncycastle.asn1.DERSequence) DERTaggedObject(org.bouncycastle.asn1.DERTaggedObject) ASN1EncodableVector(org.bouncycastle.asn1.ASN1EncodableVector) ASN1Integer(org.bouncycastle.asn1.ASN1Integer)

Aggregations

DERTaggedObject (org.bouncycastle.asn1.DERTaggedObject)25 ASN1EncodableVector (org.bouncycastle.asn1.ASN1EncodableVector)19 DERSequence (org.bouncycastle.asn1.DERSequence)17 IOException (java.io.IOException)4 BERSequence (org.bouncycastle.asn1.BERSequence)4 DEROctetString (org.bouncycastle.asn1.DEROctetString)4 DERIA5String (org.bouncycastle.asn1.DERIA5String)3 DERUTF8String (org.bouncycastle.asn1.DERUTF8String)3 Pair (android.util.Pair)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 ASN1OctetString (org.bouncycastle.asn1.ASN1OctetString)2 ASN1Primitive (org.bouncycastle.asn1.ASN1Primitive)2 BERTaggedObject (org.bouncycastle.asn1.BERTaggedObject)2 DERApplicationSpecific (org.bouncycastle.asn1.DERApplicationSpecific)2 DERInteger (org.bouncycastle.asn1.DERInteger)2 DLSequence (org.bouncycastle.asn1.DLSequence)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 CRLException (java.security.cert.CRLException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1