arturobernalg commented on PR #1535:
URL: 
https://github.com/apache/httpcomponents-core/pull/1535#issuecomment-7184599808

   I think the client side fix is right - tested a `hostname` mismatch against 
a real TLS server, master accepts it (bad), this PR rejects it with 
`SSLHandshakeException`.                                                        
                                                                                
                                                                                
                                                                                
         
   But I think there might be a side effect: since 
`ConscryptSupport#initialize` is shared with the server strategy, this may also 
enable endpoint identification server-side, and I think that breaks client-cert 
auth (tested                
    `setNeedClientAuth` with a valid client cert - works on master, fails with 
`CERTIFICATE_UNKNOWN` on this PR). Might be worth checking if the fix should 
apply to the client strategy only.   
   
   
   
   
   `
       private static final Timeout TIMEOUT = Timeout.ofSeconds(30);
   
       public static void main(final String[] args) throws Exception {
           final URL keyStoreURL = 
ConscryptServerClientAuthDemo.class.getResource("/test.p12");
           final char[] password = "nopassword".toCharArray();
   
           final SSLContext serverContext = SSLContextBuilder.create()
                   .setKeyStoreType("pkcs12")
                   .loadTrustMaterial(keyStoreURL, password)
                   .loadKeyMaterial(keyStoreURL, password, password)
                   .build();
           final SSLContext clientContext = SSLContextBuilder.create()
                   .setKeyStoreType("pkcs12")
                   .loadTrustMaterial(keyStoreURL, password)
                   .loadKeyMaterial(keyStoreURL, password, password)
                   .build();
   
           final HttpAsyncServer server = AsyncServerBootstrap.bootstrap()
                   .setCanonicalHostName("localhost")
                   
.setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build())
                   .setTlsStrategy(new ConscryptServerTlsStrategy(
                           serverContext,
                           (endpoint, sslEngine) -> 
sslEngine.setNeedClientAuth(true),
                           null))
                   
.setRequestRouter(RequestRouter.<Supplier<AsyncServerExchangeHandler>>builder()
                           .addRoute(RequestRouter.LOCAL_AUTHORITY, "*", () -> 
new AsyncEchoStreamingHandler(2048))
                           
.resolveAuthority(RequestRouter.LOCAL_AUTHORITY_RESOLVER)
                           .build())
                   .create();
           server.start();
   
           final HttpAsyncRequester client = AsyncRequesterBootstrap.bootstrap()
                   
.setIOReactorConfig(IOReactorConfig.custom().setSoTimeout(TIMEOUT).build())
                   .setTlsStrategy(new 
ConscryptClientTlsStrategy(clientContext))
                   .create();
           client.start();
   
           try {
               final Future<ListenerEndpoint> future = server.listen(
                       new InetSocketAddress(InetAddress.getLoopbackAddress(), 
0), URIScheme.HTTPS);
               final ListenerEndpoint listener = 
future.get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
               final int port = ((InetSocketAddress) 
listener.getAddress()).getPort();
   
               final HttpHost target = new HttpHost(URIScheme.HTTPS.id,
                       InetAddress.getLoopbackAddress(), "localhost", port);
   
               System.out.println("Connecting with a valid, trusted client 
certificate to a server "
                       + "requiring client auth (setNeedClientAuth=true)...");
               final Message<HttpResponse, String> message = client.execute(
                       target,
                       new BasicRequestProducer(Method.POST, target, "/stuff",
                               new StringAsyncEntityProducer("some stuff", 
ContentType.TEXT_PLAIN)),
                       new BasicResponseConsumer<>(new 
StringAsyncEntityConsumer()), TIMEOUT, null
               ).get(TIMEOUT.getDuration(), TIMEOUT.getTimeUnit());
   
               System.out.println("Result: HTTP " + message.head().getCode()
                       + " -- expected 200 on master, 
SSLHandshakeException/CERTIFICATE_UNKNOWN on the PR branch.");
           } finally {
               client.close(CloseMode.IMMEDIATE);
               server.close(CloseMode.IMMEDIATE);
           }
       }
   }
   `


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to