Skip to content

Commit 4d2c7b6

Browse files
committed
fix issue robaho#15 HttpsConfigurator.configure method not executed for https connections
1 parent 2e7f580 commit 4d2c7b6

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package robaho.net.httpserver;
2+
3+
import java.net.InetSocketAddress;
4+
5+
import javax.net.ssl.SSLParameters;
6+
import javax.net.ssl.SSLSocket;
7+
8+
import com.sun.net.httpserver.HttpsConfigurator;
9+
import com.sun.net.httpserver.HttpsParameters;
10+
11+
class SSLConfigurator {
12+
static void configure(SSLSocket s,HttpsConfigurator cfg) {
13+
s.setUseClientMode(false);
14+
if(cfg==null) return;
15+
InetSocketAddress remoteAddress = (InetSocketAddress)s.getRemoteSocketAddress();
16+
Parameters params = new Parameters (cfg, remoteAddress);
17+
cfg.configure(params);
18+
SSLParameters sslParams = params.getSSLParameters();
19+
if (sslParams != null) {
20+
s.setSSLParameters(sslParams);
21+
}
22+
}
23+
static class Parameters extends HttpsParameters {
24+
InetSocketAddress addr;
25+
HttpsConfigurator cfg;
26+
27+
Parameters (HttpsConfigurator cfg, InetSocketAddress addr) {
28+
this.addr = addr;
29+
this.cfg = cfg;
30+
}
31+
@Override
32+
public InetSocketAddress getClientAddress () {
33+
return addr;
34+
}
35+
@Override
36+
public HttpsConfigurator getHttpsConfigurator() {
37+
return cfg;
38+
}
39+
SSLParameters params;
40+
@Override
41+
public void setSSLParameters (SSLParameters p) {
42+
params = p;
43+
}
44+
SSLParameters getSSLParameters () {
45+
return params;
46+
}
47+
}
48+
}

src/main/java/robaho/net/httpserver/ServerImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package robaho.net.httpserver;
2626

27-
import java.io.EOFException;
2827
import static java.nio.charset.StandardCharsets.ISO_8859_1;
2928

3029
import java.io.IOException;
@@ -63,6 +62,7 @@
6362
import com.sun.net.httpserver.HttpHandler;
6463
import com.sun.net.httpserver.HttpServer;
6564
import com.sun.net.httpserver.HttpsConfigurator;
65+
import com.sun.net.httpserver.HttpsParameters;
6666

6767
import robaho.net.httpserver.http2.HTTP2Connection;
6868
import robaho.net.httpserver.http2.HTTP2ErrorCode;
@@ -370,17 +370,17 @@ public void run() {
370370
// not work, so upgrade to a SSLSocket after connection
371371
SSLSocketFactory ssf = httpsConfig.getSSLContext().getSocketFactory();
372372
SSLSocket sslSocket = (SSLSocket) ssf.createSocket(s, null, false);
373+
SSLConfigurator.configure(sslSocket,httpsConfig);
374+
373375
sslSocket.setHandshakeApplicationProtocolSelector((_sslSocket, protocols) -> {
374376
if (protocols.contains("h2") && ServerConfig.http2OverSSL()) {
375377
return "h2";
376378
} else {
377379
return "http/1.1";
378380
}
379381
});
380-
sslSocket.setUseClientMode(false);
381382
// the following forces the SSL handshake to complete in order to determine the negotiated protocol
382383
var session = sslSocket.getSession();
383-
384384
if ("h2".equals(sslSocket.getApplicationProtocol())) {
385385
logger.log(Level.DEBUG, () -> "http2 connection "+sslSocket.toString());
386386
http2 = true;

0 commit comments

Comments
 (0)