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


Java SSLCertificateSocketFactory类代码示例

本文整理汇总了Java中android.net.SSLCertificateSocketFactory的典型用法代码示例。如果您正苦于以下问题:Java SSLCertificateSocketFactory类的具体用法?Java SSLCertificateSocketFactory怎么用?Java SSLCertificateSocketFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: a

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public static b a(String str) {
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpProtocolParams.setVersion(basicHttpParams, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setUseExpectContinue(basicHttpParams, false);
    HttpConnectionParams.setStaleCheckingEnabled(basicHttpParams, false);
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, 20000);
    HttpConnectionParams.setSoTimeout(basicHttpParams, 30000);
    HttpConnectionParams.setSocketBufferSize(basicHttpParams, 8192);
    HttpClientParams.setRedirecting(basicHttpParams, true);
    HttpClientParams.setAuthenticating(basicHttpParams, false);
    HttpProtocolParams.setUserAgent(basicHttpParams, str);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    schemeRegistry.register(new Scheme(com.alipay.sdk.cons.b.a, SSLCertificateSocketFactory.getHttpSocketFactory(30000, null), WebSocket.DEFAULT_WSS_PORT));
    ClientConnectionManager threadSafeClientConnManager = new ThreadSafeClientConnManager(basicHttpParams, schemeRegistry);
    ConnManagerParams.setTimeout(basicHttpParams, 60000);
    ConnManagerParams.setMaxConnectionsPerRoute(basicHttpParams, new ConnPerRouteBean(10));
    ConnManagerParams.setMaxTotalConnections(basicHttpParams, 50);
    Security.setProperty("networkaddress.cache.ttl", "-1");
    HttpsURLConnection.setDefaultHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);
    return new b(threadSafeClientConnManager, basicHttpParams);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:b.java

示例2: getSocketFactory

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
private static org.apache.http.conn.ssl.SSLSocketFactory getSocketFactory(SSLSessionCache paramSSLSessionCache)
{
  javax.net.ssl.SSLSocketFactory localSSLSocketFactory = SSLCertificateSocketFactory.getDefault(5000, paramSSLSessionCache);
  try
  {
    org.apache.http.conn.ssl.SSLSocketFactory localSSLSocketFactory1 = (org.apache.http.conn.ssl.SSLSocketFactory)org.apache.http.conn.ssl.SSLSocketFactory.class.getConstructor(new Class[] { javax.net.ssl.SSLSocketFactory.class }).newInstance(new Object[] { localSSLSocketFactory });
    return localSSLSocketFactory1;
  }
  catch (NoSuchMethodException localNoSuchMethodException)
  {
    throw new IllegalStateException(localNoSuchMethodException);
  }
  catch (InstantiationException localInstantiationException)
  {
    throw new IllegalStateException(localInstantiationException);
  }
  catch (IllegalAccessException localIllegalAccessException)
  {
    throw new IllegalStateException(localIllegalAccessException);
  }
  catch (InvocationTargetException localInvocationTargetException)
  {
    throw new IllegalStateException(localInvocationTargetException);
  }
}
 
开发者ID:ChiangC,项目名称:FMTech,代码行数:26,代码来源:AndroidHttpClient.java

示例3: setSniHost

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public static void setSniHost(SSLSocketFactory factory, SSLSocket socket, String hostname) {
    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR1 &&
            factory instanceof android.net.SSLCertificateSocketFactory) {
        SSLCertificateSocketFactory sslCertificateSocketFactory = (SSLCertificateSocketFactory) factory;
        sslCertificateSocketFactory.setHostname(socket, hostname);
    } else {
        setHostnameViaReflection(socket, hostname);
    }
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:10,代码来源:DefaultTrustedSocketFactory.java

示例4: getSocketFactory

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
static SSLSocketFactory getSocketFactory() {
    if (socketFactory == null) {
        try {
            X509TrustManager trustManager = get509TrustManager();
            SSLContext sslContext = SSLContext.getInstance("TLS");
            sslContext.init(null, new TrustManager[]{trustManager}, null);
            socketFactory = sslContext.getSocketFactory();
        } catch (NoSuchAlgorithmException | KeyManagementException e) {
            VolleyLog.e(TAG, "Unable to create the ssl socket factory.");
            return SSLCertificateSocketFactory.getDefault(0, null);
        }
    }
    return socketFactory;
}
 
