Skip to content

Commit 3044740

Browse files
committed
added/improved logging of trusted certificates
1 parent b11f354 commit 3044740

File tree

6 files changed

+52
-5
lines changed

6 files changed

+52
-5
lines changed

dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/DsfClientConfig.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.security.KeyStore;
44
import java.util.UUID;
5+
import java.util.stream.Collectors;
56

67
import org.slf4j.Logger;
78
import org.slf4j.LoggerFactory;
@@ -10,6 +11,8 @@
1011
import org.springframework.context.annotation.Bean;
1112
import org.springframework.context.annotation.Configuration;
1213

14+
import de.hsheilbronn.mi.utils.crypto.cert.CertificateFormatter.X500PrincipalFormat;
15+
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreFormatter;
1316
import dev.dsf.bpe.client.dsf.ClientProvider;
1417
import dev.dsf.bpe.client.dsf.ClientProviderImpl;
1518

@@ -31,7 +34,7 @@ public class DsfClientConfig implements InitializingBean
3134
public void afterPropertiesSet() throws Exception
3235
{
3336
logger.info(
34-
"Local webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
37+
"Local DSF webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
3538
+ " url: {}, proxy: {}}",
3639
propertiesConfig.getDsfClientTrustedServerCasFileOrFolder(),
3740
propertiesConfig.getDsfClientCertificateFile(),
@@ -41,7 +44,7 @@ public void afterPropertiesSet() throws Exception
4144
propertiesConfig.proxyConfig().isEnabled(propertiesConfig.getDsfServerBaseUrl()) ? "enabled"
4245
: "disabled");
4346
logger.info(
44-
"Local websocket client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
47+
"Local DSF websocket client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
4548
+ " url: {}, proxy: {}}",
4649
propertiesConfig.getDsfClientTrustedServerCasFileOrFolder(),
4750
propertiesConfig.getDsfClientCertificateFile(),
@@ -51,7 +54,7 @@ public void afterPropertiesSet() throws Exception
5154
propertiesConfig.proxyConfig().isEnabled(getWebsocketUrl()) ? "enabled" : "disabled");
5255

5356
logger.info(
54-
"Remote webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
57+
"Remote DSF webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
5558
+ " proxy: {}}",
5659
propertiesConfig.getDsfClientTrustedServerCasFileOrFolder(),
5760
propertiesConfig.getDsfClientCertificateFile(),
@@ -60,6 +63,12 @@ public void afterPropertiesSet() throws Exception
6063
propertiesConfig.proxyConfig().isEnabled()
6164
? "enabled if remote server not in " + propertiesConfig.proxyConfig().getNoProxyUrls()
6265
: "disabled");
66+
67+
logger.info("Using trust-store with {} to validate local and remote DSF server certificates",
68+
KeyStoreFormatter
69+
.toSubjectsFromCertificates(propertiesConfig.getDsfClientTrustedServerCas(),
70+
X500PrincipalFormat.RFC1779)
71+
.values().stream().collect(Collectors.joining("; ", "[", "]")));
6372
}
6473

6574
@Bean

dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/FhirClientConnectionsConfig.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.security.NoSuchAlgorithmException;
77
import java.security.cert.CertificateException;
88
import java.time.Duration;
9+
import java.util.stream.Collectors;
910

1011
import org.slf4j.Logger;
1112
import org.slf4j.LoggerFactory;
@@ -14,6 +15,8 @@
1415
import org.springframework.context.annotation.Bean;
1516
import org.springframework.context.annotation.Configuration;
1617

18+
import de.hsheilbronn.mi.utils.crypto.cert.CertificateFormatter.X500PrincipalFormat;
19+
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreFormatter;
1720
import dev.dsf.bpe.api.client.oidc.OidcClient;
1821
import dev.dsf.bpe.api.client.oidc.OidcClientException;
1922
import dev.dsf.bpe.api.config.FhirClientConfig;
@@ -58,6 +61,13 @@ public FhirClientConfigYamlReaderImpl fhirClientYamlConfigReader()
5861
KeyStore defaultTrustStore = propertiesConfig.getFhirClientConnectionsConfigDefaultTrustStore();
5962
String defaultOidcDiscoveryPath = propertiesConfig.getFhirClientConnectionsConfigDefaultOidcDiscoveryPath();
6063

64+
logger.info(
65+
"Using trust-store with {} as default to validate server certificates for v2 process plugin client connections",
66+
KeyStoreFormatter
67+
.toSubjectsFromCertificates(propertiesConfig.getDsfClientTrustedServerCas(),
68+
X500PrincipalFormat.RFC1779)
69+
.values().stream().collect(Collectors.joining("; ", "[", "]")));
70+
6171
return new FhirClientConfigYamlReaderImpl(defaultTestConnectionOnStartup, defaultEnableDebugLogging,
6272
defaultConnectTimeout, defaultReadTimeout, defaultTrustStore, defaultOidcDiscoveryPath);
6373
}

dsf-bpe/dsf-bpe-server/src/main/java/dev/dsf/bpe/spring/config/MailConfig.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.time.format.DateTimeFormatter;
88
import java.util.List;
99
import java.util.UUID;
10+
import java.util.stream.Collectors;
1011

1112
import org.apache.logging.log4j.Level;
1213
import org.apache.logging.log4j.LogManager;
@@ -23,6 +24,8 @@
2324
import org.springframework.context.event.ContextRefreshedEvent;
2425
import org.springframework.context.event.EventListener;
2526

