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


Java HttpsURLConnection.setDefaultSSLSocketFactory方法代码示例

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


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

示例1: disableCertificateValidation

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的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: disableSslChecks

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/** Deshabilita las comprobaciones de certificados en conexiones SSL, aceptádose entonces
 * cualquier certificado.
 * @throws KeyManagementException Si hay problemas en la gestión de claves SSL.
 * @throws NoSuchAlgorithmException Si el JRE no soporta algún algoritmo necesario.
 * @throws KeyStoreException Si no se puede cargar el KeyStore SSL.
 * @throws IOException Si hay errores en la carga del fichero KeyStore SSL.
 * @throws CertificateException Si los certificados del KeyStore SSL son inválidos.
 * @throws UnrecoverableKeyException Si una clave del KeyStore SSL es inválida.
 * @throws NoSuchProviderException Si ocurre un error al recuperar la instancia del Keystore.*/
public static void disableSslChecks() throws KeyManagementException,
                                             NoSuchAlgorithmException,
                                             KeyStoreException,
                                             UnrecoverableKeyException,
                                             CertificateException,
                                             IOException,
                                             NoSuchProviderException {
	final SSLContext sc = SSLContext.getInstance(SSL_CONTEXT);
	sc.init(getKeyManager(), DUMMY_TRUST_MANAGER, new java.security.SecureRandom());
	HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
	HttpsURLConnection.setDefaultHostnameVerifier(
		new HostnameVerifier() {
			@Override
			public boolean verify(final String hostname, final SSLSession session) {
				return true;
			}
		}
	);
}
 
开发者ID:MiFirma,项目名称:mi-firma-android,代码行数:29,代码来源:UrlHttpManagerImpl.java

示例3: trustAllHttpsCertificates

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Set the default X509 Trust Manager to an instance of a dummy class that trust all certificates,
 * even the self-signed ones.
 * 
 * @param protocol e.g. TLS, TLSv1.2
 */
