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


Java SSLParameters類代碼示例

本文整理匯總了Java中javax.net.ssl.SSLParameters的典型用法代碼示例。如果您正苦於以下問題:Java SSLParameters類的具體用法?Java SSLParameters怎麽用?Java SSLParameters使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


SSLParameters類屬於javax.net.ssl包,在下文中一共展示了SSLParameters類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copySSLParameters

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
public static SSLParameters copySSLParameters(SSLParameters p) {
    SSLParameters p1 = new SSLParameters();
    p1.setAlgorithmConstraints(p.getAlgorithmConstraints());
    p1.setCipherSuites(p.getCipherSuites());
    // JDK 8 EXCL START
    p1.setEnableRetransmissions(p.getEnableRetransmissions());
    p1.setMaximumPacketSize(p.getMaximumPacketSize());
    // JDK 8 EXCL END
    p1.setEndpointIdentificationAlgorithm(p.getEndpointIdentificationAlgorithm());
    p1.setNeedClientAuth(p.getNeedClientAuth());
    String[] protocols = p.getProtocols();
    if (protocols != null) {
        p1.setProtocols(protocols.clone());
    }
    p1.setSNIMatchers(p.getSNIMatchers());
    p1.setServerNames(p.getServerNames());
    p1.setUseCipherSuitesOrder(p.getUseCipherSuitesOrder());
    p1.setWantClientAuth(p.getWantClientAuth());
    return p1;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:21,代碼來源:Utils.java

示例2: configureTlsExtensions

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
@Override
public void configureTlsExtensions(SSLSocket sslSocket, String hostname,
    List<Protocol> protocols) {
  try {
    SSLParameters sslParameters = sslSocket.getSSLParameters();

    List<String> names = alpnProtocolNames(protocols);

    setProtocolMethod.invoke(sslParameters,
        new Object[] {names.toArray(new String[names.size()])});

    sslSocket.setSSLParameters(sslParameters);
  } catch (IllegalAccessException | InvocationTargetException e) {
    throw new AssertionError();
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:Jdk9Platform.java

示例3: configureTlsExtensions

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
@Override
public void configureTlsExtensions(SSLSocket sslSocket, String hostname,
    List<Protocol> protocols) {
  try {
    SSLParameters sslParameters = sslSocket.getSSLParameters();

    List<String> names = alpnProtocolNames(protocols);

    setProtocolMethod.invoke(sslParameters,
        new Object[] {names.toArray(new String[names.size()])});

    sslSocket.setSSLParameters(sslParameters);
  } catch (IllegalAccessException | InvocationTargetException e) {
    throw assertionError("unable to set ssl parameters", e);
  }
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:17,代碼來源:Jdk9Platform.java

示例4: JedisFactory

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
public JedisFactory(final URI uri, final int connectionTimeout, final int soTimeout, final String clientName,
		final boolean ssl, final SSLSocketFactory sslSocketFactory, final SSLParameters sslParameters,
		final HostnameVerifier hostnameVerifier) {
	if (!JedisURIHelper.isValid(uri)) {
		throw new InvalidURIException(
				String.format("Cannot open Redis connection due invalid URI. %s", uri.toString()));
	}

	this.hostAndPort.set(new HostAndPort(uri.getHost(), uri.getPort()));
	this.connectionTimeout = connectionTimeout;
	this.soTimeout = soTimeout;
	this.password = JedisURIHelper.getPassword(uri);
	this.database = JedisURIHelper.getDBIndex(uri);
	this.clientName = clientName;
	this.ssl = ssl;
	this.sslSocketFactory = sslSocketFactory;
	this.sslParameters = sslParameters;
	this.hostnameVerifier = hostnameVerifier;
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:JedisFactory.java

示例5: JedisPool

import javax.net.ssl.SSLParameters; //導入依賴的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

示例6: JedisShardInfo

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
public JedisShardInfo(String host, SSLSocketFactory sslSocketFactory, SSLParameters sslParameters,
		HostnameVerifier hostnameVerifier) {
	super(Sharded.DEFAULT_WEIGHT);
	URI uri = URI.create(host);
	if (JedisURIHelper.isValid(uri)) {
		this.host = uri.getHost();
		this.port = uri.getPort();
		this.password = JedisURIHelper.getPassword(uri);
		this.db = JedisURIHelper.getDBIndex(uri);
		this.ssl = uri.getScheme().equals("rediss");
		this.sslSocketFactory = sslSocketFactory;
		this.sslParameters = sslParameters;
		this.hostnameVerifier = hostnameVerifier;
	} else {
		this.host = host;
		this.port = Protocol.DEFAULT_PORT;
	}
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:19,代碼來源:JedisShardInfo.java

示例7: setupNodeIfNotExist

import javax.net.ssl.SSLParameters; //導入依賴的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

示例8: connectWithShardInfoAndCustomHostnameVerifier

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
/**
 * Tests opening an SSL/TLS connection to redis with a custom hostname
 * verifier.
 */
@Test
public void connectWithShardInfoAndCustomHostnameVerifier() {
  final URI uri = URI.create("rediss://localhost:6390");
  final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
  final SSLParameters sslParameters = new SSLParameters();

  HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
  JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
  shardInfo.setPassword("foobared");

  Jedis jedis = new Jedis(shardInfo);
  jedis.get("foo");
  jedis.disconnect();
  jedis.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:20,代碼來源:SSLJedisTest.java

示例9: connectWithShardInfoAndCustomSocketFactory

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
/**
 * Tests opening an SSL/TLS connection to redis with a custom socket factory.
 */
@Test
public void connectWithShardInfoAndCustomSocketFactory() throws Exception {
  final URI uri = URI.create("rediss://localhost:6390");
  final SSLSocketFactory sslSocketFactory = createTrustStoreSslSocketFactory();
  final SSLParameters sslParameters = new SSLParameters();

  HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
  JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
  shardInfo.setPassword("foobared");

  Jedis jedis = new Jedis(shardInfo);
  jedis.get("foo");
  jedis.disconnect();
  jedis.close();
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:19,代碼來源:SSLJedisTest.java

示例10: connectWithShardInfoAndCustomHostnameVerifierByIpAddress

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
/**
 * Tests opening an SSL/TLS connection to redis with a custom hostname
 * verifier. This test should fail because "127.0.0.1" does not match the
 * certificate subject common name and there are no subject alternative names
 * in the certificate.
 */
@Test
public void connectWithShardInfoAndCustomHostnameVerifierByIpAddress() {
  final URI uri = URI.create("rediss://127.0.0.1:6390");
  final SSLSocketFactory sslSocketFactory = (SSLSocketFactory) SSLSocketFactory.getDefault();
  final SSLParameters sslParameters = new SSLParameters();

  HostnameVerifier hostnameVerifier = new BasicHostnameVerifier();
  JedisShardInfo shardInfo = new JedisShardInfo(uri, sslSocketFactory, sslParameters, hostnameVerifier);
  shardInfo.setPassword("foobared");

  Jedis jedis = new Jedis(shardInfo);
  try {
    jedis.get("foo");
    Assert.fail("The code did not throw the expected JedisConnectionException.");
  } catch (JedisConnectionException e) {
    Assert.assertEquals("The JedisConnectionException does not contain the expected message.",
        "The connection to '127.0.0.1' failed ssl/tls hostname verification.", e.getMessage());
  }

  try {
    jedis.close();
  } catch (Throwable e1) {
    // Expected.
  }
}
 
開發者ID:qq1588518,項目名稱:JRediClients,代碼行數:32,代碼來源:SSLJedisTest.java

示例11: createSslEngine

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
public SSLEngine createSslEngine(String peerHost, int peerPort) {
    SSLEngine sslEngine = sslContext.createSSLEngine(peerHost, peerPort);
    if (cipherSuites != null) sslEngine.setEnabledCipherSuites(cipherSuites);
    if (enabledProtocols != null) sslEngine.setEnabledProtocols(enabledProtocols);

    // SSLParameters#setEndpointIdentificationAlgorithm enables endpoint validation
    // only in client mode. Hence, validation is enabled only for clients.
    if (mode == Mode.SERVER) {
        sslEngine.setUseClientMode(false);
        if (needClientAuth)
            sslEngine.setNeedClientAuth(needClientAuth);
        else
            sslEngine.setWantClientAuth(wantClientAuth);
    } else {
        sslEngine.setUseClientMode(true);
        SSLParameters sslParams = sslEngine.getSSLParameters();
        sslParams.setEndpointIdentificationAlgorithm(endpointIdentification);
        sslEngine.setSSLParameters(sslParams);
    }
    return sslEngine;
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:22,代碼來源:SslFactory.java

示例12: HttpResponseImpl

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
public HttpResponseImpl(Response response,
                        HttpRequestImpl pushRequest,
                        ImmutableHeaders headers,
                        Stream<T> stream,
                        SSLParameters sslParameters,
                        T body) {
    this.responseCode = response.statusCode();
    this.exchange = null;
    this.initialRequest = null; // ## fix this
    this.finalRequest = pushRequest;
    this.headers = headers;
    //this.trailers = null;
    this.sslParameters = sslParameters;
    this.uri = finalRequest.uri(); // TODO: take from headers
    this.version = HttpClient.Version.HTTP_2;
    this.connection = stream.connection();
    this.stream = stream;
    this.body = body;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:HttpResponseImpl.java

示例13: initSecure

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
final ServerSocket initSecure(int port) throws Exception {
    ServerSocketFactory fac;
    if (sslContext != null) {
        fac = sslContext.getServerSocketFactory();
    } else {
        fac = SSLServerSocketFactory.getDefault();
    }
    SSLServerSocket se = (SSLServerSocket) fac.createServerSocket(port);
    SSLParameters sslp = se.getSSLParameters();
    sslp.setApplicationProtocols(new String[]{"h2"});
    se.setSSLParameters(sslp);
    se.setEnabledCipherSuites(se.getSupportedCipherSuites());
    se.setEnabledProtocols(se.getSupportedProtocols());
    // other initialisation here
    return se;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:Http2TestServer.java

示例14: getClientSSLEngine

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
/**
 * Returns client ssl engine.
 *
 * @param context - SSLContext to get SSLEngine from.
 * @param useSNI  - flag used to enable or disable using SNI extension.
 *                Needed for Kerberos.
 */
public static SSLEngine getClientSSLEngine(
        SSLContext context, boolean useSNI) {

    SSLEngine clientEngine = context.createSSLEngine(HOST, 80);
    clientEngine.setUseClientMode(true);
    if (useSNI) {
        SNIHostName serverName = new SNIHostName(SERVER_NAME);
        List<SNIServerName> serverNames = new ArrayList<>();
        serverNames.add(serverName);
        SSLParameters params = clientEngine.getSSLParameters();
        params.setServerNames(serverNames);
        clientEngine.setSSLParameters(params);
    }
    return clientEngine;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:SSLEngineTestCase.java

示例15: getServerSSLEngine

import javax.net.ssl.SSLParameters; //導入依賴的package包/類
/**
 * Returns server ssl engine.
 *
 * @param context - SSLContext to get SSLEngine from.
 * @param useSNI  - flag used to enable or disable using SNI extension.
 *                Needed for Kerberos.
 */
public static SSLEngine getServerSSLEngine(
        SSLContext context, boolean useSNI) {

    SSLEngine serverEngine = context.createSSLEngine();
    serverEngine.setUseClientMode(false);
    if (useSNI) {
        SNIMatcher matcher = SNIHostName.createSNIMatcher(SNI_PATTERN);
        List<SNIMatcher> matchers = new ArrayList<>();
        matchers.add(matcher);
        SSLParameters params = serverEngine.getSSLParameters();
        params.setSNIMatchers(matchers);
        serverEngine.setSSLParameters(params);
    }
    return serverEngine;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:23,代碼來源:SSLEngineTestCase.java


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