当前位置: 首页>>代码示例>>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;未经允许,请勿转载。