Clean ACS

This commit is contained in:
2025-12-06 11:15:55 +01:00
parent 1692e3aa84
commit 60889b668a
2 changed files with 21 additions and 22 deletions

View File

@@ -31,7 +31,7 @@ public class Main {
try (SSLSocket socket = (SSLSocket) factory.createSocket(host, port)) {
socket.startHandshake();
String message = "Hello ACS\n";
String message = "Hello ACS";
SocketManager.send(socket, message);
Logger.displaySent(message);
@@ -41,6 +41,4 @@ public class Main {
e.printStackTrace();
}
}
}

View File

@@ -1,11 +1,12 @@
package acs.acs.src;
// File: AcsServer.java
import common.common.src.crypto.KeyLoader;
import common.common.src.logger.Logger;
import common.common.src.socket.SocketManager;
import javax.net.ssl.*;
import java.io.*;
import java.security.KeyStore;
import java.io.IOException;
public class Main {
@@ -17,7 +18,6 @@ public class Main {
public static void main(String[] args) throws Exception {
int port = 8443;
KeyLoader loader = new KeyLoader(KEY_STORE_PATH, KEY_STORE_PWD, TRUST_STORE_PATH, TRUST_STORE_PWD);
KeyManagerFactory kmf = loader.loadKeyStore();
@@ -26,24 +26,25 @@ public class Main {
SSLContext ctx = SSLContext.getInstance("TLS");
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
SSLServerSocketFactory ssf = ctx.getServerSocketFactory();
SSLServerSocket serverSocket = (SSLServerSocket) ssf.createServerSocket(port);
// si vous voulez mTLS :
serverSocket.setNeedClientAuth(true);
System.out.println("ACS listening on port " + port);
while (true) {
try (SSLSocket socket = (SSLSocket) serverSocket.accept()) {
BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
SSLServerSocketFactory factory = ctx.getServerSocketFactory();
String line = in.readLine(); // simple single-line message
System.out.println("Received from ACQ: " + line);
try (SSLServerSocket serverSocket = (SSLServerSocket) factory.createServerSocket(port)) {
serverSocket.setNeedClientAuth(true);
Logger.displayInfo("ACS listening on port " + port);
out.write("ACK from ACS\n");
out.flush();
} catch (IOException e) {
e.printStackTrace();
while (true) {
try (SSLSocket clientSocket = (SSLSocket) serverSocket.accept()) {
String response = SocketManager.readResponse(clientSocket);
Logger.displayReceived(response);
String message = "ACK from ACS";
SocketManager.send(clientSocket, message);
Logger.displaySent("ACK from ACS");
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}