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


Java HttpsURLConnection.setDefaultHostnameVerifier方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: allowAllSSL

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

示例5: finalize

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
@Override
protected void finalize() throws Throwable
{
	if( originalFactory != null )
	{
		HttpsURLConnection.setDefaultSSLSocketFactory(originalFactory);
	}
	if( originalHostnameVerifier != null )
	{
		HttpsURLConnection.setDefaultHostnameVerifier(originalHostnameVerifier);
	}
	super.finalize();
}
 
开发者ID:equella,项目名称:Equella,代码行数:14,代码来源:BlindSSLSocketFactory.java

示例6: enableSslCert

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Method that bypasses every SSL certificate verification and accepts every
 * connection with any SSL protected device that ONOS has an interaction with.
 * Needs addressing for secutirty purposes.
 *
 * @throws NoSuchAlgorithmException if algorithm specified is not available
 * @throws KeyManagementException if unable to use the key
 */
//FIXME redo for security purposes.
protected static void enableSslCert() throws NoSuchAlgorithmException, KeyManagementException {
    SSLContext ctx = SSLContext.getInstance(TLS);
    ctx.init(new KeyManager[0], new TrustManager[]{new DefaultTrustManager()}, new SecureRandom());
    SSLContext.setDefault(ctx);
    HttpsURLConnection.setDefaultHostnameVerifier((hostname, session) -> {
        //FIXME better way to do this.
        return true;
    });
}
 
开发者ID:shlee89,项目名称:athena,代码行数:19,代码来源:RestDeviceProviderUtilities.java

示例7: doGet

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Get 请求
 *
 * @param pathUrl
 * @param queryString
 * @return
 */
public static String doGet(String pathUrl, String queryString) {
    StringBuilder repString = new StringBuilder();
    String path = pathUrl;
    if (null != queryString && !"".equals(queryString)) {
        path = path + "?" + queryString;
    }
    HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
    try {
        HttpsURLConnection connection = (HttpsURLConnection) (new URL(path)).openConnection();

        TrustManager[] tm = {ignoreCertificationTrustManger};
        SSLContext sslContext = SSLContext.getInstance("TLS");
        sslContext.init(null, tm, new java.security.SecureRandom());

        // 从上述SSLContext对象中得到SSLSocketFactory对象 
        SSLSocketFactory ssf = sslContext.getSocketFactory();
        connection.setSSLSocketFactory(ssf);

        InputStreamReader isr = new InputStreamReader(connection.getInputStream(), "utf-8");
        BufferedReader br = new BufferedReader(isr);
        String s;
        while (null != (s = br.readLine())) {
            repString.append(s);
        }
        isr.close();
        connection.disconnect();
    } catch (Exception ex) {
        log.error("调用链接失败:pathUrl:" + pathUrl + "queryString:" + queryString);
        log.error(ex.getMessage());
    } finally {
        log.info(repString.toString());
    }
    return repString.toString();
}
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:42,代码来源:HttpUtil.java

示例8: URLGet

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
     * GET List<NameValuePair>请求
     *
     * @param pathUrl
     * @param params
     * @return
     */
    public static String URLGet(String pathUrl, List<NameValuePair> params) {

        String queryString = "";

        StringBuilder repString = new StringBuilder();

        try {
            String path = pathUrl;
            String keyValue;
            if (null != params && params.size() > 0) {

                for (NameValuePair nvp : params) {
                    String key = nvp.getName();
                    keyValue = nvp.getValue();
                    if (null != keyValue && !"".equals(keyValue)) {
                        queryString = queryString + key + "=" + keyValue + "&";
                    }
                }
            }
            if (!"".equals(queryString)) {
                path = path + "?" + queryString;
            }
            HttpsURLConnection.setDefaultHostnameVerifier(ignoreHostnameVerifier);
            HttpsURLConnection connection = (HttpsURLConnection) (new URL(path)).openConnection();

            // Prepare SSL Context 
            TrustManager[] tm = {ignoreCertificationTrustManger};
//            SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE"); 
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, tm, new java.security.SecureRandom());


            // 从上述SSLContext对象中得到SSLSocketFactory对象 
            SSLSocketFactory ssf = sslContext.getSocketFactory();
            connection.setSSLSocketFactory(ssf);

            InputStreamReader isr = new InputStreamReader(connection.getInputStream(), "utf-8");
            BufferedReader br = new BufferedReader(isr);
            String s;
            while (null != (s = br.readLine())) {
                repString.append(s);
            }
            isr.close();
            connection.disconnect();

        } catch (Exception ex) {
            log.error("调用链接失败:pathUrl:" + pathUrl + "queryString:" + queryString);
            ex.printStackTrace();
        } finally {
            log.info(repString.toString());
        }
        return repString.toString();
    }
 
开发者ID:tong12580,项目名称:OutsourcedProject,代码行数:61,代码来源:HttpUtil.java

示例9: init

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public void init() {
    LOG.info("enabled: {}, trustAll: {}", enabled, trustAll);
    if (enabled) {
        oldHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
        LOG.info("Register me as DefaultHostnameVerifier, and backup the old one {}",
                oldHostnameVerifier);
        HttpsURLConnection.setDefaultHostnameVerifier(this);
        meAsDefaultHostnameVerifier = true;
    }
}
 
开发者ID:xipki,项目名称:xitk,代码行数:11,代码来源:HttpsHostnameVerifier.java

