本文整理汇总了Java中javax.net.ssl.SSLSocketFactory类的典型用法代码示例。如果您正苦于以下问题:Java SSLSocketFactory类的具体用法?Java SSLSocketFactory怎么用?Java SSLSocketFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SSLSocketFactory类属于javax.net.ssl包,在下文中一共展示了SSLSocketFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Address
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
SSLSocketFactory sslSocketFactory, HostnameVerifier hostnameVerifier,
CertificatePinner certificatePinner, Authenticator proxyAuthenticator, Proxy proxy,
List<Protocol> protocols, List<ConnectionSpec> connectionSpecs, ProxySelector proxySelector) {
this.url = new HttpUrl.Builder()
.scheme(sslSocketFactory != null ? "https" : "http")
.host(uriHost)
.port(uriPort)
.build();
if (dns == null) throw new NullPointerException("dns == null");
this.dns = dns;
if (socketFactory == null) throw new NullPointerException("socketFactory == null");
this.socketFactory = socketFactory;
if (proxyAuthenticator == null) {
throw new NullPointerException("proxyAuthenticator == null");
}
this.proxyAuthenticator = proxyAuthenticator;
if (protocols == null) throw new NullPointerException("protocols == null");
this.protocols = Util.immutableList(protocols);
if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
this.connectionSpecs = Util.immutableList(connectionSpecs);
if (proxySelector == null) throw new NullPointerException("proxySelector == null");
this.proxySelector = proxySelector;
this.proxy = proxy;
this.sslSocketFactory = sslSocketFactory;
this.hostnameVerifier = hostnameVerifier;
this.certificatePinner = certificatePinner;
}
示例2: RealConnection
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
RealConnection(SocketFactory socketFactory,
SSLSocketFactory sslSocketFactory,
HostnameVerifier hostnameVerifier,
Endpoint endpoint, int connectTimeout, TimeUnit timeUnit) throws IOException {
this.socketFactory = socketFactory;
this.sslSocketFactory = sslSocketFactory;
this.hostnameVerifier = hostnameVerifier;
this.endpoint = endpoint;
try {
this.rawSocket = createSocket(endpoint, (int) timeUnit.toMillis(connectTimeout));
this.socket = upgradeSocket(rawSocket, endpoint);
this.inputStream = socket.getInputStream();
this.outputStream = socket.getOutputStream();
this.source = Okio.buffer(Okio.source(inputStream));
this.sink = Okio.buffer(Okio.sink(outputStream));
socket.setSoTimeout(0);
source.timeout().timeout(readTimeout(), TimeUnit.MILLISECONDS);
sink.timeout().timeout(writeTimeout(), TimeUnit.MILLISECONDS);
connected = true;
} finally {
if (!connected) {
close();
}
}
}
示例3: build
import javax.net.ssl.SSLSocketFactory; //导入依赖的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;
}
示例4: Address
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public Address(String uriHost, int uriPort, Dns dns, SocketFactory socketFactory,
@Nullable SSLSocketFactory sslSocketFactory, @Nullable HostnameVerifier hostnameVerifier,
@Nullable CertificatePinner certificatePinner, Authenticator proxyAuthenticator,
@Nullable Proxy proxy, List<Protocol> protocols, List<ConnectionSpec> connectionSpecs,
ProxySelector proxySelector) {
this.url = new HttpUrl.Builder()
.scheme(sslSocketFactory != null ? "https" : "http")
.host(uriHost)
.port(uriPort)
.build();
if (dns == null) throw new NullPointerException("dns == null");
this.dns = dns;
if (socketFactory == null) throw new NullPointerException("socketFactory == null");
this.socketFactory = socketFactory;
if (proxyAuthenticator == null) {
throw new NullPointerException("proxyAuthenticator == null");
}
this.proxyAuthenticator = proxyAuthenticator;
if (protocols == null) throw new NullPointerException("protocols == null");
this.protocols = Util.immutableList(protocols);
if (connectionSpecs == null) throw new NullPointerException("connectionSpecs == null");
this.connectionSpecs = Util.immutableList(connectionSpecs);
if (proxySelector == null) throw new NullPointerException("proxySelector == null");
this.proxySelector = proxySelector;
this.proxy = proxy;
this.sslSocketFactory = sslSocketFactory;
this.hostnameVerifier = hostnameVerifier;
this.certificatePinner = certificatePinner;
}
示例5: accept
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
@Override
public Socket accept() throws IOException {
final SSLSocketFactory sslSocketFactory =
context == null ?
getDefaultSSLSocketFactory() : context.getSocketFactory();
Socket socket = super.accept();
SSLSocket sslSocket = (SSLSocket) sslSocketFactory.createSocket(
socket, socket.getInetAddress().getHostName(),
socket.getPort(), true);
sslSocket.setUseClientMode(false);
if (enabledCipherSuites != null) {
sslSocket.setEnabledCipherSuites(enabledCipherSuites);
}
if (enabledProtocols != null) {
sslSocket.setEnabledProtocols(enabledProtocols);
}
sslSocket.setNeedClientAuth(needClientAuth);
return sslSocket;
}
示例6: connect
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public synchronized void connect() {
Log.w(TAG, "WSC connect()...");
if (client == null) {
String filledUri = String.format(wsUri, credentialsProvider.getUser(), credentialsProvider.getPassword());
Pair<SSLSocketFactory, X509TrustManager> socketFactory = createTlsSocketFactory(trustStore);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.sslSocketFactory(socketFactory.first(), socketFactory.second())
.readTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS)
.connectTimeout(KEEPALIVE_TIMEOUT_SECONDS + 10, TimeUnit.SECONDS)
.build();
Request.Builder requestBuilder = new Request.Builder().url(filledUri);
if (userAgent != null) {
requestBuilder.addHeader("X-Signal-Agent", userAgent);
}
this.connected = false;
this.client = okHttpClient.newWebSocket(requestBuilder.build(), this);
}
}
示例7: tls_missingTlsVersion
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
@Test public void tls_missingTlsVersion() throws Exception {
ConnectionSpec tlsSpec = new ConnectionSpec.Builder(true)
.cipherSuites(CipherSuite.TLS_RSA_WITH_RC4_128_MD5)
.tlsVersions(TlsVersion.TLS_1_2)
.supportsTlsExtensions(false)
.build();
SSLSocket socket = (SSLSocket) SSLSocketFactory.getDefault().createSocket();
socket.setEnabledCipherSuites(new String[] {
CipherSuite.TLS_RSA_WITH_RC4_128_MD5.javaName,
});
socket.setEnabledProtocols(
new String[] {TlsVersion.TLS_1_2.javaName, TlsVersion.TLS_1_1.javaName});
assertTrue(tlsSpec.isCompatible(socket));
socket.setEnabledProtocols(new String[] {TlsVersion.TLS_1_1.javaName});
assertFalse(tlsSpec.isCompatible(socket));
}
示例8: getSSLSocketFactory
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
/**
* 获得SSLSocektFactory
*
* @param password 密码
* @param keyStorePath 密钥库路径
* @param trustStorePath 信任库路径
* @return SSLSocketFactory
* @throws Exception
*/
private static SSLSocketFactory getSSLSocketFactory(String password, String keyStorePath, String trustStorePath)
throws Exception {
// 实例化密钥库
KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
// 获得密钥库
KeyStore keyStore = getKeyStore(keyStorePath, password);
// 初始化密钥工厂
keyManagerFactory.init(keyStore, password.toCharArray());
// 实例化信任库
TrustManagerFactory trustManagerFactory = TrustManagerFactory
.getInstance(TrustManagerFactory.getDefaultAlgorithm());
// 获得信任库
KeyStore trustStore = getKeyStore(trustStorePath, password);
// 初始化信任库
trustManagerFactory.init(trustStore);
// 实例化SSL上下文
SSLContext ctx = SSLContext.getInstance(PROTOCOL);
// 初始化SSL上下文
ctx.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), new SecureRandom());
// 获得SSLSocketFactory
return ctx.getSocketFactory();
}
示例9: getSocketFactoryImpl
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
/**
* Retrieves the underlying javax.net.ssl.SSLSocketFactory.
*
* @throws Exception if there is a problem retrieving the
* underlying factory
* @return the underlying javax.net.ssl.SSLSocketFactory
*/
protected SSLSocketFactory getSocketFactoryImpl() throws Exception {
Object factory;
synchronized (socket_factory_mutex) {
factory = socketFactory;
if (factory == null) {
factory = SSLSocketFactory.getDefault();
socketFactory = factory;
}
}
return (SSLSocketFactory) factory;
}
示例10: createSslSocketFactory
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
private SSLSocketFactory createSslSocketFactory() throws KeyStoreException, IOException, NoSuchAlgorithmException, CertificateException, UnrecoverableKeyException, KeyManagementException {
// load up the key store
String STORETYPE = "JKS";
String KEYSTORE = "keystore.jks";
String STOREPASSWORD = "storepassword";
String KEYPASSWORD = "keypassword";
KeyStore ks = KeyStore.getInstance(STORETYPE);
ks.load(MattermostClient.class.getResourceAsStream(KEYSTORE), STOREPASSWORD.toCharArray());
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, KEYPASSWORD.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
SSLContext sslContext = null;
sslContext = SSLContext.getInstance("TLS");
// sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
sslContext.init(null, null, null); // will use java's default key and trust store which is sufficient unless you deal with self-signed certificates
return sslContext.getSocketFactory();// (SSLSocketFactory) SSLSocketFactory.getDefault();
}
示例11: JedisPool
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public JedisPool(final String host, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
final HostnameVerifier hostnameVerifier) {
URI uri = URI.create(host);
if (JedisURIHelper.isValid(uri)) {
String h = uri.getHost();
int port = uri.getPort();
String password = JedisURIHelper.getPassword(uri);
int database = JedisURIHelper.getDBIndex(uri);
boolean ssl = uri.getScheme().equals("rediss");
this.internalPool = new GenericObjectPool<Jedis>(
new JedisFactory(h, port, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT, password, database,
null, ssl, sslSocketFactory, sslParameters, hostnameVerifier),
new GenericObjectPoolConfig());
} else {
this.internalPool = new GenericObjectPool<Jedis>(
new JedisFactory(host, Protocol.DEFAULT_PORT, Protocol.DEFAULT_TIMEOUT, Protocol.DEFAULT_TIMEOUT,
null, Protocol.DEFAULT_DATABASE, null, false, null, null, null),
new GenericObjectPoolConfig());
}
}
示例12: setupNodeIfNotExist
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public JedisPool setupNodeIfNotExist(HostAndPort node, boolean ssl, SSLSocketFactory sslSocketFactory,
SSLParameters sslParameters, HostnameVerifier hostnameVerifier) {
w.lock();
try {
String nodeKey = getNodeKey(node);
JedisPool existingPool = nodes.get(nodeKey);
if (existingPool != null)
return existingPool;
JedisPool nodePool = new JedisPool(poolConfig, node.getHost(), node.getPort(), connectionTimeout, soTimeout,
password, 0, null, ssl, sslSocketFactory, sslParameters, hostnameVerifier);
nodes.put(nodeKey, nodePool);
return nodePool;
} finally {
w.unlock();
}
}
示例13: getSSLSocketFactory
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public static SSLSocketFactory getSSLSocketFactory () throws KeyManagementException, NoSuchProviderException, NoSuchAlgorithmException {
if(VISSLFACTORY == null) {
TrustManager[] tm = {new MyX509TrustManager()};
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new SecureRandom());
VISSLFACTORY = sslContext.getSocketFactory();
}
return VISSLFACTORY;
}
示例14: configHttps
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
public static void configHttps(HttpURLConnection conn) throws Exception {
TrustManager[] tm = { new TrustAllX509TrustManager() };
SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
sslContext.init(null, tm, new java.security.SecureRandom());
SSLSocketFactory ssf = sslContext.getSocketFactory();
// ssf.setHostnameVerifier(new TrustAllHostnameVerifier());
((HttpsURLConnection) conn).setSSLSocketFactory(ssf);
((HttpsURLConnection) conn)
.setHostnameVerifier(new TrustAllHostnameVerifier());
}
示例15: setSSLSocketFactory
import javax.net.ssl.SSLSocketFactory; //导入依赖的package包/类
/**
* Sets the SSL socket factory.
* @param sf the SSL socket factory
*/
public void setSSLSocketFactory(SSLSocketFactory sf) {
if (sf == null) {
throw new IllegalArgumentException(
"no SSLSocketFactory specified");
}
SecurityManager sm = System.getSecurityManager();
if (sm != null) {
sm.checkSetFactory();
}
sslSocketFactory = sf;
}