HTTP server has evolved in HTTPS server and ACQ now runs its own server

This commit is contained in:
2025-12-06 13:32:13 +01:00
parent ddf1def881
commit a9cc2d79a9
3 changed files with 58 additions and 15 deletions

View File

@@ -20,10 +20,13 @@ public class SSLServerFactory {
*/
public static Thread createServer(SSLContext ctx, int listeningPort, Consumer<SSLSocket> consumer) {
return new Thread(() -> {
SSLServerSocketFactory serverSocketFactory = ctx.getServerSocketFactory();
try (SSLServerSocket serverSocket = (SSLServerSocket) serverSocketFactory.createServerSocket(listeningPort)) {
serverSocket.setNeedClientAuth(true);
Logger.displayInfo("Server listening on port " + listeningPort);
while (true) {
try (SSLSocket clientSocket = (SSLSocket) serverSocket.accept()) {
consumer.accept(clientSocket);
@@ -31,6 +34,7 @@ public class SSLServerFactory {
throw new RuntimeException(e);
}
}
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}

View File

@@ -1,22 +1,54 @@
package httpServer.httpServer.src;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpsConfigurator;
import com.sun.net.httpserver.HttpsParameters;
import com.sun.net.httpserver.HttpsServer;
import common.common.src.crypto.KeyLoader;
import common.common.src.logger.Logger;
import httpServer.httpServer.src.handlers.IRequestHandler;
import httpServer.httpServer.src.handlers.RequestHandler;
import httpServer.httpServer.src.interceptors.RequestInterceptor;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.TrustManagerFactory;
import java.io.*;
import java.lang.reflect.Proxy;
import java.net.InetSocketAddress;
import static common.common.src.ports.Ports.HTTP_SERVER_PORT;
public class Main {
public static void main(String[] args) throws IOException {
private static final String KEY_STORE_PATH = "assets/certs/https.p12";
private static final String KEY_STORE_PWD = "hepl";
final int port = 8043;
private static final String TRUST_STORE_PATH = "assets/certs/https-trust.jks";
private static final String TRUST_STORE_PWD = "heplhepl";
HttpServer server = HttpServer.create(new InetSocketAddress(port), 5);
public static void main(String[] args) {
try {
HttpsServer server = HttpsServer.create(new InetSocketAddress(HTTP_SERVER_PORT), 5);
KeyLoader loader = new KeyLoader(KEY_STORE_PATH, KEY_STORE_PWD, TRUST_STORE_PATH, TRUST_STORE_PWD);
KeyManagerFactory kmf = loader.loadKeyStore();
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), null, null);
server.setHttpsConfigurator(new HttpsConfigurator(ctx) {
@Override
public void configure(HttpsParameters params) {
SSLContext context = getSSLContext();
SSLEngine engine = context.createSSLEngine();
params.setNeedClientAuth(false);
params.setCipherSuites(engine.getEnabledCipherSuites());
params.setProtocols(engine.getEnabledProtocols());
params.setSSLParameters(context.getDefaultSSLParameters());
}
});
IRequestHandler requestHandler = new RequestHandler();
@@ -33,6 +65,9 @@ public class Main {
server.createContext("/login", proxy::handleLogin);
server.start();
Logger.displayInfo("Server started on port " + port);
Logger.displayInfo("Server started on port " + HTTP_SERVER_PORT);
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -1,6 +1,7 @@
package httpServer.httpServer.src.interceptors;
import com.sun.net.httpserver.HttpExchange;
import common.common.src.logger.Logger;
import httpServer.httpServer.src.annotations.AllowedVerb;
import httpServer.httpServer.src.annotations.OnlyAuthorizedClients;
import httpServer.httpServer.src.authorization.AuthorizedClients;
@@ -24,6 +25,9 @@ public class RequestInterceptor implements InvocationHandler {
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
HttpExchange exchange = (HttpExchange) args[0];
try{
Logger.displayReceived("Request to " + exchange.getRequestURI() + " received");
Method realMethod = target.getClass().getMethod(method.getName(), method.getParameterTypes());
checkAuthorizedVerb(realMethod, exchange.getRequestMethod());