GeezerVison is showing github.com — HttpsConfigurator.configure method not executed for https connections · Issue #15 · robaho/httpserver
HttpsConfigurator.configure method not executed for https connections #15DescriptionWe are trying to update from jdk httpserver to robaho httpserver and are experiencing following problem:
The HttpsConfigurator.configure method does not seem to get called when starting a new https connection.
We need the configure in order to be able to set up diverses SSL settings, f.i. setWantClientAuth(true) on the SSLParams, to get a client certificate from the remote connection.
I have searched through the robaho code but I could not figure out where the configure method is getting called.
In the jdk httpserver implementation this is performed in ServerImpl.Exchange.run() when creating the new SSLStream instance (the call is in the SSLStream constructor).
This means that using the same code we cannot replace the jdk httpserver with robaho httpserver, and we cannot even figure out how to change our code in order to have the configure method called.
Version used: 1.0.19
Thanks in advance for any help. Activityrobaho commented on Jan 16, 2025 This is fixed in version 1.0.20 that is being pushed to maven now. Sorry about that - strangely, it doesn't appear that the JDK has any tests surrounding this. All of the current tests pass. I am fairly certain it is fixed correctly - feel free to reopen if it isn't. robaho commented on Jan 16, 2025 @viretp do you think you might be able to attach a minimal usage in your case so I can create a test case? SentryMan commented on Jan 16, 2025 I was able to replicate it by creating a keystore using
keytool -genkey -keyalg RSA -alias selfsigned -keystore sus.jks -storepass password -validity 360 -keysize 2048
and using it in the code with
char[] passphrase = "password".toCharArray();
KeyStore ks = KeyStore.getInstance("JKS");
var path =
Path.of("sus.jks").toAbsolutePath();
ks.load(Files.newInputStream(path), passphrase);
// Set up the key manager factory
KeyManagerFactory kmf = KeyManagerFactory.getInstance("SunX509");
kmf.init(ks, passphrase);
// Set up the trust manager factory
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(ks);
// Set up the SSL context
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
// Create Server
HttpsConfigurator https =
new HttpsConfigurator(sslContext) {
@Override
public void configure(HttpsParameters params) {
//didn't get here
System.out.println("Here");
}
};
var httpsServer = HttpsServer.create(new InetSocketAddress(8443), 0);
httpsServer.setHttpsConfigurator(https);
httpsServer.createContext(
"/",
exchange -> {
var str = "sus".getBytes();
exchange.sendResponseHeaders(200, str.length);
exchange.getResponseBody().write(str);
});robaho commented on Jan 17, 2025 I am re-opening this, the code changes seem to have broken https. robaho commented on Jan 17, 2025 false alarm. The code changes work as expected, added test case HttpsConfiguratorTest. viretp commented on Jan 17, 2025 ContributorAuthor More actions That was really fast! I have tested the new version 1.0.20 and the problem is gone.
Great job: thank you very much. robaho commented on Jan 17, 2025
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|