Example usage for org.bouncycastle.asn1.x509 X509Name DefaultLookUp

List of usage examples for org.bouncycastle.asn1.x509 X509Name DefaultLookUp

Introduction

In this page you can find the example usage for org.bouncycastle.asn1.x509 X509Name DefaultLookUp.

Prototype

Hashtable DefaultLookUp

To view the source code for org.bouncycastle.asn1.x509 X509Name DefaultLookUp.

Click Source Link

Document

look up table translating common symbols into their OIDS.

Usage

From source file:com.yacme.ext.oxsit.cust_it.comp.security.cert.X509CertDisplayCA_IT.java

License:Open Source License

protected void initIssuerName() {
    m_sIssuerName = "";
    X509Name aName = m_aX509.getIssuer();
    Vector<DERObjectIdentifier> oidv = aName.getOIDs();
    HashMap<DERObjectIdentifier, String> hm = new HashMap<DERObjectIdentifier, String>(20);
    Vector<?> values = aName.getValues();
    for (int i = 0; i < oidv.size(); i++) {
        m_sIssuerName = m_sIssuerName + X509Name.DefaultSymbols.get(oidv.elementAt(i)) + "="
                + values.elementAt(i).toString()
                + ((m_bDisplayOID) ? (" (OID: " + oidv.elementAt(i).toString() + ")") : "") + " \n";
        hm.put(oidv.elementAt(i), values.elementAt(i).toString());
    }//from   w  w w .  j a  v a  2 s  . c  o m
    //look for givename (=nome di battesimo)
    m_sIssuerDisplayName = "";
    //see BC source code for details about DefaultLookUp behaviour
    DERObjectIdentifier oix;
    if (m_sIssuerDisplayName.length() == 0) {
        //check for O
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("o"));
        if (hm.containsKey(oix)) {
            m_sIssuerDisplayName = hm.get(oix).toString();
        }
    }
    if (m_sIssuerDisplayName.length() == 0) {
        //check for CN
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
        if (hm.containsKey(oix)) {
            m_sIssuerDisplayName = hm.get(oix).toString();
            m_sIssuerCommonName = m_sIssuerDisplayName;
        }
    }
    if (m_sIssuerDisplayName.length() == 0) {
        //if still not, check for pseudodym
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("pseudonym"));
        if (hm.containsKey(oix))
            m_sIssuerDisplayName = hm.get(oix).toString();
    }
    if (m_sIssuerDisplayName.length() == 0)
        m_sIssuerDisplayName = m_sIssuerName;
    //check for CN
    oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
    if (hm.containsKey(oix)) {
        m_sIssuerCommonName = hm.get(oix).toString();
    }
}

From source file:com.yacme.ext.oxsit.cust_it.comp.security.cert.X509CertDisplaySubject_IT.java

License:Open Source License

protected void initSubjectName() {
    m_sSubjectName = "";
    //print the subject
    //order of printing is as got in the CNIPA spec
    //first, grab the OID in the subject name
    X509Name aName = m_aX509.getSubject();
    Vector<DERObjectIdentifier> oidv = aName.getOIDs();
    Vector<?> values = aName.getValues();
    HashMap<DERObjectIdentifier, String> hm = new HashMap<DERObjectIdentifier, String>(20);
    for (int i = 0; i < oidv.size(); i++) {
        m_sSubjectName = m_sSubjectName + X509Name.DefaultSymbols.get(oidv.elementAt(i)) + "="
                + values.elementAt(i).toString()
                + ((m_bDisplayOID) ? (" (OID: " + oidv.elementAt(i).toString() + ")") : "") + " \n";
        hm.put(oidv.elementAt(i), values.elementAt(i).toString());
    }/*from  w  w  w . j a  va  2s. c om*/
    //extract data from subject name following CNIPA recommendation
    /*
     * first lookup for givenname and surname, if not existent
     * lookup for commonName (cn), if not existent
     * lookup for pseudonym ()
     */

    //look for givename (=nome di battesimo)
    m_sSubjectDisplayName = "";
    //see BC source code for details about DefaultLookUp behaviour
    DERObjectIdentifier oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("givenname"));
    if (hm.containsKey(oix)) {
        String tmpName = hm.get(oix).toString();
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("surname"));
        if (hm.containsKey(oix))
            m_sSubjectDisplayName = tmpName + " " + hm.get(oix).toString();
    }
    if (m_sSubjectDisplayName.length() == 0) {
        //check for CN
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
        if (hm.containsKey(oix)) {
            m_sSubjectDisplayName = hm.get(oix).toString();
        }
    }
    if (m_sSubjectDisplayName.length() == 0) {
        //if still not, check for pseudodym
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("pseudonym"));
        if (hm.containsKey(oix))
            m_sSubjectDisplayName = hm.get(oix).toString();
    }
    if (m_sSubjectDisplayName.length() == 0)
        m_sSubjectDisplayName = m_sSubjectName;
}

