當前位置: 首頁>>代碼示例>>Java>>正文


Java X509Certificate.getSubjectDN方法代碼示例

本文整理匯總了Java中javax.security.cert.X509Certificate.getSubjectDN方法的典型用法代碼示例。如果您正苦於以下問題:Java X509Certificate.getSubjectDN方法的具體用法?Java X509Certificate.getSubjectDN怎麽用?Java X509Certificate.getSubjectDN使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.security.cert.X509Certificate的用法示例。


在下文中一共展示了X509Certificate.getSubjectDN方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: enrichWithClientCertInformation

import javax.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Enriches the message with client certificate details such as subject name, serial number etc.
 * <p/>
 * If the certificate is unverified then the headers is not enriched.
 *
 * @param sslSession  the SSL session
 * @param message     the message to enrich
 */
protected void enrichWithClientCertInformation(SSLSession sslSession, Message message) {
    try {
        X509Certificate[] certificates = sslSession.getPeerCertificateChain();
        if (certificates != null && certificates.length > 0) {
            X509Certificate cert = certificates[0];

            Principal subject = cert.getSubjectDN();
            if (subject != null) {
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SUBJECT_NAME, subject.getName());
            }
            Principal issuer = cert.getIssuerDN();
            if (issuer != null) {
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_ISSUER_NAME, issuer.getName());
            }
            BigInteger serial = cert.getSerialNumber();
            if (serial != null) {
                message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_SERIAL_NO, serial.toString());
            }
            message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_BEFORE, cert.getNotBefore());
            message.setHeader(NettyConstants.NETTY_SSL_CLIENT_CERT_NOT_AFTER, cert.getNotAfter());
        }
    } catch (SSLPeerUnverifiedException e) {
        // ignore
    }
}
 
開發者ID:HydAu,項目名稱:Camel,代碼行數:34,代碼來源:NettyEndpoint.java

示例2: verify

import javax.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Verifies the certificate chain presented by the server to which
 * a secure Socket has just connected.  Specifically, the provided host
 * name is checked against the Common Name of the server certificate;
 * additional checks may or may not be performed.
 *
 * @param host the requested host name
 * @param session SSLSession used on the connection to host
 * @throws Exception if the certificate chain cannot be verified
 */
protected void verify(String host, SSLSession session) throws Exception {

    X509Certificate[] chain;
    X509Certificate   certificate;
    Principal         principal;
    PublicKey         publicKey;
    String            DN;
    String            CN;
    int               start;
    int               end;
    String            emsg;

    chain       = session.getPeerCertificateChain();
    certificate = chain[0];
    principal   = certificate.getSubjectDN();
    DN          = String.valueOf(principal);
    start       = DN.indexOf("CN=");

    if (start < 0) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_1));
    }

    start += 3;
    end   = DN.indexOf(',', start);
    CN    = DN.substring(start, (end > -1) ? end
                                           : DN.length());

    if (CN.length() < 1) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_2));
    }

    if (!CN.equalsIgnoreCase(host)) {

        // TLS_HOSTNAME_MISMATCH
        throw new UnknownHostException(
            Error.getMessage(
                ErrorCode.M_SERVER_SECURE_VERIFY_3, 0, new Object[] {
            CN, host
        }));
    }
}
 
開發者ID:tiweGH,項目名稱:OpenDiabetes,代碼行數:54,代碼來源:HsqlSocketFactorySecure.java

示例3: verify

import javax.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Verifyies the certificate chain presented by the server to which
 * a secure Socket has just connected.  Specifically, the provided host
 * name is checked against the Common Name of the server certificate;
 * additional checks may or may not be performed.
 *
 * @param host the requested host name
 * @param session SSLSession used on the connection to host
 * @throws Exception if the certificate chain cannot be verified
 */
