Example usage for java.security.cert X509Certificate getSubjectDN

List of usage examples for java.security.cert X509Certificate getSubjectDN

Introduction

In this page you can find the example usage for java.security.cert X509Certificate getSubjectDN.

Prototype

public abstract Principal getSubjectDN();

Source Link

Document

Denigrated, replaced by #getSubjectX500Principal() .

Usage

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
 *//*from w  w w . j a  va  2s . co m*/
public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isInfoEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.info(" Client certificate " + (c + 1) + ":");
            LOG.info("  Subject DN: " + cert.getSubjectDN());
            LOG.info("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.info("  Valid from: " + cert.getNotBefore());
            LOG.info("  Valid until: " + cert.getNotAfter());
            LOG.info("  Issuer: " + cert.getIssuerDN());
        }
    }
    defaultTrustManager.checkClientTrusted(certificates, authType);
}

From source file:au.edu.monash.merc.capture.util.httpclient.ssl.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[],String authType)
 *///from w  ww  .j  a  va 2s .  c  om
public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isInfoEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.info(" Server certificate " + (c + 1) + ":");
            LOG.info("  Subject DN: " + cert.getSubjectDN());
            LOG.info("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.info("  Valid from: " + cert.getNotBefore());
            LOG.info("  Valid until: " + cert.getNotAfter());
            LOG.info("  Issuer: " + cert.getIssuerDN());
        }
    }
    defaultTrustManager.checkServerTrusted(certificates, authType);
}

From source file:org.ovirt.engine.core.utils.ssl.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[], String authType)
 */// w  w w  .  j ava 2 s. c o m
public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isDebugEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.debug(" Client certificate " + (c + 1) + ":");
            LOG.debug("  Subject DN: " + cert.getSubjectDN());
            LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.debug("  Valid from: " + cert.getNotBefore());
            LOG.debug("  Valid until: " + cert.getNotAfter());
            LOG.debug("  Issuer: " + cert.getIssuerDN());
        }
    }
    defaultTrustManager.checkClientTrusted(certificates, authType);
}

From source file:org.ovirt.engine.core.utils.ssl.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkServerTrusted(X509Certificate[], String authType)
 *//*from  www.j a va  2 s  . co  m*/
public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isDebugEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.debug(" Server certificate " + (c + 1) + ":");
            LOG.debug("  Subject DN: " + cert.getSubjectDN());
            LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.debug("  Valid from: " + cert.getNotBefore());
            LOG.debug("  Valid until: " + cert.getNotAfter());
            LOG.debug("  Issuer: " + cert.getIssuerDN());
        }
    }
    defaultTrustManager.checkServerTrusted(certificates, authType);
}

From source file:com.netscape.cmstools.pkcs7.PKCS7CertExportCLI.java

public void execute(String[] args) throws Exception {

    CommandLine cmd = parser.parse(options, args, true);

    if (cmd.hasOption("help")) {
        printHelp();//w  w w .  ja v a 2s .co  m
        return;
    }

    if (cmd.hasOption("verbose")) {
        PKILogger.setLevel(PKILogger.Level.INFO);

    } else if (cmd.hasOption("debug")) {
        PKILogger.setLevel(PKILogger.Level.DEBUG);
    }

    String filename = cmd.getOptionValue("pkcs7-file");

    if (filename == null) {
        throw new Exception("Missing PKCS #7 file.");
    }

    logger.info("Loading PKCS #7 data from " + filename);
    String str = new String(Files.readAllBytes(Paths.get(filename))).trim();
    PKCS7 pkcs7 = new PKCS7(str);

    X509Certificate[] certs = pkcs7.getCertificates();
    if (certs == null || certs.length == 0) {
        System.out.println("PKCS #7 data contains no certificates");
        return;
    }

    // sort certs from root to leaf
    certs = CryptoUtil.sortCertificateChain(certs);

    String prefix = cmd.getOptionValue("output-prefix", filename + "-");
    String suffix = cmd.getOptionValue("output-suffix", "");
    int i = 0;

    for (X509Certificate cert : certs) {

        logger.info("Exporting certificate #" + i + ": " + cert.getSubjectDN());

        String output = prefix + i + suffix;

        try (PrintWriter out = new PrintWriter(new FileWriter(output))) {
            out.println(Cert.HEADER);
            out.print(Utils.base64encode(cert.getEncoded(), true));
            out.println(Cert.FOOTER);
        }

        System.out.println(output + ": " + cert.getSubjectDN());

        i++;
    }
}

From source file:org.wso2.carbon.identity.application.common.util.IdentityApplicationManagementUtil.java

