當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。