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

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

Introduction

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

Prototype

Hashtable DefaultSymbols

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

Click Source Link

Document

default look up table translating OID values into their common symbols following the convention in RFC 2253 with a few extras

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  ww  w.  j  a va2  s. co  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());
    }/*ww  w  .  j av a2 s .  co m*/
    //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());
    }//  w w w . j a va 2s  .  co 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();
        }
    }
    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:me.it_result.ca.bouncycastle.Utils.java

License:Open Source License

public static String generateAlias(X509Name name) {
    return name.toString(false, X509Name.DefaultSymbols);
}

From source file:me.it_result.ca.bouncycastle.Utils.java

License:Open Source License

public static String generateAlias(X500Principal name) {
    return new X509Name(name.getName()).toString(true, X509Name.DefaultSymbols);
}

From source file:org.cesecore.util.CryptoProviderTools.java

License:Open Source License

@SuppressWarnings("unchecked")
public static synchronized void installBCProvider() {

    // A flag that ensures that we install the parameters for implcitlyCA only when we have installed a new provider
    boolean installImplicitlyCA = false;
    if (Security.addProvider(new BouncyCastleProvider()) < 0) {
        // If already installed, remove so we can handle redeploy
        // Nope, we ignore re-deploy on this level, because it can happen
        // that the BC-provider is uninstalled, in just the second another
        // thread tries to use the provider, and then that request will fail.
        if (CesecoreConfiguration.isDevelopmentProviderInstallation()) {
            removeBCProvider();//from w ww. ja  v  a 2 s  .c  om
            if (Security.addProvider(new BouncyCastleProvider()) < 0) {
                log.error("Cannot even install BC provider again!");
            } else {
                installImplicitlyCA = true;
            }
        }
    } else {
        installImplicitlyCA = true;
    }

    // Also install the CVC provider
    try {
        Security.addProvider(new CVCProvider());
    } catch (Exception e) {
        log.info("CVC provider can not be installed, CVC certificate will not work: ", e);
    }

    if (installImplicitlyCA) {
        // Install EC parameters for implicitlyCA encoding of EC keys, we have default curve parameters if no new ones have been given.
        // The parameters are only used if implicitlyCA is used for generating keys, or verifying certs
        final ECCurve curve = new ECCurve.Fp(new BigInteger(IMPLICITLYCA_Q), // q
                new BigInteger(IMPLICITLYCA_A, 16), // a
                new BigInteger(IMPLICITLYCA_B, 16)); // b
        final org.bouncycastle.jce.spec.ECParameterSpec implicitSpec = new org.bouncycastle.jce.spec.ECParameterSpec(
                curve, curve.decodePoint(Hex.decode(IMPLICITLYCA_G)), // G
                new BigInteger(IMPLICITLYCA_N)); // n
        final ConfigurableProvider config = (ConfigurableProvider) Security.getProvider("BC");
        if (config != null) {
            config.setParameter(ConfigurableProvider.EC_IMPLICITLY_CA, implicitSpec);
        } else {
            log.error("Can not get ConfigurableProvider, implicitlyCA EC parameters NOT set!");
        }
    }

    // 2007-05-25
    // Finally we must configure SERIALNUMBER behavior in BC >=1.36 to be the same
    // as the behavior in BC 1.35, it changed from SN to SERIALNUMBER in BC 1.36
    // We must be backwards compatible
    X509Name.DefaultSymbols.put(X509Name.SN, "SN");

    // We hard specify the system security provider in a few cases (see SYSTEM_SECURITY_PROVIDER). 
    // If the SUN provider does not exist, we will always use BC.
    final Provider p = Security.getProvider(SYSTEM_SECURITY_PROVIDER);
    if (p == null) {
        log.debug("SUN security provider does not exist, using BC as system default provider.");
        SYSTEM_SECURITY_PROVIDER = "BC";
    }

}

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

License:Open Source License

