本文整理汇总了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() + ")"); }
}