Example usage for org.bouncycastle.asn1 DERSequence DERSequence

List of usage examples for org.bouncycastle.asn1 DERSequence DERSequence

Introduction

In this page you can find the example usage for org.bouncycastle.asn1 DERSequence DERSequence.

Prototype

public DERSequence(ASN1Encodable[] elements) 

Source Link

Document

Create a sequence containing an array of objects.

Usage

From source file:org.ejbca.util.CertTools.java

License:Open Source License

public static X509Certificate genSelfCertForPurpose(String dn, long validity, String policyId,
        PrivateKey privKey, PublicKey pubKey, String sigAlg, boolean isCA, int keyusage, String provider)
        throws NoSuchAlgorithmException, SignatureException, InvalidKeyException, CertificateEncodingException,
        IllegalStateException, NoSuchProviderException {
    // Create self signed certificate
    Date firstDate = new Date();

    // Set back startdate ten minutes to avoid some problems with wrongly set clocks.
    firstDate.setTime(firstDate.getTime() - (10 * 60 * 1000));

    Date lastDate = new Date();

    // validity in days = validity*24*60*60*1000 milliseconds
    lastDate.setTime(lastDate.getTime() + (validity * (24 * 60 * 60 * 1000)));

    X509V3CertificateGenerator certgen = new X509V3CertificateGenerator();

    // Transform the PublicKey to be sure we have it in a format that the X509 certificate generator handles, it might be 
    // a CVC public key that is passed as parameter
    PublicKey publicKey = null;/*from w  ww .  j a v a  2s. co m*/
    if (pubKey instanceof RSAPublicKey) {
        RSAPublicKey rsapk = (RSAPublicKey) pubKey;
        RSAPublicKeySpec rSAPublicKeySpec = new RSAPublicKeySpec(rsapk.getModulus(), rsapk.getPublicExponent());
        try {
            publicKey = KeyFactory.getInstance("RSA").generatePublic(rSAPublicKeySpec);
        } catch (InvalidKeySpecException e) {
            log.error("Error creating RSAPublicKey from spec: ", e);
            publicKey = pubKey;
        }
    } else if (pubKey instanceof ECPublicKey) {
        ECPublicKey ecpk = (ECPublicKey) pubKey;
        try {
            ECPublicKeySpec ecspec = new ECPublicKeySpec(ecpk.getW(), ecpk.getParams()); // will throw NPE if key is "implicitlyCA"
            publicKey = KeyFactory.getInstance("EC").generatePublic(ecspec);
        } catch (InvalidKeySpecException e) {
            log.error("Error creating ECPublicKey from spec: ", e);
            publicKey = pubKey;
        } catch (NullPointerException e) {
            log.debug("NullPointerException, probably it is implicitlyCA generated keys: " + e.getMessage());
            publicKey = pubKey;
        }
    } else {
        log.debug("Not converting key of class. " + pubKey.getClass().getName());
        publicKey = pubKey;
    }

    // Serialnumber is random bits, where random generator is initialized with Date.getTime() when this
    // bean is created.
    byte[] serno = new byte[8];
    SecureRandom random = SecureRandom.getInstance("SHA1PRNG");
    random.setSeed(new Date().getTime());
    random.nextBytes(serno);
    certgen.setSerialNumber(new java.math.BigInteger(serno).abs());
    certgen.setNotBefore(firstDate);
    certgen.setNotAfter(lastDate);
    certgen.setSignatureAlgorithm(sigAlg);
    certgen.setSubjectDN(CertTools.stringToBcX509Name(dn));
    certgen.setIssuerDN(CertTools.stringToBcX509Name(dn));
    certgen.setPublicKey(publicKey);

    // Basic constranits is always critical and MUST be present at-least in CA-certificates.
    BasicConstraints bc = new BasicConstraints(isCA);
    certgen.addExtension(X509Extensions.BasicConstraints.getId(), true, bc);

    // Put critical KeyUsage in CA-certificates
    if (isCA) {
        X509KeyUsage ku = new X509KeyUsage(keyusage);
        certgen.addExtension(X509Extensions.KeyUsage.getId(), true, ku);
    }

    // Subject and Authority key identifier is always non-critical and MUST be present for certificates to verify in Firefox.
    try {
        if (isCA) {
            SubjectPublicKeyInfo spki = new SubjectPublicKeyInfo(
                    (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(publicKey.getEncoded()))
                            .readObject());
            SubjectKeyIdentifier ski = new SubjectKeyIdentifier(spki);

            SubjectPublicKeyInfo apki = new SubjectPublicKeyInfo(
                    (ASN1Sequence) new ASN1InputStream(new ByteArrayInputStream(publicKey.getEncoded()))
                            .readObject());
            AuthorityKeyIdentifier aki = new AuthorityKeyIdentifier(apki);

            certgen.addExtension(X509Extensions.SubjectKeyIdentifier.getId(), false, ski);
            certgen.addExtension(X509Extensions.AuthorityKeyIdentifier.getId(), false, aki);
        }
    } catch (IOException e) { // do nothing
    }

    // CertificatePolicies extension if supplied policy ID, always non-critical
    if (policyId != null) {
        PolicyInformation pi = new PolicyInformation(new DERObjectIdentifier(policyId));
        DERSequence seq = new DERSequence(pi);
        certgen.addExtension(X509Extensions.CertificatePolicies.getId(), false, seq);
    }

    X509Certificate selfcert = certgen.generate(privKey, provider);

    return selfcert;
}

