From 8c14d1dee0f297e344c8abb5882593e7c9a81651 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 9 Sep 2026 16:35:36 +0300 Subject: [PATCH 01/14] lwm2m: fix bootstrap-short-server-id = null --- .../src/main/resources/thingsboard.yml | 4 +- .../server/edge/DeviceProfileEdgeTest.java | 30 +++++------ .../lwm2m/AbstractLwM2MIntegrationTest.java | 25 +++++---- .../AbstractSecurityLwM2MIntegrationTest.java | 52 +++++++++--------- ...oSecLwM2MIntegrationDtlsCidLengthTest.java | 2 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 2 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 3 +- ...oSecLwM2MIntegrationDtlsCidLengthTest.java | 3 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 3 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 2 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 2 +- ...oSecLwM2MIntegrationDtlsCidLengthTest.java | 2 +- .../PskLwm2mIntegrationDtlsCidLengthTest.java | 2 +- .../LwM2MIntegrationDiffPortTest.java | 4 +- .../security/sql/PskLwm2mIntegrationTest.java | 14 ++--- .../security/sql/RpkLwM2MIntegrationTest.java | 8 +-- .../sql/X509_NoTrustLwM2MIntegrationTest.java | 8 +-- .../sql/X509_TrustLwM2MIntegrationTest.java | 4 +- .../bootstrap/LwM2MServerSecurityConfig.java | 6 +-- .../secure/LwM2MBootstrapConfig.java | 3 -- .../validator/DeviceProfileDataValidator.java | 53 ++++++++++++++++--- .../src/main/resources/tb-lwm2m-transport.yml | 4 +- 22 files changed, 133 insertions(+), 103 deletions(-) diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 7a2e002750..77369c73e2 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1344,8 +1344,8 @@ transport: bootstrap: # Enable/disable Bootstrap Server enabled: "${LWM2M_ENABLED_BS:true}" - # Default value in LwM2M client after start in mode Bootstrap for the object : name "LWM2M Security" field: "Short Server ID" (deviceProfile: Bootstrap.BOOTSTRAP SERVER.Short ID) - id: "${LWM2M_SERVER_ID_BS:0}" + # Short Server ID for Bootstrap Server is not applicable according to OMA LwM2M spec (Object 0 Resource 10 must be omitted/null for Bootstrap Server). + id: "${LWM2M_SERVER_ID_BS:}" # LwM2M bootstrap server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BS_BIND_ADDRESS:0.0.0.0}" # LwM2M bootstrap server bind port diff --git a/application/src/test/java/org/thingsboard/server/edge/DeviceProfileEdgeTest.java b/application/src/test/java/org/thingsboard/server/edge/DeviceProfileEdgeTest.java index 3ac7b3d648..8646a69751 100644 --- a/application/src/test/java/org/thingsboard/server/edge/DeviceProfileEdgeTest.java +++ b/application/src/test/java/org/thingsboard/server/edge/DeviceProfileEdgeTest.java @@ -245,13 +245,13 @@ public class DeviceProfileEdgeTest extends AbstractEdgeTest { Assert.assertFalse(transportConfiguration.getBootstrap().isEmpty()); LwM2MBootstrapServerCredential lwM2MBootstrapServerCredential = transportConfiguration.getBootstrap().get(0); Assert.assertTrue(lwM2MBootstrapServerCredential instanceof NoSecLwM2MBootstrapServerCredential); - NoSecLwM2MBootstrapServerCredential noSecLwM2MBootstrapServerCredential = (NoSecLwM2MBootstrapServerCredential) lwM2MBootstrapServerCredential; + NoSecLwM2MBootstrapServerCredential noSecLwM2MBootstrapSectionDmServerCredential = (NoSecLwM2MBootstrapServerCredential) lwM2MBootstrapServerCredential; - Assert.assertEquals("PUBLIC_KEY", noSecLwM2MBootstrapServerCredential.getServerPublicKey()); - Assert.assertEquals(Integer.valueOf(123), noSecLwM2MBootstrapServerCredential.getShortServerId()); - Assert.assertFalse(noSecLwM2MBootstrapServerCredential.isBootstrapServerIs()); - Assert.assertEquals("localhost", noSecLwM2MBootstrapServerCredential.getHost()); - Assert.assertEquals(Integer.valueOf(5685), noSecLwM2MBootstrapServerCredential.getPort()); + Assert.assertEquals("PUBLIC_KEY", noSecLwM2MBootstrapSectionDmServerCredential.getServerPublicKey()); + Assert.assertEquals(Integer.valueOf(123), noSecLwM2MBootstrapSectionDmServerCredential.getShortServerId()); + Assert.assertFalse(noSecLwM2MBootstrapSectionDmServerCredential.isBootstrapServerIs()); + Assert.assertEquals("localhost", noSecLwM2MBootstrapSectionDmServerCredential.getHost()); + Assert.assertEquals(Integer.valueOf(5685), noSecLwM2MBootstrapSectionDmServerCredential.getPort()); TelemetryMappingConfiguration observeAttr = transportConfiguration.getObserveAttr(); Assert.assertEquals("batteryLevel", observeAttr.getKeyName().get("/3_1.2/0/9")); @@ -413,15 +413,15 @@ public class DeviceProfileEdgeTest extends AbstractEdgeTest { JacksonUtil.fromString(AbstractLwM2MIntegrationTest.TELEMETRY_WITHOUT_OBSERVE, TelemetryMappingConfiguration.class); transportConfiguration.setObserveAttr(observeAttrConfiguration); - List bootstrap = new ArrayList<>(); - AbstractLwM2MBootstrapServerCredential bootstrapServerCredential = new NoSecLwM2MBootstrapServerCredential(); - bootstrapServerCredential.setServerPublicKey("PUBLIC_KEY"); - bootstrapServerCredential.setShortServerId(123); - bootstrapServerCredential.setBootstrapServerIs(false); - bootstrapServerCredential.setHost("localhost"); - bootstrapServerCredential.setPort(5685); - bootstrap.add(bootstrapServerCredential); - transportConfiguration.setBootstrap(bootstrap); + List bootstrapSections = new ArrayList<>(); + AbstractLwM2MBootstrapServerCredential bootstrapSectionServerCredential = new NoSecLwM2MBootstrapServerCredential(); + bootstrapSectionServerCredential.setServerPublicKey("PUBLIC_KEY"); + bootstrapSectionServerCredential.setShortServerId(123); + bootstrapSectionServerCredential.setBootstrapServerIs(false); + bootstrapSectionServerCredential.setHost("localhost"); + bootstrapSectionServerCredential.setPort(5685); + bootstrapSections.add(bootstrapSectionServerCredential); + transportConfiguration.setBootstrap(bootstrapSections); return transportConfiguration; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java index 258a173451..527915062e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java @@ -19,7 +19,6 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.node.ObjectNode; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import jnr.ffi.annotations.In; import lombok.extern.slf4j.Slf4j; import org.apache.commons.io.IOUtils; import org.awaitility.core.ConditionTimeoutException; @@ -725,28 +724,28 @@ public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportInte List bootstrap = new ArrayList<>(); switch (bootstrapConfigType) { case BOTH: - bootstrap.add(getBootstrapServerCredentialNoSec(false)); - bootstrap.add(getBootstrapServerCredentialNoSec(true)); + bootstrap.add(getBootstrapSectionServerCredentialNoSec(false)); + bootstrap.add(getBootstrapSectionServerCredentialNoSec(true)); break; case BOOTSTRAP_ONLY: - bootstrap.add(getBootstrapServerCredentialNoSec(true)); + bootstrap.add(getBootstrapSectionServerCredentialNoSec(true)); break; case LWM2M_ONLY: - bootstrap.add(getBootstrapServerCredentialNoSec(false)); + bootstrap.add(getBootstrapSectionServerCredentialNoSec(false)); break; case NONE: } return bootstrap; } - protected AbstractLwM2MBootstrapServerCredential getBootstrapServerCredentialNoSec(boolean isBootstrap) { - AbstractLwM2MBootstrapServerCredential bootstrapServerCredential = new NoSecLwM2MBootstrapServerCredential(); - bootstrapServerCredential.setServerPublicKey(""); - bootstrapServerCredential.setShortServerId(isBootstrap ? null : shortServerId); - bootstrapServerCredential.setBootstrapServerIs(isBootstrap); - bootstrapServerCredential.setHost(isBootstrap ? LWM2M_BOOTSTRAP_HOST : LWM2M_HOST); - bootstrapServerCredential.setPort(isBootstrap ? LWM2M_BOOTSTRAP_PORT : LWM2M_PORT); - return bootstrapServerCredential; + protected AbstractLwM2MBootstrapServerCredential getBootstrapSectionServerCredentialNoSec(boolean isBootstrap) { + AbstractLwM2MBootstrapServerCredential bootstrapSectionServerCredential = new NoSecLwM2MBootstrapServerCredential(); + bootstrapSectionServerCredential.setServerPublicKey(""); + bootstrapSectionServerCredential.setShortServerId(isBootstrap ? null : shortServerId); + bootstrapSectionServerCredential.setBootstrapServerIs(isBootstrap); + bootstrapSectionServerCredential.setHost(isBootstrap ? LWM2M_BOOTSTRAP_HOST : LWM2M_HOST); + bootstrapSectionServerCredential.setPort(isBootstrap ? LWM2M_BOOTSTRAP_PORT : LWM2M_PORT); + return bootstrapSectionServerCredential; } protected LwM2MDeviceCredentials getDeviceCredentialsNoSec(LwM2MClientCredential clientCredentials) { diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java index 52bef912f2..55471f2d20 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/AbstractSecurityLwM2MIntegrationTest.java @@ -239,10 +239,10 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M public void basicTestConnectionBootstrapRequestTriggerBefore(String clientEndpoint, String awaitAlias, LwM2MProfileBootstrapConfigType type, int cnt) throws Exception { List bootstrapServerCredentialsNoSec = getBootstrapServerCredentialsNoSec(type); for (int i = 2; i <= cnt; i++) { - AbstractLwM2MBootstrapServerCredential bsCredential = getBootstrapServerCredentialNoSec(false); - bsCredential.setHost("0.0.0." + i); - bsCredential.setShortServerId(bsCredential.getShortServerId() + i); - bootstrapServerCredentialsNoSec.add(bsCredential); + AbstractLwM2MBootstrapServerCredential bsSectionCredential = getBootstrapSectionServerCredentialNoSec(false); + bsSectionCredential.setHost("0.0.0." + i); + bsSectionCredential.setShortServerId(bsSectionCredential.getShortServerId() + i); + bootstrapServerCredentialsNoSec.add(bsSectionCredential); } Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, bootstrapServerCredentialsNoSec); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint)); @@ -316,46 +316,46 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M Assert.assertTrue(lwM2MTestClient.getClientStates().containsAll(expectedStatusesBs)); } - protected List getBootstrapServerCredentialsSecure(LwM2MSecurityMode mode, LwM2MProfileBootstrapConfigType bootstrapConfigType) { - List bootstrap = new ArrayList<>(); + protected List getBootstrapSectionsServerCredentialsSecure(LwM2MSecurityMode mode, LwM2MProfileBootstrapConfigType bootstrapConfigType) { + List bootstrapSections = new ArrayList<>(); switch (bootstrapConfigType) { case BOTH: - bootstrap.add(getBootstrapServerCredential(mode, false)); - bootstrap.add(getBootstrapServerCredential(mode, true)); + bootstrapSections.add(getBootstrapSectionServerCredential(mode, false)); + bootstrapSections.add(getBootstrapSectionServerCredential(mode, true)); break; case BOOTSTRAP_ONLY: - bootstrap.add(getBootstrapServerCredential(mode, true)); + bootstrapSections.add(getBootstrapSectionServerCredential(mode, true)); break; case LWM2M_ONLY: - bootstrap.add(getBootstrapServerCredential(mode, false)); + bootstrapSections.add(getBootstrapSectionServerCredential(mode, false)); break; case NONE: } - return bootstrap; + return bootstrapSections; } - private AbstractLwM2MBootstrapServerCredential getBootstrapServerCredential(LwM2MSecurityMode mode, boolean isBootstrap) { - AbstractLwM2MBootstrapServerCredential bootstrapServerCredential; + private AbstractLwM2MBootstrapServerCredential getBootstrapSectionServerCredential(LwM2MSecurityMode mode, boolean isBootstrap) { + AbstractLwM2MBootstrapServerCredential bootstrapSectionServerCredential; switch (mode) { case PSK: - bootstrapServerCredential = new PSKLwM2MBootstrapServerCredential(); - bootstrapServerCredential.setServerPublicKey(""); + bootstrapSectionServerCredential = new PSKLwM2MBootstrapServerCredential(); + bootstrapSectionServerCredential.setServerPublicKey(""); break; case RPK: - bootstrapServerCredential = new RPKLwM2MBootstrapServerCredential(); + bootstrapSectionServerCredential = new RPKLwM2MBootstrapServerCredential(); if (isBootstrap) { - bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCertBs.getEncoded())); + bootstrapSectionServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCertBs.getEncoded())); } else { - bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCert.getEncoded())); + bootstrapSectionServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCert.getEncoded())); } break; case X509: - bootstrapServerCredential = new X509LwM2MBootstrapServerCredential(); + bootstrapSectionServerCredential = new X509LwM2MBootstrapServerCredential(); try { if (isBootstrap) { - bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509CertBs.getEncoded())); + bootstrapSectionServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509CertBs.getEncoded())); } else { - bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509Cert.getEncoded())); + bootstrapSectionServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509Cert.getEncoded())); } } catch (CertificateEncodingException e) { e.printStackTrace(); @@ -364,11 +364,11 @@ public abstract class AbstractSecurityLwM2MIntegrationTest extends AbstractLwM2M default: throw new IllegalStateException("Unexpected value: " + mode); } - bootstrapServerCredential.setShortServerId(isBootstrap ? null : shortServerId); - bootstrapServerCredential.setBootstrapServerIs(isBootstrap); - bootstrapServerCredential.setHost(isBootstrap ? LWM2M_BOOTSTRAP_HOST : LWM2M_HOST); - bootstrapServerCredential.setPort(isBootstrap ? LWM2MS_BOOTSTRAP_PORT : LWM2MS_PORT); - return bootstrapServerCredential; + bootstrapSectionServerCredential.setShortServerId(isBootstrap ? null : shortServerId); + bootstrapSectionServerCredential.setBootstrapServerIs(isBootstrap); + bootstrapSectionServerCredential.setHost(isBootstrap ? LWM2M_BOOTSTRAP_HOST : LWM2M_HOST); + bootstrapSectionServerCredential.setPort(isBootstrap ? LWM2MS_BOOTSTRAP_PORT : LWM2MS_PORT); + return bootstrapSectionServerCredential; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/NoSecLwM2MIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/NoSecLwM2MIntegrationDtlsCidLengthTest.java index 5c2a4ceb29..5cec2a0a89 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/NoSecLwM2MIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/NoSecLwM2MIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class NoSecLwM2MIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2 @Before public void setUpNoSecDtlsCidLength() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(NO_SEC, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(NO_SEC, NONE)); awaitAlias = "await on client state (NoSec_Lwm2m) serverDtlsCidLength = 0"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/PskLwm2mIntegrationDtlsCidLengthTest.java index d080e1bc65..0773e56aed 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_0/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = 0"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_1/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_1/PskLwm2mIntegrationDtlsCidLengthTest.java index d39afdd504..124d32e090 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_1/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_1/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -17,7 +17,6 @@ package org.thingsboard.server.transport.lwm2m.security.cid.serverDtlsCidLength_ import org.junit.Before; import org.junit.Test; -import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength0Test; import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength1Test; import static org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode.PSK; @@ -27,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = 1"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/NoSecLwM2MIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/NoSecLwM2MIntegrationDtlsCidLengthTest.java index ca36137295..d59d2c7d60 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/NoSecLwM2MIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/NoSecLwM2MIntegrationDtlsCidLengthTest.java @@ -18,7 +18,6 @@ package org.thingsboard.server.transport.lwm2m.security.cid.serverDtlsCidLength_ import org.junit.Before; import org.junit.Test; import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength16Test; -import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength4Test; import static org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode.NO_SEC; import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.NONE; @@ -27,7 +26,7 @@ public class NoSecLwM2MIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2 @Before public void setUpNoSecDtlsCidLength() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(NO_SEC, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(NO_SEC, NONE)); awaitAlias = "await on client state (NoSec_Lwm2m) serverDtlsCidLength = 16"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/PskLwm2mIntegrationDtlsCidLengthTest.java index 45b52c6ddd..90955c2a44 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_16/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -18,7 +18,6 @@ package org.thingsboard.server.transport.lwm2m.security.cid.serverDtlsCidLength_ import org.junit.Before; import org.junit.Test; import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength16Test; -import org.thingsboard.server.transport.lwm2m.security.cid.AbstractSecurityLwM2MIntegrationDtlsCidLength4Test; import static org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode.PSK; import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfileBootstrapConfigType.NONE; @@ -27,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = 16"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_2/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_2/PskLwm2mIntegrationDtlsCidLengthTest.java index 2e0b40da3d..ff4692bf63 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_2/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_2/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = 2"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_4/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_4/PskLwm2mIntegrationDtlsCidLengthTest.java index aa281020a7..ff76104a30 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_4/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_4/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = 4"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/NoSecLwM2MIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/NoSecLwM2MIntegrationDtlsCidLengthTest.java index 88bc5a2622..da5ef9085e 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/NoSecLwM2MIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/NoSecLwM2MIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class NoSecLwM2MIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2 @Before public void setUpNoSecDtlsCidLength() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(NO_SEC, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(NO_SEC, NONE)); awaitAlias = "await on client state (NoSec_Lwm2m) serverDtlsCidLength = Null"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/PskLwm2mIntegrationDtlsCidLengthTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/PskLwm2mIntegrationDtlsCidLengthTest.java index 37611c2bdb..fae638d62c 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/PskLwm2mIntegrationDtlsCidLengthTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/cid/serverDtlsCidLength_null/PskLwm2mIntegrationDtlsCidLengthTest.java @@ -26,7 +26,7 @@ public class PskLwm2mIntegrationDtlsCidLengthTest extends AbstractSecurityLwM2MI @Before public void createProfileRpc() { - transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); awaitAlias = "await on client state (Psk_Lwm2m) serverDtlsCidLength = Null"; } diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/LwM2MIntegrationDiffPortTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/LwM2MIntegrationDiffPortTest.java index 8301905b85..e667484f21 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/LwM2MIntegrationDiffPortTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/diffPort/LwM2MIntegrationDiffPortTest.java @@ -27,7 +27,7 @@ public class LwM2MIntegrationDiffPortTest extends AbstractLwM2MIntegrationDiffPo @Test public void testWithNoSecConnectLwm2mSuccess_AfterRegistration_UpdateRegistrationFromDifferentPort_Ok() throws Exception { String awaitAlias = "await on client state (NoSec different port)"; - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(NO_SEC, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(NO_SEC, NONE)); initDeviceCredentialsNoSek(); basicTestConnectionDifferentPort( transportConfiguration, @@ -36,7 +36,7 @@ public class LwM2MIntegrationDiffPortTest extends AbstractLwM2MIntegrationDiffPo @Test public void testWithPskConnectLwm2mSuccess_AfterRegistration_UpdateRegistrationFromDifferentPort_Ok() throws Exception { String awaitAlias = "await on client state (Psk different port)"; - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); initDeviceCredentialsPsk(); basicTestConnectionDifferentPort( transportConfiguration, diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/PskLwm2mIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/PskLwm2mIntegrationTest.java index a80e9c4643..f01ea6d6ea 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/PskLwm2mIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/PskLwm2mIntegrationTest.java @@ -56,7 +56,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes shortServerId, identity.getBytes(StandardCharsets.UTF_8), Hex.decodeHex(keyPsk.toCharArray())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); this.basicTestConnection(security, null, deviceCredentials, @@ -83,7 +83,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes shortServerId, identity.getBytes(StandardCharsets.UTF_8), Hex.decodeHex(keyPsk.toCharArray())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); String awaitAlias = "await on client state (Psk_Lwm2m)"; Device lwm2mDevice = this.basicTestConnection(security, null, @@ -98,7 +98,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes awaitObserveReadAll(1, lwm2mDevice.getId().getId().toString()); DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + lwm2mDevice.getDeviceProfileId().getId().toString(), DeviceProfile.class); - transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); foundDeviceProfile.getProfileData().setTransportConfiguration(transportConfiguration); DeviceProfile lwm2mDeviceProfileManyParams = doPost("/api/deviceProfile", foundDeviceProfile, DeviceProfile.class); Assert.assertNotNull(lwm2mDeviceProfileManyParams); @@ -120,7 +120,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes shortServerId, identity.getBytes(StandardCharsets.UTF_8), Hex.decodeHex(keyPsk.toCharArray())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_ONE_OBSERVE, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); String awaitAlias = "await on client state (Psk_Lwm2m)"; Device lwm2mDevice = this.basicTestConnection(security, null, @@ -137,7 +137,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes lwM2MTestClient.stop(true); DeviceProfile foundDeviceProfile = doGet("/api/deviceProfile/" + lwm2mDevice.getDeviceProfileId().getId().toString(), DeviceProfile.class); - transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapServerCredentialsSecure(PSK, NONE)); + transportConfiguration = getTransportConfiguration(TELEMETRY_WITH_MANY_OBSERVE, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); foundDeviceProfile.getProfileData().setTransportConfiguration(transportConfiguration); DeviceProfile lwm2mDeviceProfileManyParams = doPost("/api/deviceProfile", foundDeviceProfile, DeviceProfile.class); Assert.assertNotNull(lwm2mDeviceProfileManyParams); @@ -156,7 +156,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes clientCredentials.setEndpoint(clientEndpoint); clientCredentials.setIdentity(identity); clientCredentials.setKey(keyPsk); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + clientEndpoint, transportConfiguration); // Wait for the profile to become available. This synchronizes asynchronous processes and prevents TenantNotFoundException during tearDown. @@ -192,7 +192,7 @@ public class PskLwm2mIntegrationTest extends AbstractSecurityLwM2MIntegrationTes Security securityPskBs = pskBootstrap(SECURE_URI_BS, identity.getBytes(StandardCharsets.UTF_8), Hex.decodeHex(keyPsk.toCharArray())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, BOTH)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, BOTH)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false); this.basicTestConnection(null, securityPskBs, deviceCredentials, diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/RpkLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/RpkLwM2MIntegrationTest.java index ce942090e9..ccf02d94f9 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/RpkLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/RpkLwM2MIntegrationTest.java @@ -56,7 +56,7 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes certificate.getPublicKey().getEncoded(), privateKey.getEncoded(), serverX509Cert.getPublicKey().getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(RPK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(RPK, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, false); this.basicTestConnection(security, null, deviceCredentials, @@ -77,7 +77,7 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes RPKClientCredential clientCredentials = new RPKClientCredential(); clientCredentials.setEndpoint(clientEndpoint); clientCredentials.setKey(Hex.encodeHexString(certificate.getPublicKey().getEncoded())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + clientEndpoint, transportConfiguration); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, false); @@ -95,7 +95,7 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes RPKClientCredential clientCredentials = new RPKClientCredential(); clientCredentials.setEndpoint(clientEndpoint); clientCredentials.setKey(Base64.encodeBase64String(certificate.getPublicKey().getEncoded())); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + clientEndpoint, transportConfiguration); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, true); MvcResult result = createDeviceWithMvcResult(deviceCredentials, clientEndpoint, deviceProfile.getId()); @@ -117,7 +117,7 @@ public class RpkLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegrationTes certificate.getPublicKey().getEncoded(), privateKey.getEncoded(), serverX509CertBs.getPublicKey().getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(RPK, BOTH)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(RPK, BOTH)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, clientPrivateKeyFromCertTrust, certificate, RPK, false); this.basicTestConnection(null, securityRpkBs, deviceCredentials, diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_NoTrustLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_NoTrustLwM2MIntegrationTest.java index 5b385dfea0..c461460c57 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_NoTrustLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_NoTrustLwM2MIntegrationTest.java @@ -56,7 +56,7 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg certificate.getEncoded(), privateKey.getEncoded(), serverX509Cert.getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(X509, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(X509, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, false); this.basicTestConnection(securityX509, null, deviceCredentials, @@ -78,7 +78,7 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg clientCredentials.setEndpoint(clientEndpoint); clientCredentials.setCert(Hex.encodeHexString(certificate.getEncoded())); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, false); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + clientEndpoint, transportConfiguration); MvcResult result = createDeviceWithMvcResult(deviceCredentials, clientEndpoint, deviceProfile.getId()); assertEquals(HttpServletResponse.SC_BAD_REQUEST, result.getResponse().getStatus()); @@ -95,7 +95,7 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg clientCredentials.setEndpoint(clientEndpoint); clientCredentials.setCert(Base64.getEncoder().encodeToString(certificate.getEncoded())); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, true); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(PSK, NONE)); DeviceProfile deviceProfile = createLwm2mDeviceProfile("profileFor" + clientEndpoint, transportConfiguration); MvcResult result = createDeviceWithMvcResult(deviceCredentials, clientEndpoint, deviceProfile.getId()); assertEquals(HttpServletResponse.SC_BAD_REQUEST, result.getResponse().getStatus()); @@ -116,7 +116,7 @@ public class X509_NoTrustLwM2MIntegrationTest extends AbstractSecurityLwM2MInteg certificate.getEncoded(), privateKey.getEncoded(), serverX509CertBs.getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(X509, BOTH)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(X509, BOTH)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, false); this.basicTestConnection(security, null, deviceCredentials, diff --git a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_TrustLwM2MIntegrationTest.java b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_TrustLwM2MIntegrationTest.java index 44eeb96d5f..a7019ca9ea 100644 --- a/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_TrustLwM2MIntegrationTest.java +++ b/application/src/test/java/org/thingsboard/server/transport/lwm2m/security/sql/X509_TrustLwM2MIntegrationTest.java @@ -48,7 +48,7 @@ public class X509_TrustLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegra certificate.getEncoded(), privateKey.getEncoded(), serverX509Cert.getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(X509, NONE)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(X509, NONE)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, false); this.basicTestConnection(security, null, deviceCredentials, @@ -74,7 +74,7 @@ public class X509_TrustLwM2MIntegrationTest extends AbstractSecurityLwM2MIntegra certificate.getEncoded(), privateKey.getEncoded(), serverX509CertBs.getEncoded()); - Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(X509, BOTH)); + Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapSectionsServerCredentialsSecure(X509, BOTH)); LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, X509, false); this.basicTestConnection(security,null, deviceCredentials, diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java index 8d826b6e5c..d88705fa8c 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java @@ -25,9 +25,9 @@ import java.io.Serializable; public class LwM2MServerSecurityConfig implements Serializable { @Schema(description = "Server short Id. Used as link to associate server Object Instance. This identifier uniquely identifies each LwM2M Server configured for the LwM2M Client. " + - "This Resource MUST be set when the Bootstrap-Server Resource has a value of 'false'. " + - "The values ID:0 and ID:65535 values MUST NOT be used for identifying the LwM2M Server.", example = "123", accessMode = Schema.AccessMode.READ_ONLY) - protected Integer shortServerId = 123; + "This Resource MUST be set when the Bootstrap-Server Resource has a value of 'false' and MUST be null when Bootstrap-Server is 'true'. " + + "The values ID:0 and ID:65535 values MUST NOT be used for identifying the LwM2M Server.", example = "1", accessMode = Schema.AccessMode.READ_ONLY) + protected Integer shortServerId; /** Security -> ObjectId = 0 'LWM2M Security' */ @Schema(description = "Is Bootstrap Server or Lwm2m Server. " + "The LwM2M Client MAY be configured to use one or more LwM2M Server Account(s). " + diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java index 45b3148219..1308e23a13 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java @@ -127,9 +127,6 @@ public class LwM2MBootstrapConfig implements Serializable { private BootstrapConfig.ServerConfig setServerConfig (AbstractLwM2MBootstrapServerCredential serverCredential) { BootstrapConfig.ServerConfig serverConfig = new BootstrapConfig.ServerConfig(); - if (serverCredential.getShortServerId() != null) { - serverConfig.shortId = serverCredential.getShortServerId(); - } serverConfig.lifetime = serverCredential.getLifetime(); serverConfig.defaultMinPeriod = serverCredential.getDefaultMinPeriod(); serverConfig.notifIfDisabled = serverCredential.isNotifIfDisabled(); diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java index 74fa56dc87..b7aff6d5db 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java @@ -346,9 +346,27 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator lwM2MBootstrapServersConfigurations, boolean isBootstrapServerUpdateEnable) { Set uris = new HashSet<>(); Set shortServerIds = new HashSet<>(); + boolean hasBootstrapServer = false; + for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) { AbstractLwM2MBootstrapServerCredential serverConfig = (AbstractLwM2MBootstrapServerCredential) bootstrapServerCredential; if (!isBootstrapServerUpdateEnable && serverConfig.isBootstrapServerIs()) { @@ -356,14 +374,29 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator Date: Sun, 13 Sep 2026 20:27:55 +0300 Subject: [PATCH 02/14] lwm2m: fix bootstrap-short-server-id = null - comments 1 --- application/src/main/resources/thingsboard.yml | 2 +- .../lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java | 5 ++++- .../dao/service/validator/DeviceProfileDataValidator.java | 8 +------- transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml | 2 +- 4 files changed, 7 insertions(+), 10 deletions(-) diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 77369c73e2..c83672ee60 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1344,7 +1344,7 @@ transport: bootstrap: # Enable/disable Bootstrap Server enabled: "${LWM2M_ENABLED_BS:true}" - # Short Server ID for Bootstrap Server is not applicable according to OMA LwM2M spec (Object 0 Resource 10 must be omitted/null for Bootstrap Server). + # Short Server ID for Bootstrap Server is not applicable according to OMA LwM2M spec (Object 0 Resource 10 must be omitted/null); left empty by default, and any provided value is normalized to null by the validator upon save. id: "${LWM2M_SERVER_ID_BS:}" # LwM2M bootstrap server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BS_BIND_ADDRESS:0.0.0.0}" diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java index 1308e23a13..59d8120554 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java @@ -51,7 +51,7 @@ public class LwM2MBootstrapConfig implements Serializable { * clientSecretKey?: string, * serverPublicKey?: string; * clientHoldOffTime?: number, - * serverId?: number, + * shortServerId?: number for DM server; null for BS server, * bootstrapServerAccountTimeout: number * */ @Getter @@ -127,6 +127,9 @@ public class LwM2MBootstrapConfig implements Serializable { private BootstrapConfig.ServerConfig setServerConfig (AbstractLwM2MBootstrapServerCredential serverCredential) { BootstrapConfig.ServerConfig serverConfig = new BootstrapConfig.ServerConfig(); + if (!serverCredential.isBootstrapServerIs()) { + serverConfig.shortId = serverCredential.getShortServerId(); + } serverConfig.lifetime = serverCredential.getLifetime(); serverConfig.defaultMinPeriod = serverCredential.getDefaultMinPeriod(); serverConfig.notifIfDisabled = serverCredential.isNotifIfDisabled(); diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java index b7aff6d5db..a8d0ddcee8 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java @@ -380,14 +380,8 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator Date: Tue, 15 Sep 2026 11:49:13 +0300 Subject: [PATCH 03/14] lwm2m: fix bootstrap-short-server-id = null - tests --- .../validator/DeviceProfileDataValidator.java | 1 - .../DeviceProfileDataValidatorTest.java | 60 +++++++++++++------ 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java index 9a6cda8a1d..bf72cf286c 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java @@ -367,7 +367,6 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator validator.validateDataImpl(tenantId, deviceProfile)) .hasMessageContaining(msgError); From e0fd388da90d27008260911cac0ccf96e5502bf0 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 16 Sep 2026 15:50:46 +0300 Subject: [PATCH 04/14] lwm2m: fix bootstrap-short-server-id = null - tests 2 --- .../secure/LwM2MBootstrapConfig.java | 2 +- .../DeviceProfileDataValidatorTest.java | 67 ++++++++++--------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java index 285d6bc9f9..fe6701a1ed 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java @@ -114,7 +114,7 @@ public class LwM2MBootstrapConfig implements Serializable { private BootstrapConfig.ServerConfig setServerConfig (AbstractLwM2MBootstrapServerCredential serverCredential) { BootstrapConfig.ServerConfig serverConfig = new BootstrapConfig.ServerConfig(); - if (!serverCredential.isBootstrapServerIs()) { + if (!serverCredential.isBootstrapServerIs() && serverCredential.getShortServerId() != null) { serverConfig.shortId = serverCredential.getShortServerId(); } serverConfig.lifetime = serverCredential.getLifetime(); diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java index 477b410d6c..3a4fa13281 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java @@ -33,6 +33,7 @@ import java.util.List; import java.util.UUID; import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.willReturn; import static org.mockito.Mockito.verify; import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.LWM2M_SERVER_MAX; @@ -115,7 +116,7 @@ class DeviceProfileDataValidatorTest { void testValidateDeviceProfile_Lwm2mBootstrap_ShortServerId_Ok() { Integer shortServerId = 123; Integer shortServerIdBs = null; - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, 1); + DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, false); validator.validateDataImpl(tenantId, deviceProfile); verify(validator).validateString("Device profile name", deviceProfile.getName()); @@ -123,66 +124,49 @@ class DeviceProfileDataValidatorTest { @Test void testValidateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_validate_0_to_null_Warn() { - Integer shortServerId = 123; - Integer shortServerIdBs = 0; - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, 1); - - validator.validateDataImpl(tenantId, deviceProfile); - verify(validator).validateString("Device profile name", deviceProfile.getName()); + validateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Number_to_null_Warn(0); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_More_65535_to_null_Warn() { - Integer shortServerId = 123; - Integer shortServerIdBs = 65536; - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, 1); - validator.validateDataImpl(tenantId, deviceProfile); - verify(validator).validateString("Device profile name", deviceProfile.getName()); + validateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Number_to_null_Warn(65536); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_111_to_null_Warn() { - Integer shortServerId = 123; - Integer shortServerIdBs = 111; - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, 1); - validator.validateDataImpl(tenantId, deviceProfile); - verify(validator).validateString("Device profile name", deviceProfile.getName()); + validateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Number_to_null_Warn(111); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Less_0_to_null_Warn() { - Integer shortServerId = 123; - Integer shortServerIdBs = -1; - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, 1); - validator.validateDataImpl(tenantId, deviceProfile); - verify(validator).validateString("Device profile name", deviceProfile.getName()); + validateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Number_to_null_Warn(-1); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_null_Error_BootstrapShortServerId_null_Ok() { - verifyValidationError(null, null, "LwM2M" + msgErrorNotNull, 1); + verifyValidationError(null, null, "LwM2M" + msgErrorNotNull, false); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_More_65534_Error_BootstrapShortServerId_null_Ok() { - verifyValidationError(NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(), null, msgErrorLwm2mRange, 1); + verifyValidationError(NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(), null, msgErrorLwm2mRange, false); } @Test void testValidateDeviceProfile_Lwm2mShortServerId_Less_1_Error_BootstrapShortServerId_null_Ok() { - verifyValidationError(0, null, msgErrorLwm2mRange, 1); + verifyValidationError(0, null, msgErrorLwm2mRange, false); } @Test - void testValidateDeviceProfile_Lwm2mShortServerId_Ok_Cnt_BootstrapShortServerId_Less_1_Error() { - verifyValidationError(123, null, msgErrorBsOnlyOne, 2); + void testValidateDeviceProfile_MoreThanOneBootstrapServer_Error() { + verifyValidationError(123, null, msgErrorBsOnlyOne, true); } - private DeviceProfile getDeviceProfile(Integer shortServerId, Integer shortServerIdBs, int cntBsServer) { + private DeviceProfile getDeviceProfile(Integer shortServerId, Integer shortServerIdBs, boolean withSecondBsServer) { Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsNoSec(shortServerId, shortServerIdBs)); - if (cntBsServer == 2) { - AbstractLwM2MBootstrapServerCredential bootstrapServerCredentialNoSecTwo = getBootstrapServerCredentialNoSec(true, shortServerId, shortServerIdBs == null ? 111 : shortServerIdBs++); + if (withSecondBsServer) { + AbstractLwM2MBootstrapServerCredential bootstrapServerCredentialNoSecTwo = getBootstrapServerCredentialNoSec(true, shortServerId, shortServerIdBs == null ? 111 : ++shortServerIdBs); transportConfiguration.getBootstrap().add(bootstrapServerCredentialNoSecTwo); } DeviceProfile deviceProfile = new DeviceProfile(); @@ -224,11 +208,30 @@ class DeviceProfileDataValidatorTest { return bootstrapServerCredential; } - private void verifyValidationError(Integer shortServerId, Integer shortServerIdBs, String msgError, int cntBsServer) { - DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, cntBsServer); + private void verifyValidationError(Integer shortServerId, Integer shortServerIdBs, String msgError, boolean withSecondBsServer) { + DeviceProfile deviceProfile = getDeviceProfile(shortServerId, shortServerIdBs, withSecondBsServer); assertThatThrownBy(() -> validator.validateDataImpl(tenantId, deviceProfile)) .hasMessageContaining(msgError); } + private LwM2MBootstrapServerCredential getBootstrapCredential(DeviceProfile deviceProfile) { + Lwm2mDeviceProfileTransportConfiguration transportConfig = + (Lwm2mDeviceProfileTransportConfiguration) deviceProfile.getProfileData().getTransportConfiguration(); + + return transportConfig.getBootstrap().stream() + .filter(credential -> ((NoSecLwM2MBootstrapServerCredential)credential).isBootstrapServerIs()) + .findFirst() + .orElseThrow(() -> new AssertionError("Bootstrap server not found in profile")); + } + + + private void validateDeviceProfile_Lwm2mShortServerId_Ok_BootstrapShortServerId_Number_to_null_Warn(Integer shortServerIdBs) { + DeviceProfile deviceProfile = getDeviceProfile(123, shortServerIdBs, false); + validator.validateDataImpl(tenantId, deviceProfile); + verify(validator).validateString("Device profile name", deviceProfile.getName()); + LwM2MBootstrapServerCredential bsCredential = getBootstrapCredential(deviceProfile); + assertThat(((NoSecLwM2MBootstrapServerCredential)bsCredential).getShortServerId()); + } + } From 7ef912dfadb43a6cd20d0ef7e6b886f798083234 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Wed, 16 Sep 2026 16:23:57 +0300 Subject: [PATCH 05/14] lwm2m: fix bootstrap-short-server-id = null - comments 2 --- .../lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java | 2 +- .../validator/DeviceProfileDataValidator.java | 12 +++++------- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java index fe6701a1ed..d592183440 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/bootstrap/secure/LwM2MBootstrapConfig.java @@ -38,7 +38,7 @@ public class LwM2MBootstrapConfig implements Serializable { * clientSecretKey?: string, * serverPublicKey?: string; * clientHoldOffTime?: number, - * shortServerId?: number for DM server; null for BS server, + * shortServerId?: number, // DM server only; null for the BS entry * bootstrapServerAccountTimeout: number * */ @Getter diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java index bf72cf286c..938b15616b 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java @@ -169,7 +169,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator lwM2MBootstrapServersConfigurations = ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).getBootstrap(); if (lwM2MBootstrapServersConfigurations != null) { validateLwm2mServersConfigOfBootstrapForClient(lwM2MBootstrapServersConfigurations, - ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).isBootstrapServerUpdateEnable()); + ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).isBootstrapServerUpdateEnable(), deviceProfile.getName(), tenantId); for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) { validateLwm2mServersCredentialOfBootstrapForClient(bootstrapServerCredential); } @@ -344,12 +344,11 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator lwM2MBootstrapServersConfigurations, boolean isBootstrapServerUpdateEnable) { + private void validateLwm2mServersConfigOfBootstrapForClient(List lwM2MBootstrapServersConfigurations, + boolean isBootstrapServerUpdateEnable, String deviceProfileName, TenantId tenantId) { Set uris = new HashSet<>(); Set shortServerIds = new HashSet<>(); boolean hasBootstrapServer = false; @@ -363,14 +362,13 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator Date: Wed, 16 Sep 2026 16:27:28 +0300 Subject: [PATCH 06/14] lwm2m: fix bootstrap-short-server-id = null - comments 3 --- .../org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java index 8c7deeea1b..6f8a39ce73 100644 --- a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java +++ b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java @@ -30,6 +30,9 @@ public class LwM2MServiceImpl implements LwM2MService { if (bsServerConfig!= null) { LwM2MServerSecurityConfigDefault result = getServerSecurityConfig(bsServerConfig); result.setBootstrapServerIs(bootstrapServer); + if (bootstrapServer) { + result.setShortServerId(null); + } return result; } else { From dfd0c5c7fa98a1ae63761c7e3fa65e7f0e794ce7 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Thu, 17 Sep 2026 14:28:19 +0300 Subject: [PATCH 07/14] lwm2m: fix bootstrap-short-server-id = null - comments 4 --- .../service/lwm2m/LwM2MServiceImpl.java | 26 +++++++++++++------ .../DeviceProfileControllerTest.java | 24 +++++++++++++++++ .../bootstrap/LwM2MServerSecurityConfig.java | 2 +- .../DeviceProfileDataValidatorTest.java | 4 +-- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java index 6f8a39ce73..33d0487fdd 100644 --- a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java +++ b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java @@ -28,23 +28,33 @@ public class LwM2MServiceImpl implements LwM2MService { public LwM2MServerSecurityConfigDefault getServerSecurityInfo(boolean bootstrapServer) { LwM2MSecureServerConfig bsServerConfig = bootstrapServer ? bootstrapConfig.orElse(null) : serverConfig; if (bsServerConfig!= null) { - LwM2MServerSecurityConfigDefault result = getServerSecurityConfig(bsServerConfig); - result.setBootstrapServerIs(bootstrapServer); - if (bootstrapServer) { - result.setShortServerId(null); - } - return result; + return getServerSecurityConfig(bsServerConfig, bootstrapServer); } else { return null; } } - private LwM2MServerSecurityConfigDefault getServerSecurityConfig(LwM2MSecureServerConfig bsServerConfig) { + private LwM2MServerSecurityConfigDefault getServerSecurityConfig(LwM2MSecureServerConfig bsServerConfig, boolean bootstrapServer) { LwM2MServerSecurityConfigDefault bsServ = new LwM2MServerSecurityConfigDefault(); - bsServ.setShortServerId(bsServerConfig.getId()); bsServ.setHost(bsServerConfig.getHost()); bsServ.setPort(bsServerConfig.getPort()); + bsServ.setBootstrapServerIs(bootstrapServer); + if (bootstrapServer) { + if (bsServerConfig.getId() != null) { + log.warn("Ignoring Short Server ID [{}] on the Bootstrap Server entry: cleared to null for backward compatibility (ThingsBoard <= 4.2).", + bsServerConfig.getId()); + } + bsServ.setShortServerId(null); + } else { + Integer configId = bsServerConfig.getId(); + if (configId == null || configId <= 0 || configId >= 65535) { + log.warn("Invalid Short Server ID [{}] for LwM2M Server entry: defaulting to [1] for backward compatibility (ThingsBoard <= 4.2).", + configId); + configId = 1; + } + bsServ.setShortServerId(configId); + } bsServ.setSecurityHost(bsServerConfig.getSecureHost()); bsServ.setSecurityPort(bsServerConfig.getSecurePort()); byte[] publicKeyBase64 = getPublicKey(bsServerConfig); diff --git a/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java b/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java index fa4d65b1a4..3d226d903a 100644 --- a/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/DeviceProfileControllerTest.java @@ -34,6 +34,7 @@ import org.thingsboard.server.common.data.audit.ActionType; import org.thingsboard.server.common.data.device.profile.JsonTransportPayloadConfiguration; import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.ProtoTransportPayloadConfiguration; +import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageLink; @@ -1167,6 +1168,29 @@ public class DeviceProfileControllerTest extends AbstractControllerTest { assertThat(deviceProfile.getVersion()).isEqualTo(3); } + @Test + public void testGetLwm2mBootstrapSecurityInfo_BootstrapServer_Returns_ShortServerId_Null() throws Exception { + LwM2MServerSecurityConfigDefault result = doGet( + "/api/lwm2m/deviceProfile/bootstrap/true", + LwM2MServerSecurityConfigDefault.class + ); + Assert.assertNotNull(result); + Assert.assertTrue(result.isBootstrapServerIs()); + Assert.assertNull(result.getShortServerId()); + } + + @Test + public void testGetLwm2mBootstrapSecurityInfo_BootstrapServer_Returns_ShortServerId_1() throws Exception { + LwM2MServerSecurityConfigDefault result = doGet( + "/api/lwm2m/deviceProfile/bootstrap/false", + LwM2MServerSecurityConfigDefault.class + ); + Assert.assertNotNull(result); + Assert.assertFalse(result.isBootstrapServerIs()); + Assert.assertNotNull(result.getShortServerId()); + Assert.assertEquals(Integer.valueOf(123), result.getShortServerId()); + } + private DeviceProfile saveDeviceProfile(String name) { DeviceProfile deviceProfile = createDeviceProfile(name); return saveDeviceProfile(deviceProfile); diff --git a/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java b/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java index 7b98bae597..e2bdb9a6fd 100644 --- a/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java +++ b/common/data/src/main/java/org/thingsboard/server/common/data/device/profile/lwm2m/bootstrap/LwM2MServerSecurityConfig.java @@ -13,7 +13,7 @@ public class LwM2MServerSecurityConfig implements Serializable { @Schema(description = "Server short Id. Used as link to associate server Object Instance. This identifier uniquely identifies each LwM2M Server configured for the LwM2M Client. " + "This Resource MUST be set when the Bootstrap-Server Resource has a value of 'false' and MUST be null when Bootstrap-Server is 'true'. " + - "The values ID:0 and ID:65535 values MUST NOT be used for identifying the LwM2M Server.", example = "1", accessMode = Schema.AccessMode.READ_ONLY) + "The values 0 and 65535 MUST NOT be used for identifying the LwM2M Server.", example = "1", accessMode = Schema.AccessMode.READ_ONLY) protected Integer shortServerId; /** Security -> ObjectId = 0 'LWM2M Security' */ @Schema(description = "Is Bootstrap Server or Lwm2m Server. " + diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java index 3a4fa13281..2231b52d2e 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidatorTest.java @@ -220,7 +220,7 @@ class DeviceProfileDataValidatorTest { (Lwm2mDeviceProfileTransportConfiguration) deviceProfile.getProfileData().getTransportConfiguration(); return transportConfig.getBootstrap().stream() - .filter(credential -> ((NoSecLwM2MBootstrapServerCredential)credential).isBootstrapServerIs()) + .filter(credential -> ((AbstractLwM2MBootstrapServerCredential)credential).isBootstrapServerIs()) .findFirst() .orElseThrow(() -> new AssertionError("Bootstrap server not found in profile")); } @@ -231,7 +231,7 @@ class DeviceProfileDataValidatorTest { validator.validateDataImpl(tenantId, deviceProfile); verify(validator).validateString("Device profile name", deviceProfile.getName()); LwM2MBootstrapServerCredential bsCredential = getBootstrapCredential(deviceProfile); - assertThat(((NoSecLwM2MBootstrapServerCredential)bsCredential).getShortServerId()); + assertThat(((AbstractLwM2MBootstrapServerCredential) bsCredential).getShortServerId()).isNull(); } } From 73fdbdcd1576a2514c18f643edeebecbc77b72de Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Thu, 17 Sep 2026 20:00:01 +0300 Subject: [PATCH 08/14] lwm2m: fix bootstrap-short-server-id = null - comments 5 --- application/src/main/resources/thingsboard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 287d88a00d..05586b01f8 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1333,7 +1333,7 @@ transport: bootstrap: # Enable/disable Bootstrap Server enabled: "${LWM2M_ENABLED_BS:true}" - # Short Server ID for Bootstrap Server is not applicable according to OMA LwM2M spec (Object 0 Resource 10 must be omitted/null); left empty by default, and any provided value is normalized to null by the validator upon save. + # Deprecated: Short Server ID is not applicable for Bootstrap Server per OMA LwM2M spec (Object 0 Resource 10 must be omitted/null); setting this property has no effect and any value is ignored and forced to null. id: "${LWM2M_SERVER_ID_BS:}" # LwM2M bootstrap server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BS_BIND_ADDRESS:0.0.0.0}" From 5c5492793b8860b6a517b59569cbb48a648be13c Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Thu, 17 Sep 2026 21:10:54 +0300 Subject: [PATCH 09/14] lwm2m: fix bootstrap-short-server-id = null - comments 6 --- .../service/lwm2m/LwM2MServiceImpl.java | 9 +- .../LwM2MServiceImplInvalidConfigTest.java | 95 +++++++++++++++++++ 2 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java diff --git a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java index 33d0487fdd..9071babb45 100644 --- a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java +++ b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java @@ -14,6 +14,8 @@ import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConf import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; import java.util.Optional; +import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.LWM2M_SERVER_MAX; +import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.PRIMARY_LWM2M_SERVER; @Slf4j @Service @@ -49,9 +51,10 @@ public class LwM2MServiceImpl implements LwM2MService { } else { Integer configId = bsServerConfig.getId(); if (configId == null || configId <= 0 || configId >= 65535) { - log.warn("Invalid Short Server ID [{}] for LwM2M Server entry: defaulting to [1] for backward compatibility (ThingsBoard <= 4.2).", - configId); - configId = 1; + throw new IllegalArgumentException(String.format( + "Invalid LwM2M Server ShortServerId [%s] in configuration (transport.lwm2m.server.id). Must be in range [%d - %d]!", + configId, PRIMARY_LWM2M_SERVER.getId(), LWM2M_SERVER_MAX.getId() + )); } bsServ.setShortServerId(configId); } diff --git a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java new file mode 100644 index 0000000000..7273e2c558 --- /dev/null +++ b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java @@ -0,0 +1,95 @@ +// SPDX-FileCopyrightText: Copyright The Thingsboard Authors +// SPDX-License-Identifier: Apache-2.0 +package org.thingsboard.server.controller; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; +import org.thingsboard.server.service.lwm2m.LwM2MServiceImpl; +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.mockito.BDDMockito.given; +import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX; +import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.PRIMARY_LWM2M_SERVER; + +@ExtendWith(MockitoExtension.class) +public class LwM2MServiceImplInvalidConfigTest { + + @Mock + private LwM2MTransportServerConfig serverConfig; + + @Mock + private LwM2MTransportBootstrapConfig bootstrapConfig; + + private LwM2MServiceImpl lwM2MService; + + @BeforeEach + void setUp() { + lwM2MService = new LwM2MServiceImpl(serverConfig, Optional.of(bootstrapConfig)); + } + + @Test + void testGetServerSecurityInfo_BsServerWithNonEmptyId_ClearsToNullAndLogsWarn() { + given(bootstrapConfig.getId()).willReturn(111); + given(bootstrapConfig.getHost()).willReturn("0.0.0.0"); + given(bootstrapConfig.getPort()).willReturn(5687); + + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(true); + + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isTrue(); + assertThat(result.getShortServerId()).isNull(); + } + + @Test + void testGetServerSecurityInfo_DmServerWithValidId_Success() { + Integer validShortServerId = 123; + given(serverConfig.getId()).willReturn(validShortServerId); + given(serverConfig.getHost()).willReturn("0.0.0.0"); + given(serverConfig.getPort()).willReturn(5685); + + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(validShortServerId); + } + + @Test + void testGetServerSecurityInfo_DmServer_Less_PRIMARY_LWM2M_SERVER_ThrowsIllegalArgumentException() { + Integer shortServerId = PRIMARY_LWM2M_SERVER.getId() - 1; + given(serverConfig.getId()).willReturn(shortServerId); + + assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); + } + + @Test + void testGetServerSecurityInfo_DmServer_NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX_ThrowsIllegalArgumentException() { + Integer shortServerId = NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(); + given(serverConfig.getId()).willReturn(shortServerId); + + assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); + } + + @Test + void testGetServerSecurityInfo_DmServerWithNullId_ThrowsIllegalArgumentException() { + Integer shortServerId = null; + given(serverConfig.getId()).willReturn(shortServerId); + + assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) + .isInstanceOf(IllegalArgumentException.class) + .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); + } +} \ No newline at end of file From 150c2a5fc6b5ac8d3b0518542a4420463450d634 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Thu, 17 Sep 2026 21:17:33 +0300 Subject: [PATCH 10/14] lwm2m: fix bootstrap-short-server-id = null - comments 7 --- .../dao/service/validator/DeviceProfileDataValidator.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java index 938b15616b..aba492ef07 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/validator/DeviceProfileDataValidator.java @@ -169,7 +169,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator lwM2MBootstrapServersConfigurations = ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).getBootstrap(); if (lwM2MBootstrapServersConfigurations != null) { validateLwm2mServersConfigOfBootstrapForClient(lwM2MBootstrapServersConfigurations, - ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).isBootstrapServerUpdateEnable(), deviceProfile.getName(), tenantId); + ((Lwm2mDeviceProfileTransportConfiguration) transportConfiguration).isBootstrapServerUpdateEnable(), deviceProfile); for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) { validateLwm2mServersCredentialOfBootstrapForClient(bootstrapServerCredential); } @@ -348,7 +348,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator lwM2MBootstrapServersConfigurations, - boolean isBootstrapServerUpdateEnable, String deviceProfileName, TenantId tenantId) { + boolean isBootstrapServerUpdateEnable, DeviceProfile deviceProfile) { Set uris = new HashSet<>(); Set shortServerIds = new HashSet<>(); boolean hasBootstrapServer = false; @@ -368,7 +368,7 @@ public class DeviceProfileDataValidator extends AbstractHasOtaPackageValidator Date: Thu, 17 Sep 2026 21:39:24 +0300 Subject: [PATCH 11/14] lwm2m: fix bootstrap-short-server-id = null - comments 8 --- application/src/main/resources/thingsboard.yml | 2 +- transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 05586b01f8..85ad4b1806 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1333,7 +1333,7 @@ transport: bootstrap: # Enable/disable Bootstrap Server enabled: "${LWM2M_ENABLED_BS:true}" - # Deprecated: Short Server ID is not applicable for Bootstrap Server per OMA LwM2M spec (Object 0 Resource 10 must be omitted/null); setting this property has no effect and any value is ignored and forced to null. + # Deprecated: Short Server ID is not applicable for Bootstrap Server per OMA spec (Object 0 Resource 10) and is forced to null. id: "${LWM2M_SERVER_ID_BS:}" # LwM2M bootstrap server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BS_BIND_ADDRESS:0.0.0.0}" diff --git a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml index 3719947dac..b9c22ad5f2 100644 --- a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml +++ b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml @@ -216,7 +216,7 @@ transport: bootstrap: # Enable/disable Bootstrap Server enabled: "${LWM2M_ENABLED_BS:true}" - # Short Server ID for Bootstrap Server is not applicable according to OMA LwM2M spec (Object 0 Resource 10 must be omitted/null); left empty by default, and any provided value is normalized to null by the validator upon save. + # Deprecated: Short Server ID is not applicable for Bootstrap Server per OMA spec (Object 0 Resource 10) and is forced to null. id: "${LWM2M_SERVER_ID_BS:}" # LwM2M bootstrap server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BS_BIND_ADDRESS:0.0.0.0}" From 3f37cb28b3e5caa1049bf2fae9f0bc708d1a4643 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Fri, 18 Sep 2026 11:16:29 +0300 Subject: [PATCH 12/14] lwm2m: fix bootstrap-short-server-id = null - comments 9 --- .../service/lwm2m/LwM2MServiceImpl.java | 11 ++++--- .../src/main/resources/thingsboard.yml | 2 +- .../LwM2MServiceImplInvalidConfigTest.java | 32 +++++++++++-------- .../config/LwM2MTransportServerConfig.java | 2 +- .../src/main/resources/tb-lwm2m-transport.yml | 2 +- 5 files changed, 27 insertions(+), 22 deletions(-) diff --git a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java index 9071babb45..ae777fbff7 100644 --- a/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java +++ b/application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServiceImpl.java @@ -6,6 +6,7 @@ import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.binary.Base64; import org.springframework.stereotype.Service; +import org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier; import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; import org.thingsboard.server.common.transport.config.ssl.SslCredentials; import org.thingsboard.server.queue.util.TbCoreComponent; @@ -50,11 +51,11 @@ public class LwM2MServiceImpl implements LwM2MService { bsServ.setShortServerId(null); } else { Integer configId = bsServerConfig.getId(); - if (configId == null || configId <= 0 || configId >= 65535) { - throw new IllegalArgumentException(String.format( - "Invalid LwM2M Server ShortServerId [%s] in configuration (transport.lwm2m.server.id). Must be in range [%d - %d]!", - configId, PRIMARY_LWM2M_SERVER.getId(), LWM2M_SERVER_MAX.getId() - )); + if (Lwm2mServerIdentifier.isNotLwm2mServer(configId)) { + log.warn("Invalid LwM2M Server ShortServerId [{}] in configuration (transport.lwm2m.server.id). " + + "Must be in range [{} - {}]. Using [{}] instead.", + configId, PRIMARY_LWM2M_SERVER.getId(), LWM2M_SERVER_MAX.getId(), PRIMARY_LWM2M_SERVER.getId()); + configId = PRIMARY_LWM2M_SERVER.getId(); } bsServ.setShortServerId(configId); } diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index 85ad4b1806..beb29333ba 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1291,7 +1291,7 @@ transport: #
  • A value that are > 4: MultiNodeConnectionIdGenerator is used
  • connection_id_length: "${LWM2M_DTLS_CONNECTION_ID_LENGTH:8}" server: - # LwM2M Server ID + # LwM2M Server Short Server ID [1 - 65534]: 0 and 65535 are reserved. An invalid or missing value is ignored and 1 is used instead. id: "${LWM2M_SERVER_ID:123}" # LwM2M server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" diff --git a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java index 7273e2c558..6beeccb1af 100644 --- a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java @@ -15,7 +15,6 @@ import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.BDDMockito.given; import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX; import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.PRIMARY_LWM2M_SERVER; @@ -64,32 +63,37 @@ public class LwM2MServiceImplInvalidConfigTest { } @Test - void testGetServerSecurityInfo_DmServer_Less_PRIMARY_LWM2M_SERVER_ThrowsIllegalArgumentException() { + void testGetServerSecurityInfo_Server_Less_PRIMARY_LWM2M_SERVER_DefaultsToOneAndLogsWarn() { Integer shortServerId = PRIMARY_LWM2M_SERVER.getId() - 1; given(serverConfig.getId()).willReturn(shortServerId); - assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); } @Test - void testGetServerSecurityInfo_DmServer_NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX_ThrowsIllegalArgumentException() { + void testGetServerSecurityInfo_Server_NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX_DefaultsToOneAndLogsWarn() { Integer shortServerId = NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(); given(serverConfig.getId()).willReturn(shortServerId); - assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); } @Test - void testGetServerSecurityInfo_DmServerWithNullId_ThrowsIllegalArgumentException() { + void testGetServerSecurityInfo_ServerWithNullId_DefaultsToOneAndLogsWarn() { Integer shortServerId = null; given(serverConfig.getId()).willReturn(shortServerId); - assertThatThrownBy(() -> lwM2MService.getServerSecurityInfo(false)) - .isInstanceOf(IllegalArgumentException.class) - .hasMessageContaining("Invalid LwM2M Server ShortServerId [" + shortServerId + "] in configuration (transport.lwm2m.server.id). Must be in range [1 - 65534]!"); - } + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); } } \ No newline at end of file diff --git a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java index 15f5a03555..6f2a510783 100644 --- a/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java +++ b/common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java @@ -81,7 +81,7 @@ public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig { private int cleanPeriodInSec; @Getter - @Value("${transport.lwm2m.server.id:}") + @Value("${transport.lwm2m.server.id:123}") private Integer id; @Getter diff --git a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml index b9c22ad5f2..c7cf5100db 100644 --- a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml +++ b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml @@ -174,7 +174,7 @@ transport: #
  • A value that are > 4: MultiNodeConnectionIdGenerator is used
  • connection_id_length: "${LWM2M_DTLS_CONNECTION_ID_LENGTH:8}" server: - # LwM2M Server ID + # LwM2M Server Short Server ID [1 - 65534]: 0 and 65535 are reserved. An invalid or missing value is ignored and 1 is used instead. id: "${LWM2M_SERVER_ID:123}" # LwM2M server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" From a9e8f0fb3c23213d2b0d6cdde5a8c085a04fdca0 Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Fri, 18 Sep 2026 16:14:45 +0300 Subject: [PATCH 13/14] lwm2m: fix bootstrap-short-server-id = null - comments 10 --- .../src/main/resources/thingsboard.yml | 2 +- .../LwM2MServiceImplInvalidConfigTest.java | 48 +++++++++++-------- .../src/main/resources/tb-lwm2m-transport.yml | 2 +- 3 files changed, 30 insertions(+), 22 deletions(-) diff --git a/application/src/main/resources/thingsboard.yml b/application/src/main/resources/thingsboard.yml index beb29333ba..fe454447c5 100644 --- a/application/src/main/resources/thingsboard.yml +++ b/application/src/main/resources/thingsboard.yml @@ -1291,7 +1291,7 @@ transport: #
  • A value that are > 4: MultiNodeConnectionIdGenerator is used
  • connection_id_length: "${LWM2M_DTLS_CONNECTION_ID_LENGTH:8}" server: - # LwM2M Server Short Server ID [1 - 65534]: 0 and 65535 are reserved. An invalid or missing value is ignored and 1 is used instead. + # LwM2M Server Short Server ID. Valid range [1 - 65534]; 0 and 65535 are reserved. Default: 123. id: "${LWM2M_SERVER_ID:123}" # LwM2M server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" diff --git a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java index 6beeccb1af..0951f71b40 100644 --- a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java @@ -16,6 +16,7 @@ import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.BDDMockito.given; +import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.LWM2M_SERVER_MAX; import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX; import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.PRIMARY_LWM2M_SERVER; @@ -38,11 +39,7 @@ public class LwM2MServiceImplInvalidConfigTest { @Test void testGetServerSecurityInfo_BsServerWithNonEmptyId_ClearsToNullAndLogsWarn() { given(bootstrapConfig.getId()).willReturn(111); - given(bootstrapConfig.getHost()).willReturn("0.0.0.0"); - given(bootstrapConfig.getPort()).willReturn(5687); - LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(true); - assertThat(result).isNotNull(); assertThat(result.isBootstrapServerIs()).isTrue(); assertThat(result.getShortServerId()).isNull(); @@ -52,11 +49,27 @@ public class LwM2MServiceImplInvalidConfigTest { void testGetServerSecurityInfo_DmServerWithValidId_Success() { Integer validShortServerId = 123; given(serverConfig.getId()).willReturn(validShortServerId); - given(serverConfig.getHost()).willReturn("0.0.0.0"); - given(serverConfig.getPort()).willReturn(5685); + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(validShortServerId); + } + @Test + void testGetServerSecurityInfo_DmServerWithMinValidId_ReturnedUnchanged() { + Integer validShortServerId = PRIMARY_LWM2M_SERVER.getId(); + given(serverConfig.getId()).willReturn(validShortServerId); LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); + assertThat(result).isNotNull(); + assertThat(result.isBootstrapServerIs()).isFalse(); + assertThat(result.getShortServerId()).isEqualTo(validShortServerId); + } + @Test + void testGetServerSecurityInfo_DmServerWithMaxValidId_ReturnedUnchanged() { + Integer validShortServerId = LWM2M_SERVER_MAX.getId(); + given(serverConfig.getId()).willReturn(validShortServerId); + LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); assertThat(result).isNotNull(); assertThat(result.isBootstrapServerIs()).isFalse(); assertThat(result.getShortServerId()).isEqualTo(validShortServerId); @@ -64,11 +77,9 @@ public class LwM2MServiceImplInvalidConfigTest { @Test void testGetServerSecurityInfo_Server_Less_PRIMARY_LWM2M_SERVER_DefaultsToOneAndLogsWarn() { - Integer shortServerId = PRIMARY_LWM2M_SERVER.getId() - 1; - given(serverConfig.getId()).willReturn(shortServerId); - + Integer inValidShortServerId = PRIMARY_LWM2M_SERVER.getId() - 1; + given(serverConfig.getId()).willReturn(inValidShortServerId); LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); - assertThat(result).isNotNull(); assertThat(result.isBootstrapServerIs()).isFalse(); assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); @@ -76,11 +87,9 @@ public class LwM2MServiceImplInvalidConfigTest { @Test void testGetServerSecurityInfo_Server_NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX_DefaultsToOneAndLogsWarn() { - Integer shortServerId = NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(); - given(serverConfig.getId()).willReturn(shortServerId); - + Integer inValidShortServerId = NOT_USED_IDENTIFYING_LWM2M_SERVER_MAX.getId(); + given(serverConfig.getId()).willReturn(inValidShortServerId); LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); - assertThat(result).isNotNull(); assertThat(result.isBootstrapServerIs()).isFalse(); assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); @@ -88,12 +97,11 @@ public class LwM2MServiceImplInvalidConfigTest { @Test void testGetServerSecurityInfo_ServerWithNullId_DefaultsToOneAndLogsWarn() { - Integer shortServerId = null; - given(serverConfig.getId()).willReturn(shortServerId); - + Integer inValidShortServerId = null; + given(serverConfig.getId()).willReturn(inValidShortServerId); LwM2MServerSecurityConfigDefault result = lwM2MService.getServerSecurityInfo(false); - assertThat(result).isNotNull(); assertThat(result.isBootstrapServerIs()).isFalse(); - assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); } -} \ No newline at end of file + assertThat(result.getShortServerId()).isEqualTo(PRIMARY_LWM2M_SERVER.getId()); + } +} diff --git a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml index c7cf5100db..4380cf3fb1 100644 --- a/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml +++ b/transport/lwm2m/src/main/resources/tb-lwm2m-transport.yml @@ -174,7 +174,7 @@ transport: #
  • A value that are > 4: MultiNodeConnectionIdGenerator is used
  • connection_id_length: "${LWM2M_DTLS_CONNECTION_ID_LENGTH:8}" server: - # LwM2M Server Short Server ID [1 - 65534]: 0 and 65535 are reserved. An invalid or missing value is ignored and 1 is used instead. + # LwM2M Server Short Server ID. Valid range [1 - 65534]; 0 and 65535 are reserved. Default: 123. id: "${LWM2M_SERVER_ID:123}" # LwM2M server bind address. Bind to all interfaces by default bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" From 91025b11f1e710919020246182ed42007058dd5e Mon Sep 17 00:00:00 2001 From: nickAS21 Date: Fri, 18 Sep 2026 18:34:24 +0300 Subject: [PATCH 14/14] lwm2m: fix bootstrap-short-server-id = null - comments 11 --- ...plInvalidConfigTest.java => LwM2MServiceImplConfigTest.java} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename application/src/test/java/org/thingsboard/server/controller/{LwM2MServiceImplInvalidConfigTest.java => LwM2MServiceImplConfigTest.java} (99%) diff --git a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplConfigTest.java similarity index 99% rename from application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java rename to application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplConfigTest.java index 0951f71b40..30afb0e667 100644 --- a/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplInvalidConfigTest.java +++ b/application/src/test/java/org/thingsboard/server/controller/LwM2MServiceImplConfigTest.java @@ -21,7 +21,7 @@ import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mS import static org.thingsboard.server.common.data.device.credentials.lwm2m.Lwm2mServerIdentifier.PRIMARY_LWM2M_SERVER; @ExtendWith(MockitoExtension.class) -public class LwM2MServiceImplInvalidConfigTest { +public class LwM2MServiceImplConfigTest { @Mock private LwM2MTransportServerConfig serverConfig;