27+
import de.hsheilbronn.mi.utils.crypto.cert.CertificateFormatter.X500PrincipalFormat;
28+
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreFormatter;
2629
import dev.dsf.bpe.api.service.BpeMailService;
2730
import dev.dsf.bpe.mail.LoggingMailService;
2831
import dev.dsf.bpe.mail.SmtpMailService;
@@ -106,6 +109,15 @@ public void afterPropertiesSet() throws Exception
106109
propertiesConfig.getSendTestMailOnStartup(), propertiesConfig.getSendMailOnErrorLogEvent(),
107110
propertiesConfig.getMailOnErrorLogEventBufferSize(),
108111
propertiesConfig.getMailOnErrorLogEventDebugLogLocation());
112+
113+
if (propertiesConfig.getMailUseSmtps())
114+
{
115+
logger.info("Using trust-store with {} to validate mail server certificate",
116+
KeyStoreFormatter
117+
.toSubjectsFromCertificates(propertiesConfig.getDsfClientTrustedServerCas(),
118+
X500PrincipalFormat.RFC1779)
119+
.values().stream().collect(Collectors.joining("; ", "[", "]")));
120+
}
109121
}
110122
else
111123
{

dsf-common/dsf-common-jetty/src/main/java/dev/dsf/common/auth/ClientCertificateAuthenticator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ public AuthenticationState validateRequest(Request request, Response response, C
8282

8383
private X509TrustManager createX509TrustManager(KeyStore clientTrustStore)
8484
{
85-
logger.info("Using {} to validate client certificates",
85+
logger.info("Using trust-store with {} to validate client certificates",
8686
KeyStoreFormatter.toSubjectsFromCertificates(clientTrustStore, X500PrincipalFormat.RFC1779).values()
8787
.stream().collect(Collectors.joining("; ", "[", "]")));
8888

dsf-common/dsf-common-jetty/src/main/java/dev/dsf/common/config/AbstractJettyConfig.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,12 @@
4343
import org.springframework.context.support.PropertySourcesPlaceholderConfigurer;
4444
import org.springframework.core.env.ConfigurableEnvironment;
4545

46+
import de.hsheilbronn.mi.utils.crypto.cert.CertificateFormatter.X500PrincipalFormat;
4647
import de.hsheilbronn.mi.utils.crypto.cert.CertificateValidator;
4748
import de.hsheilbronn.mi.utils.crypto.io.PemReader;
4849
import de.hsheilbronn.mi.utils.crypto.keypair.KeyPairValidator;
4950
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreCreator;
51+
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreFormatter;
5052
import dev.dsf.common.auth.BackChannelLogoutAuthenticator;
5153
import dev.dsf.common.auth.BearerTokenAuthenticator;
5254
import dev.dsf.common.auth.ClientCertificateAuthenticator;
@@ -391,7 +393,13 @@ private HttpClient createOidcClient()
391393

392394
SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(false);
393395
if (oidcProviderClientTrustStore != null)
396+
{
394397
sslContextFactory.setTrustStore(oidcProviderClientTrustStore);
398+
logger.info("Using trust-store with {} to validate OIDC provider server certificate",
399+
KeyStoreFormatter
400+
.toSubjectsFromCertificates(oidcProviderClientTrustStore, X500PrincipalFormat.RFC1779)
401+
.values().stream().collect(Collectors.joining("; ", "[", "]")));
402+
}
395403
if (oidcProviderClientKeyStore != null)
396404
{
397405
sslContextFactory.setKeyStore(oidcProviderClientKeyStore);

dsf-fhir/dsf-fhir-server/src/main/java/dev/dsf/fhir/spring/config/ClientConfig.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import java.security.cert.X509Certificate;
1313
import java.util.List;
1414
import java.util.UUID;
15+
import java.util.stream.Collectors;
1516

1617
import org.bouncycastle.pkcs.PKCSException;
1718
import org.slf4j.Logger;
@@ -21,10 +22,12 @@
2122
import org.springframework.context.annotation.Bean;
2223
import org.springframework.context.annotation.Configuration;
2324

25+
import de.hsheilbronn.mi.utils.crypto.cert.CertificateFormatter.X500PrincipalFormat;
2426
import de.hsheilbronn.mi.utils.crypto.cert.CertificateValidator;
2527
import de.hsheilbronn.mi.utils.crypto.io.PemReader;
2628
import de.hsheilbronn.mi.utils.crypto.keypair.KeyPairValidator;
2729
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreCreator;
30+
import de.hsheilbronn.mi.utils.crypto.keystore.KeyStoreFormatter;
2831
import dev.dsf.fhir.client.ClientProvider;
2932
import dev.dsf.fhir.client.ClientProviderImpl;
3033

@@ -110,13 +113,18 @@ else if (!KeyPairValidator.matches(privateKey, certificates.get(0).getPublicKey(
110113
public void afterPropertiesSet() throws Exception
111114
{
112115
logger.info(
113-
"Remote webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
116+
"Remote DSF webservice client config: {trustStorePath: {}, certificatePath: {}, privateKeyPath: {}, privateKeyPassword: {},"
114117
+ " proxy: {}, no_proxy: {}}",
115118
propertiesConfig.getDsfClientTrustedServerCasFileOrFolder(),
116119
propertiesConfig.getDsfClientCertificateFile(),
117120
propertiesConfig.getDsfClientCertificatePrivateKeyFile(),
118121
propertiesConfig.getDsfClientCertificatePrivateKeyFilePassword() != null ? "***" : "null",
119122
propertiesConfig.proxyConfig().isEnabled() ? "enabled" : "disabled",
120123
propertiesConfig.proxyConfig().getNoProxyUrls());
124+
logger.info("Using trust-store with {} to validate remote DSF server certificates",
125+
KeyStoreFormatter
126+
.toSubjectsFromCertificates(propertiesConfig.getDsfClientTrustedServerCas(),
127+
X500PrincipalFormat.RFC1779)
128+
.values().stream().collect(Collectors.joining("; ", "[", "]")));
121129
}
122130
}

0 commit comments

Comments
 (0)