Skip to content

Commit

Permalink
Merge branch 'develop' into wpa-enterprise-certificate-support-frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
GregoryIvo authored Oct 12, 2023
2 parents 478fac4 + f82c490 commit 8e72c92
Show file tree
Hide file tree
Showing 25 changed files with 369 additions and 72 deletions.
37 changes: 23 additions & 14 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
node {
properties([disableConcurrentBuilds(abortPrevious: true), buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')), gitLabConnection('gitlab.eclipse.org'), [$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false], [$class: 'JobLocalConfiguration', changeReasonComment: '']])
properties([
disableConcurrentBuilds(abortPrevious: true),
buildDiscarder(logRotator(artifactDaysToKeepStr: '', artifactNumToKeepStr: '', daysToKeepStr: '', numToKeepStr: '10')),
gitLabConnection('gitlab.eclipse.org'),
[$class: 'RebuildSettings', autoRebuild: false, rebuildDisabled: false],
[$class: 'JobLocalConfiguration', changeReasonComment: '']
])

deleteDir()

stage('Preparation') {
stage('Preparation') {
dir("kura") {
checkout scm
}
Expand All @@ -14,7 +20,7 @@ node {
dir("kura") {
withMaven(jdk: 'adoptopenjdk-hotspot-jdk8-latest', maven: 'apache-maven-3.6.3') {
sh "touch /tmp/isJenkins.txt"
sh "mvn -f target-platform/pom.xml clean install -Pno-mirror -Pcheck-exists-plugin"
sh "mvn -f target-platform/pom.xml clean install -Pno-mirror -Pcheck-exists-plugin"
sh "mvn -f kura/pom.xml clean install -Pcheck-exists-plugin"
sh "mvn -f kura/distrib/pom.xml clean install -DbuildAll"
sh "mvn -f kura/examples/pom.xml clean install -Pcheck-exists-plugin"
Expand All @@ -41,17 +47,20 @@ node {
withMaven(jdk: 'temurin-jdk17-latest', maven: 'apache-maven-3.6.3') {
withCredentials([string(credentialsId: 'sonarcloud-token', variable: 'SONARCLOUD_TOKEN')]) {
withSonarQubeEnv {
sh '''mvn -f kura/pom.xml sonar:sonar \
-Dmaven.test.failure.ignore=true \
-Dsonar.organization=eclipse \
-Dsonar.host.url=${SONAR_HOST_URL} \
-Dsonar.login=${SONARCLOUD_TOKEN} \
-Dsonar.branch.name=${BRANCH_NAME} \
-Dsonar.branch.target=${CHANGE_TARGET} \
-Dsonar.java.binaries='target/' \
-Dsonar.core.codeCoveragePlugin=jacoco \
-Dsonar.projectKey=org.eclipse.kura:kura \
-Dsonar.exclusions=test/**/*.java,test-util/**/*.java,org.eclipse.kura.web2/**/*.java,org.eclipse.kura.nm/src/main/java/org/freedesktop/**/*,org.eclipse.kura.nm/src/main/java/fi/w1/**/*'''
sh '''
mvn -f kura/pom.xml sonar:sonar \
-Dmaven.test.failure.ignore=true \
-Dsonar.organization=eclipse \
-Dsonar.host.url=${SONAR_HOST_URL} \
-Dsonar.login=${SONARCLOUD_TOKEN} \
-Dsonar.branch.name=${BRANCH_NAME} \
-Dsonar.branch.target=${CHANGE_TARGET} \
-Dsonar.java.source=8 \
-Dsonar.java.binaries='target/' \
-Dsonar.core.codeCoveragePlugin=jacoco \
-Dsonar.projectKey=org.eclipse.kura:kura \
-Dsonar.exclusions=test/**/*.java,test-util/**/*.java,org.eclipse.kura.web2/**/*.java,org.eclipse.kura.nm/src/main/java/org/freedesktop/**/*,org.eclipse.kura.nm/src/main/java/fi/w1/**/*
'''
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<properties>
<kura.basedir>${project.basedir}/../../..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<properties>
<kura.basedir>${project.basedir}/../../..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@

<properties>
<kura.basedir>${project.basedir}/../../..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<properties>
<kura.basedir>${project.basedir}/../../..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

<properties>
<kura.basedir>${project.basedir}/../../..</kura.basedir>
<sonar.coverage.jacoco.xmlReportPaths>${project.build.directory}/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<build>
Expand Down
3 changes: 0 additions & 3 deletions kura/examples/test/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,6 @@
<properties>
<kura.basedir>${project.basedir}/../..</kura.basedir>
<tycho.argline>${jacocoArgs} -Dlog4j.configurationFile=file:${kura.basedir}/emulator/org.eclipse.kura.emulator/src/main/resources/log4j.xml</tycho.argline>
<jacoco.reportDir>target/jacoco/</jacoco.reportDir>
<sonar.coverage.jacoco.xmlReportPaths>
${project.basedir}/../../test/*/target/site/jacoco-aggregate/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
</properties>

<modules>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -712,9 +712,7 @@ private boolean isValidMessage(KuraApplicationTopic kuraTopic, KuraPayload kuraP
public void onMessagePublished(int messageId, String topic) {
synchronized (this.messageId) {
if (this.messageId.get() != -1 && this.messageId.get() == messageId) {
if (CloudServiceOptions.getLifeCycleMessageQos() == 0) {
this.messageId.set(-1);
}
this.messageId.set(-1);
this.messageId.notifyAll();
return;
}
Expand Down Expand Up @@ -885,7 +883,7 @@ private void publishLifeCycleMessage(LifecycleMessage message) throws KuraExcept
payload.setTimestamp(new Date());
byte[] encodedPayload = encodePayload(payload);
int id = this.dataService.publish(message.getTopic(), encodedPayload,
CloudServiceOptions.getLifeCycleMessageQos(), CloudServiceOptions.getLifeCycleMessageRetain(),
message.getQos(), CloudServiceOptions.getLifeCycleMessageRetain(),
CloudServiceOptions.getLifeCycleMessagePriority());
this.messageId.set(id);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ public class CloudServiceOptions {
private static final String ENABLE_DFLT_SUBSCRIPTIONS = "enable.default.subscriptions";
private static final String PAYLOAD_ENCODING = "payload.encoding";

private static final int LIFECYCLE_QOS = 0;
private static final int LIFECYCLE_PRIORITY = 0;
private static final boolean LIFECYCLE_RETAIN = false;

Expand Down Expand Up @@ -217,10 +216,6 @@ public static String getTopicWildCard() {
return TOPIC_WILD_CARD;
}

public static int getLifeCycleMessageQos() {
return LIFECYCLE_QOS;
}

public static int getLifeCycleMessagePriority() {
return LIFECYCLE_PRIORITY;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public class LifecycleMessage {
private KuraPayload payload;
private boolean isAppCertificateMessage = false;
private boolean isBirthCertificateMessage = false;
private int qos = 0;

public LifecycleMessage(CloudServiceOptions options, CloudServiceImpl cloudServiceImpl) {
this.topicBuilder = new StringBuilder(options.getTopicControlPrefix());
Expand All @@ -37,13 +38,15 @@ public LifecycleMessage asBirthCertificateMessage() {
this.topicBuilder.append(CloudServiceOptions.getTopicBirthSuffix());
this.payload = this.payloadBuilder.buildBirthPayload();
this.isBirthCertificateMessage = true;
this.qos = 1;
return this;
}

public LifecycleMessage asAppCertificateMessage() {
this.topicBuilder.append(CloudServiceOptions.getTopicAppsSuffix());
this.payload = this.payloadBuilder.buildBirthPayload();
this.isAppCertificateMessage = true;
this.qos = 1;
return this;
}

Expand All @@ -68,5 +71,9 @@ public boolean isAppCertificateMessage() {
public boolean isBirthCertificateMessage() {
return this.isBirthCertificateMessage;
}

public int getQos() {
return this.qos;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ private void findAndDecodeCertificatesForInterface(String interfaceName, Map<Str
}

final String clientCertString = String.format("net.interface.%s.config.802-1x.client-cert-name", interfaceName);
final String caCertString = String.format("net.interface.%s.config.802-1x.802-1x.ca-cert-name", interfaceName);
final String caCertString = String.format("net.interface.%s.config.802-1x.ca-cert-name", interfaceName);
final String privateKeyString = String.format("net.interface.%s.config.802-1x.private-key-name", interfaceName);
final List<String> keyCertStrings = Arrays.asList(clientCertString, caCertString, privateKeyString);

Expand All @@ -367,7 +367,7 @@ private void findAndDecodeCertificatesForInterface(String interfaceName, Map<Str
}

private boolean isCertificate(String key) {
return key.contains("cert");
return key.contains("802-1x.client-cert-name") || key.contains("802-1x.ca-cert-name");
}

private Certificate getTrustedCertificateFromKeystore(String certificateName, KeystoreService keystoreService)
Expand All @@ -380,14 +380,18 @@ private Certificate getTrustedCertificateFromKeystore(String certificateName, Ke
return cert.getCertificate();
} else {
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR,
String.format("Certificate %s is not expected key type or not found.", certificateName));
String.format("Certificate \"%s\" is not of the expected key type or not found.", certificateName));
}
}

private PrivateKey getTrustedPrivateKeyFromKeystore(String privateKeyName, KeystoreService keystoreService)
throws KuraException {
PrivateKeyEntry key = (PrivateKeyEntry) keystoreService.getEntry(privateKeyName);
if (!(keystoreService.getEntry(privateKeyName) instanceof PrivateKeyEntry)) {
throw new KuraException(KuraErrorCode.CONFIGURATION_ERROR,
String.format("Private key \"%s\" is not of the expected key type or not found.", privateKeyName));
}

PrivateKeyEntry key = (PrivateKeyEntry) keystoreService.getEntry(privateKeyName);
return key.getPrivateKey();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Import-Package: javax.annotation.security;version="1.2.0",
org.osgi.service.component;version="1.3.0",
org.osgi.service.useradmin;version="1.1.0";resolution:=optional,
org.slf4j;version="1.7.25"
Export-Package: org.eclipse.kura.rest.configuration.api;version="1.0.0"
Export-Package: org.eclipse.kura.rest.configuration.api;version="1.1.0"
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -361,7 +361,7 @@ public ComponentConfigurationList listComponentConfigurations() {
throw DefaultExceptionHandler.toWebApplicationException(e);
}

return DTOUtil.toComponentConfigurationList(ccs, this.cryptoService, false);
return DTOUtil.toComponentConfigurationList(ccs, this.cryptoService, false).replacePasswordsWithPlaceholder();

}

Expand Down Expand Up @@ -398,7 +398,8 @@ public ComponentConfigurationList listComponentConfigurations(final PidSet pids)
}
});

return DTOUtil.toComponentConfigurationList(configs, this.cryptoService, false);
return DTOUtil.toComponentConfigurationList(configs, this.cryptoService, false)
.replacePasswordsWithPlaceholder();
}

/**
Expand Down Expand Up @@ -562,4 +563,5 @@ public Response rollbackSnapshot(final SnapshotId id) {

return Response.ok().build();
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -12,12 +12,15 @@
*******************************************************************************/
package org.eclipse.kura.rest.configuration.api;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Optional;

import javax.ws.rs.core.Response.Status;

import org.eclipse.kura.configuration.metatype.OCD;
import org.eclipse.kura.configuration.metatype.Scalar;
import org.eclipse.kura.request.handler.jaxrs.DefaultExceptionHandler;

public class ComponentConfigurationDTO implements Validable {
Expand Down Expand Up @@ -45,6 +48,43 @@ public Map<String, PropertyDTO> getProperties() {
return this.properties;
}

public ComponentConfigurationDTO replacePasswordsWithPlaceholder() {

if (properties == null) {
return this;
}

final Map<String, PropertyDTO> result = new HashMap<>(this.properties);

for (final Entry<String, PropertyDTO> e : result.entrySet()) {
e.setValue(replacePasswordsWithPlaceholder(e.getValue()));
}

return new ComponentConfigurationDTO(pid, definition, result);
}

public PropertyDTO replacePasswordsWithPlaceholder(final PropertyDTO property) {

if (property == null || property.getType() != Scalar.PASSWORD) {
return property;
}

if (property.getValue() instanceof String[]) {
final String[] asStringArray = (String[]) property.getValue();
final String[] result = new String[asStringArray.length];

for (int i = 0; i < asStringArray.length; i++) {
if (asStringArray[i] != null) {
result[i] = "placeholder";
}
}

return new PropertyDTO(result, Scalar.PASSWORD);
} else {
return new PropertyDTO("placeholder", Scalar.PASSWORD);
}
}

@Override
public void validate() {
FailureHandler.requireParameter(this.pid, "pid");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2021, 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2021, 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -13,6 +13,7 @@
package org.eclipse.kura.rest.configuration.api;

import java.util.List;
import java.util.stream.Collectors;

public class ComponentConfigurationList implements Validable {

Expand All @@ -30,4 +31,14 @@ public List<ComponentConfigurationDTO> getConfigs() {
public void validate() {
FailureHandler.requireParameter(this.configs, "configs");
}

public ComponentConfigurationList replacePasswordsWithPlaceholder() {
if (configs == null) {
return this;
}

return new ComponentConfigurationList(
configs.stream().map(ComponentConfigurationDTO::replacePasswordsWithPlaceholder)
.collect(Collectors.toList()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Import-Package: com.google.gson;version="2.7.0",
org.eclipse.kura.internal.wire.asset;version="[1.0,2.0)",
org.eclipse.kura.marshalling;version="[1.0,2.0)",
org.eclipse.kura.request.handler.jaxrs;version="[1.0,2.0)",
org.eclipse.kura.rest.configuration.api;version="[1.0,2.0)",
org.eclipse.kura.rest.configuration.api;version="[1.1,2.0)",
org.eclipse.kura.util.service;version="[1.0,2.0)",
org.eclipse.kura.wire;version="[2.0,3.0)",
org.eclipse.kura.wire.graph;version="[1.0,2.0)",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2022 Eurotech and/or its affiliates and others
* Copyright (c) 2023 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -362,7 +362,7 @@ public ComponentConfigurationList getWireConfigsByPid(final PidSet pidSet) {
}
}

return DTOUtil.toComponentConfigurationList(result, cryptoService, true);
return DTOUtil.toComponentConfigurationList(result, cryptoService, false).replacePasswordsWithPlaceholder();

} catch (final Exception e) {
throw DefaultExceptionHandler.toWebApplicationException(e);
Expand Down
Loading

0 comments on commit 8e72c92

Please sign in to comment.