本文整理汇总了Java中javax.net.ssl.SSLParameters.setSNIMatchers方法的典型用法代码示例。如果您正苦于以下问题:Java SSLParameters.setSNIMatchers方法的具体用法?Java SSLParameters.setSNIMatchers怎么用?Java SSLParameters.setSNIMatchers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.net.ssl.SSLParameters
的用法示例。
在下文中一共展示了SSLParameters.setSNIMatchers方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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;
}
示例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: getSSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
/**
* Returns the SSLParameters in effect for newly accepted connections.
*/
@Override
synchronized public SSLParameters getSSLParameters() {
SSLParameters params = super.getSSLParameters();
// the super implementation does not handle the following parameters
params.setEndpointIdentificationAlgorithm(identificationProtocol);
params.setAlgorithmConstraints(algorithmConstraints);
params.setSNIMatchers(sniMatchers);
params.setUseCipherSuitesOrder(preferLocalCipherSuites);
return params;
}
示例5: init
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
static SSLEchoServer init(String cipherSuiteFilter,
String sniPattern) throws NoSuchAlgorithmException, IOException {
SSLContext context = SSLContext.getDefault();
SSLServerSocketFactory ssf =
(SSLServerSocketFactory) context.getServerSocketFactory();
SSLServerSocket ssocket =
(SSLServerSocket) ssf.createServerSocket(0);
// specify enabled cipher suites
if (cipherSuiteFilter != null) {
String[] ciphersuites = UnboundSSLUtils.filterStringArray(
ssf.getSupportedCipherSuites(), cipherSuiteFilter);
System.out.println("Server: enabled cipher suites: "
+ Arrays.toString(ciphersuites));
ssocket.setEnabledCipherSuites(ciphersuites);
}
// specify SNI matcher pattern
if (sniPattern != null) {
System.out.println("Server: set SNI matcher: " + sniPattern);
SNIMatcher matcher = SNIHostName.createSNIMatcher(sniPattern);
List<SNIMatcher> matchers = new ArrayList<>();
matchers.add(matcher);
SSLParameters params = ssocket.getSSLParameters();
params.setSNIMatchers(matchers);
ssocket.setSSLParameters(params);
}
return new SSLEchoServer(ssocket);
}
示例6: getSSLParameters
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
/**
* Returns the SSLParameters in effect for newly accepted connections.
*/
@Override
public synchronized SSLParameters getSSLParameters() {
SSLParameters params = super.getSSLParameters();
// the super implementation does not handle the following parameters
params.setEndpointIdentificationAlgorithm(identificationProtocol);
params.setAlgorithmConstraints(algorithmConstraints);
params.setSNIMatchers(sniMatchers);
params.setUseCipherSuitesOrder(preferLocalCipherSuites);
params.setApplicationProtocols(applicationProtocols);
return params;
}
示例7: 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;
}
示例8: test_SSLParameters_setSNIMatchers_duplicatedNameThrows
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setSNIMatchers_duplicatedNameThrows() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
ArrayList<SNIMatcher> dupeMatchers = new ArrayList<SNIMatcher>();
dupeMatchers.add(SNIHostName.createSNIMatcher("www\\.example\\.com"));
dupeMatchers.add(SNIHostName.createSNIMatcher("www\\.example\\.com"));
try {
p.setSNIMatchers(dupeMatchers);
fail("Should throw IllegalArgumentException when matchers are duplicated");
} catch (IllegalArgumentException expected) {
// Ignored.
}
}
示例9: test_SSLParameters_setSNIMatchers_setNull_getNull
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setSNIMatchers_setNull_getNull() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setSNIMatchers(
Collections.singletonList(SNIHostName.createSNIMatcher("www\\.example\\.com")));
assertNotNull(p.getSNIMatchers());
p.setSNIMatchers(null);
assertNull(p.getSNIMatchers());
}
示例10: test_SSLParameters_setSNIMatchers_setEmpty_getEmpty
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_setSNIMatchers_setEmpty_getEmpty() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setSNIMatchers(
Collections.singletonList(SNIHostName.createSNIMatcher("www\\.example\\.com")));
assertEquals(1, p.getSNIMatchers().size());
p.setSNIMatchers(Collections.<SNIMatcher>emptyList());
Collection<SNIMatcher> actual = p.getSNIMatchers();
assertNotNull(actual);
assertEquals(0, actual.size());
}
示例11: test_SSLParameters_getSNIMatchers_unmodifiable
import javax.net.ssl.SSLParameters; //导入方法依赖的package包/类
@Test
public void test_SSLParameters_getSNIMatchers_unmodifiable() throws Exception {
TestUtils.assumeSNIHostnameAvailable();
SSLParameters p = new SSLParameters();
p.setSNIMatchers(
Collections.singletonList(SNIHostName.createSNIMatcher("www\\.example\\.com")));
Collection<SNIMatcher> actual = p.getSNIMatchers();
try {
actual.add(SNIHostName.createSNIMatcher("www\\.google\\.com"));
fail("Should not allow modification of list");
} catch (UnsupportedOperationException expected) {
// Ignored.
}
}
示例12: 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());
}