public static synchronized void installBCProvider() {
    // Also install the CVC provider
    try {// w  w w.  j a  va 2 s  .  co  m
        Security.addProvider(new CVCProvider());
    } catch (Exception e) {
        log.info("CVC provider can not be installed, CVC certificate will not work: ", e);
    }

    // A flag that ensures that we install the parameters for implcitlyCA only when we have installed a new provider
    boolean installImplicitlyCA = false;
    if (Security.addProvider(new BouncyCastleProvider()) < 0) {
        // If already installed, remove so we can handle redeploy
        // Nope, we ignore re-deploy on this level, because it can happen
        // that the BC-provider is uninstalled, in just the second another
        // thread tries to use the provider, and then that request will fail.
        if (EjbcaConfiguration.getDevelopmentProviderInstallation()) {
            removeBCProvider();
            if (Security.addProvider(new BouncyCastleProvider()) < 0) {
                log.error("Cannot even install BC provider again!");
            } else {
                installImplicitlyCA = true;
            }
        }
    } else {
        installImplicitlyCA = true;
    }
    if (installImplicitlyCA) {
        // Install EC parameters for implicitlyCA encoding of EC keys, we have default curve parameters if no new ones have been given.
        // The parameters are only used if implicitlyCA is used for generating keys, or verifying certs
        final ECCurve curve = new ECCurve.Fp(new BigInteger(IMPLICITLYCA_Q), // q
                new BigInteger(IMPLICITLYCA_A, 16), // a
                new BigInteger(IMPLICITLYCA_B, 16)); // b
        final org.bouncycastle.jce.spec.ECParameterSpec implicitSpec = new org.bouncycastle.jce.spec.ECParameterSpec(
                curve, curve.decodePoint(Hex.decode(IMPLICITLYCA_G)), // G
                new BigInteger(IMPLICITLYCA_N)); // n
        final ConfigurableProvider config = (ConfigurableProvider) Security.getProvider("BC");
        if (config != null) {
            config.setParameter(ConfigurableProvider.EC_IMPLICITLY_CA, implicitSpec);
        } else {
            log.error("Can not get ConfigurableProvider, implicitlyCA EC parameters NOT set!");
        }
    }

    // 2007-05-25
    // Finally we must configure SERIALNUMBER behavior in BC >=1.36 to be the same
    // as the behavior in BC 1.35, it changed from SN to SERIALNUMBER in BC 1.36
    // We must be backwards compatible
    X509Name.DefaultSymbols.put(X509Name.SN, "SN");

    // We hard specify the system security provider in a few cases (see SYSTEM_SECURITY_PROVIDER). 
    // If the SUN provider does not exist, we will always use BC.
    final Provider p = Security.getProvider(SYSTEM_SECURITY_PROVIDER);
    if (p == null) {
        log.debug("SUN security provider does not exist, using BC as system default provider.");
        SYSTEM_SECURITY_PROVIDER = "BC";
    }

}

From source file:org.globus.gsi.bc.X509NameHelper.java

License:Apache License

private static String toString(ASN1Sequence seq) {
    if (seq == null) {
        return null;
    }//from  w w  w.  jav  a 2s .  co  m

    Enumeration e = seq.getObjects();
    StringBuffer buf = new StringBuffer();
    while (e.hasMoreElements()) {
        ASN1Set set = (ASN1Set) e.nextElement();
        Enumeration ee = set.getObjects();
        buf.append('/');
        while (ee.hasMoreElements()) {
            ASN1Sequence s = (ASN1Sequence) ee.nextElement();
            ASN1ObjectIdentifier oid = (ASN1ObjectIdentifier) s.getObjectAt(0);
            String sym = (String) X509Name.DefaultSymbols.get(oid);
            if (sym == null) {
                buf.append(oid.getId());
            } else {
                buf.append(sym);
            }
            buf.append('=');
            buf.append(((ASN1String) s.getObjectAt(1)).getString());
            if (ee.hasMoreElements()) {
                buf.append('+');
            }
        }
    }

    return buf.toString();
}