/**
 * @param cert/*www  . j  a v  a  2s. c om*/
 * @param formatter
 * @return
 * @throws CertificateEncodingException
 */
private static CertData fillCertData(X509Certificate cert, Format formatter)
        throws CertificateEncodingException {

    CertData certData = new CertData();
    certData.setSubjectDN(cert.getSubjectDN().getName());
    certData.setIssuerDN(cert.getIssuerDN().getName());
    certData.setSerialNumber(cert.getSerialNumber());
    certData.setVersion(cert.getVersion());
    certData.setNotAfter(formatter.format(cert.getNotAfter()));
    certData.setNotBefore(formatter.format(cert.getNotBefore()));
    certData.setPublicKey(Base64.encode(cert.getPublicKey().getEncoded()));
    return certData;
}

From source file:io.cloudslang.content.mail.sslconfig.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkServerTrusted(java.security.cert.X509Certificate[], String authType)
 *//*w w w . j a v  a2s.com*/
public void checkServerTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isInfoEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.info(" Server certificate " + (c + 1) + ":");
            LOG.info("  Subject DN: " + cert.getSubjectDN());
            LOG.info("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.info("  Valid from: " + cert.getNotBefore());
            LOG.info("  Valid until: " + cert.getNotAfter());
            LOG.info("  Issuer: " + cert.getIssuerDN());
            LOG.info("  SN: " + cert.getSerialNumber().toString(16));
        }
    }
    defaultTrustManager.checkServerTrusted(certificates, authType);
}

From source file:com.thoughtworks.go.security.AuthSSLKeyManagerFactory.java

private void logKeyStore(KeyStore store) throws KeyStoreException {
    LOG.trace("Certificates count: " + store.size());
    Enumeration aliases = store.aliases();
    while (aliases.hasMoreElements()) {
        String alias = (String) aliases.nextElement();
        Certificate[] certs = store.getCertificateChain(alias);
        if (certs != null) {
            LOG.debug("Certificate chain '" + alias + "':");
            for (int c = 0; c < certs.length; c++) {
                if (certs[c] instanceof X509Certificate) {
                    X509Certificate cert = (X509Certificate) certs[c];
                    LOG.trace(" Certificate " + (c + 1) + ":");
                    LOG.trace("  Subject DN: " + cert.getSubjectDN());
                    LOG.trace("  Signature Algorithm: " + cert.getSigAlgName());
                    LOG.trace("  Valid from: " + cert.getNotBefore());
                    LOG.trace("  Valid until: " + cert.getNotAfter());
                    LOG.trace("  Issuer: " + cert.getIssuerDN());
                }/*from  www .j a  v a 2 s .  c o m*/
            }
        }
    }
}

From source file:com.adito.boot.KeyStoreManager.java

/**
 * Utility method to extract an entity from a certificates subject DN
 * //from  ww w.ja  va 2  s . c  o m
 * @param c certificate
 * @param entity entity to extract
 * @return entity value
 */
public static String getX509CertificateEntity(X509Certificate c, String entity) {
    // This assumes the keystore returns the last certificate in the chain
    // the actual certifcate that is signed by a CA or untrusted cert
    Principal subjectPrincipal = c.getSubjectDN();
    StringTokenizer t = new StringTokenizer(subjectPrincipal.getName(), ",");
    while (t.hasMoreTokens()) {
        String e = t.nextToken().trim();
        String f = entity.trim() + "=";
        if (e.toLowerCase().startsWith(f.toLowerCase())) {
            return e.substring(f.length()).trim();
        }
    }
    return "";
}

From source file:gov.va.med.imaging.proxy.ssl.AuthSSLX509TrustManager.java

/**
 * @see javax.net.ssl.X509TrustManager#checkClientTrusted(X509Certificate[],String authType)
 *///from  w  w w . j  a v a 2s  .c  o m
public void checkClientTrusted(X509Certificate[] certificates, String authType) throws CertificateException {
    if (LOG.isInfoEnabled() && certificates != null) {
        for (int c = 0; c < certificates.length; c++) {
            X509Certificate cert = certificates[c];
            LOG.debug(" Client certificate " + (c + 1) + ":");
            LOG.debug("  Subject DN: " + cert.getSubjectDN());
            LOG.debug("  Signature Algorithm: " + cert.getSigAlgName());
            LOG.debug("  Valid from: " + cert.getNotBefore());
            LOG.debug("  Valid until: " + cert.getNotAfter());
            LOG.debug("  Issuer: " + cert.getIssuerDN());
        }
    }
    defaultTrustManager.checkClientTrusted(certificates, authType);
}