本文整理汇总了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) {}
}
示例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;
}
}
);
}
示例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());
}
}
}
}
示例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;
}
示例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();
}
示例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());
}
示例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;
}
});
}
}
示例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;
}
示例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);
}
}
示例10: untrustEveryone
import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
private void untrustEveryone() {
if(defaultVerifier != null) {
HttpsURLConnection.setDefaultHostnameVerifier(defaultVerifier);
}
if(defaultSSLSocketFactory != null) {
HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);
}
}
示例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());
}
示例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());
}
示例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());
}
示例14: setDefaultSSLSocketFactory
import javax.net.ssl.HttpsURLConnection; //导入方法依赖的package包/类
public static void setDefaultSSLSocketFactory(SSLSocketFactory sslSocketFactory) {
HttpsURLConnection.setDefaultSSLSocketFactory(sslSocketFactory);
}
示例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());
}