From source file:com.yacme.ext.oxsit.cust_it.comp.security.cert.X509CertDisplaySubject_IT.java

License:Open Source License

protected void initIssuerName() {
    m_sIssuerName = "";
    X509Name aName = m_aX509.getIssuer();
    Vector<DERObjectIdentifier> oidv = aName.getOIDs();
    HashMap<DERObjectIdentifier, String> hm = new HashMap<DERObjectIdentifier, String>(20);
    Vector<?> values = aName.getValues();
    for (int i = 0; i < oidv.size(); i++) {
        m_sIssuerName = m_sIssuerName + X509Name.DefaultSymbols.get(oidv.elementAt(i)) + "="
                + values.elementAt(i).toString()
                + ((m_bDisplayOID) ? (" (OID: " + oidv.elementAt(i).toString() + ")") : "") + " \n";
        hm.put(oidv.elementAt(i), values.elementAt(i).toString());
    }//from  ww  w  . j  av a 2  s . c  om
    //look for givename (=nome di battesimo)
    m_sIssuerDisplayName = "";
    //see BC source code for details about DefaultLookUp behaviour
    DERObjectIdentifier oix;
    if (m_sIssuerDisplayName.length() == 0) {
        //check for O
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("o"));
        if (hm.containsKey(oix)) {
            m_sIssuerDisplayName = hm.get(oix).toString();
        }
    }
    if (m_sIssuerDisplayName.length() == 0) {
        //check for CN
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
        if (hm.containsKey(oix)) {
            m_sIssuerDisplayName = hm.get(oix).toString();
        }
    }
    if (m_sIssuerDisplayName.length() == 0) {
        //if still not, check for pseudodym
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("pseudonym"));
        if (hm.containsKey(oix))
            m_sIssuerDisplayName = hm.get(oix).toString();
    }
    if (m_sIssuerDisplayName.length() == 0)
        m_sIssuerDisplayName = m_sIssuerName;
    //check for CN
    oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
    if (hm.containsKey(oix)) {
        m_sIssuerCommonName = hm.get(oix).toString();
    }
}

From source file:com.yacme.ext.oxsit.Helpers.java

License:Open Source License

