Fix certificates chain
This commit is contained in:
20
README.md
20
README.md
@@ -1,2 +1,18 @@
|
||||
Password : hepl
|
||||
Truststore password : heplhepl
|
||||
# Generate a keystore
|
||||
```bash
|
||||
keytool -genkeypair -alias <alias> -keyalg RSA -keysize 2048 -keystore <path/to/keystore.p12> -storetype PKCS12 -storepass <password> -validity 365
|
||||
```
|
||||
|
||||
# Export certificate
|
||||
```bash
|
||||
keytool -exportcert -alias <alias> -keystore <path/to/keystore.p12> -storetype PKCS12 -storepass hepl -file <path/to/generated/cert.crt>
|
||||
```
|
||||
|
||||
# Import certificate
|
||||
```bash
|
||||
keytool -importcert -alias <alias> -file <path/to/cert.crt> -keystore <path/to/keystore.p12> -storetype PKCS12 -storepass <password>
|
||||
```
|
||||
|
||||
# Passwords
|
||||
- Key store pwd : hepl_keystore
|
||||
- Trust store pwd : hepl_truststore
|
||||
|
||||
@@ -12,11 +12,11 @@ public class Main {
|
||||
|
||||
private static final String HOST = "127.0.0.1";
|
||||
|
||||
private static final String KEY_STORE_PATH = "assets/certs/acq.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl";
|
||||
private static final String KEY_STORE_PATH = "assets/certs/acq/acq.keystore.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl_keystore";
|
||||
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/acq-trust.jks";
|
||||
private static final String TRUST_STORE_PWD = "heplhepl";
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/acq/acq.truststore.p12";
|
||||
private static final String TRUST_STORE_PWD = "hepl_truststore";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
@@ -28,7 +28,7 @@ public class Main {
|
||||
SSLContext ctx = SSLContext.getInstance("TLS");
|
||||
ctx.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
requestACS(ctx);
|
||||
//requestACS(ctx);
|
||||
|
||||
Thread ACQServer = SSLServerFactory.createServer(ctx, ACQ_SERVER_PORT, Main::handleRequest);
|
||||
ACQServer.start();
|
||||
|
||||
@@ -14,11 +14,11 @@ import static common.common.src.ports.Ports.PORT_AUTH;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final String KEY_STORE_PATH = "assets/certs/acs.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl";
|
||||
private static final String KEY_STORE_PATH = "assets/certs/acs/acs.keystore.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl_keystore";
|
||||
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/acs-trust.jks";
|
||||
private static final String TRUST_STORE_PWD = "heplhepl";
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/acs/acs.truststore.p12";
|
||||
private static final String TRUST_STORE_PWD = "hepl_truststore";
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public class KeyFactory {
|
||||
try (FileInputStream fis = new FileInputStream(path)) {
|
||||
char[] truststorePass = pwd.toCharArray();
|
||||
|
||||
KeyStore ts = KeyStore.getInstance("JKS");
|
||||
KeyStore ts = KeyStore.getInstance("PKCS12");
|
||||
ts.load(fis, truststorePass);
|
||||
|
||||
tmf = TrustManagerFactory.getInstance("SunX509");
|
||||
|
||||
@@ -18,30 +18,35 @@ import java.security.*;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.util.Base64;
|
||||
|
||||
import static common.common.src.ports.Ports.ACS_HOST;
|
||||
import static common.common.src.ports.Ports.ACS_SERVER_PORT;
|
||||
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final String KEY_STORE_PATH = "assets/certs/externalApp.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl";
|
||||
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/externalApp.jks";
|
||||
private static final String TRUST_STORE_PWD = "heplhepl";
|
||||
private static final String KEY_STORE_PATH = "assets/certs/externalApp/externalApp.keystore.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl_keystore";
|
||||
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/externalApp/externalApp.truststore.p12";
|
||||
private static final String TRUST_STORE_PWD = "hepl_truststore";
|
||||
|
||||
public static void main(String[] args) throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, InvalidKeyException, SignatureException, URISyntaxException, CertificateException, KeyManagementException {
|
||||
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
|
||||
String expirationDate = acquireStringInput( br,"Quel est la date d'expiration de la carte de crédit ? (MM/AA)");
|
||||
String cardNumber = acquireStringInput(br, "Numéro de la carte de crédit : ");
|
||||
//String expirationDate = acquireStringInput( br,"Quel est la date d'expiration de la carte de crédit ? (MM/AA)");
|
||||
//String cardNumber = acquireStringInput(br, "Numéro de la carte de crédit : ");
|
||||
|
||||
String expirationDate = "01/01";
|
||||
String cardNumber = "0123456789012345";
|
||||
|
||||
String jsonString = buildCreditCardJson(expirationDate, cardNumber);
|
||||
|
||||
KeyFactory keyFactory = new KeyFactory();
|
||||
|
||||
KeyStore keyStore = keyFactory.createKeyStore("PKCS12", KEY_STORE_PATH, TRUST_STORE_PWD);
|
||||
KeyStore keyStore = keyFactory.createKeyStore("PKCS12", KEY_STORE_PATH, KEY_STORE_PWD);
|
||||
KeyManagerFactory kmf = keyFactory.loadKeyStore(KEY_STORE_PATH, KEY_STORE_PWD);
|
||||
TrustManagerFactory tmf = keyFactory.loadTrustStore(TRUST_STORE_PATH, TRUST_STORE_PWD);
|
||||
|
||||
PrivateKey privateKey = keyFactory.createPrivateKey(keyStore, "externalApp", TRUST_STORE_PWD);
|
||||
PrivateKey privateKey = keyFactory.createPrivateKey(keyStore, "externalApp", KEY_STORE_PWD);
|
||||
|
||||
Signature signature = Signature.getInstance("SHA256withRSA");
|
||||
signature.initSign(privateKey);
|
||||
@@ -51,9 +56,6 @@ public class Main {
|
||||
String signatureBase64 = Base64.getEncoder().encodeToString(signedBytes);
|
||||
String finalPayload = buildFinalJson(jsonString, signatureBase64);
|
||||
|
||||
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.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);
|
||||
|
||||
@@ -90,12 +92,11 @@ public class Main {
|
||||
}
|
||||
}
|
||||
|
||||
private static void sendToACS(SSLContext ctx, String payload) throws URISyntaxException, MalformedURLException {
|
||||
private static void sendToACS(SSLContext ctx, String payload) {
|
||||
Logger.displayInfo("Envoi des informations au service d'authentification à l'hôte " + Ports.ACS_HOST + ":" + Ports.PORT_AUTH);
|
||||
URL url = new URI("https://" + Ports.ACS_HOST + ":" + Ports.PORT_AUTH).toURL();
|
||||
|
||||
SSLSocketFactory factory = ctx.getSocketFactory();
|
||||
try (SSLSocket socket = (SSLSocket) factory.createSocket(url.toString(), ACS_SERVER_PORT)) {
|
||||
try (SSLSocket socket = (SSLSocket) factory.createSocket(ACS_HOST, ACS_SERVER_PORT)) {
|
||||
socket.startHandshake();
|
||||
|
||||
SocketManager.send(socket, payload);
|
||||
|
||||
@@ -5,22 +5,24 @@ import com.sun.net.httpserver.HttpsParameters;
|
||||
import com.sun.net.httpserver.HttpsServer;
|
||||
import common.common.src.crypto.KeyFactory;
|
||||
import common.common.src.logger.Logger;
|
||||
import common.common.src.socket.SocketManager;
|
||||
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.*;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import static common.common.src.ports.Ports.HTTP_SERVER_PORT;
|
||||
import static common.common.src.ports.Ports.*;
|
||||
|
||||
public class Main {
|
||||
|
||||
private static final String KEY_STORE_PATH = "assets/certs/https.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl";
|
||||
private static final String KEY_STORE_PATH = "assets/certs/httpServer/httpserver.keystore.p12";
|
||||
private static final String KEY_STORE_PWD = "hepl_keystore";
|
||||
|
||||
private static final String TRUST_STORE_PATH = "assets/certs/httpServer/httpserver.truststore.p12";
|
||||
private static final String TRUST_STORE_PWD = "hepl_keystore";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
@@ -60,9 +62,29 @@ public class Main {
|
||||
server.createContext("/login", proxy::handleLogin);
|
||||
|
||||
server.start();
|
||||
|
||||
requestACQ(ctx);
|
||||
|
||||
Logger.displayInfo("Server started on port " + HTTP_SERVER_PORT);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static void requestACQ(SSLContext ctx) {
|
||||
SSLSocketFactory factory = ctx.getSocketFactory();
|
||||
try (SSLSocket socket = (SSLSocket) factory.createSocket("127.0.0.1", ACQ_SERVER_PORT)) {
|
||||
socket.startHandshake();
|
||||
|
||||
String message = "Hello ACQ";
|
||||
SocketManager.send(socket, message);
|
||||
Logger.displaySent(message);
|
||||
|
||||
String response = SocketManager.readResponse(socket);
|
||||
Logger.displayReceived(response);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user