fix simone review comments

Signed-off-by: olivier lamy <oliver.lamy@gmail.com>
This commit is contained in:
olivier lamy 2019-03-13 16:29:21 +01:00
parent 9471eff332
commit a21dab222f
3 changed files with 24 additions and 43 deletions

View File

@ -62,10 +62,7 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
{ {
try try
{ {
// with java 9+ we must use Conscrypt.setApplicationProtocolSelector(sslEngine,new ALPNCallback((ALPNServerConnection)connection));
//sslEngine.setHandshakeApplicationProtocolSelector(new ALPNCallback((ALPNServerConnection)connection));
Conscrypt.setApplicationProtocolSelector(sslEngine,
toApplicationProtocolSelector(new ALPNCallback((ALPNServerConnection)connection)));
} }
catch (RuntimeException x) catch (RuntimeException x)
{ {
@ -77,34 +74,29 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
} }
} }
private static ApplicationProtocolSelector toApplicationProtocolSelector(BiFunction<SSLEngine, List<String>, String> selector) private final class ALPNCallback extends ApplicationProtocolSelector implements BiFunction<SSLEngine,List<String>,String>, SslHandshakeListener
{
return new ApplicationProtocolSelector()
{
@Override
public String selectApplicationProtocol(SSLEngine engine, List<String> protocols)
{
return selector.apply(engine, protocols);
}
@Override
public String selectApplicationProtocol(SSLSocket socket, List<String> protocols)
{
throw new UnsupportedOperationException();
}
};
}
private final class ALPNCallback implements BiFunction<SSLEngine,List<String>,String>, SslHandshakeListener
{ {
private final ALPNServerConnection alpnConnection; private final ALPNServerConnection alpnConnection;
private ALPNCallback(ALPNServerConnection connection) private ALPNCallback(ALPNServerConnection connection)
{ {
alpnConnection = connection; alpnConnection = connection;
((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this); ((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this);
} }
@Override
public String selectApplicationProtocol(SSLEngine engine, List<String> protocols)
{
return apply(engine, protocols);
}
@Override
public String selectApplicationProtocol(SSLSocket socket, List<String> protocols)
{
throw new UnsupportedOperationException();
}
@Override @Override
public String apply(SSLEngine engine, List<String> protocols) public String apply(SSLEngine engine, List<String> protocols)
{ {

View File

@ -63,12 +63,6 @@ public class ConscryptHTTP2ServerTest
Security.addProvider(new OpenSSLProvider()); Security.addProvider(new OpenSSLProvider());
} }
public static void main(String[] args)
throws Exception
{
new ConscryptHTTP2ServerTest().startServer();
}
private SslContextFactory newSslContextFactory() private SslContextFactory newSslContextFactory()
{ {
Path path = Paths.get("src", "test", "resources"); Path path = Paths.get("src", "test", "resources");
@ -81,17 +75,16 @@ public class ConscryptHTTP2ServerTest
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setProvider("Conscrypt"); sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setEndpointIdentificationAlgorithm(null); sslContextFactory.setEndpointIdentificationAlgorithm(null);
if (JavaVersion.VERSION.getPlatform() < 9) if (JavaVersion.VERSION.getPlatform()<9)
{ {
// conscrypt enable TLSv1.3 per default but it's not supported in jdk8 // conscrypt enable TLSv1.3 per default but it's not supported in jdk8
sslContextFactory.addExcludeProtocols( "TLSv1.3" ); sslContextFactory.addExcludeProtocols("TLSv1.3");
} }
return sslContextFactory; return sslContextFactory;
} }
@BeforeEach @BeforeEach
public void startServer() public void startServer() throws Exception
throws Exception
{ {
HttpConfiguration httpsConfig = new HttpConfiguration(); HttpConfiguration httpsConfig = new HttpConfiguration();
@ -114,9 +107,7 @@ public class ConscryptHTTP2ServerTest
server.setHandler(new AbstractHandler() server.setHandler(new AbstractHandler()
{ {
@Override @Override
public void handle(String target,Request baseRequest,HttpServletRequest request, public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
HttpServletResponse response)
throws IOException, ServletException
{ {
response.setStatus(200); response.setStatus(200);
baseRequest.setHandled(true); baseRequest.setHandled(true);
@ -128,8 +119,7 @@ public class ConscryptHTTP2ServerTest
} }
@AfterEach @AfterEach
public void stopServer() public void stopServer() throws Exception
throws Exception
{ {
if (server != null) if (server != null)
{ {
@ -139,8 +129,7 @@ public class ConscryptHTTP2ServerTest
@Test @Test
public void test_simple_query() public void test_simple_query() throws Exception
throws Exception
{ {
HTTP2Client h2Client = new HTTP2Client(); HTTP2Client h2Client = new HTTP2Client();

View File

@ -146,10 +146,10 @@ public class TestJettyOSGiBootHTTP2Conscrypt
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setProvider("Conscrypt"); sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setEndpointIdentificationAlgorithm(null); sslContextFactory.setEndpointIdentificationAlgorithm(null);
if ( JavaVersion.VERSION.getPlatform() < 9) if ( JavaVersion.VERSION.getPlatform()<9)
{ {
// conscrypt enable TLSv1.3 per default but it's not supported in jdk8 // conscrypt enable TLSv1.3 per default but it's not supported in jdk8
sslContextFactory.addExcludeProtocols( "TLSv1.3" ); sslContextFactory.addExcludeProtocols("TLSv1.3");
} }
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory); HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
Executor executor = new QueuedThreadPool(); Executor executor = new QueuedThreadPool();