protected void verify(String host, SSLSession session) throws Exception {

    X509Certificate[] chain;
    X509Certificate   certificate;
    Principal         principal;
    PublicKey         publicKey;
    String            DN;
    String            CN;
    int               start;
    int               end;
    String            emsg;

    chain       = session.getPeerCertificateChain();
    certificate = chain[0];
    principal   = certificate.getSubjectDN();
    DN          = String.valueOf(principal);
    start       = DN.indexOf("CN=");

    if (start < 0) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_1));
    }

    start += 3;
    end   = DN.indexOf(',', start);
    CN    = DN.substring(start, (end > -1) ? end
                                           : DN.length());

    if (CN.length() < 1) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_2));
    }

    if (!CN.equalsIgnoreCase(host)) {

        // TLS_HOSTNAME_MISMATCH
        throw new UnknownHostException(
            Error.getMessage(
                ErrorCode.M_SERVER_SECURE_VERIFY_3, 0, new Object[] {
            CN, host
        }));
    }
}
 
開發者ID:Julien35,項目名稱:dev-courses,代碼行數:54,代碼來源:HsqlSocketFactorySecure.java

示例4: verify

import javax.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Verifyies the certificate chain presented by the server to which
 * a secure Socket has just connected.  Specifically, the provided host
 * name is checked against the Common Name of the server certificate;
 * additional checks may or may not be performed.
 *
 * @param host the requested host name
 * @param session SSLSession used on the connection to host
 * @throws Exception if the certificate chain cannot be verified
 */
protected void verify(String host, SSLSession session) throws Exception {

    X509Certificate[] chain;
    X509Certificate   certificate;
    Principal         principal;
    PublicKey         publicKey;
    String            DN;
    String            CN;
    int               start;
    int               end;
    String            emsg;

    chain       = session.getPeerCertificateChain();
    certificate = chain[0];
    principal   = certificate.getSubjectDN();
    DN          = String.valueOf(principal);
    start       = DN.indexOf("CN=");

    if (start < 0) {
        throw new UnknownHostException(
            Trace.getMessage(Trace.HsqlSocketFactorySecure_verify));
    }

    start += 3;
    end   = DN.indexOf(',', start);
    CN    = DN.substring(start, (end > -1) ? end
                                           : DN.length());

    if (CN.length() < 1) {
        throw new UnknownHostException(
            Trace.getMessage(Trace.HsqlSocketFactorySecure_verify2));
    }

    if (!CN.equalsIgnoreCase(host)) {

        // TLS_HOSTNAME_MISMATCH
        throw new UnknownHostException(
            Trace.getMessage(
                Trace.HsqlSocketFactorySecure_verify3, true,
                new Object[] {
            CN, host
        }));
    }
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:55,代碼來源:HsqlSocketFactorySecure.java

示例5: verify

import javax.security.cert.X509Certificate; //導入方法依賴的package包/類
/**
 * Verifyies the certificate chain presented by the server to which
 * a secure Socket has just connected.  Specifically, the provided host
 * name is checked against the Common Name of the server certificate;
 * additional checks may or may not be performed.
 *
 * @param host the requested host name
 * @param session SSLSession used on the connection to host
 * @throws Exception if the certificate chain cannot be verified
 */
protected void verify(String host, SSLSession session) throws Exception {

    X509Certificate[] chain;
    X509Certificate   certificate;
    Principal         principal;
    PublicKey         publicKey;
    String            DN;
    String            CN;
    int               start;
    int               end;
    String            emsg;

    chain       = session.getPeerCertificateChain();
    certificate = chain[0];
    principal   = certificate.getSubjectDN();
    DN          = String.valueOf(principal);
    start       = DN.indexOf("CN=");

    if (start < 0) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_1));
    }

    start += 3;
    end   = DN.indexOf(',', start);
    CN    = DN.substring(start, (end > -1) ? end
                                           : DN.length());

    if (CN.length() < 1) {
        throw new UnknownHostException(
            Error.getMessage(ErrorCode.M_SERVER_SECURE_VERIFY_2));
    }

    if (!CN.equalsIgnoreCase(host)) {

        // TLS_HOSTNAME_MISMATCH
        throw new UnknownHostException(
            Error.getMessage(
                ErrorCode.M_SERVER_SECURE_VERIFY_3, 0,
                new Object[] {
            CN, host
        }));
    }
}
 
開發者ID:RabadanLab,項目名稱:Pegasus,代碼行數:55,代碼來源:HsqlSocketFactorySecure.java


注:本文中的javax.security.cert.X509Certificate.getSubjectDN方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。