示例10: doClientSide

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
void doClientSide() throws Exception {
    // Wait for server to get started.
    while (!serverReady) {
        Thread.sleep(50);
    }

    HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
        public boolean verify(String hostname, SSLSession session) {
            return true;
        }});

    URL url = new URL("https://localhost:" + serverPort +"/");

    // Run without a CookieHandler first
    InputStream in = url.openConnection().getInputStream();
    while (in.read() != -1);  // read response body so connection can be reused

    // Set a CookeHandler and retest using the HttpClient from the KAC
    CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(manager);

    in = url.openConnection().getInputStream();
    while (in.read() != -1);

    if (manager.getCookieStore().getCookies().isEmpty()) {
        throw new RuntimeException("Failed: No cookies in the cookie Handler.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:CookieHttpsClientTest.java

示例11: Builder

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private Builder() {
      //Reset hostname/certificate verifiers to defaults for repeated programmatic uses
      HttpsURLConnection.setDefaultHostnameVerifier(DEFAULT_HOSTNAME_VERIFIER);
//      HttpsURLConnection.setDefaultSSLSocketFactory(DEFAULT_SSL_SOCKET_FACTORY);

      instance = new JCurl();
    }
 
开发者ID:symphonyoss,项目名称:JCurl,代码行数:8,代码来源:JCurl.java

示例12: trustAllHostnames

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Disable SSL hostname verification.
 * @param disableChecks
 * @return
 */
public Builder trustAllHostnames(boolean disableChecks) {
  instance.trustAllHostnames = disableChecks;
  if (disableChecks) {
    HttpsURLConnection.setDefaultHostnameVerifier(new AllValidatingHostnameVerifier());
  }
  return this;
}
 
开发者ID:symphonyoss,项目名称:JCurl,代码行数:13,代码来源:JCurl.java

示例13: _trustAllHostnames

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * Set the default Hostname Verifier to an instance of a fake class that 
 * trust all hostnames.
 */
private static void _trustAllHostnames() {
    // Create a trust manager that does not validate certificate chains
    if(_hostnameVerifier == null) {
        _hostnameVerifier = new FakeHostnameVerifier();
    } // if
      // Install the all-trusting host name verifier:
    HttpsURLConnection.setDefaultHostnameVerifier(_hostnameVerifier);
}
 
开发者ID:oci-pronghorn,项目名称:GreenLightning,代码行数:13,代码来源:SSLUtilities.java

示例14: ignoreSsl

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
/**
 * 忽略HTTPS请求的SSL证书,必须在openConnection之前调用
 * @throws Exception
 */
public static void ignoreSsl() throws Exception{
    HostnameVerifier hv = new HostnameVerifier() {
        public boolean verify(String urlHostName, SSLSession session) {
            return true;
        }
    };
    trustAllHttpsCertificates();
    HttpsURLConnection.setDefaultHostnameVerifier(hv);
}
 
开发者ID:aliyun,项目名称:aliyun-cloudphotos-android-demo,代码行数:14,代码来源:SSLUtil.java

示例15: reset

import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public void reset() {
    // Reset system properties.
    System.setProperties(null);

    // From "L" release onwards, calling System.setProperties(null) clears the java.io.tmpdir,
    // so we set it again. No-op on earlier releases.
    System.setProperty("java.io.tmpdir", tmpDir);

    if (JAVA_RUNTIME_VERSION != null) {
        System.setProperty("java.runtime.version", JAVA_RUNTIME_VERSION);
    }
    if (JAVA_VM_INFO != null) {
        System.setProperty("java.vm.info", JAVA_VM_INFO);
    }
    if (JAVA_VM_VERSION != null) {
        System.setProperty("java.vm.version", JAVA_VM_VERSION);
    }
    if (JAVA_VM_VENDOR != null) {
        System.setProperty("java.vm.vendor", JAVA_VM_VENDOR);
    }
    if (JAVA_VM_NAME != null) {
        System.setProperty("java.vm.name", JAVA_VM_NAME);
    }

    // Require writable java.home and user.dir directories for preferences
    if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
        String javaHome = tmpDir + "/java.home";
        IoUtils.safeMkdirs(new File(javaHome));
        System.setProperty("java.home", javaHome);
    }
    String userHome = System.getProperty("user.home");
    if (userHome.length() == 0) {
        userHome = tmpDir + "/user.home";
        IoUtils.safeMkdirs(new File(userHome));
        System.setProperty("user.home", userHome);
    }

    // Localization
    Locale.setDefault(Locale.US);
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));

    // Preferences
    // Temporarily silence the java.util.prefs logger, which otherwise emits
    // an unactionable warning. See RI bug 4751540.
    Logger loggerToMute = Logger.getLogger("java.util.prefs");
    boolean usedParentHandlers = loggerToMute.getUseParentHandlers();
    loggerToMute.setUseParentHandlers(false);
    try {
        // resetPreferences(Preferences.systemRoot());
        resetPreferences(Preferences.userRoot());
    } finally {
        loggerToMute.setUseParentHandlers(usedParentHandlers);
    }

    // HttpURLConnection
    Authenticator.setDefault(null);
    CookieHandler.setDefault(null);
    ResponseCache.setDefault(null);
    HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
    HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);

    // Logging
    LogManager.getLogManager().reset();
    Logger.getLogger("").addHandler(new ConsoleHandler());

    // Cleanup to force CloseGuard warnings etc
    System.gc();
    System.runFinalization();
}
 
开发者ID:dryganets,项目名称:vogar,代码行数:70,代码来源:TestEnvironment.java


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