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