开发者ID:octaware,项目名称:super-volley,代码行数:15,代码来源:ClientSSLSocketFactory.java

示例5: createLayeredSocket

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
@TargetApi(17)
public Socket createLayeredSocket(
        final Socket socket,
        final String target,
        final int port,
        final HttpContext context) throws IOException {
    final SSLSocket sslsock = (SSLSocket) this.socketfactory.createSocket(
            socket,
            target,
            port,
            true);
    if (supportedProtocols != null) {
        sslsock.setEnabledProtocols(supportedProtocols);
    }
    if (supportedCipherSuites != null) {
        sslsock.setEnabledCipherSuites(supportedCipherSuites);
    }
    prepareSocket(sslsock);

    // Android specific code to enable SNI
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        if (this.socketfactory instanceof SSLCertificateSocketFactory) {
            if (Log.isLoggable(TAG, Log.DEBUG)) {
                Log.d(TAG, "Enabling SNI for " + target);
            }
            ((SSLCertificateSocketFactory) this.socketfactory).setHostname(sslsock, target);
        }
    }
    // End of Android specific code

    sslsock.startHandshake();
    verifyHostname(sslsock, target);
    return sslsock;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:35,代码来源:SSLConnectionSocketFactory.java

示例6: startConnection

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public void startConnection() {
    try {
        String host = mWebSocketURI.getHost();
        int port = mWebSocketURI.getPort();

        if (port == -1) {
            if (mWebSocketURI.getScheme().equals(WSS_URI_SCHEME)) {
                port = 443;
            } else {
                port = 80;
            }
        }

        SocketFactory factory = null;
        if (mWebSocketURI.getScheme().equalsIgnoreCase(WSS_URI_SCHEME)) {
            factory = SSLCertificateSocketFactory.getDefault();
        } else {
            factory = SocketFactory.getDefault();
        }

        // Do not replace host string with InetAddress or you lose automatic host name verification
        this.mSocket = factory.createSocket(host, port);
    } catch (IOException e) {
        this.mFailureMessage = e.getLocalizedMessage();
    }

    synchronized (this) {
        notifyAll();
    }
}
 
开发者ID:kenCode-de,项目名称:smartcoins-wallet,代码行数:31,代码来源:WebSocketConnection.java

示例7: TrustUserSSLCertsSocketFactory

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public TrustUserSSLCertsSocketFactory() throws IOException, GeneralSecurityException {
    super(null);
    // No handshake timeout used
    mFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);
    TrustManager[] trustAllowedCerts;
    try {
        trustAllowedCerts = new TrustManager[]{
                new WPTrustManager(SelfSignedSSLCertsManager.getInstance(null).getLocalKeyStore())
        };
        mFactory.setTrustManagers(trustAllowedCerts);
    } catch (GeneralSecurityException e1) {
        AppLog.e(T.API, "Cannot set TrustAllSSLSocketFactory on our factory. Proceding without it...", e1);
    }
}
 
开发者ID:ldsddn,项目名称:wordpress_app_android,代码行数:15,代码来源:TrustUserSSLCertsSocketFactory.java

示例8: startConnection

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public void startConnection() {
	try {
		String host = mWebSocketURI.getHost();
		int port = mWebSocketURI.getPort();

		if (port == -1) {
			if (mWebSocketURI.getScheme().equals(WSS_URI_SCHEME)) {
				port = 443;
			} else {
				port = 80;
			}
		}

		SocketFactory factory = null;
		if (mWebSocketURI.getScheme().equalsIgnoreCase(WSS_URI_SCHEME)) {
			if (mWebSocketOptions != null) {
				factory = mWebSocketOptions.getSSLCertificateSocketFactory();
			}

			if (factory == null) {
				factory = SSLCertificateSocketFactory.getDefault();
			}
		} else {
			factory = SocketFactory.getDefault();
		}

		// Do not replace host string with InetAddress or you lose automatic host name verification
		this.mSocket = factory.createSocket(host, port);
	} catch (IOException e) {
		this.mFailureMessage = e.getLocalizedMessage();
	}

	synchronized (this) {
		notifyAll();
	}
}
 
开发者ID:loentar,项目名称:Android-DDP-WSS,代码行数:37,代码来源:WebSocketConnection.java

