本文整理了Java中javax.net.ssl.HttpsURLConnection.setDefaultHostnameVerifier()
方法的一些代码示例,展示了HttpsURLConnection.setDefaultHostnameVerifier()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpsURLConnection.setDefaultHostnameVerifier()
方法的具体详情如下:
包路径:javax.net.ssl.HttpsURLConnection
类名称:HttpsURLConnection
方法名:setDefaultHostnameVerifier
[英]Sets the default hostname verifier to be used by new instances.
[中]设置新实例要使用的默认主机名验证器。
代码示例来源:origin: stackoverflow.com
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCertificates, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(trustAllHostnames);
代码示例来源:origin: apache/cloudstack
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(new SecureSSLSocketFactory(sc));
HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception e) {
代码示例来源:origin: com.aliyun/aliyun-java-sdk-core
public static void restoreSSLCertificate() {
if (null != defaultSSLFactory) {
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLFactory);
HttpsURLConnection.setDefaultHostnameVerifier(defaultVerifier);
}
}
代码示例来源:origin: com.bitplan/mediawiki-japi
/**
* initialize this wiki
*/
public void init() throws Exception {
// configure the SSLContext with a TrustManager
SSLContext ctx = SSLContext.getInstance("TLS");
if (ignoreCertificates) {
ctx.init(new KeyManager[0],
new TrustManager[] { new DefaultTrustManager() }, new SecureRandom());
SSLContext.setDefault(ctx);
}
HostnameVerifier hv = new IgnoreHostName();
HttpsURLConnection.setDefaultHostnameVerifier(hv);
}
代码示例来源:origin: io.tesla.aether.test/aether-test-harness
private void enableSslRequests() {
enableSsl = true;
//
// You would never do this in production code but it's way easier to test with a generated
// SSLContext and a hostname verifier that just returns true.
//
SSLContext.setDefault(sslContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String host, SSLSession session) {
return true;
}
});
server.useHttps(sslContext.getSocketFactory(), enableProxy);
}
代码示例来源:origin: stackoverflow.com
HttpsURLConnection.setDefaultHostnameVerifier(new NullHostNameVerifier());
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[]{new NullX509TrustManager()}, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
代码示例来源:origin: io.tesla.aether.test/aether-test-harness
protected void enableSsl() throws Exception {
enableSsl = true;
server.enableSsl(sslContext);
//
// You would never do this in production code but it's way easier to test with a generated
// SSLContext and a hostname verifier that just returns true.
//
SSLContext.setDefault(sslContext);
HttpsURLConnection.setDefaultSSLSocketFactory(sslContext.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String host, SSLSession session) {
return true;
}
});
}
代码示例来源:origin: net.trajano.commons/commons-testing
/**
* This will re-enable the SSL checks after it was disabled by
* {@link #disableChecks()}.
*/
public static void reenableChecks() {
if (!disabled) {
return;
}
setDefaultSSLSocketFactory(originalSslSocketFactory);
setDefaultHostnameVerifier(originalHostnameVerifier);
disabled = false;
}
代码示例来源:origin: knowm/XChange
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
代码示例来源:origin: wso2/msf4j
@Override
protected HttpURLConnection request(String path, String method, boolean keepAlive) throws IOException {
URL url = baseURI.resolve(path).toURL();
HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getClientContext().getSocketFactory());
HostnameVerifier allHostsValid = (hostname1, session) -> true;
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
HttpURLConnection urlConn = (HttpsURLConnection) url.openConnection();
if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) {
urlConn.setDoOutput(true);
}
urlConn.setRequestMethod(method);
if (!keepAlive) {
urlConn.setRequestProperty(HttpHeaderNames.CONNECTION.toString(), HEADER_VAL_CLOSE);
}
return urlConn;
}
代码示例来源:origin: com.alibaba.edas.acm/acm-sdk
public static void restoreSSLCertificate() {
if (null != defaultSSLFactory) {
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLFactory);
HttpsURLConnection.setDefaultHostnameVerifier(defaultVerifier);
}
}
代码示例来源:origin: jphp-group/jphp
@Signature
public static void disableSSLVerificationForHttps() throws NoSuchAlgorithmException, KeyManagementException {
TrustManager[] trustAllCerts = new TrustManager[] {
new X509TrustManager() {
public java.security.cert.X509Certificate[] getAcceptedIssuers() {
return null;
}
public void checkClientTrusted(X509Certificate[] certs, String authType) { }
public void checkServerTrusted(X509Certificate[] certs, String authType) { }
}
};
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new java.security.SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
// Create all-trusting host name verifier
HostnameVerifier allHostsValid = new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}
};
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
}
}
代码示例来源:origin: wso2/msf4j
@Override
protected HttpURLConnection request(String path, String method, boolean keepAlive) throws IOException {
URL url = baseURI.resolve(path).toURL();
HttpsURLConnection.setDefaultSSLSocketFactory(sslClientContext.getClientContext().getSocketFactory());
HostnameVerifier allHostsValid = (hostname1, session) -> true;
// Install the all-trusting host verifier
HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid);
HttpURLConnection urlConn = (HttpsURLConnection) url.openConnection();
if (method.equals(HttpMethod.POST) || method.equals(HttpMethod.PUT)) {
urlConn.setDoOutput(true);
}
urlConn.setRequestMethod(method);
if (!keepAlive) {
urlConn.setRequestProperty(HttpHeaderNames.CONNECTION.toString(), HEADER_VAL_CLOSE);
}
return urlConn;
}
代码示例来源:origin: com.quhaodian.discover/discover-plug-alidayu
public static void restoreSSLCertificate() {
if (null != defaultSSLFactory) {
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLFactory);
HttpsURLConnection.setDefaultHostnameVerifier(defaultVerifier);
}
}
代码示例来源:origin: stackoverflow.com
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, trustAllCerts, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(hv);
} catch (Exception e) {}
代码示例来源:origin: apache/attic-polygene-java
@BeforeClass
public static void beforeSecureClass()
throws IOException, GeneralSecurityException
{
defaultHostnameVerifier = HttpsURLConnection.getDefaultHostnameVerifier();
defaultSSLSocketFactory = HttpsURLConnection.getDefaultSSLSocketFactory();
HttpsURLConnection.setDefaultHostnameVerifier( ( string, ssls ) -> true );
HttpsURLConnection.setDefaultSSLSocketFactory( buildTrustSSLContext().getSocketFactory() );
}
代码示例来源:origin: es.gob.afirma/afirma-core
/** Habilita las comprobaciones de certificados en conexiones SSL dejándolas con su
* comportamiento por defecto. */
public static void enableSslChecks() {
HttpsURLConnection.setDefaultSSLSocketFactory(DEFAULT_SSL_SOCKET_FACTORY);
HttpsURLConnection.setDefaultHostnameVerifier(DEFAULT_HOSTNAME_VERIFIER);
LOGGER.info(
"Habilitadas comprobaciones SSL" //$NON-NLS-1$
);
}
代码示例来源:origin: stackoverflow.com
private void trustEveryone() {
try {
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier(){
public boolean verify(String hostname, SSLSession session) {
return true;
}});
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new X509TrustManager[]{new X509TrustManager(){
public void checkClientTrusted(X509Certificate[] chain,
String authType) throws CertificateException {}
public void checkServerTrusted(X509Certificate[] chain,
String authType) throws CertificateException {}
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[0];
}}}, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(
context.getSocketFactory());
} catch (Exception e) { // should never happen
e.printStackTrace();
}
}
代码示例来源:origin: beders/Resty
/**
* Defines the HttpsURLConnection's default SSLSocketFactory and HostnameVerifier so that all subsequence HttpsURLConnection instances
* will trusts all certificates and accept all certificate hostnames.
* <p/>
* WARNING: Using this is dangerous as it bypasses most of what ssl certificates are made for. However, self-signed certificate, testing, and
* domains with multiple sub-domains will not fail handshake verification when this setting is applied.
*/
public static void ignoreAllCerts() {
try {
HttpsURLConnection.setDefaultSSLSocketFactory(TrustAllX509SocketFactory.getSSLSocketFactory());
HttpsURLConnection.setDefaultHostnameVerifier(AllowAllHostnameVerifier.ALLOW_ALL_HOSTNAMES);
} catch (Exception e) {
throw new RuntimeException("Failed to set 'Trust all' default SSL SocketFactory and Hostname Verifier", e);
}
}
代码示例来源:origin: apache/geode
private void configureHttpsURLConnection(SSLConfig sslConfig, boolean skipSslVerification)
throws Exception {
KeyManager[] keyManagers = getKeyManagers(sslConfig);
TrustManager[] trustManagers = getTrustManagers(sslConfig, skipSslVerification);
if (skipSslVerification) {
HttpsURLConnection.setDefaultHostnameVerifier((String s, SSLSession sslSession) -> true);
}
SSLContext ssl =
SSLContext.getInstance(SSLUtil.getSSLAlgo(SSLUtil.readArray(sslConfig.getProtocols())));
ssl.init(keyManagers, trustManagers, new SecureRandom());
HttpsURLConnection.setDefaultSSLSocketFactory(ssl.getSocketFactory());
}
内容来源于网络,如有侵权,请联系作者删除!