From source file:org.ejbca.util.CertTools.java

License:Open Source License

/**
 * From an altName string as defined in getSubjectAlternativeName 
 * @param altName//from   ww w.  j a va2 s .c  o  m
 * @return ASN.1 GeneralNames
 * @see #getSubjectAlternativeName
 */
public static GeneralNames getGeneralNamesFromAltName(String altName) {
    if (log.isTraceEnabled()) {
        log.trace(">getGeneralNamesFromAltName: " + altName);
    }
    ASN1EncodableVector vec = new ASN1EncodableVector();

    ArrayList<String> emails = CertTools.getEmailFromDN(altName);
    if (!emails.isEmpty()) {
        Iterator<String> iter = emails.iterator();
        while (iter.hasNext()) {
            GeneralName gn = new GeneralName(1, new DERIA5String((String) iter.next()));
            vec.add(gn);
        }
    }

    ArrayList<String> dns = CertTools.getPartsFromDN(altName, CertTools.DNS);
    if (!dns.isEmpty()) {
        Iterator<String> iter = dns.iterator();
        while (iter.hasNext()) {
            GeneralName gn = new GeneralName(2, new DERIA5String((String) iter.next()));
            vec.add(gn);
        }
    }

    String directoryName = getDirectoryStringFromAltName(altName);
    if (directoryName != null) {
        X509Name x509DirectoryName = new X509Name(directoryName);
        GeneralName gn = new GeneralName(4, x509DirectoryName);
        vec.add(gn);
    }

    ArrayList<String> uri = CertTools.getPartsFromDN(altName, CertTools.URI);
    if (!uri.isEmpty()) {
        Iterator<String> iter = uri.iterator();
        while (iter.hasNext()) {
            GeneralName gn = new GeneralName(6, new DERIA5String((String) iter.next()));
            vec.add(gn);
        }
    }
    uri = CertTools.getPartsFromDN(altName, CertTools.URI1);
    if (!uri.isEmpty()) {
        Iterator<String> iter = uri.iterator();
        while (iter.hasNext()) {
            GeneralName gn = new GeneralName(6, new DERIA5String((String) iter.next()));
            vec.add(gn);
        }
    }
    uri = CertTools.getPartsFromDN(altName, CertTools.URI2);
    if (!uri.isEmpty()) {
        Iterator<String> iter = uri.iterator();
        while (iter.hasNext()) {
            GeneralName gn = new GeneralName(6, new DERIA5String((String) iter.next()));
            vec.add(gn);
        }
    }

    ArrayList<String> ipstr = CertTools.getPartsFromDN(altName, CertTools.IPADDR);
    if (!ipstr.isEmpty()) {
        Iterator<String> iter = ipstr.iterator();
        while (iter.hasNext()) {
            byte[] ipoctets = StringTools.ipStringToOctets((String) iter.next());
            GeneralName gn = new GeneralName(7, new DEROctetString(ipoctets));
            vec.add(gn);
        }
    }

    // UPN is an OtherName see method getUpn... for asn.1 definition
    ArrayList<String> upn = CertTools.getPartsFromDN(altName, CertTools.UPN);
    if (!upn.isEmpty()) {
        Iterator<String> iter = upn.iterator();
        while (iter.hasNext()) {
            ASN1EncodableVector v = new ASN1EncodableVector();
            v.add(new DERObjectIdentifier(CertTools.UPN_OBJECTID));
            v.add(new DERTaggedObject(true, 0, new DERUTF8String((String) iter.next())));
            //GeneralName gn = new GeneralName(new DERSequence(v), 0);
            DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
            vec.add(gn);
        }
    }

    ArrayList<String> guid = CertTools.getPartsFromDN(altName, CertTools.GUID);
    if (!guid.isEmpty()) {
        Iterator<String> iter = guid.iterator();
        while (iter.hasNext()) {
            ASN1EncodableVector v = new ASN1EncodableVector();
            byte[] guidbytes = Hex.decode((String) iter.next());
            if (guidbytes != null) {
                v.add(new DERObjectIdentifier(CertTools.GUID_OBJECTID));
                v.add(new DERTaggedObject(true, 0, new DEROctetString(guidbytes)));
                DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
                vec.add(gn);
            } else {
                log.error("Cannot decode hexadecimal guid: " + guid);
            }
        }
    }

    // Krb5PrincipalName is an OtherName, see method getKrb5Principal...for ASN.1 definition
    ArrayList<String> krb5principalname = CertTools.getPartsFromDN(altName, CertTools.KRB5PRINCIPAL);
    if (!krb5principalname.isEmpty()) {
        Iterator<String> iter = krb5principalname.iterator();
        while (iter.hasNext()) {
            // Start by parsing the input string to separate it in different parts
            String principalString = (String) iter.next();
            if (log.isDebugEnabled()) {
                log.debug("principalString: " + principalString);
            }
            // The realm is the last part moving back until an @
            int index = principalString.lastIndexOf('@');
            String realm = "";
            if (index > 0) {
                realm = principalString.substring(index + 1);
            }
            if (log.isDebugEnabled()) {
                log.debug("realm: " + realm);
            }
            // Now we can have several principals separated by /
            ArrayList<String> principalarr = new ArrayList<String>();
            int jndex = 0;
            int bindex = 0;
            while (jndex < index) {
                // Loop and add all strings separated by /
                jndex = principalString.indexOf('/', bindex);
                if (jndex == -1) {
                    jndex = index;
                }
                String s = principalString.substring(bindex, jndex);
                if (log.isDebugEnabled()) {
                    log.debug("adding principal name: " + s);
                }
                principalarr.add(s);
                bindex = jndex + 1;
            }

            // Now we must construct the rather complex asn.1...
            ASN1EncodableVector v = new ASN1EncodableVector(); // this is the OtherName
            v.add(new DERObjectIdentifier(CertTools.KRB5PRINCIPAL_OBJECTID));

            // First the Krb5PrincipalName sequence
            ASN1EncodableVector krb5p = new ASN1EncodableVector();
            // The realm is the first tagged GeneralString
            krb5p.add(new DERTaggedObject(true, 0, new DERGeneralString(realm)));
            // Second is the sequence of principal names, which is at tagged position 1 in the krb5p 
            ASN1EncodableVector principals = new ASN1EncodableVector();
            // According to rfc4210 the type NT-UNKNOWN is 0, and according to some other rfc this type should be used...
            principals.add(new DERTaggedObject(true, 0, new DERInteger(0)));
            // The names themselves are yet another sequence
            Iterator<String> i = principalarr.iterator();
            ASN1EncodableVector names = new ASN1EncodableVector();
            while (i.hasNext()) {
                String principalName = (String) i.next();
                names.add(new DERGeneralString(principalName));
            }
            principals.add(new DERTaggedObject(true, 1, new DERSequence(names)));
            krb5p.add(new DERTaggedObject(true, 1, new DERSequence(principals)));

            v.add(new DERTaggedObject(true, 0, new DERSequence(krb5p)));
            DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
            vec.add(gn);
        }
    }

    // To support custom OIDs in altNames, they must be added as an OtherName of plain type UTF8String
    ArrayList<String> customoids = CertTools.getCustomOids(altName);
    if (!customoids.isEmpty()) {
        Iterator<String> iter = customoids.iterator();
        while (iter.hasNext()) {
            String oid = (String) iter.next();
            ArrayList<String> oidval = CertTools.getPartsFromDN(altName, oid);
            if (!oidval.isEmpty()) {
                Iterator<String> valiter = oidval.iterator();
                while (valiter.hasNext()) {
                    ASN1EncodableVector v = new ASN1EncodableVector();
                    v.add(new DERObjectIdentifier(oid));
                    v.add(new DERTaggedObject(true, 0, new DERUTF8String((String) valiter.next())));
                    DERObject gn = new DERTaggedObject(false, 0, new DERSequence(v));
                    vec.add(gn);
                }
            }
        }
    }

    GeneralNames ret = null;
    if (vec.size() > 0) {
        ret = new GeneralNames(new DERSequence(vec));
    }
    return ret;
}