示例9: createSocket

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
@Override
public Socket createSocket(Socket plainSocket, String host, int port, boolean autoClose) throws IOException {
    if (autoClose) {
        // we don't need the plainSocket
        plainSocket.close();
    }

    // create and connect SSL socket, but don't do hostname/certificate verification yet
    SSLCertificateSocketFactory sslSocketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);
    SSLSocket ssl = (SSLSocket) sslSocketFactory.createSocket(InetAddress.getByName(host), port);

    // enable TLSv1.1/1.2 if available
    // (see https://github.com/rfc2822/davdroid/issues/229)
    ssl.setEnabledProtocols(ssl.getSupportedProtocols());

    // set up SNI before the handshake
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        sslSocketFactory.setHostname(ssl, host);
    } else {
        try {
            java.lang.reflect.Method setHostnameMethod = ssl.getClass().getMethod("setHostname", String.class);
            setHostnameMethod.invoke(ssl, host);
        } catch (Exception ignored) {
        }
    }

    // verify hostname and certificate
    SSLSession session = ssl.getSession();
    if (!hostnameVerifier.verify(host, session))
        throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host);

    return ssl;
}
 
开发者ID:MarvinMenzerath,项目名称:BlackPhantom.DE-Shoutbox-App,代码行数:34,代码来源:TlsSniSocketFactory.java

示例10: getSslCertificateSocketFactory

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
@TargetApi(14)
private static SSLCertificateSocketFactory getSslCertificateSocketFactory(
    @Nullable InputStream testCa, String androidSocketFatoryTls) throws Exception {
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH /* API level 14 */) {
    throw new RuntimeException(
        "android_socket_factory_tls doesn't work with API level less than 14.");
  }
  SSLCertificateSocketFactory factory = (SSLCertificateSocketFactory)
      SSLCertificateSocketFactory.getDefault(5000 /* Timeout in ms*/);
  // Use HTTP/2.0
  byte[] h2 = "h2".getBytes();
  byte[][] protocols = new byte[][]{h2};
  if (androidSocketFatoryTls.equals("alpn")) {
    Method setAlpnProtocols =
        factory.getClass().getDeclaredMethod("setAlpnProtocols", byte[][].class);
    setAlpnProtocols.invoke(factory, new Object[] { protocols });
  } else if (androidSocketFatoryTls.equals("npn")) {
    Method setNpnProtocols =
        factory.getClass().getDeclaredMethod("setNpnProtocols", byte[][].class);
    setNpnProtocols.invoke(factory, new Object[]{protocols});
  } else {
    throw new RuntimeException("Unknown protocol: " + androidSocketFatoryTls);
  }

  if (testCa != null) {
    factory.setTrustManagers(getTrustManagers(testCa));
  }

  return factory;
}
 
开发者ID:grpc,项目名称:grpc-java,代码行数:31,代码来源:TesterOkHttpChannelBuilder.java

示例11: createHttpClient

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public static DefaultHttpClient createHttpClient(String userAgent, boolean redirecting) {
	HttpParams params = new BasicHttpParams();

	// Turn off stale checking.  Our connections break all the time anyway,
       // and it's not worth it to pay the penalty of checking every time.
       HttpConnectionParams.setStaleCheckingEnabled(params, false);

       // Set the timeout in milliseconds until a connection is established. The default value is zero, that means the timeout is not used.
       HttpConnectionParams.setConnectionTimeout(params, SOCKET_OPERATION_TIMEOUT);
       // Set the default socket timeout (SO_TIMEOUT) in milliseconds which is the timeout for waiting for data.
       HttpConnectionParams.setSoTimeout(params, SOCKET_OPERATION_TIMEOUT);

       HttpConnectionParams.setSocketBufferSize(params, 8192);

       // Don't handle redirects -- return them to the caller.  Our code
       // often wants to re-POST after a redirect, which we must do ourselves.
       HttpClientParams.setRedirecting(params, redirecting);

       HttpProtocolParams.setUserAgent(params, userAgent);
	HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
	HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

       // Set the specified user agent and register standard protocols.
       SchemeRegistry schemeRegistry = new SchemeRegistry();
       schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
       if (AndroidUtils.isFroyo()) schemeRegistry.register(new Scheme("https", SSLCertificateSocketFactory.getHttpSocketFactory(SOCKET_OPERATION_TIMEOUT, null), 443));
       else schemeRegistry.register(new Scheme("https", SSLSocketFactory.getSocketFactory(), 443));

       final ClientConnectionManager manager = new ThreadSafeClientConnManager(params, schemeRegistry);

	return new DefaultHttpClient(manager, params);
}
 
