本文整理汇总了Java中org.apache.http.conn.ssl.DefaultHostnameVerifier类的典型用法代码示例。如果您正苦于以下问题:Java DefaultHostnameVerifier类的具体用法?Java DefaultHostnameVerifier怎么用?Java DefaultHostnameVerifier使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
DefaultHostnameVerifier类属于org.apache.http.conn.ssl包,在下文中一共展示了DefaultHostnameVerifier类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateSslConfig
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* @param httpConfig
* @param config
*/
@SuppressWarnings("nls")
private void updateSslConfig(Builder httpConfig, Map<String, String> config) {
try {
String clientKeystorePath = config.get("client-keystore");
String clientKeystorePassword = config.get("client-keystore.password");
String trustStorePath = config.get("trust-store");
String trustStorePassword = config.get("trust-store.password");
SSLContext sslContext = SSLContext.getInstance("TLS");
Info kPathInfo = new Info(clientKeystorePath, clientKeystorePassword);
Info tPathInfo = new Info(trustStorePath, trustStorePassword);
sslContext.init(KeyStoreUtil.getKeyManagers(kPathInfo), KeyStoreUtil.getTrustManagers(tPathInfo), null);
HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
httpConfig.defaultSchemeForDiscoveredNodes("https");
httpConfig.sslSocketFactory(sslSocketFactory); // for sync calls
httpConfig.httpsIOSessionStrategy(httpsIOSessionStrategy); // for async calls
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例2: setDefaultSSLSocketFactory
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* Sets a Safecharge's default {@link LayeredConnectionSocketFactory} object to set connection properties,
* such as supported SSL Protocols, hostname verifier, etc(needed to create a https connection).
*
* @return this object
*/
public SafechargeClientBuilder setDefaultSSLSocketFactory() {
SSLContext sslContext = SSLContexts.createDefault();
String[] javaSupportedProtocols = sslContext.getSupportedSSLParameters()
.getProtocols();
List<String> supportedProtocols = new ArrayList<>();
for (String SERVER_SUPPORTED_SSL_PROTOCOL : SERVER_SUPPORTED_SSL_PROTOCOLS) {
for (String javaSupportedProtocol : javaSupportedProtocols) {
if (SERVER_SUPPORTED_SSL_PROTOCOL.equals(javaSupportedProtocol)) {
supportedProtocols.add(SERVER_SUPPORTED_SSL_PROTOCOL);
}
}
}
if (!supportedProtocols.isEmpty()) {
sslSocketFactory =
new SSLConnectionSocketFactory(sslContext, supportedProtocols.toArray(new String[]{}), null, new DefaultHostnameVerifier());
} else {
throw new UnsupportedOperationException("Your Java version doesn't support any of the server supported SSL protocols: " + Arrays.toString(
SERVER_SUPPORTED_SSL_PROTOCOLS));
}
return this;
}
示例3: testHostnameVerification
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
@Test public void testHostnameVerification() throws Exception {
AvaticaCommonsHttpClientImpl client = mock(AvaticaCommonsHttpClientImpl.class);
// Call the real method
when(client.getHostnameVerifier(nullable(HostnameVerification.class)))
.thenCallRealMethod();
// No verification should give the default (strict) verifier
HostnameVerifier actualVerifier = client.getHostnameVerifier(null);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof DefaultHostnameVerifier);
actualVerifier = client.getHostnameVerifier(HostnameVerification.STRICT);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof DefaultHostnameVerifier);
actualVerifier = client.getHostnameVerifier(HostnameVerification.NONE);
assertNotNull(actualVerifier);
assertTrue(actualVerifier instanceof NoopHostnameVerifier);
}
示例4: initHttpClient
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
private void initHttpClient() {
ApacheHttpClientBuilder apacheHttpClientBuilder = this.configStorage
.getApacheHttpClientBuilder();
if (null == apacheHttpClientBuilder) {
apacheHttpClientBuilder = DefaultApacheHttpClientBuilder.get();
}
apacheHttpClientBuilder.httpProxyHost(this.configStorage.getHttpProxyHost())
.httpProxyPort(this.configStorage.getHttpProxyPort())
.httpProxyUsername(this.configStorage.getHttpProxyUsername())
.httpProxyPassword(this.configStorage.getHttpProxyPassword());
if (this.configStorage.getSSLContext() != null) {
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(
this.configStorage.getSSLContext(), new String[] { "TLSv1" }, null,
new DefaultHostnameVerifier());
apacheHttpClientBuilder.sslConnectionSocketFactory(sslsf);
}
if (this.configStorage.getHttpProxyHost() != null && this.configStorage.getHttpProxyPort() > 0) {
this.httpProxy = new HttpHost(this.configStorage.getHttpProxyHost(), this.configStorage.getHttpProxyPort());
}
this.httpClient = apacheHttpClientBuilder.build();
}
示例5: testGetHostnameVerifier
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
@Test
public void testGetHostnameVerifier() {
// Default
HostnameVerifier verifier = SSLUtils.getHostnameVerifier(config);
assertTrue(verifier instanceof DefaultHostnameVerifier);
// Override
config.setOverrideHostnameVerifier(new TestHostnameVerifier());
verifier = SSLUtils.getHostnameVerifier(config);
assertTrue(verifier instanceof TestHostnameVerifier);
// Disabled
config.setDisableSSLValidation(true);
verifier = SSLUtils.getHostnameVerifier(config);
assertTrue(verifier instanceof NoopHostnameVerifier);
}
示例6: withSsl
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* Adds Keystore for SSL
*
* @param keyStore KeyStore input stream
* @param keyStorePass KeyStore password
* @return This builder
*/
public final Builder withSsl(InputStream keyStore, String keyStorePass) {
SSLContext sslcontext;
try {
sslcontext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(IOUtils.loadKeyStore(keyStore, keyStorePass), null)
.build();
} catch (Exception e) {
throw new IllegalArgumentException("Unable to load trust store", e);
}
/*
* Unreal magic, but we can't use
* org.apache.http.conn.ssl.SSLConnectionSocketFactory
* .BROWSER_COMPATIBLE_HOSTNAME_VERIFIER here due to some problems
* related to classloaders. Initialize host name verifier explicitly
*/
SSLIOSessionStrategy sslSessionStrategy = new SSLIOSessionStrategy(
sslcontext,
new DefaultHostnameVerifier());
httpClientBuilder.setSSLStrategy(sslSessionStrategy);
return this;
}
示例7: updateSslConfig
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* @param httpConfig
*/
@SuppressWarnings("nls")
private void updateSslConfig(Builder httpConfig) {
try {
String clientKeystorePath = getConfig().get("client-keystore");
String clientKeystorePassword = getConfig().get("client-keystore.password");
String trustStorePath = getConfig().get("trust-store");
String trustStorePassword = getConfig().get("trust-store.password");
SSLContext sslContext = SSLContext.getInstance("TLS");
Info kPathInfo = new Info(clientKeystorePath, clientKeystorePassword);
Info tPathInfo = new Info(trustStorePath, trustStorePassword);
sslContext.init(KeyStoreUtil.getKeyManagers(kPathInfo), KeyStoreUtil.getTrustManagers(tPathInfo), null);
HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
SchemeIOSessionStrategy httpsIOSessionStrategy = new SSLIOSessionStrategy(sslContext, hostnameVerifier);
httpConfig.defaultSchemeForDiscoveredNodes("https");
httpConfig.sslSocketFactory(sslSocketFactory); // for sync calls
httpConfig.httpsIOSessionStrategy(httpsIOSessionStrategy); // for async calls
} catch (Exception e) {
throw new RuntimeException(e);
}
}
示例8: hostnameVerifier
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
@ConditionalOnMissingBean(name = "hostnameVerifier")
@Bean
public HostnameVerifier hostnameVerifier() {
if (casProperties.getHttpClient().getHostNameVerifier().equalsIgnoreCase("none")) {
return NoopHostnameVerifier.INSTANCE;
}
return new DefaultHostnameVerifier();
}
示例9: executeWithKey
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
private String executeWithKey(String url, String requestStr) throws WxErrorException {
try {
SSLContext sslContext = getConfig().getSslContext();
if (null == sslContext) {
throw new IllegalArgumentException("请先初始化配置类(即WxMpConfigStorage的实现类)中的SSLContext!");
}
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslContext, new String[]{"TLSv1"}, null,
new DefaultHostnameVerifier());
HttpPost httpPost = new HttpPost(url);
if (this.wxMpService.getHttpProxy() != null) {
httpPost.setConfig(RequestConfig.custom().setProxy(this.wxMpService.getHttpProxy()).build());
}
try (CloseableHttpClient httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).build()) {
httpPost.setEntity(new StringEntity(new String(requestStr.getBytes("UTF-8"), "ISO-8859-1")));
try (CloseableHttpResponse response = httpclient.execute(httpPost)) {
String result = EntityUtils.toString(response.getEntity(), Consts.UTF_8);
this.log.debug("\n[URL]: {}\n[PARAMS]: {}\n[RESPONSE]: {}", url, requestStr, result);
return result;
}
} finally {
httpPost.releaseConnection();
}
} catch (Exception e) {
this.log.error("\n[URL]: {}\n[PARAMS]: {}\n[EXCEPTION]: {}", url, requestStr, e.getMessage());
throw new WxErrorException(WxError.newBuilder().setErrorCode(-1).setErrorMsg(e.getMessage()).build(), e);
}
}
示例10: get
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
public static CloseableHttpClient get(SSLContext ssl, CookieStore cookieStore, boolean hostVerificationEnabled) {
RequestConfig defaultRequestConfig = RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build();
HttpClientBuilder builder = HttpClients.custom().setSSLContext(ssl).setDefaultCookieStore(cookieStore)
.setDefaultRequestConfig(defaultRequestConfig);
if (hostVerificationEnabled) {
builder.setSSLHostnameVerifier(new DefaultHostnameVerifier());
} else {
builder.setSSLHostnameVerifier(new NoopHostnameVerifier());
}
return builder.build();
}
示例11: initializeFactory
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* Creates a new SSLConnectionSocketFactory with the behavior described in
* {@link #getFactory(String)}. Instead of returning, this method registers
* the factory instance to the <code>factoriesByHost<code> map, as well as
* registering its <code>ExtraCertManager</code> to the
* <code>certManagersByHost</code> map. The cert manager registration is
* important in order to detect and purge trusted certificates on a per-host
* basis.
*
* @param host
* @param burpExtender
* @throws IOException
* @throws GeneralSecurityException
*/
private static void initializeFactory(String host, BurpExtender burpExtender) throws IOException, GeneralSecurityException {
// set up the certificate management
File managedKeyStoreFile = getTrustStoreForHost(host);
ExtraCertManager certManager = new SingleExtraCertManager(managedKeyStoreFile, "u9lwIfUpaN");
// get the default hostname verifier that gets used by the modified one
// and the invalid cert dialog
HostnameVerifier defaultHostnameVerifier = new DefaultHostnameVerifier();
InvalidCertificateStrategy invalidCertStrat = new InvalidCertificateDialogStrategy(defaultHostnameVerifier, host, burpExtender);
/*
* Set up a composite trust manager that uses the default trust manager
* before delegating to the "reloadable" trust manager that allows users
* to accept invalid certificates.
*/
List<X509TrustManager> trustManagersForComposite = new LinkedList<>();
X509TrustManager systemTrustManager = getDefaultTrustManager();
ReloadableX509TrustManager customTrustManager = new ReloadableX509TrustManager(certManager, invalidCertStrat);
trustManagersForComposite.add(systemTrustManager);
trustManagersForComposite.add(customTrustManager);
X509TrustManager trustManager = new CompositeX509TrustManager(trustManagersForComposite);
// setup the SSLContext using the custom trust manager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, new TrustManager[] { trustManager }, null);
// the actual hostname verifier that will be used with the socket
// factory
Set<String> allowedHosts = new HashSet<>();
allowedHosts.add(host);
HostnameVerifier modifiedHostnameVerifier = new HostnameVerifierWithExceptions(defaultHostnameVerifier, allowedHosts);
SSLConnectionSocketFactory factory = new SSLConnectionSocketFactory(sslContext, modifiedHostnameVerifier);
// Register the `factory` and the `customTrustManager` under the given
// `host`
factoriesByHost.put(host, factory);
customTrustByHost.put(host, customTrustManager);
}
示例12: createConnectionSocketFactory
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
private static Registry<ConnectionSocketFactory> createConnectionSocketFactory() {
HostnameVerifier hostnameVerifier = new DefaultHostnameVerifier(PublicSuffixMatcherLoader.getDefault());
ConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(sslContext != null ? sslContext :
SSLContexts.createDefault(), hostnameVerifier);
return RegistryBuilder.<ConnectionSocketFactory>create()
.register("http", PlainConnectionSocketFactory.getSocketFactory())
.register("https", sslSocketFactory)
.build();
}
示例13: getHostnameVerifier
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
/**
* If SSL validation is disabled then return a HostnameVerifier that accepts
* everything. Otherwise, return the override HostnameVerifier in the config
* if specified, or return a new DefaultHostnameVerifier
*
* @param config
*/
public static HostnameVerifier getHostnameVerifier(ClientConfig config) {
if (config.isDisableSSLValidation()) {
return new NoopHostnameVerifier();
}
if (config.getOverrideHostnameVerifier() == null) {
return new DefaultHostnameVerifier();
} else {
return config.getOverrideHostnameVerifier();
}
}
示例14: initialize
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
private HttpAsyncClientBuilder initialize() {
try {
final PoolingNHttpClientConnectionManager connManager = new PoolingNHttpClientConnectionManager(
new DefaultConnectingIOReactor( IOReactorConfig.custom()
.setConnectTimeout( connectTimeout )
.setSoTimeout( readTimeout )
.build() ),
RegistryBuilder.<SchemeIOSessionStrategy>create()
.register( "http", NoopIOSessionStrategy.INSTANCE )
.register( "https",
new SSLIOSessionStrategy( certificateLocation != null ?
createSSLContext( certificateLocation, certificatePassword )
: SSLContexts.createDefault(),
split( System.getProperty( "https.protocols" ) ),
split( System.getProperty( "https.cipherSuites" ) ),
new DefaultHostnameVerifier( PublicSuffixMatcherLoader.getDefault() ) ) )
.build() );
connManager.setMaxTotal( maxConnTotal );
connManager.setDefaultMaxPerRoute( maxConnPerRoute );
return ( certificateLocation != null ?
HttpAsyncClients.custom()
.setSSLContext( createSSLContext( certificateLocation, certificatePassword ) )
: HttpAsyncClients.custom() )
.setMaxConnPerRoute( maxConnPerRoute )
.setConnectionManager( connManager )
.setMaxConnTotal( maxConnTotal )
.setKeepAliveStrategy( DefaultConnectionKeepAliveStrategy.INSTANCE )
.setDefaultRequestConfig( RequestConfig
.custom()
.setRedirectsEnabled( redirectsEnabled )
.setCookieSpec( cookieSpec )
.build() )
.setDefaultCookieStore( basicCookieStore );
} catch( IOReactorException e ) {
throw new UncheckedIOException( e );
}
}
示例15: BrickLinkClient
import org.apache.http.conn.ssl.DefaultHostnameVerifier; //导入依赖的package包/类
public BrickLinkClient(String consumerKey, String consumerSecret, String tokenValue, String tokenSecret) throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {
super();
consumer = new CommonsHttpOAuthConsumer(consumerKey, consumerSecret);
consumer.setTokenWithSecret(tokenValue, tokenSecret);
SSLContext sslcontext = SSLContexts.custom().loadTrustMaterial(null, new TrustAllStrategy()).build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext, new String[] { "TLSv1" }, null, new DefaultHostnameVerifier());
client = HttpClients.custom().setSSLSocketFactory(sslsf).build();
}