WIP ACQ
This commit is contained in:
@@ -6,6 +6,9 @@ import common.common.src.socket.SocketManager;
|
||||
|
||||
import javax.net.ssl.*;
|
||||
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import static common.common.src.ports.Ports.*;
|
||||
|
||||
import java.io.IOException;
|
||||
@@ -20,6 +23,8 @@ public class Main {
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/acq/acq.truststore.p12";
|
||||
private static final String TRUST_STORE_PWD = "hepl_truststore";
|
||||
|
||||
private static SSLContext ctx;
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
KeyFactory keyFactory = new KeyFactory();
|
||||
@@ -27,42 +32,40 @@ public class Main {
|
||||
KeyManagerFactory kmf = keyFactory.loadKeyStore(KEY_STORE_PATH, KEY_STORE_PWD);
|
||||
TrustManagerFactory tmf = keyFactory.loadTrustStore(TRUST_STORE_PATH, TRUST_STORE_PWD);
|
||||
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
requestACS(ctx, ACS_SERVER_PORT);
|
||||
requestACS(ctx, AUTH_PORT);
|
||||
//requestACS(ctx, ACS_SERVER_PORT);
|
||||
//requestACS(ctx, AUTH_PORT);
|
||||
|
||||
Thread ACQServer = SSLServerFactory.createServer(ctx, ACQ_SERVER_PORT, Main::handleRequest);
|
||||
ACQServer.start();
|
||||
}
|
||||
|
||||
public static void requestACS(SSLContext ctx, int port) {
|
||||
SSLSocketFactory factory = ctx.getSocketFactory();
|
||||
try (SSLSocket socket = (SSLSocket) factory.createSocket(Main.HOST, port)) {
|
||||
socket.startHandshake();
|
||||
|
||||
String message = "Hello ACS";
|
||||
SocketManager.send(socket, message);
|
||||
Logger.displaySent(message);
|
||||
|
||||
String response = SocketManager.readResponse(socket);
|
||||
Logger.displayReceived(response);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void handleRequest(SSLSocket serverSocket) {
|
||||
try{
|
||||
String request = SocketManager.readResponse(serverSocket);
|
||||
Logger.displayReceived(request);
|
||||
String response = SocketManager.readResponse(serverSocket);
|
||||
Logger.displayReceived(response);
|
||||
|
||||
|
||||
// contact ACS
|
||||
|
||||
SSLSocketFactory factory = ctx.getSocketFactory();
|
||||
SSLSocket socketACS = (SSLSocket) factory.createSocket(Main.HOST, AUTH_PORT);
|
||||
socketACS.startHandshake();
|
||||
|
||||
String request = response;
|
||||
|
||||
SocketManager.send(socketACS, request);
|
||||
Logger.displaySent(request);
|
||||
|
||||
response = SocketManager.readResponse(socketACS);
|
||||
Logger.displayReceived(response);
|
||||
|
||||
// Send back ACK or NAK
|
||||
|
||||
SocketManager.send(serverSocket, response);
|
||||
|
||||
}catch (IOException ioe){
|
||||
throw new RuntimeException(ioe);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package acq.acq.src.json;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
public record Token(
|
||||
@JsonProperty("token")
|
||||
String token,
|
||||
@JsonProperty("signature")
|
||||
String signature) {
|
||||
}
|
||||
Reference in New Issue
Block a user