当前位置: 首页>>代码示例>>Java>>正文


Java TrustManager类代码示例

本文整理汇总了Java中javax.net.ssl.TrustManager的典型用法代码示例。如果您正苦于以下问题:Java TrustManager类的具体用法?Java TrustManager怎么用?Java TrustManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


TrustManager类属于javax.net.ssl包,在下文中一共展示了TrustManager类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: disableCertificateValidation

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public static void disableCertificateValidation() 
{
    // Create a trust manager that does not validate certificate chains
    TrustManager[] trustAllCerts = new TrustManager[] 
    { 
      new TrustAllManager() 
    };

    // Ignore differences between given hostname and certificate hostname
    HostnameVerifier hv = new TrustAllHostnameVerifier();
    
    // Install the all-trusting trust manager
    try 
    {
      SSLContext sc = SSLContext.getInstance("SSL");
      sc.init(null, trustAllCerts, new SecureRandom());
      HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
      HttpsURLConnection.setDefaultHostnameVerifier(hv);
    } catch (Exception e) {}
}
 
开发者ID:johndavidbustard,项目名称:RoughWorld,代码行数:21,代码来源:WebClient.java

示例2: afterPropertiesSet

import javax.net.ssl.TrustManager; //导入依赖的package包/类
@PostConstruct
public void afterPropertiesSet() throws Exception {
	RegistryBuilder<ConnectionSocketFactory> schemeRegistry = RegistryBuilder.create();

	schemeRegistry.register("http", PlainConnectionSocketFactory.getSocketFactory());

	SSLContext sslcontext = SSLContext.getInstance("TLS");
	sslcontext.init(new KeyManager[0], new TrustManager[]{new SimpleTrustManager()}, null);
	SSLConnectionSocketFactory sf = new SSLConnectionSocketFactory(sslcontext);
	schemeRegistry.register("https", sf);

	pool = new PoolingHttpClientConnectionManager(schemeRegistry.build());
	pool.setMaxTotal(maxConnection);
	pool.setDefaultMaxPerRoute(maxConnection);
	pool.setDefaultSocketConfig(SocketConfig.custom().setSoTimeout(sotimeout).build());
}
 
开发者ID:funtl,项目名称:framework,代码行数:17,代码来源:HttpClientUtil.java

示例3: createSocketFactory

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public SocketFactory createSocketFactory() {
    try {
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, new TrustManager[] { this }, null);
        return sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException | KeyManagementException e) {
        throw new RuntimeException("Failed to create a SSL socket factory");
    }
}
 
开发者ID:MCMrARM,项目名称:revolution-irc,代码行数:10,代码来源:UserOverrideTrustManager.java

示例4: KeyStoresTrustManager

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public KeyStoresTrustManager(KeyStore... keyStores) throws NoSuchAlgorithmException, KeyStoreException {
    super();

    for (KeyStore keystore : keyStores) {
        TrustManagerFactory factory = TrustManagerFactory.getInstance("JKS");
        factory.init(keystore);
        TrustManager[] tms = factory.getTrustManagers();
        if (tms.length == 0) {
            throw new NoSuchAlgorithmException("Unable to load keystore");
        }
        trustManagers.add((X509TrustManager) tms[0]);
    }

    //Build accepted issuers list
    Set<X509Certificate> issuers = new HashSet<X509Certificate>();
    for (X509TrustManager tm : trustManagers) {
        for (X509Certificate issuer : tm.getAcceptedIssuers()) {
            issuers.add(issuer);
        }
    }
    acceptedIssuers = issuers.toArray(new X509Certificate[issuers.size()]);
}
 
开发者ID:blackarbiter,项目名称:Android_Code_Arbiter,代码行数:23,代码来源:KeyStoresTrustManager.java

示例5: allowAllSSL

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public static void allowAllSSL() {
    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        public boolean verify(String arg0, SSLSession arg1) {
            return true;
        }
    });
    SSLContext context = null;
    if (trustManagers == null) {
        trustManagers = new TrustManager[]{new HttpsTrustManager()};
    }
    try {
        context = SSLContext.getInstance("TLS");
        context.init(null, trustManagers, new SecureRandom());
    } catch (NoSuchAlgorithmException e) {
        e.printStackTrace();
    } catch (KeyManagementException e2) {
        e2.printStackTrace();
    }
    HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:HttpsTrustManager.java

示例6: testConstructor