From source file:org.ejbca.util.NonEjbTestTools.java

License:Open Source License

public static byte[] generatePKCS10Req(String dn, String password)
        throws InvalidKeyException, NoSuchAlgorithmException, NoSuchProviderException, SignatureException,
        InvalidAlgorithmParameterException, IOException, OperatorCreationException {
    // Generate keys
    KeyPair keys = KeyTools.genKeys("512", AlgorithmConstants.KEYALGORITHM_RSA);

    // Create challenge password attribute for PKCS10
    // Attributes { ATTRIBUTE:IOSet } ::= SET OF Attribute{{ IOSet }}
    ///*from  w w w. jav a 2s. co  m*/
    // Attribute { ATTRIBUTE:IOSet } ::= SEQUENCE {
    //    type    ATTRIBUTE.&id({IOSet}),
    //    values  SET SIZE(1..MAX) OF ATTRIBUTE.&Type({IOSet}{\@type})
    // }
    ASN1EncodableVector vec = new ASN1EncodableVector();
    vec.add(PKCSObjectIdentifiers.pkcs_9_at_challengePassword);
    ASN1EncodableVector values = new ASN1EncodableVector();
    values.add(new DERUTF8String(password));
    vec.add(new DERSet(values));
    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(new DERSequence(vec));
    DERSet set = new DERSet(v);
    // Create PKCS#10 certificate request
    PKCS10CertificationRequest p10request = CertTools.genPKCS10CertificationRequest("SHA1WithRSA",
            CertTools.stringToBcX500Name(dn), keys.getPublic(), set, keys.getPrivate(), null);
    return p10request.toASN1Structure().getEncoded();
}

