當前位置: 首頁>>代碼示例>>Java>>正文


Java SSLSocketFactory類代碼示例

本文整理匯總了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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:36,代碼來源:Address.java

示例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();
        }
    }
}
 
開發者ID:pCloud,項目名稱:pcloud-networking-java,代碼行數:26,代碼來源:RealConnection.java

示例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;
}
 
開發者ID:symphonyoss,項目名稱:JCurl,代碼行數:30,代碼來源:JCurl.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:37,代碼來源:Address.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:20,代碼來源:ConnectorBootstrap.java

示例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);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-lib,代碼行數:24,代碼來源:WebSocketConnection.java

示例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));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:20,代碼來源:ConnectionSpecTest.java

示例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();

}
 
開發者ID:youngMen1,項目名稱:JAVA-,代碼行數:33,代碼來源:HTTPSCoder.java

示例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;
}
 
開發者ID:parabuild-ci,項目名稱:parabuild-ci,代碼行數:23,代碼來源:HsqlSocketFactorySecure.java

示例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();
}
 
開發者ID:stefandotti,項目名稱:intellij-mattermost-plugin,代碼行數:23,代碼來源:MattermostClient.java

示例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());
	}
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:21,代碼來源:JedisPool.java

示例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();
	}
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:18,代碼來源:JedisClusterInfoCache.java

示例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;
    }
 
開發者ID:ctripcorp,項目名稱:cornerstone,代碼行數:11,代碼來源:SecurityUtil.java

示例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());
}
 
開發者ID:zhaojunfei,項目名稱:lemon,代碼行數:14,代碼來源:CdnUtils.java

示例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;
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:18,代碼來源:HttpsURLConnection.java


注:本文中的javax.net.ssl.SSLSocketFactory類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。