public static String getIssuerName(X509Certificate _Cert) {
    //convert to bouncycaste
    String sRet = "";

    ByteArrayInputStream as;//  ww  w  . ja va 2 s.c om
    try {
        as = new ByteArrayInputStream(_Cert.getEncoded());
        ASN1InputStream aderin = new ASN1InputStream(as);
        DERObject ado;
        ado = aderin.readObject();
        X509CertificateStructure _aX509 = new X509CertificateStructure((ASN1Sequence) ado);
        //extract the name, same as in display         
        X509Name aName = _aX509.getIssuer();
        Vector<DERObjectIdentifier> oidv = aName.getOIDs();
        HashMap<DERObjectIdentifier, String> hm = new HashMap<DERObjectIdentifier, String>(20);
        Vector<?> values = aName.getValues();
        for (int i = 0; i < oidv.size(); i++) {
            hm.put(oidv.elementAt(i), values.elementAt(i).toString());
        }
        //look for givename (=nome di battesimo)
        //see BC source code for details about DefaultLookUp behaviour
        DERObjectIdentifier oix;
        if (sRet.length() == 0) {
            //check for O
            oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("o"));
            if (hm.containsKey(oix)) {
                sRet = hm.get(oix).toString();
            }
        }
        if (sRet.length() == 0) {
            //check for CN
            oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
            if (hm.containsKey(oix)) {
                sRet = hm.get(oix).toString();
            }
        }
        if (sRet.length() == 0) {
            //if still not, check for pseudodym
            oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("pseudonym"));
            if (hm.containsKey(oix))
                sRet = hm.get(oix).toString();
        }
        //check for CN
        oix = (DERObjectIdentifier) (X509Name.DefaultLookUp.get("cn"));
        if (hm.containsKey(oix)) {
            sRet = sRet + ((sRet.length() > 0) ? ", " : "") + hm.get(oix).toString();
        }
    } catch (IOException e) {
        e.printStackTrace();
    } catch (CertificateEncodingException e) {
        e.printStackTrace();
    }
    return sRet;
}

From source file:org.glite.slcs.pki.bouncycastle.X509PrincipalUtil.java

License:eu-egee.org license

/**
 * Reads the given {@link Attribute} and recurses into RDN attributes, fills
 * the given vectors.//  w  ww  .  jav a 2s . com
 * 
 * @param attr
 *            The {@link Attribute} to read.
 * @param oids
 *            The vector of OID.
 * @param values
 *            The vector of value.
 * @param added
 *            The added status vector.
 * @throws NamingException
 *             if a naming error occurs.
 */
private void readAttr(Attribute attr, Vector<DERObjectIdentifier> oids, Vector<Object> values,
        Vector<Boolean> added) throws NamingException {
    // Recursively looking into each attribute
    LOG.debug("Attribute: " + attr);
    for (int i = 0; i < attr.size(); i++) {
        if (attr.get(i) instanceof Attribute) {
            Attribute rdnAttr = (Attribute) attr.get(i);
            LOG.debug("Attribute RDN: " + rdnAttr);
            readAttr(rdnAttr, oids, values, added);
        } else { // Get back the OID from name
            DERObjectIdentifier oid = (DERObjectIdentifier) X509Name.DefaultLookUp
                    .get(Strings.toLowerCase(attr.getID()));
            oids.add(oid);
            Object attrValue = attr.get(i);
            LOG.debug("Attribute value: " + attrValue);
            values.add(attrValue);
            added.add(start_);
            start_ = true;

        }
    }

}

From source file:org.globus.tools.GridCertRequest.java

License:Open Source License

private static String getOrgName() {

    System.out.println("-----");
    System.out.println("You are about to be asked to enter information that will be incorporated");
    System.out.println("into your certificate request.");
    System.out.println("What you are about to enter is what is called a Distinguished Name or a DN.");
    System.out.println("Enter organization DN by entering individual component names and their values.");
    System.out.println("The component name can be one of: " + X509Name.DefaultLookUp.keySet());
    System.out.println("-----");

    StringBuffer orgName = new StringBuffer();
    String component = null;/*from ww w. j  a  va2 s .c o  m*/
    while ((component = getComponent()) != null) {
        if (orgName.length() != 0) {
            orgName.append(", ");
        }
        orgName.append(component);
    }

    if (orgName.length() == 0) {
        exit("Invalid organization DN");
    }

    return orgName.toString();
}

From source file:org.globus.tools.GridCertRequest.java

License:Open Source License

