本文整理匯總了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);
}
示例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;
}
示例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() + ")"); }
}