Skip to content
This repository was archived by the owner on Oct 6, 2025. It is now read-only.

Commit 0845374

Browse files
committed
support for encrypted fTTP certificate private-keys
1 parent ca44b62 commit 0845374

2 files changed

Lines changed: 19 additions & 13 deletions

File tree

codex-process-data-transfer/src/main/java/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/client/FttpClientFactory.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ public void testConnection()
8080
private final Path trustStorePath;
8181
private final Path certificatePath;
8282
private final Path privateKeyPath;
83+
private final char[] privateKeyPassword;
8384

8485
private final String fttpServerBase;
8586
private final String fttpBasicAuthUsername;
@@ -99,14 +100,15 @@ public void testConnection()
99100

100101
private final boolean hapiClientVerbose;
101102

102-
public FttpClientFactory(Path trustStorePath, Path certificatePath, Path privateKeyPath, int connectTimeout,
103-
int socketTimeout, int connectionRequestTimeout, String fttpBasicAuthUsername, String fttpBasicAuthPassword,
104-
String fttpServerBase, String fttpApiKey, String fttpStudy, String fttpTarget, String proxySchemeHostPort,
105-
String proxyUsername, String proxyPassword, boolean hapiClientVerbose)
103+
public FttpClientFactory(Path trustStorePath, Path certificatePath, Path privateKeyPath, char[] privateKeyPassword,
104+
int connectTimeout, int socketTimeout, int connectionRequestTimeout, String fttpBasicAuthUsername,
105+
String fttpBasicAuthPassword, String fttpServerBase, String fttpApiKey, String fttpStudy, String fttpTarget,
106+
String proxySchemeHostPort, String proxyUsername, String proxyPassword, boolean hapiClientVerbose)
106107
{
107108
this.trustStorePath = trustStorePath;
108109
this.certificatePath = certificatePath;
109110
this.privateKeyPath = privateKeyPath;
111+
this.privateKeyPassword = privateKeyPassword;
110112

111113
this.connectTimeout = connectTimeout;
112114
this.socketTimeout = socketTimeout;
@@ -133,8 +135,9 @@ public void onContextRefreshedEvent(ContextRefreshedEvent event)
133135
try
134136
{
135137
logger.info(
136-
"Testing connection to fTTP with {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, fttpServerBase: {}, fttpApiKey: {}, fttpStudy: {}, fttpTarget: {}}",
137-
trustStorePath, certificatePath, privateKeyPath, fttpServerBase, fttpApiKey, fttpStudy, fttpTarget);
138+
"Testing connection to fTTP with {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {}, fttpServerBase: {}, fttpApiKey: {}, fttpStudy: {}, fttpTarget: {}}",
139+
trustStorePath, certificatePath, privateKeyPath, privateKeyPassword != null ? "***" : "null",
140+
fttpServerBase, fttpApiKey, fttpStudy, fttpTarget);
138141

139142
getFttpClient().testConnection();
140143
}
@@ -166,7 +169,7 @@ protected FttpClient createFttpClient()
166169
char[] keyStorePassword = UUID.randomUUID().toString().toCharArray();
167170

168171
logger.debug("Creating key-store from {} and {}", certificatePath.toString(), privateKeyPath.toString());
169-
KeyStore keyStore = readKeyStore(certificatePath, privateKeyPath, keyStorePassword);
172+
KeyStore keyStore = readKeyStore(certificatePath, privateKeyPath, privateKeyPassword, keyStorePassword);
170173

171174
return new FttpClientImpl(trustStore, keyStore, keyStorePassword, connectTimeout, socketTimeout,
172175
connectionRequestTimeout, fttpBasicAuthUsername, fttpBasicAuthPassword, fttpServerBase, fttpApiKey,
@@ -185,11 +188,11 @@ private KeyStore readTrustStore(Path trustPath)
185188
}
186189
}
187190

188-
private KeyStore readKeyStore(Path certificatePath, Path keyPath, char[] keyStorePassword)
191+
private KeyStore readKeyStore(Path certificatePath, Path keyPath, char[] keyPassword, char[] keyStorePassword)
189192
{
190193
try
191194
{
192-
PrivateKey privateKey = PemIo.readPrivateKeyFromPem(keyPath);
195+
PrivateKey privateKey = PemIo.readPrivateKeyFromPem(keyPath, keyPassword);
193196
X509Certificate certificate = PemIo.readX509CertificateFromPem(certificatePath);
194197

195198
return CertificateHelper.toJksKeyStore(privateKey, new Certificate[] { certificate },

codex-process-data-transfer/src/main/java/de/netzwerk_universitaetsmedizin/codex/processes/data_transfer/spring/config/TransferDataConfig.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public class TransferDataConfig
134134
@Value("${de.netzwerk.universitaetsmedizin.codex.fttp.private.key:#{null}}")
135135
private String fttpPrivateKey;
136136

137+
@Value("${de.netzwerk.universitaetsmedizin.codex.fttp.private.key.password:#{null}}")
138+
private char[] fttpPrivateKeyPassword;
139+
137140
@Value("${de.netzwerk.universitaetsmedizin.codex.fttp.timeout.connect:10000}")
138141
private int fttpConnectTimeout;
139142

@@ -198,10 +201,10 @@ public FttpClientFactory fttpClientFactory()
198201
Path certificatePath = checkExists(fttpCertificate);
199202
Path privateKeyPath = checkExists(fttpPrivateKey);
200203

201-
return new FttpClientFactory(trustStorePath, certificatePath, privateKeyPath, fttpConnectTimeout,
202-
fttpSocketTimeout, fttpConnectionRequestTimeout, fttpBasicAuthUsername, fttpBasicAuthPassword,
203-
fttpServerBase, fttpApiKey, fttpStudy, fttpTarget, proxySchemeHostPort, proxyUsername, proxyPassword,
204-
fttpHapiClientVerbose);
204+
return new FttpClientFactory(trustStorePath, certificatePath, privateKeyPath, fttpPrivateKeyPassword,
205+
fttpConnectTimeout, fttpSocketTimeout, fttpConnectionRequestTimeout, fttpBasicAuthUsername,
206+
fttpBasicAuthPassword, fttpServerBase, fttpApiKey, fttpStudy, fttpTarget, proxySchemeHostPort,
207+
proxyUsername, proxyPassword, fttpHapiClientVerbose);
205208
}
206209

207210
@Bean

0 commit comments

Comments
 (0)