private static String getComponent() {
    String component = null;/*from   w ww.j a  va2 s  .  com*/

    while (true) {
        component = Util.getInput("Enter name component: ");
        if (component == null || component.trim().length() == 0) {
            return null;
        }
        component = component.trim();
        if (X509Name.DefaultLookUp.get(component.toLowerCase()) == null) {
            System.out.println("Invalid component name");
        } else {
            break;
        }
    }

    component = component.toUpperCase();

    String value = Util.getInput("Enter '" + component + "' value: ");
    if (value == null || value.trim().length() == 0) {
        return null;
    }
    return component + "=" + value.trim();
}

From source file:org.krakenapps.ca.util.CertificateBuilder.java

License:Apache License

private static X509Principal parseDn(String dn) {
    Vector<Object> oids = new Vector<Object>();
    Vector<Object> values = new Vector<Object>();

    String[] tokens = dn.split(",");
    for (String token : tokens) {
        int p = token.indexOf('=');
        String key = token.substring(0, p).trim().toLowerCase();
        String value = token.substring(p + 1).trim();

        DERObjectIdentifier oid = (DERObjectIdentifier) X509Name.DefaultLookUp.get(key);
        if (oid != null) {
            oids.add(oid);/*from  www  . ja va2 s.c om*/
            values.add(value);
        }
    }

    return new X509Principal(oids, values);
}

From source file:org.mailster.core.crypto.CertificateUtilities.java

License:Open Source License

public static X509V3CertificateGenerator initCertificateGenerator(KeyPair pair, String issuerDN,
        String subjectDN, boolean isCA, long validityPeriod, String signatureAlgorithm) throws Exception {
    X509V3CertificateGenerator v3CertGen = new X509V3CertificateGenerator();
    setSerialNumberAndValidityPeriod(v3CertGen, isCA, validityPeriod);

    v3CertGen.setIssuerDN(new X509Name(true, X509Name.DefaultLookUp, issuerDN));
    v3CertGen.setSubjectDN(new X509Name(true, X509Name.DefaultLookUp, subjectDN));
    v3CertGen.setPublicKey(pair.getPublic());
    if (signatureAlgorithm != null)
        v3CertGen.setSignatureAlgorithm(signatureAlgorithm);
    else//from   w  w w .  ja v  a 2s  .com
        v3CertGen.setSignatureAlgorithm("SHA1WithRSAEncryption");

    return v3CertGen;
}

From source file:org.mailster.core.crypto.CertificateUtilities.java

License:Open Source License

/**
 * Generate a CA Root certificate./*from  w ww.  ja v  a  2s.  co  m*/
 */
private static X509Certificate generateRootCert(String DN, KeyPair pair) throws Exception {
    X509V3CertificateGenerator certGen = new X509V3CertificateGenerator();
    certGen.setIssuerDN(new X509Name(true, X509Name.DefaultLookUp, DN));
    certGen.setSubjectDN(new X509Name(true, X509Name.DefaultLookUp, DN));

    setSerialNumberAndValidityPeriod(certGen, true, DEFAULT_VALIDITY_PERIOD);

    certGen.setPublicKey(pair.getPublic());
    certGen.setSignatureAlgorithm("SHA1WithRSAEncryption");

    certGen.addExtension(X509Extensions.AuthorityKeyIdentifier, false, new AuthorityKeyIdentifier(
            new GeneralNames(new GeneralName(new X509Name(true, X509Name.DefaultLookUp, DN))), BigInteger.ONE));
    certGen.addExtension(X509Extensions.SubjectKeyIdentifier, false,
            new SubjectKeyIdentifierStructure(pair.getPublic()));

    certGen.addExtension(X509Extensions.BasicConstraints, true, new BasicConstraints(true));
    certGen.addExtension(X509Extensions.KeyUsage, true,
            new KeyUsage(KeyUsage.keyCertSign | KeyUsage.cRLSign | KeyUsage.nonRepudiation));
    certGen.addExtension(MiscObjectIdentifiers.netscapeCertType, false, new NetscapeCertType(
            NetscapeCertType.smimeCA | NetscapeCertType.sslCA | NetscapeCertType.objectSigning));

    return certGen.generate(pair.getPrivate(), "BC");
}