Skip to content

Commit

Permalink
Merge pull request #1166 from OSGP/feature/SMHE-1918_tls_support
Browse files Browse the repository at this point in the history
Feature/smhe 1918 tls support
  • Loading branch information
kroesctrl authored Feb 19, 2024
2 parents 5bdaefb + 31fbaa1 commit 4a4061d
Show file tree
Hide file tree
Showing 18 changed files with 81 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class CoreNotificationClientConfig extends AbstractConfig {
@Value("${web.service.notification.application.name}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

@Bean
public String webserviceNotificationApplicationName() {
return this.webserviceNotificationApplicationName;
Expand Down Expand Up @@ -77,7 +80,8 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
return new NotificationWebServiceTemplateFactory(
configRepository,
this.messageFactory(),
Collections.singletonList(addOsgpHeadersInterceptor));
Collections.singletonList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ web.service.notification.application.name=OSGP
web.service.notification.enabled=true
web.service.notification.username=test-org
web.service.notification.organisation=OSGP
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

#Firmware Management
firmware.domain=127.0.0.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ public class WebServiceConfig extends AbstractConfig {
@Value("${web.service.notification.application.name:DISTRIBUTION_AUTOMATION}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

// === DISTRIBUTION AUTOMATION MARSHALLERS ===

/**
Expand Down Expand Up @@ -255,7 +258,10 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
.build();

return new NotificationWebServiceTemplateFactory(
configRepository, this.messageFactory(), Arrays.asList(addOsgpHeadersInterceptor));
configRepository,
this.messageFactory(),
Arrays.asList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ web.service.notification.username=test-org
web.service.notification.organisation=OSGP
web.service.notification.enabled=true
web.service.notification.application.name=DISTRIBUTION_AUTOMATION
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

# =========================================================
# PERSISTENCE CONFIG
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ public class WebServiceConfig extends AbstractConfig {
@Value("${web.service.notification.application.name}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

private static final String SERVER = "SERVER";

// === MICROGRIDS MARSHALLERS ===
Expand Down Expand Up @@ -236,7 +239,10 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
.build();

return new NotificationWebServiceTemplateFactory(
configRepository, this.messageFactory(), Arrays.asList(addOsgpHeadersInterceptor));
configRepository,
this.messageFactory(),
Arrays.asList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ web.service.notification.username=test-org
web.service.notification.organisation=OSGP
web.service.notification.enabled=true
web.service.notification.application.name=ZownStream
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

stub.responses=false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class PublicLightingNotificationClientConfig extends AbstractConfig {
@Value("${web.service.notification.application.name:OSGP}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

@Bean
public NotificationService publicLightingNotificationService(
final NotificationWebServiceTemplateFactory templateFactory,
Expand Down Expand Up @@ -72,7 +75,10 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
.build();

return new NotificationWebServiceTemplateFactory(
configRepository, this.messageFactory(), Arrays.asList(addOsgpHeadersInterceptor));
configRepository,
this.messageFactory(),
Arrays.asList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ paging.default.pagesize=15
#Notification Settings
web.service.notification.enabled=true
web.service.notification.application.name=OSGP
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

publiclighting.scheduling.job.resend.notification.cron.expression=0 0/1 * * * ?
publiclighting.scheduling.job.resend.notification.maximum=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ public class NotificationWebServiceTemplateFactory {
private final WebServiceMessageFactory messageFactory;
private final List<ClientInterceptor> fixedInterceptors = new ArrayList<>();

private final String[] supportedTlsProtocols;

/**
* Web service template factory that creates web service templates based on configuration from the
* database.
Expand All @@ -62,14 +64,16 @@ public class NotificationWebServiceTemplateFactory {
public NotificationWebServiceTemplateFactory(
final NotificationWebServiceConfigurationRepository configRepository,
final WebServiceMessageFactory messageFactory,
final List<ClientInterceptor> fixedInterceptors) {
final List<ClientInterceptor> fixedInterceptors,
final String[] supportedTlsProtocols) {

this.configRepository =
Objects.requireNonNull(configRepository, "configRepository must not be null");
this.messageFactory = Objects.requireNonNull(messageFactory, "messageFactory must not be null");
if (fixedInterceptors != null) {
this.fixedInterceptors.addAll(fixedInterceptors);
}
this.supportedTlsProtocols = supportedTlsProtocols;
}

public WebServiceTemplate getTemplate(final ApplicationDataLookupKey templateKey) {
Expand Down Expand Up @@ -184,7 +188,10 @@ private LayeredConnectionSocketFactory createSslConnectionSocketFactory(
this.loadTrustMaterial(sslContextBuilder, config);
try {
return new SSLConnectionSocketFactory(
sslContextBuilder.build(), SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
sslContextBuilder.build(),
this.supportedTlsProtocols,
null,
SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
} catch (final GeneralSecurityException e) {
LOGGER.error("Exception creating SSL connection socket factory", e);
throw new WebServiceSecurityException("Unable to build SSL context", e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public class SmartMeteringNotificationClientConfig extends AbstractConfig {
@Value("${web.service.notification.application.name}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

@Bean
public String webserviceNotificationApplicationName() {
return this.webserviceNotificationApplicationName;
Expand Down Expand Up @@ -77,7 +80,8 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
return new NotificationWebServiceTemplateFactory(
configRepository,
this.messageFactory(),
Collections.singletonList(addOsgpHeadersInterceptor));
Collections.singletonList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ web.service.notification.enabled=true
web.service.notification.username=test-org
web.service.notification.organisation=OSGP
web.service.notification.application.name=SMART_METERS
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

#Paging
paging.maximum.pagesize=30
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class TariffSwitchingNotificationClientConfig extends AbstractConfig {
@Value("${web.service.notification.application.name:OSGP}")
private String webserviceNotificationApplicationName;

@Value("${web.service.notification.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] webserviceNotificationSupportedTlsProtocols;

@Bean
public NotificationService tariffSwitchingNotificationService(
final NotificationWebServiceTemplateFactory templateFactory,
Expand Down Expand Up @@ -72,7 +75,10 @@ public NotificationWebServiceTemplateFactory notificationWebServiceTemplateFacto
.build();

return new NotificationWebServiceTemplateFactory(
configRepository, this.messageFactory(), Arrays.asList(addOsgpHeadersInterceptor));
configRepository,
this.messageFactory(),
Arrays.asList(addOsgpHeadersInterceptor),
this.webserviceNotificationSupportedTlsProtocols);
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ soap.message.printing.enabled=true
#Notification Settings
web.service.notification.enabled=true
web.service.notification.application.name=OSGP
web.service.notification.supported.tls.protocols=TLSv1.2,TLSv1.3

tariffswitching.scheduling.job.resend.notification.cron.expression=0 0/1 * * * ?
tariffswitching.scheduling.job.resend.notification.maximum=3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ public class SoapClientConfig {
@Value("${soapclient.max-conn-total:100}")
private int maxConnTotal;

@Value("${soapclient.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] supportedTlsProtocols;

@Bean
Jaxb2Marshaller soapClientJaxb2Marshaller() {
final Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
Expand Down Expand Up @@ -125,9 +128,14 @@ public SSLConnectionSocketFactory sslConnectionSocketFactory()
throws IOException, UnrecoverableKeyException, CertificateException, NoSuchAlgorithmException,
KeyStoreException, KeyManagementException {
if (!Boolean.parseBoolean(this.useHostNameVerifier)) {
return new SSLConnectionSocketFactory(this.sslContext(), NoopHostnameVerifier.INSTANCE);
return new SSLConnectionSocketFactory(
this.sslContext(), this.supportedTlsProtocols, null, NoopHostnameVerifier.INSTANCE);
} else {
return new SSLConnectionSocketFactory(this.sslContext());
return new SSLConnectionSocketFactory(
this.sslContext(),
this.supportedTlsProtocols,
null,
SSLConnectionSocketFactory.getDefaultHostnameVerifier());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ soapclient.max-conn-per-route=20
soapclient.max-conn-total=100
soapclient.use.client.auth=true
soapclient.use.hostname.verifier=false
soapclient.supported.tls.protocols=TLSv1.2,TLSv1.3
soapclient.default-uri=https://localhost:443/osgp-secret-management/ws/SecretManagement
soapclient.ssl.trust-store=file:/etc/ssl/certs/trust.jks
soapclient.ssl.key-store=file:/etc/ssl/certs/OSGP.pfx
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class DefaultWebServiceTemplateFactory implements WebserviceTemplateFacto
private String keyStoreLocation;
private String keyStorePassword;
private KeyStoreFactoryBean trustStoreFactory;
private String[] supportedTlsProtocols;
private String applicationName;
private int maxConnectionsPerRoute;
private int maxConnectionsTotal;
Expand Down Expand Up @@ -90,6 +91,7 @@ public static class Builder {
private String keyStoreLocation;
private String keyStorePassword;
private KeyStoreFactoryBean trustStoreFactory;
private String[] supportedTlsProtocols = new String[] {"TLSv1.2", "TLSv1.3"};
private int maxConnectionsPerRoute = 2;
private int maxConnectionsTotal = 20;
private int connectionTimeout = 120000;
Expand Down Expand Up @@ -148,6 +150,11 @@ public Builder setMaxConnectionsPerRoute(final int maxConnectionsPerRoute) {
return this;
}

public Builder setSupportedTlsProtocols(final String[] supportedTlsProtocols) {
this.supportedTlsProtocols = supportedTlsProtocols;
return this;
}

public Builder setMaxConnectionsTotal(final int maxConnectionsTotal) {
this.maxConnectionsTotal = maxConnectionsTotal;
return this;
Expand Down Expand Up @@ -191,6 +198,7 @@ public DefaultWebServiceTemplateFactory build() {
webServiceTemplateFactory.circuitBreaker = this.circuitBreaker;
webServiceTemplateFactory.webServiceTemplateHostnameVerificationStrategy =
this.webServiceTemplateHostnameVerificationStrategy;
webServiceTemplateFactory.supportedTlsProtocols = this.supportedTlsProtocols;
return webServiceTemplateFactory;
}
}
Expand Down Expand Up @@ -284,7 +292,7 @@ private HttpComponentsMessageSender webServiceMessageSender(final String keystor
if (this.isSecurityEnabled) {
try {
clientbuilder.setSSLSocketFactory(this.getSSLConnectionSocketFactory(keystore));
} catch (GeneralSecurityException | IOException e) {
} catch (final GeneralSecurityException | IOException e) {
LOGGER.error("Webservice exception occurred: Certificate not available", e);
throw new WebServiceSecurityException("Certificate not available", e);
}
Expand Down Expand Up @@ -330,7 +338,8 @@ private SSLConnectionSocketFactory getSSLConnectionSocketFactory(final String ke

final HostnameVerifier hostnameVerifier = this.getHostnameVerifier();

return new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
return new SSLConnectionSocketFactory(
sslContext, this.supportedTlsProtocols, null, hostnameVerifier);
}

private HostnameVerifier getHostnameVerifier() throws GeneralSecurityException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ public class SoapRequestHelper {
@Value("${web.service.template.default.uri.publiclighting.adhocmanagement}")
private String publicLightingWebServiceAdHocManagementUri;

@Value("${web.service.template.default.supported.tls.protocols:TLSv1.2,TLSv1.3}")
private String[] supportedTlsProtocols;

@Value("${web.service.hostname.verification.strategy}")
private String webServiceHostnameVerificationStrategy;

Expand Down Expand Up @@ -154,7 +157,8 @@ private HttpComponentsMessageSender createHttpMessageSender() {
final HostnameVerifier hostnameVerifier = this.getHostnameVerifier();

final SSLConnectionSocketFactory sslConnectionFactory =
new SSLConnectionSocketFactory(sslContext, hostnameVerifier);
new SSLConnectionSocketFactory(
sslContext, this.supportedTlsProtocols, null, hostnameVerifier);
builder.setSSLSocketFactory(sslConnectionFactory);
sender.setHttpClient(builder.build());
} catch (final GeneralSecurityException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ application.name=demo-app

# OSGP Web Service URL
base.uri=https://localhost/
web.service.template.default.supported.tls.protocols=TLSv1.2,TLSv1.3
web.service.template.default.uri.admin.devicemanagement=osgp-adapter-ws-admin/admin/deviceManagementService/DeviceManagement
web.service.template.default.uri.common.devicemanagement=osgp-adapter-ws-core/common/deviceManagementService/DeviceManagement
web.service.template.default.uri.common.deviceinstallation=osgp-adapter-ws-core/common/deviceInstallationService/DeviceInstallation
Expand Down

0 comments on commit 4a4061d

Please sign in to comment.