From d5a3798edb3cf7ca77df1710dcd02732bb8bcf45 Mon Sep 17 00:00:00 2001 From: Christopher Broderick Date: Wed, 4 Dec 2024 22:42:10 +0000 Subject: [PATCH] Cater for Windows mess with backslashes in file path when rendering as string --- .../java/org/openas2/app/CertificatesTest.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Server/src/test/java/org/openas2/app/CertificatesTest.java b/Server/src/test/java/org/openas2/app/CertificatesTest.java index 4ca11d23..04cd8f80 100644 --- a/Server/src/test/java/org/openas2/app/CertificatesTest.java +++ b/Server/src/test/java/org/openas2/app/CertificatesTest.java @@ -46,7 +46,7 @@ public class CertificatesTest extends BaseServerSetup { private static final String url = "https://localhost:" + receiverPort + "/"; private File customPropsFile = null; private File sslCertsFile = null; // The private key and certificate for the HTTPS - private File sslTrustCertsFile = null; // The public key for the SSL private key + private String sslTrustCertsFilePath = null; // The public key for the SSL private key private X509CertificateFactory trustFx = null; // The trust certificates protected static Message testMsg; // Created just once for all tests to minimise runtime private InternetHeaders ih = null; @@ -84,14 +84,17 @@ public void setUp() throws Exception { String tgtHostName = "test.openas2.org"; this.alias = tgtHostName; // Create the SSL file for the server to use - String sslCertsFilePath = sslCertsFile.getAbsolutePath(); + // Switch to forward slash to avoid backslash being dropped when creating property string when on Windows + String sslCertsFilePath = sslCertsFile.getAbsolutePath().replace("\\", "/"); this.certFx = genSelfSignedCert(alias, sslCertsFilePath, "RSA", "SHA256", 2048, tgtHostName); // Create the trust store with the public key so the certificate returned from the server is trusted - sslTrustCertsFile = Files.createFile(Paths.get(tmpDirAbsolutePath, "ssl_trust_certs.p12")).toFile(); + File sslTrustCertsFile = Files.createFile(Paths.get(tmpDirAbsolutePath, "ssl_trust_certs.p12")).toFile(); + // Switch to forward slash to avoid backslash being dropped when creating property string when on Windows + sslTrustCertsFilePath = sslTrustCertsFile.getAbsolutePath().replace("\\", "/"); String trustAlias = "trust-" + tgtHostName; - this.certFx.exportPublicKey(sslTrustCertsFile.getAbsolutePath(), this.alias, trustAlias, password); + this.certFx.exportPublicKey(sslTrustCertsFilePath, this.alias, trustAlias, password); this.trustFx = new X509CertificateFactory(); - this.trustFx.setFilename(sslTrustCertsFile.getAbsolutePath()); + this.trustFx.setFilename(sslTrustCertsFilePath); this.trustFx.setPassword(password); this.trustFx.setKeyStore(AS2Util.getCryptoHelper().getKeyStore()); this.trustFx.load(); @@ -99,6 +102,7 @@ public void setUp() throws Exception { customPropsFile = Files.createFile(Paths.get(tmpDirAbsolutePath, "openas2.properties")).toFile(); System.setProperty(Properties.OPENAS2_PROPERTIES_FILE_PROP, customPropsFile.getAbsolutePath()); FileOutputStream fos = new FileOutputStream(customPropsFile); + // Switch to forward slash to avoid backslash being dropped when creating property string when on Windows fos.write(("ssl_keystore=" + sslCertsFilePath + "\n").getBytes()); fos.write(("ssl_keystore_password=" + new String(password) + "\n").getBytes()); //fos.write(("ssl_trust_keystore=" + sslTrustCertsFile.getAbsolutePath() + "\n").getBytes()); @@ -147,7 +151,7 @@ public void a1_shouldFailSSLConnect() throws Exception { public void a2_shouldConnect() throws Exception { FileOutputStream fos = new FileOutputStream(customPropsFile, true); fos.write(("ssl_trust_keystore.enabled=true\n").getBytes()); - fos.write(("ssl_trust_keystore=" + sslTrustCertsFile.getAbsolutePath() + "\n").getBytes()); + fos.write(("ssl_trust_keystore=" + sslTrustCertsFilePath + "\n").getBytes()); fos.write(("ssl_trust_keystore_password=" + new String(password) + "\n").getBytes()); fos.close(); super.refresh();