开发者ID:asafge,项目名称:NewsBlurPlus,代码行数:33,代码来源:Utils.java

示例12: AndroidTls

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
public AndroidTls(Socket socket, InputStream in, OutputStream out,
        String authHost)
        throws NoSuchAlgorithmException, KeyManagementException, IOException {
    sslFactory = SSLCertificateSocketFactory.getInsecure(0, null);
    tls = (SSLSocket) (sslFactory.createSocket(socket, authHost, socket.getPort(), true));
    tls.setUseClientMode(true);
}
 
开发者ID:BombusMod,项目名称:BombusMod,代码行数:8,代码来源:AndroidTls.java

示例13: createSocket

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public Socket createSocket(Socket plainSocket, String host, int port, boolean autoClose) throws IOException {
	if (autoClose) {
		// we don't need the plainSocket
		plainSocket.close();
	}

	SSLCertificateSocketFactory sslSocketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);

	// create and connect SSL socket, but don't do hostname/certificate verification yet
	SSLSocket ssl = (SSLSocket) sslSocketFactory.createSocket(InetAddress.getByName(host), port);

	// enable TLSv1.1/1.2 if available
	ssl.setEnabledProtocols(ssl.getSupportedProtocols());

	// set up SNI before the handshake
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
		sslSocketFactory.setHostname(ssl, host);
	} else {
		try {
			java.lang.reflect.Method setHostnameMethod = ssl.getClass().getMethod("setHostname", String.class);
			setHostnameMethod.invoke(ssl, host);
		} catch (Exception e) {
			Log.d(TlsSniSocketFactory.class.getSimpleName(), "SNI not usable: " + e);
		}
	}

	// verify hostname and certificate
	SSLSession session = ssl.getSession();
	if (!hostnameVerifier.verify(host, session)) {
		throw new SSLPeerUnverifiedException("Cannot verify hostname: " + host);
	}

	return ssl;
}
 
开发者ID:erickok,项目名称:transdroid-search,代码行数:37,代码来源:TlsSniSocketFactory.java

示例14: createSocket

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
@Override
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public Socket createSocket(Socket plainSocket, String host, int port, boolean autoClose) throws IOException {
	if (autoClose) {
		// we don't need the plainSocket
		plainSocket.close();
	}

	SSLCertificateSocketFactory sslSocketFactory = (SSLCertificateSocketFactory) SSLCertificateSocketFactory.getDefault(0);

	// For self-signed certificates use a custom trust manager
	sslSocketFactory.setTrustManagers(new TrustManager[]{new IgnoreSSLTrustManager()});

	// create and connect SSL socket, but don't do hostname/certificate verification yet
	SSLSocket ssl = (SSLSocket) sslSocketFactory.createSocket(InetAddress.getByName(host), port);

	// enable TLSv1.1/1.2 if available
	ssl.setEnabledProtocols(ssl.getSupportedProtocols());

	// set up SNI before the handshake
	if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
		sslSocketFactory.setHostname(ssl, host);
	} else {
		try {
			java.lang.reflect.Method setHostnameMethod = ssl.getClass().getMethod("setHostname", String.class);
			setHostnameMethod.invoke(ssl, host);
		} catch (Exception e) {
			throw new IOException("SNI not usable: " + e, e);
		}
	}

	return ssl;
}
 
开发者ID:erickok,项目名称:transdroid-search,代码行数:34,代码来源:IgnoreTlsSniSocketFactory.java

示例15: TlsSocketFactory

import android.net.SSLCertificateSocketFactory; //导入依赖的package包/类
TlsSocketFactory(Context context) {
    SSLSessionCache cache = new SSLSessionCache(context);
    factory = SSLCertificateSocketFactory.getDefault(WebHelper.SOCKET_TIMEOUT, cache);
    hostnameVerifier = new org.apache.http.conn.ssl.BrowserCompatHostnameVerifier();
    cipherSuites = initCipherSuites();
}
 
开发者ID:bfabiszewski,项目名称:ulogger-android,代码行数:7,代码来源:TlsSocketFactory.java


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