From source file:org.elasticsearch.xpack.core.ssl.CertGenUtils.java

License:Open Source License

/**
 * Creates an X.509 {@link GeneralName} for use as a <em>Common Name</em> in the certificate's <em>Subject Alternative Names</em>
 * extension. A <em>common name</em> is a name with a tag of {@link GeneralName#otherName OTHER}, with an object-id that references
 * the {@link #CN_OID cn} attribute, an explicit tag of '0', and a DER encoded UTF8 string for the name.
 * This usage of using the {@code cn} OID as a <em>Subject Alternative Name</em> is <strong>non-standard</strong> and will not be
 * recognised by other X.509/TLS implementations.
 *///from  w w w . ja va2s  .c  om
public static GeneralName createCommonName(String cn) {
    final ASN1Encodable[] sequence = { new ASN1ObjectIdentifier(CN_OID),
            new DERTaggedObject(true, 0, new DERUTF8String(cn)) };
    return new GeneralName(GeneralName.otherName, new DERSequence(sequence));
}

From source file:org.fdroid.enigtext.crypto.IdentityKeyUtil.java

License:Open Source License

public static byte[] getSignedKeyExchange(Context context, MasterSecret masterSecret, byte[] keyExchangeBytes) {
    try {/*w  ww .j av a2 s . co  m*/

        MasterCipher masterCipher = new MasterCipher(masterSecret);
        byte[] publicKeyBytes = getIdentityKey(context).serialize();
        byte[] messageHash = getMessageHash(keyExchangeBytes, publicKeyBytes);
        byte[] privateKeyBytes = Base64.decode(retrieve(context, IDENTITY_PRIVATE_KEY_PREF));
        ECPrivateKeyParameters privateKey = masterCipher.decryptKey(privateKeyBytes);
        ECDSASigner signer = new ECDSASigner();

        signer.init(true, privateKey);

        BigInteger[] messageSignatureInts = signer.generateSignature(messageHash);
        DERInteger[] derMessageSignatureInts = new DERInteger[] { new DERInteger(messageSignatureInts[0]),
                new DERInteger(messageSignatureInts[1]) };
        byte[] messageSignatureBytes = new DERSequence(derMessageSignatureInts).getEncoded(ASN1Encodable.DER);
        byte[] messageSignature = new byte[2 + messageSignatureBytes.length];

        Conversions.shortToByteArray(messageSignature, 0, messageSignatureBytes.length);
        System.arraycopy(messageSignatureBytes, 0, messageSignature, 2, messageSignatureBytes.length);

        byte[] combined = Combiner.combine(keyExchangeBytes, publicKeyBytes, messageSignature);

        return combined;
    } catch (IOException ioe) {
        throw new AssertionError(ioe);
    }
}

