Skip to content

CXF test #1428

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 15 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ SPDX-License-Identifier: Apache-2.0

<properties>
<!-- override version in super pom -->
<cxf.version>4.0.3</cxf.version>
<cxf.version>4.0.5</cxf.version>
</properties>

<artifactId>cucumber-tests-platform-smartmetering</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ SPDX-License-Identifier: Apache-2.0
<outputDirectory>META-INF/cxf</outputDirectory>
</file>
</files>
</assembly>
</assembly>
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,21 @@
@Configuration
public class DlmsSimulatorConfig extends AbstractConfig {

public DlmsSimulatorConfig() {}
@Value("${web.service.truststore.location}")
private String truststoreLocation;

@Value("${dynamic.properties.base.url}")
private String dynamicPropertiesBaseUrl;
@Value("${web.service.truststore.password}")
private String truststorePassword;

@Value("${web.service.truststore.type}")
private String truststoreType;

@Value("${triggered.simulator.url}")
private String baseAddress;

@Bean
public SimulatorTriggerClient simulatorTriggerClient() throws SimulatorTriggerClientException {

return new SimulatorTriggerClient(this.dynamicPropertiesBaseUrl);
return new SimulatorTriggerClient(
this.truststoreLocation, this.truststorePassword, this.truststoreType, this.baseAddress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ alarm.notifications.host=${server.domain}
alarm.notifications.port=9598

# Settings for rest service to dynamically set DLMS attribute values in a device simulator.
dynamic.properties.base.url=https://${server.domain}/osgp-simulator-dlms-triggered/wakeup
dynamic.properties.base.url=${base.uri}osgp-simulator-dlms-triggered/wakeup

# When waiting for a SmartMeter response notification for a correlation UID
# retrieved earlier, what is the maximum duration in milliseconds after which
Expand Down Expand Up @@ -60,4 +60,10 @@ jre.encryption.key.resource=classpath:osgp-secret-management-jre.key
simulator.max.logicalids.per.port=100

smartmetering.firmware.path=/etc/osp/firmwarefiles
smartmetering.firmware.imageidentifier.extention=imgid
smartmetering.firmware.imageidentifier.extention=imgid


web.service.truststore.location=${certificate.basepath}/trust.jks
web.service.truststore.password=123456
web.service.truststore.type=jks
triggered.simulator.url=${base.uri}osgp-simulator-dlms-triggered/wakeup
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,4 @@ web.service.truststore.type=jks
#firmware file location for loading firmware files into the DB
firmware.file.path=/var/www/html/firmware

#triggered.simulator.url=https://localhost/osgp-simulator-dlms-triggered/wakeup
2 changes: 0 additions & 2 deletions osgp/protocol-adapter-dlms/osgp-protocol-adapter-dlms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ SPDX-License-Identifier: Apache-2.0
<osgp-ws-secret-management-version>${project.version}</osgp-ws-secret-management-version>
<skipITs>true</skipITs>
<openmuc.jdlms.version>1.8.0</openmuc.jdlms.version>
<!-- override version in super pom -->
<cxf.version>4.0.3</cxf.version>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,22 @@
import com.fasterxml.jackson.jakarta.rs.json.JacksonJsonProvider;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.Response.Status;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import lombok.extern.slf4j.Slf4j;
import org.apache.cxf.configuration.jsse.TLSClientParameters;
import org.apache.cxf.jaxrs.client.ClientConfiguration;
import org.apache.cxf.jaxrs.client.WebClient;
Expand All @@ -27,6 +33,7 @@
import org.opensmartgridplatform.shared.usermanagement.AbstractClient;
import org.opensmartgridplatform.shared.usermanagement.ResponseException;

@Slf4j
public class SimulatorTriggerClient extends AbstractClient {

private static final String CONSTRUCTION_FAILED = "SimulatorTriggerClient construction failed";
Expand All @@ -50,10 +57,40 @@ public SimulatorTriggerClient(
final String baseAddress)
throws SimulatorTriggerClientException {

// test
log.info("baseAddress: {}", baseAddress);
final File truststoreLocationFile = new File(truststoreLocation);
log.info("{} is parent", truststoreLocationFile.getParentFile());
if (truststoreLocationFile.exists()) {
log.info("{} exists", truststoreLocation);
if (truststoreLocationFile.getParentFile().isDirectory()) {
log.info("{} is directoru", truststoreLocationFile.getParentFile());
Arrays.stream(truststoreLocationFile.getParentFile().listFiles())
.forEach(file -> log.info("== {}", file.getName()));
}
}
// end test
try (final InputStream stream = new FileInputStream(truststoreLocation)) {
// Create the KeyStore.
final KeyStore truststore = KeyStore.getInstance(truststoreType.toUpperCase());

// test
final Iterator<String> iterator = truststore.aliases().asIterator();
log.info("== aliases == ");
while (iterator.hasNext()) {
final String alias = iterator.next();
log.info("alias: {}", alias);
final Certificate certificate = truststore.getCertificate(alias);
log.info("certificate: {}", certificate.toString());
final Certificate[] certificateChain = truststore.getCertificateChain(alias);
Arrays.stream(certificateChain)
.forEach(cc -> log.info("certificate chain: {}", cc.toString()));
log.info("creationdate: {}", truststore.getCreationDate(alias));
}
log.info("== end of aliases == ");

// end test

truststore.load(stream, truststorePassword.toCharArray());

// Create TrustManagerFactory and initialize it using the KeyStore.
Expand Down Expand Up @@ -130,6 +167,14 @@ public void checkClientTrusted(final X509Certificate[] chain, final String authT

tlsParams.setSecureSocketProtocol("TLSv1.2");

try {
final SSLContext sc = SSLContext.getDefault();
tlsParams.setUseHttpsURLConnectionDefaultSslSocketFactory(false);
tlsParams.setSSLSocketFactory(sc.getSocketFactory());
} catch (final Exception e) {
throw new RuntimeException(e);
}

conduit.setTlsClientParameters(tlsParams);

return client;
Expand Down
2 changes: 1 addition & 1 deletion runTestsAtRemoteServer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ CMD="ssh -oStrictHostKeyChecking=no -oTCPKeepAlive=yes -oServerAliveInterval=50
${CMD}

echo '- Create zip file from files from server ...'
CMD="sudo tar zhcvf /tmp/${SERVER}-${PROJECT}.tgz /etc/osgp /etc/httpd/conf.d /usr/share/tomcat/conf /var/log/tomcat /var/log/osgp /var/lib/pgsql/9.6/data/pg_log --warning=no-file-changed || true"
CMD="sudo tar zhcvf /tmp/${SERVER}-${PROJECT}.tgz /etc/ssl/certs /etc/osgp /etc/httpd/conf.d /usr/share/tomcat/conf /var/log/tomcat /var/log/osgp /var/lib/pgsql/9.6/data/pg_log --warning=no-file-changed || true"
echo " [${CMD}]"
CMD="ssh -oStrictHostKeyChecking=no ${SSH_KEY_FILE} ${USER}@${SERVER} \"\"cd /data/software/${PROJECT} && ${CMD}\"\""
${CMD}
Expand Down
Loading