本文整理汇总了Java中javax.net.ssl.SSLParameters.setServerNames方法的典型用法代码示例。如果您正苦于以下问题:Java SSLParameters.setServerNames方法的具体用法?Java SSLParameters.setServerNames怎么用?Java SSLParameters.setServerNames使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLParameters
的用法示例。
在下文中一共展示了SSLParameters.setServerNames方法的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;
}
示例2: 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;
}
示例3: copySSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
static SSLParameters copySSLParameters(SSLParameters p) {
SSLParameters p1 = new SSLParameters();
p1.setAlgorithmConstraints(p.getAlgorithmConstraints());
p1.setCipherSuites(p.getCipherSuites());
p1.setEnableRetransmissions(p.getEnableRetransmissions());
p1.setEndpointIdentificationAlgorithm(p.getEndpointIdentificationAlgorithm());
p1.setMaximumPacketSize(p.getMaximumPacketSize());
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;
}
示例4: test_setSSLParameters_Socket
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_setSSLParameters_Socket() throws Exception {
assumeJava8();
Socket socket = new OpenSSLSocketFactoryImpl().createSocket();
SSLParametersImpl impl = SSLParametersImpl.getDefault();
SSLParameters params = new SSLParameters();
List<SNIServerName> names = new ArrayList<SNIServerName>();
names.add(new SNIHostName("some.host"));
params.setServerNames(names);
params.setUseCipherSuitesOrder(false);
params.setEndpointIdentificationAlgorithm("ABC");
String[] applicationProtocols = new String[] {"foo", "bar"};
if (isJavaVersion(9)) {
setApplicationProtocols(params, applicationProtocols);
}
Platform.setSSLParameters(params, impl, (AbstractConscryptSocket) socket);
assertEquals("some.host", ((AbstractConscryptSocket) socket).getHostname());
assertFalse(impl.getUseCipherSuitesOrder());
assertEquals("ABC", impl.getEndpointIdentificationAlgorithm());
if (isJavaVersion(9)) {
assertArrayEquals(applicationProtocols, impl.getApplicationProtocols());
}
}
示例5: test_setSSLParameters_Engine
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_setSSLParameters_Engine() throws Exception {
assumeJava8();
SSLParametersImpl impl = SSLParametersImpl.getDefault();
SSLParameters params = new SSLParameters();
ConscryptEngine engine = new ConscryptEngine(impl);
List<SNIServerName> names = new ArrayList<SNIServerName>();
names.add(new SNIHostName("some.host"));
params.setServerNames(names);
params.setUseCipherSuitesOrder(false);
params.setEndpointIdentificationAlgorithm("ABC");
String[] applicationProtocols = new String[] {"foo", "bar"};
if (isJavaVersion(9)) {
setApplicationProtocols(params, applicationProtocols);
}
Platform.setSSLParameters(params, impl, engine);
assertEquals("some.host", engine.getHostname());
assertFalse(impl.getUseCipherSuitesOrder());
assertEquals("ABC", impl.getEndpointIdentificationAlgorithm());
if (isJavaVersion(9)) {
assertArrayEquals(applicationProtocols, impl.getApplicationProtocols());
}
}
示例6: init
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
static SSLClient init(String host, int port, String cipherSuiteFilter,
String sniHostName) throws NoSuchAlgorithmException, IOException {
SSLContext sslContext = SSLContext.getDefault();
SSLSocketFactory ssf = (SSLSocketFactory) sslContext.getSocketFactory();
SSLSocket socket = (SSLSocket) ssf.createSocket(host, port);
SSLParameters params = new SSLParameters();
if (cipherSuiteFilter != null) {
String[] cipherSuites = UnboundSSLUtils.filterStringArray(
ssf.getSupportedCipherSuites(), cipherSuiteFilter);
System.out.println("Client: enabled cipher suites: "
+ Arrays.toString(cipherSuites));
params.setCipherSuites(cipherSuites);
}
if (sniHostName != null) {
System.out.println("Client: set SNI hostname: " + sniHostName);
SNIHostName serverName = new SNIHostName(sniHostName);
List<SNIServerName> serverNames = new ArrayList<>();
serverNames.add(serverName);
params.setServerNames(serverNames);
}
socket.setSSLParameters(params);
return new SSLClient(socket);
}
示例7: 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;
}
示例8: getSSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
static void getSSLParameters(
SSLParameters params, SSLParametersImpl impl, AbstractConscryptSocket socket) {
params.setEndpointIdentificationAlgorithm(impl.getEndpointIdentificationAlgorithm());
params.setUseCipherSuitesOrder(impl.getUseCipherSuitesOrder());
if (impl.getUseSni() && AddressUtils.isValidSniHostname(socket.getHostname())) {
params.setServerNames(Collections.<SNIServerName>singletonList(
new SNIHostName(socket.getHostname())));
}
}
示例9: getSSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
static void getSSLParameters(
SSLParameters params, SSLParametersImpl impl, AbstractConscryptSocket socket) {
Java7PlatformUtil.getSSLParameters(params, impl);
params.setUseCipherSuitesOrder(impl.getUseCipherSuitesOrder());
if (impl.getUseSni() && AddressUtils.isValidSniHostname(socket.getHostname())) {
params.setServerNames(Collections.singletonList(
(SNIServerName) new SNIHostName(socket.getHostname())));
}
}
示例10: test_SSLParameters_setServerNames_duplicatedNameThrows
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setServerNames_duplicatedNameThrows() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
ArrayList<SNIServerName> dupeNames = new ArrayList<SNIServerName>();
dupeNames.add(new SNIHostName("www.example.com"));
dupeNames.add(new SNIHostName("www.example.com"));
try {
p.setServerNames(dupeNames);
fail("Should throw IllegalArgumentException when names are duplicated");
} catch (IllegalArgumentException expected) {
// Ignored.
}
}
示例11: test_SSLParameters_setServerNames_setNull_getNull
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setServerNames_setNull_getNull() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setServerNames(
Collections.singletonList((SNIServerName) new SNIHostName("www.example.com")));
assertNotNull(p.getServerNames());
p.setServerNames(null);
assertNull(p.getServerNames());
}
示例12: test_SSLParameters_setServerNames_setEmpty_getEmpty
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setServerNames_setEmpty_getEmpty() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setServerNames(new ArrayList<SNIServerName>());
Collection<SNIServerName> actual = p.getServerNames();
assertNotNull(actual);
assertEquals(0, actual.size());
}
示例13: test_SSLParameters_getServerNames_unmodifiable
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_getServerNames_unmodifiable() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setServerNames(
Collections.singletonList((SNIServerName) new SNIHostName("www.example.com")));
Collection<SNIServerName> actual = p.getServerNames();
try {
actual.add(new SNIHostName("www.foo.com"));
fail("Should not allow modifications to the list");
} catch (UnsupportedOperationException expected) {
// Ignored.
}
}
示例14: test_SSLSocket_SNIHostName
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLSocket_SNIHostName() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
TestSSLContext c = TestSSLContext.create();
final SSLSocket client = (SSLSocket) c.clientContext.getSocketFactory().createSocket();
SSLParameters clientParams = client.getSSLParameters();
clientParams.setServerNames(
Collections.singletonList((SNIServerName) new SNIHostName("www.example.com")));
client.setSSLParameters(clientParams);
SSLParameters serverParams = c.serverSocket.getSSLParameters();
serverParams.setSNIMatchers(
Collections.singletonList(SNIHostName.createSNIMatcher("www\\.example\\.com")));
c.serverSocket.setSSLParameters(serverParams);
client.connect(new InetSocketAddress(c.host, c.port));
final SSLSocket server = (SSLSocket) c.serverSocket.accept();
@SuppressWarnings("unused")
Future<?> future = runAsync(new Callable<Object>() {
@Override
public Object call() throws Exception {
client.startHandshake();
return null;
}
});
server.startHandshake();
SSLSession serverSession = server.getSession();
assertTrue(serverSession instanceof ExtendedSSLSession);
ExtendedSSLSession extendedServerSession = (ExtendedSSLSession) serverSession;
List<SNIServerName> requestedNames = extendedServerSession.getRequestedServerNames();
assertNotNull(requestedNames);
assertEquals(1, requestedNames.size());
SNIServerName serverName = requestedNames.get(0);
assertEquals(StandardConstants.SNI_HOST_NAME, serverName.getType());
assertTrue(serverName instanceof SNIHostName);
SNIHostName serverHostName = (SNIHostName) serverName;
assertEquals("www.example.com", serverHostName.getAsciiName());
}
示例15: readCertificatesHelper
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
private Certificate[] readCertificatesHelper(SSLProtocalHelper protocolHelper)
throws GeneralSecurityException, IOException {
SSLContext sslContext = SSLContext.getInstance("TLS");
// Accept as much certificates as possible
sslContext.init(null, new TrustManager[] { INSECURE_TRUST_MANAGER }, null);
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
// Prepare additional options: SNI server names
List<SNIServerName> serverNames = Arrays.asList(new SNIHostName(this.address.getHostName()));
// Start SSL handshake and retrieve certificates
Certificate[] certificates = null;
try (SSLSocket sslSocket = protocolHelper.createSSLSocket(sslSocketFactory, this.address, this.port)) {
sslSocket.setSoTimeout(SOCKET_TIMEOUT);
SSLParameters sslParams = sslSocket.getSSLParameters();
sslParams.setServerNames(serverNames);
sslSocket.setSSLParameters(sslParams);
sslSocket.startHandshake();
certificates = sslSocket.getSession().getPeerCertificates();
}
return certificates;
}