import javax.net.ssl.TrustManager; //导入依赖的package包/类
@SuppressWarnings("unused")
@Test
public void testConstructor() {
  String keyStoreName = custom.getFullPath(option.getKeyStore());
  char[] keyStoreValue = custom.decode(option.getKeyStoreValue().toCharArray());
  String trustStoreName = custom.getFullPath(option.getTrustStore());
  char[] trustStoreValue =
      custom.decode(option.getTrustStoreValue().toCharArray());
  KeyStore trustStore =
      KeyStoreUtil.createKeyStore(trustStoreName,
          option.getTrustStoreType(),
          trustStoreValue);
  TrustManager[] trustManager = KeyStoreUtil.createTrustManagers(trustStore);

  TrustManagerExt trustManagerExt = new TrustManagerExt((X509ExtendedTrustManager) trustManager[0],
      option, custom);
  Assert.assertEquals(3, trustManagerExt.getAcceptedIssuers()[0].getVersion());
  Assert.assertNotNull(trustManagerExt);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:20,代码来源:TrustManagerExtTest.java

示例7: getSslContext

import javax.net.ssl.TrustManager; //导入依赖的package包/类
/**
 * Gets the ssl context for use making the connections
 *
 * @return the ssl context
 */
public SSLContext getSslContext() {
    KeyManager[] keyManagers = getKeyManagers();
    TrustManager[] trustManagers = getTrustManagers();
    if (keyManagers != null || trustManagers != null) {
        try {
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(getKeyManagers(), trustManagers, null);
            sslContext.getDefaultSSLParameters().setNeedClientAuth(true);
            return sslContext;
        } catch (Exception e) {
            throw new IllegalStateException("Created keystore and truststore but failed to initialize SSLContext", e);
        }
    } else {
        return null;
    }
}
 
开发者ID:hortonworks,项目名称:nifi-android-s2s,代码行数:22,代码来源:SiteToSiteRemoteCluster.java

示例8: getTrustManagers

import javax.net.ssl.TrustManager; //导入依赖的package包/类
@Override
public TrustManager[] getTrustManagers() throws Exception {
	String truststoreType = endpoint.getTruststoreType();
	if (truststoreType == null) {
		truststoreType = System.getProperty("javax.net.ssl.trustStoreType");
	}
	if (truststoreType == null) {
		truststoreType = endpoint.getKeystoreType();
	}
	if (truststoreType == null) {
		truststoreType = defaultKeystoreType;
	}

	String algorithm = endpoint.getTruststoreAlgorithm();
	if (algorithm == null) {
		algorithm = TrustManagerFactory.getDefaultAlgorithm();
	}

	return getTrustManagers(truststoreType, endpoint.getKeystoreProvider(), algorithm);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:21,代码来源:JSSESocketFactory.java

示例9: __trustAllHttpsCertificates

import javax.net.ssl.TrustManager; //导入依赖的package包/类
/**
 * Set the default X509 Trust Manager to an instance of a fake class that
 * trust all certificates, even the self-signed ones. This method uses the
 * old deprecated API from the com.sun.ssl package.
 *
 * @deprecated see {@link #_trustAllHttpsCertificates()}.
 */
private static void __trustAllHttpsCertificates() {
  com.sun.net.ssl.SSLContext context;

  // Create a trust manager that does not validate certificate chains
  if (__trustManagers == null) {
    __trustManagers =
        new com.sun.net.ssl.TrustManager[]{new SSLUtilities._FakeX509TrustManager()};
  } // if
  // Install the all-trusting trust manager
  try {
    context = com.sun.net.ssl.SSLContext.getInstance("SSL");
    context.init(null, __trustManagers, new SecureRandom());
  } catch (GeneralSecurityException gse) {
    throw new IllegalStateException(gse.getMessage());
  } // catch
  com.sun.net.ssl.HttpsURLConnection.setDefaultSSLSocketFactory(context
      .getSocketFactory());
}
 
开发者ID:logistimo,项目名称:logistimo-web-service,代码行数:26,代码来源:SSLUtilities.java

示例10: getSslSocketFactory

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public static SSLParams getSslSocketFactory(InputStream[] certificates, InputStream bksFile, String password) {
    SSLParams sslParams = new SSLParams();
    try {
        TrustManager[] trustManagers = prepareTrustManager(certificates);
        KeyManager[] keyManagers = prepareKeyManager(bksFile, password);
        SSLContext sslContext = SSLContext.getInstance("TLS");
        X509TrustManager trustManager = null;
        if (trustManagers != null) {
            trustManager = new MyTrustManager(chooseTrustManager(trustManagers));
        } else {
            trustManager = new UnSafeTrustManager();
        }
        sslContext.init(keyManagers, new TrustManager[]{trustManager}, null);
        sslParams.sSLSocketFactory = sslContext.getSocketFactory();
        sslParams.trustManager = trustManager;
        return sslParams;
    } catch (NoSuchAlgorithmException | KeyManagementException | KeyStoreException e) {
        throw new AssertionError(e);
    }
}
 
开发者ID:huashengzzz,项目名称:SmartChart,代码行数:21,代码来源:HttpsUtils.java

示例11: createSocketFactory

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public static SSLSocketFactory createSocketFactory(
	final String caCertificateFileName, 
	final String clientCertificateFileName, 
	final String clientKeyFileName) throws Exception
{
	// Creates a TLS socket factory with the given 
	// CA certificate file, client certificate, client key
	// In this case, we are working without a client key password
	final String clientKeyPassword = "";
	try
	{
		Security.addProvider(new BouncyCastleProvider());
		final KeyManager[] keyManagers = createKeyManagerFactory(clientCertificateFileName, clientKeyFileName, clientKeyPassword).getKeyManagers();
		final TrustManager[] trustManagers = createTrustManagerFactory(caCertificateFileName).getTrustManagers();
		
		// Create the TLS socket factory for the desired TLS version
		final SSLContext context = SSLContext.getInstance(TLS_VERSION);
		
		context.init(keyManagers, trustManagers, new SecureRandom());
		//context.init(keyManagers, trustManagers, null);

		return context.getSocketFactory();			
	}
	catch (Exception e)
	{
		throw new Exception("I cannot create the TLS socket factory.", e);
	}		
}
 
开发者ID:PacktPublishing,项目名称:MQTT-Essentials-A-Lightweight-IoT-Protocol,代码行数:29,代码来源:SecurityHelper.java

示例12: createDefaultSSLSocketFactory

import javax.net.ssl.TrustManager; //导入依赖的package包/类
/**
 * 创建一个默认的,空的信任管理工厂
 *
 * @return 返回创建的信任管理工厂
 */
private static SSLSocketFactory createDefaultSSLSocketFactory() throws Exception {
    TrustManager[] tm = {new DefaultX509TrustManager()};
    SSLContext sslContext = null;
    SSLSocketFactory factory = null;
    try {
        sslContext = SSLContext.getInstance("SSL", "SunJSSE");
        sslContext.init(null, tm, new SecureRandom());

        factory = sslContext.getSocketFactory();
    } catch (NoSuchAlgorithmException | NoSuchProviderException | KeyManagementException e) {
        logger.error(e.getMessage());
    }

    if (null == factory) {
        throw new Exception("SSLSocketFactory is null");
    }

    return factory;
}
 
开发者ID:DomKing,项目名称:server-utility,代码行数:25,代码来源:HttpsUtil.java

示例13: newChannel

import javax.net.ssl.TrustManager; //导入依赖的package包/类
@Override
public SocketChannel newChannel(ChannelPipeline pipeline) {
  try {
    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(null, new TrustManager[]{new PermissiveTrustManager()},
                    null);
    SSLEngine sslEngine = sslContext.createSSLEngine();
    sslEngine.setUseClientMode(true);
    // addFirst() will make SSL handling the first stage of decoding
    // and the last stage of encoding
    pipeline.addFirst("ssl", new SslHandler(sslEngine));
    return super.newChannel(pipeline);
  } catch (Exception ex) {
    throw new RuntimeException("Cannot create SSL channel", ex);
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:17,代码来源:TestAvroSource.java

示例14: initTrustAllSSLcontext

import javax.net.ssl.TrustManager; //导入依赖的package包/类
public static SSLSocketFactory initTrustAllSSLcontext(TrustManager[] trustAllCerts) throws NoSuchAlgorithmException,
                                                                                   KeyManagementException {
   // Install the all-trusting trust manager
   SSLSocketFactory sslSocketfactory = null;
   final SSLContext sc = SSLContext.getInstance("SSL");
   sc.init(null, trustAllCerts, new java.security.SecureRandom());
   HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
   sslSocketfactory = sc.getSocketFactory();
   return sslSocketfactory;
}
 
开发者ID:mqsysadmin,项目名称:dpdirect,代码行数:11,代码来源:SSL.java

示例15: getX509TrustManager

import javax.net.ssl.TrustManager; //导入依赖的package包/类
private X509TrustManager getX509TrustManager() {
	try {
		TrustManagerFactory trustManagerFactory = TrustManagerFactory
				.getInstance(TrustManagerFactory.getDefaultAlgorithm());
		trustManagerFactory.init((KeyStore) null);
		TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
		if (trustManagers.length == 1 && (trustManagers[0] instanceof X509TrustManager)) {
			return (X509TrustManager) trustManagers[0];
		} else {
			LOG.error(String.format("Error while retrieving X509 trust manager! " + "(TrustMangers: %s)",
					Arrays.toString(trustManagers)));
			return null;
		}
	} catch (NoSuchAlgorithmException | KeyStoreException e) {
		LOG.error("Error while retrieving X509 trust manager!", e);
		return null;
	}
}
 
开发者ID:michaelnetter,项目名称:dracoon-dropzone,代码行数:19,代码来源:RestClient.java


注:本文中的javax.net.ssl.TrustManager类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。