SSLSocketTest.java 文件源码

java
阅读 29 收藏 0 点赞 0 评论 0

项目:conscrypt 作者:
@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());
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号