本文整理汇总了Java中com.sun.net.ssl.TrustManager类的典型用法代码示例。如果您正苦于以下问题:Java TrustManager类的具体用法?Java TrustManager怎么用?Java TrustManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TrustManager类属于com.sun.net.ssl包,在下文中一共展示了TrustManager类的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createSSLContext
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static SSLContext createSSLContext() {
try {
ClassLoader cl = SimpleSocketFactory.class.getClassLoader();
URL url = cl.getResource("org/apache/commons/httpclient/ssl/simpleserver.keystore");
KeyStore keystore = KeyStore.getInstance("jks");
keystore.load(url.openStream(), "nopassword".toCharArray());
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(keystore);
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, trustmanagers, null);
return sslcontext;
} catch (Exception ex) {
// this is not the way a sane exception handling should be done
// but for our simple HTTP testing framework this will suffice
LOG.error(ex.getMessage(), ex);
throw new IllegalStateException(ex.getMessage());
}
}
示例2: createTrustManagers
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static TrustManager[] createTrustManagers(final KeyStore keystore)
throws KeyStoreException, NoSuchAlgorithmException
{
if (keystore == null) {
throw new IllegalArgumentException("Keystore may not be null");
}
LOG.debug("Initializing trust manager");
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(keystore);
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
for (int i = 0; i < trustmanagers.length; i++) {
if (trustmanagers[i] instanceof X509TrustManager) {
trustmanagers[i] = new AuthSSLX509TrustManager(
(X509TrustManager)trustmanagers[i]);
}
}
return trustmanagers;
}
示例3: createTrustManagers
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static TrustManager[] createTrustManagers(final KeyStore keystore, String algorithm)
throws KeyStoreException, NoSuchAlgorithmException
{
if (keystore == null) {
throw new IllegalArgumentException("Keystore may not be null");
}
log.debug("Initializing trust manager");
if (StringUtils.isEmpty(algorithm)) {
algorithm=TrustManagerFactory.getDefaultAlgorithm();
log.debug("using default TrustManager algorithm ["+algorithm+"]");
} else {
log.debug("using configured TrustManager algorithm ["+algorithm+"]");
}
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(algorithm);
tmfactory.init(keystore);
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
return trustmanagers;
}
示例4: createSSLContext
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static SSLContext createSSLContext() {
try {
ClassLoader cl = SimpleSocketFactory.class.getClassLoader();
URL url = cl.getResource("org/apache/commons/httpclient/ssl/simpleserver.keystore");
KeyStore keystore = KeyStore.getInstance("jks");
InputStream is = null;
try {
is = url.openStream();
keystore.load(is, "nopassword".toCharArray());
} finally {
if (is != null) is.close();
}
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(keystore);
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
SSLContext sslcontext = SSLContext.getInstance("TLS");
sslcontext.init(null, trustmanagers, null);
return sslcontext;
} catch (Exception ex) {
// this is not the way a sane exception handling should be done
// but for our simple HTTP testing framework this will suffice
LOG.error(ex.getMessage(), ex);
throw new IllegalStateException(ex.getMessage());
}
}
示例5: EasyX509TrustManager
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
/**
* Constructor for EasyX509TrustManager.
*/
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
super();
TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
factory.init(keystore);
TrustManager[] trustmanagers = factory.getTrustManagers();
if (trustmanagers.length == 0) {
throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
}
this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}
示例6: createEasySSLContext
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] { new EasyX509TrustManager(null) },
null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
示例7: initSSL
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
protected final Object initSSL(SSL ssl, TrustChain tc, KeyMaterial k)
throws NoSuchAlgorithmException, KeyStoreException,
CertificateException, KeyManagementException, IOException {
SSLContext context = SSLContext.getInstance(ssl.getDefaultProtocol());
TrustManager[] trustManagers = null;
KeyManager[] keyManagers = null;
if (tc != null) {
trustManagers = (TrustManager[]) tc.getTrustManagers();
}
if (k != null) {
keyManagers = (KeyManager[]) k.getKeyManagers();
}
if (keyManagers != null) {
for (int i = 0; i < keyManagers.length; i++) {
if (keyManagers[i] instanceof X509KeyManager) {
X509KeyManager km = (X509KeyManager) keyManagers[i];
keyManagers[i] = new Java13KeyManagerWrapper(km, k, ssl);
}
}
}
if (trustManagers != null) {
for (int i = 0; i < trustManagers.length; i++) {
if (trustManagers[i] instanceof X509TrustManager) {
X509TrustManager tm = (X509TrustManager) trustManagers[i];
trustManagers[i] = new Java13TrustManagerWrapper(tm, tc, ssl);
}
}
}
context.init(keyManagers, trustManagers, null);
return context;
}
示例8: EasyX509TrustManager
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
/**
* Constructor for EasyX509TrustManager.
*/
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
super();
TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
factory.init(keystore);
TrustManager[] trustmanagers = factory.getTrustManagers();
if (trustmanagers.length == 0) {
throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
}
this.standardTrustManager = (X509TrustManager)trustmanagers[0];
}
示例9: createEasySSLContext
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {new EasyX509TrustManager(null)},
null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
示例10: AuthSslTrustManager
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
AuthSslTrustManager(KeyStore keystore, TrustManager[] trustmanagers) throws NoSuchAlgorithmException, KeyStoreException {
if (trustmanagers == null || trustmanagers.length == 0) {
TrustManagerFactory factory = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
factory.init(keystore);
trustmanagers = factory.getTrustManagers();
}
if (trustmanagers.length != 1) {
throw new NoSuchAlgorithmException("Only works with X509 trustmanagers");
}
trustManager = (X509TrustManager)trustmanagers[0];
}
示例11: EasyX509TrustManager
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
/**
* Constructor for EasyX509TrustManager.
*/
public EasyX509TrustManager(KeyStore keystore) throws NoSuchAlgorithmException, KeyStoreException {
super();
TrustManagerFactory factory = TrustManagerFactory.getInstance("SunX509");
factory.init(keystore);
TrustManager[] trustmanagers = factory.getTrustManagers();
if (trustmanagers.length == 0) {
throw new NoSuchAlgorithmException("SunX509 trust manager not supported");
}
this.standardTrustManager = (X509TrustManager) trustmanagers[0];
}
示例12: createEasySSLContext
import com.sun.net.ssl.TrustManager; //导入依赖的package包/类
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[]{new EasyX509TrustManager(null)}, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}