From source file:org.fuin.esmp.EventStoreCertificateMojo.java

License:Open Source License

private static X509Certificate generateCertificate(final String domain, final KeyPair pair) {
    try {// w ww .  jav  a  2  s  .c om
        final X500Name issuerName = new X500Name("CN=" + domain);
        final X500Name subjectName = issuerName;
        final BigInteger serial = BigInteger.valueOf(new Random().nextInt());
        final Date notBefore = Date.from(LocalDateTime.of(2016, 1, 1, 0, 0).toInstant(ZoneOffset.UTC));
        final Date notAfter = Date.from(LocalDateTime.of(2099, 1, 1, 0, 0).toInstant(ZoneOffset.UTC));
        final X509v3CertificateBuilder builder = new JcaX509v3CertificateBuilder(issuerName, serial, notBefore,
                notAfter, subjectName, pair.getPublic());
        builder.addExtension(Extension.basicConstraints, true, new BasicConstraints(true));
        final ASN1EncodableVector purposes = new ASN1EncodableVector();
        purposes.add(KeyPurposeId.id_kp_serverAuth);
        builder.addExtension(Extension.extendedKeyUsage, false, new DERSequence(purposes));
        return signCertificate(builder, pair.getPrivate());
    } catch (final CertIOException ex) {
        throw new RuntimeException("Couldn't generate certificate", ex);
    }
}

From source file:org.glite.security.delegation.GrDProxyGenerator.java

License:Apache License

/**
 * Create a proxy certificate from a given certificate
 * //from   w w  w.j ava2 s  . c  o m
 * @param issuerCert
 *            issuer certificate
 * @param issuerKey
 *            issuer private key
 * @param publicKey
 *            public key of delegatee
 * @param lifetime
 *            life time of proxy
 * @param proxyType
 *            type of proxy
 * @param cnValue
 *            common name of proxy
 * @return created proxy certificate
 * @throws GeneralSecurityException
 * @deprecated Use proxy generator from util-java
 */
public X509Certificate createProxyCertificate(X509Certificate issuerCert, PrivateKey issuerKey,
        PublicKey publicKey, int lifetime1, int proxyType1, String cnValue) throws GeneralSecurityException {
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();

    BigInteger serialNum = null;
    serialNum = issuerCert.getSerialNumber();

    X509Name issuer = (X509Name) issuerCert.getSubjectDN();

    ASN1Sequence seqSubject = (ASN1Sequence) issuer.getDERObject();

    logger.debug("SubjectDN of IssuerCert" + issuer);

    ASN1EncodableVector v = new ASN1EncodableVector();
    v.add(X509Name.CN);
    v.add(new DERPrintableString(cnValue));

    Enumeration subjectParts = seqSubject.getObjects();

    ASN1EncodableVector subjectVector = new ASN1EncodableVector();

    while (subjectParts.hasMoreElements()) {
        DERObject part = (DERObject) subjectParts.nextElement();
        subjectVector.add(part);
    }

    subjectVector.add(new DERSet(new DERSequence(v)));

    DERSequence subjDerSeq = new DERSequence(subjectVector);

    X509Name subjectX = new X509Name(subjDerSeq);

    logger.debug("SubjectDN :" + subjectX);

    certGen.setSubjectDN(subjectX);
    certGen.setIssuerDN(issuer);

    certGen.setSerialNumber(serialNum);
    certGen.setPublicKey(publicKey);
    certGen.setSignatureAlgorithm(issuerCert.getSigAlgName());
    certGen.addExtension(X509Extensions.KeyUsage, false,
            new KeyUsage(KeyUsage.dataEncipherment | KeyUsage.digitalSignature));

    GregorianCalendar date = new GregorianCalendar(TimeZone.getTimeZone("UTC"));

    date.add(Calendar.MINUTE, -5);
    certGen.setNotBefore(date.getTime());

    if (lifetime1 <= 0) {
        certGen.setNotAfter(issuerCert.getNotAfter());
    } else {
        date.add(Calendar.MINUTE, 5);
        date.add(Calendar.SECOND, lifetime1);
        certGen.setNotAfter(date.getTime());
    }

    return certGen.generateX509Certificate(issuerKey);
}

