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


Java SSLSession.getPeerPrincipal方法代碼示例

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


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

示例1: verify

import javax.net.ssl.SSLSession; //導入方法依賴的package包/類
/**
 * Verify that the host name is an acceptable match with
 * the server's authentication scheme.
 *
 * @param hostname the host name
 * @param session SSLSession used on the connection to host
 * @return true if the host name is acceptable
 */
@Override
public boolean verify(String hostname, SSLSession session) {
    ParamUtil.requireNonNull("hostname", hostname);
    if (trustAll) {
        return true;
    }

    LOG.info("hostname: {}", hostname);
    String commonName = null;
    try {
        Principal peerPrincipal = session.getPeerPrincipal();
        if (peerPrincipal == null) {
            return false;
        }
        commonName = X509Util.getCommonName(new X500Name(peerPrincipal.getName()));
        LOG.info("commonName: {}", commonName);
    } catch (Exception ex) {
        LogUtil.error(LOG, ex);
        return false;
    }

    Set<String> hostnames = hostnameMap.get(commonName);
    return (hostnames == null) ? false : hostnames.contains(hostname);
}
 
開發者ID:xipki,項目名稱:xitk,代碼行數:33,代碼來源:HttpsHostnameVerifier.java

示例2: getPeerPrincipal

import javax.net.ssl.SSLSession; //導入方法依賴的package包/類
private static Principal getPeerPrincipal(SSLSession session)
        throws SSLPeerUnverifiedException {
    Principal principal;
    try {
        principal = session.getPeerPrincipal();
    } catch (AbstractMethodError e) {
        // if the JSSE provider does not support it, return null, since
        // we need it only for Kerberos.
        principal = null;
    }
    return principal;
}
 
開發者ID:SunburstApps,項目名稱:OpenJSharp,代碼行數:13,代碼來源:StartTlsResponseImpl.java

示例3: verifyHostname

import javax.net.ssl.SSLSession; //導入方法依賴的package包/類
/**
 * Verify hostname against certificate
 * @param sslSocket Socket
 * @param host Host name
 * @throws IOException Exception if host name is not verified
 */
private void verifyHostname(SSLSocket sslSocket, String host) throws IOException {
    // Make sure we started handshake before verifying
    sslSocket.startHandshake();

    SSLSession session = sslSocket.getSession();
    if (session == null) {
        throw new SSLException("Hostname '" + host + "' was not verified (no session)");
    }
    if (!hostnameVerifier.verify(host, session)) {
        throw new SSLPeerUnverifiedException("Hostname '" + host + "' was not verified (" + session.getPeerPrincipal() + ")");
    }
    if (Logger.DEBUG) { Log.d(TAG, "Connected to " + session.getPeerHost() + " using " + session.getProtocol() + " (" + session.getCipherSuite() + ")"); }
}
 
開發者ID:bfabiszewski,項目名稱:ulogger-android,代碼行數:20,代碼來源:TlsSocketFactory.java


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