public static void trustAllHttpsCertificates( String protocol ) {

    // Create a trust manager that does not validate certificate chains
    if (instance.trustManagers == null) {
        synchronized (instance) {
            if (instance.trustManagers == null) { // if several threads had waited for entering the synchronized block
                instance.trustManagers = new TrustManager[]{ new DefaultTrustManager() };
                // Install the all-trusting trust manager:
                try {
                    trustAllSSlContext = SSLContext.getInstance(protocol);
                    trustAllSSlContext.init(null, instance.trustManagers, null);
                } catch (GeneralSecurityException gse) {
                    throw new IllegalStateException(gse.getMessage());
                }
                HttpsURLConnection.setDefaultSSLSocketFactory(trustAllSSlContext.getSocketFactory());
            }
        }
    }
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:SslUtils.java

示例4: build

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Get an instance of JCurl with options configured by the {@link #Builder()}.
 * @return
 */
public JCurl build() {
  instance.expectedResponseSet.add(200);

  setSystemProperty("javax.net.ssl.keyStore", instance.keyStore);
  setSystemProperty("javax.net.ssl.keyStoreType", instance.storeType);
  setSystemProperty("javax.net.ssl.keyStorePassword", instance.storePass);
  setSystemProperty("javax.net.ssl.trustStore", instance.trustStore);
  setSystemProperty("javax.net.ssl.trustStoreType", instance.trustType);
  setSystemProperty("javax.net.ssl.trustStorePassword", instance.trustPass);
  setSystemProperty("http.proxyHost", instance.httpProxyHost);
  setSystemProperty("http.proxyPort", instance.httpProxyPort);
  setSystemProperty("https.proxyHost", instance.httpsProxyHost);
  setSystemProperty("https.proxyPort", instance.httpsProxyPort);
  setSystemProperty("https.nonProxyHosts", instance.nonProxyHosts);

  if (instance.verbosity >= 3) {
    System.setProperty("javax.net.debug", "ssl");
  }

  HttpsURLConnection.setDefaultSSLSocketFactory((SSLSocketFactory) SSLSocketFactory.getDefault());

  initSSLContext();

  return instance;
}
 
开发者ID:symphonyoss,项目名称:JCurl,代码行数:30,代码来源:JCurl.java

示例5: initBmob

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * 初始化Bmob
 * 
 * @param appId 填写 Application ID
 * @param apiKey 填写 REST API Key
 * @param timeout 设置超时(1000~20000ms)
 * @return 注册结果
 */
public static boolean initBmob(String appId, String apiKey, int timeout) {
    APP_ID = appId;
    REST_API_KEY = apiKey;
    if (!APP_ID.equals(STRING_EMPTY) && !REST_API_KEY.equals(STRING_EMPTY)) {
        IS_INIT = true;
    }
    if (timeout > 1000 && timeout < 20000) {
        TIME_OUT = timeout;
    }
    try {
        SSLContext sc = SSLContext.getInstance("SSL");
        sc.init(null, trustAllCerts, new SecureRandom());
        HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
    } catch (Exception e) {
        IS_INIT = false;
    }
    return isInit();
}
 
开发者ID:IaHehe,项目名称:classchecks,代码行数:27,代码来源:Bmob.java

示例6: initialize

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private static void initialize(String[] args) throws Exception {
    keystore = args[0];
    hostname = args[1];

    String password = "changeit";
    String keyFilename =
            System.getProperty("test.src", ".") + "/" + keystore;
    String trustFilename =
            System.getProperty("test.src", ".") + "/" + keystore;

    System.setProperty("javax.net.ssl.keyStore", keyFilename);
    System.setProperty("javax.net.ssl.keyStorePassword", password);
    System.setProperty("javax.net.ssl.trustStore", trustFilename);
    System.setProperty("javax.net.ssl.trustStorePassword", password);

    context = SSLContext.getDefault();
    HttpsURLConnection.setDefaultSSLSocketFactory(
            context.getSocketFactory());
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:20,代码来源:ServerIdentityTest.java

示例7: register

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Easy way of not worrying about stupid SSL validation.
 */
public static void register()
{
	if( !(HttpsURLConnection.getDefaultSSLSocketFactory() instanceof BlindSSLSocketFactory) )
	{
		originalFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
		originalHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
		LOGGER.info("Registering BlindSSLSocketFactory");

		HttpsURLConnection.setDefaultSSLSocketFactory(getDefaultSSL());
		// I'm not sure if you need this...
		HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
		{
			@Override
			public boolean verify(String hostname, SSLSession session)
			{
				return true;
			}
		});
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:24,代码来源:BlindSSLSocketFactory.java

示例8: initTrustAllSSLcontext

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的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

示例9: prepare

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
@Override public void prepare(Benchmark benchmark) {
  super.prepare(benchmark);
  if (benchmark.tls) {
    SslClient sslClient = SslClient.localhost();
    SSLSocketFactory socketFactory = sslClient.socketFactory;
    HostnameVerifier hostnameVerifier = new HostnameVerifier() {
      @Override public boolean verify(String s, SSLSession session) {
        return true;
      }
    };
    HttpsURLConnection.setDefaultHostnameVerifier(hostnameVerifier);
    HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
  }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:UrlConnection.java

示例10: untrustEveryone

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private void untrustEveryone() {
    if(defaultVerifier != null) {
        HttpsURLConnection.setDefaultHostnameVerifier(defaultVerifier);
    }
    if(defaultSSLSocketFactory != null) {
         HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:9,代码来源:Tanstagi.java

示例11: turnOffSslChecking

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public static void turnOffSslChecking() 
    throws NoSuchAlgorithmException, KeyManagementException {
  // Install the all-trusting trust manager
  final SSLContext sc = SSLContext.getInstance("SSL");
  sc.init(null, UNQUESTIONING_TRUST_MANAGER, null);
  HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
 
开发者ID:Huawei,项目名称:Server_Management_Common_eSightApi,代码行数:8,代码来源:HttpRequestUtil.java

示例12: trustAllHttpsCertificates

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private static void trustAllHttpsCertificates() throws Exception {
    TrustManager[] trustAllCerts = new TrustManager[1];
    TrustManager tm = new miTM();
    trustAllCerts[0] = tm;
    SSLContext sc = SSLContext.getInstance("SSL");
    sc.init(null, trustAllCerts, null);
    HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:9,代码来源:SSLUtil.java

示例13: fixHttpsURLConnection

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Makes HttpsURLConnection trusts a set of certificates specified by the KeyStore
 */
public void fixHttpsURLConnection() {
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:7,代码来源:MySSLSocketFactory.java

示例14: setDefaultSSLSocketFactory

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public static void setDefaultSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
	HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
}
 
开发者ID:haducloc,项目名称:appslandia-sweetsop,代码行数:4,代码来源:HttpClient.java

示例15: fixHttpsURLConnection

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Makes HttpsURLConnection trusts getUrl set of certificates specified by the KeyStore
 */
public void fixHttpsURLConnection() {
    HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
}
 
开发者ID:yiwent,项目名称:Mobike,代码行数:7,代码来源:MySSLSocketFactory.java


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