From source file:org.glite.security.util.proxy.ProxyCertificateGenerator.java

License:Apache License

/**
 * Generates a new proxy DN based on the basename. If newCN is given, it is added to the end of the DN and the new
 * DN is returned. If newCN is null, the basename is analyzed. In case of old proxy DN, either "CN=proxy" or
 * "CN=limited proxy" is added depending on the value of limited argument. In case of new style proxy or nonproxy
 * DN, new style proxy is assumed and "CN=" with random number following it is added.
 * //from   w w w  . j  ava2  s. co  m
 * @param basename The DN to use as the basis of the new DN.
 * @param inputCN If given, this is used as the new CN value.
 * @param limited in case the newCN is not given and the basename is old style proxy, setting this to true will
 *            generate limited proxy.
 * @return the new DN.
 */
@SuppressWarnings("unchecked")
public X509Name generateDN(X509Name basename, String inputCN, boolean limited) {
    if (basename == null) {
        throw new IllegalArgumentException("generateDN: no basename given, can't generate DN.");
    }

    String newCN;

    if (inputCN == null) { // if no CN part given, guess it
        newCN = guessCN(basename, limited);
    } else {
        newCN = inputCN;
    }

    // generate new cn part
    ASN1EncodableVector newCnPart = new ASN1EncodableVector();
    newCnPart.add(X509Name.CN);
    newCnPart.add(new DERPrintableString(newCN));

    // copy the RDNs to a new vector so that the new part can be added.
    ASN1Sequence subjectSequence = (ASN1Sequence) basename.getDERObject();
    Enumeration subjectParts = subjectSequence.getObjects();

    ASN1EncodableVector subjectVector = new ASN1EncodableVector();

    while (subjectParts.hasMoreElements()) {
        DERObject part = (DERObject) subjectParts.nextElement();
        subjectVector.add(part);
    }

    subjectVector.add(new DERSet(new DERSequence(newCnPart)));

    // transform the vector into a new X509Name
    DERSequence subjDerSeq = new DERSequence(subjectVector);
    X509Name proxySubject = new X509Name(subjDerSeq);

    LOGGER.debug("SubjectDN :" + proxySubject);

    return proxySubject;
}

From source file:org.glite.security.util.proxy.ProxyCertificateGenerator.java

License:Apache License

/**
 * Adds a new CN part to the end of the DN and sets it as the subject DN. Also sets the issuer DN.
 * /*from   www . j  a v  a 2s  .  com*/
 * @param newCn The string to be added as the CN value.
 */
@SuppressWarnings("unchecked")
private void setupDNs(String newCn) {
    ASN1Sequence seqSubject = (ASN1Sequence) m_baseName.getDERObject();

    ASN1EncodableVector newCnPart = new ASN1EncodableVector();
    newCnPart.add(X509Name.CN);
    newCnPart.add(new DERPrintableString(newCn));

    Enumeration subjectParts = seqSubject.getObjects();

    ASN1EncodableVector subjectVector = new ASN1EncodableVector();

    while (subjectParts.hasMoreElements()) {
        DERObject part = (DERObject) subjectParts.nextElement();
        subjectVector.add(part);
    }

    subjectVector.add(new DERSet(new DERSequence(newCnPart)));

    DERSequence subjDerSeq = new DERSequence(subjectVector);

    X509Name proxySubject = new X509Name(subjDerSeq);
    m_newDN = proxySubject;

    LOGGER.debug("SubjectDN :" + proxySubject);

    m_certGen.setSubjectDN(proxySubject);
    m_certGen.setIssuerDN(m_baseName);

}

From source file:org.glite.security.util.proxy.ProxyCertInfoExtension.java

License:Apache License

public DERObject toASN1Object() {
    ASN1EncodableVector v = new ASN1EncodableVector();
    if (m_pathLen > -1 && m_pathLen != UNLIMITED) {
        v.add(new DERInteger(m_pathLen));
    }/*ww w .j a  va  2s  . c  o m*/
    if (m_policy != null) {
        v.add(m_policy.toASN1Object());
    } else {
        throw new IllegalArgumentException("Can't generate ProxyCertInfoExtension without mandatory policy");
    }

    return new DERSequence(v);
}