Search in sources :

Example 11 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class RpkLwM2MIntegrationTest method testWithRpkConnectBsSuccess_UpdateTwoSectionsBootstrapAndLm2m_ConnectLwm2mSuccess.

// Bootstrap + Lwm2m
@Test
public void testWithRpkConnectBsSuccess_UpdateTwoSectionsBootstrapAndLm2m_ConnectLwm2mSuccess() throws Exception {
    String clientEndpoint = CLIENT_ENDPOINT_RPK_BS;
    X509Certificate certificate = clientX509CertTrust;
    PrivateKey privateKey = clientPrivateKeyFromCertTrust;
    RPKClientCredential clientCredentials = new RPKClientCredential();
    clientCredentials.setEndpoint(clientEndpoint);
    clientCredentials.setKey(Base64.encodeBase64String(certificate.getPublicKey().getEncoded()));
    Security securityBs = rpkBootstrap(SECURE_URI_BS, certificate.getPublicKey().getEncoded(), privateKey.getEncoded(), serverX509CertBs.getPublicKey().getEncoded());
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(RPK, BOTH));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, clientPrivateKeyFromCertTrust, certificate, RPK, false);
    this.basicTestConnection(securityBs, deviceCredentials, COAP_CONFIG_BS, clientEndpoint, transportConfiguration, "await on client state (RpkBS two section)", expectedStatusesRegistrationBsSuccess, true, ON_REGISTRATION_SUCCESS, true);
}
Also used : PrivateKey(java.security.PrivateKey) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) Security(org.eclipse.leshan.client.object.Security) X509Certificate(java.security.cert.X509Certificate) RPKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Example 12 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class RpkLwM2MIntegrationTest method testWithRpkConnectLwm2mSuccess.

// Lwm2m only
@Test
public void testWithRpkConnectLwm2mSuccess() throws Exception {
    String clientEndpoint = CLIENT_ENDPOINT_RPK;
    X509Certificate certificate = clientX509CertTrust;
    PrivateKey privateKey = clientPrivateKeyFromCertTrust;
    RPKClientCredential clientCredentials = new RPKClientCredential();
    clientCredentials.setEndpoint(clientEndpoint);
    clientCredentials.setKey(Base64.encodeBase64String(certificate.getPublicKey().getEncoded()));
    Security securityBs = rpk(SECURE_URI, shortServerId, certificate.getPublicKey().getEncoded(), privateKey.getEncoded(), serverX509Cert.getPublicKey().getEncoded());
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(RPK, NONE));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, false);
    this.basicTestConnection(securityBs, deviceCredentials, COAP_CONFIG, clientEndpoint, transportConfiguration, "await on client state (Rpk_Lwm2m)", expectedStatusesRegistrationLwm2mSuccess, false, ON_REGISTRATION_SUCCESS, true);
}
Also used : PrivateKey(java.security.PrivateKey) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) Security(org.eclipse.leshan.client.object.Security) X509Certificate(java.security.cert.X509Certificate) RPKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Example 13 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class RpkLwM2MIntegrationTest method testWithRpkValidationPrivateKeyBase64format_BAD_REQUEST.

@Test
public void testWithRpkValidationPrivateKeyBase64format_BAD_REQUEST() throws Exception {
    String clientEndpoint = CLIENT_ENDPOINT_RPK + "BadPrivateKey";
    X509Certificate certificate = clientX509CertTrust;
    PrivateKey privateKey = clientPrivateKeyFromCertTrust;
    RPKClientCredential clientCredentials = new RPKClientCredential();
    clientCredentials.setEndpoint(clientEndpoint);
    clientCredentials.setKey(Base64.encodeBase64String(certificate.getPublicKey().getEncoded()));
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(RPK, NONE));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, privateKey, certificate, RPK, true);
    createDeviceProfile(transportConfiguration);
    MvcResult result = createDeviceWithMvcResult(deviceCredentials, clientEndpoint);
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, result.getResponse().getStatus());
    String msgExpected = "Bootstrap server client RPK secret key must be in PKCS#8 format (DER encoding, standard [RFC5958]) and then encoded to Base64 format!";
    assertTrue(result.getResponse().getContentAsString().contains(msgExpected));
}
Also used : PrivateKey(java.security.PrivateKey) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) MvcResult(org.springframework.test.web.servlet.MvcResult) X509Certificate(java.security.cert.X509Certificate) RPKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Example 14 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class DefaultLwM2mUplinkMsgHandler method initClientTelemetry.

/**
 * #1 clientOnlyObserveAfterConnect == true
 * - Only Observe Request to the client marked as observe from the profile configuration.
 * #2. clientOnlyObserveAfterConnect == false
 * - Read Request to the client after registration to read all resource values for all objects
 * - then Observe Request to the client marked as observe from the profile configuration.
 *
 * @param lwM2MClient - object with All parameters off client
 */
private void initClientTelemetry(LwM2mClient lwM2MClient) {
    Lwm2mDeviceProfileTransportConfiguration profile = clientContext.getProfile(lwM2MClient.getProfileId());
    Set<String> supportedObjects = clientContext.getSupportedIdVerInClient(lwM2MClient);
    if (supportedObjects != null && supportedObjects.size() > 0) {
        this.sendReadRequests(lwM2MClient, profile, supportedObjects);
        this.sendObserveRequests(lwM2MClient, profile, supportedObjects);
        this.sendWriteAttributeRequests(lwM2MClient, profile, supportedObjects);
    // Removed. Used only for debug.
    // this.sendDiscoverRequests(lwM2MClient, profile, supportedObjects);
    }
}
Also used : Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) LwM2MTransportUtil.convertOtaUpdateValueToString(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.convertOtaUpdateValueToString)

Example 15 with Lwm2mDeviceProfileTransportConfiguration

use of org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testFirmwareUpdateByObject5.

@Test
public void testFirmwareUpdateByObject5() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS_OTA, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_OTA5));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_OTA5);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_OTA5, false, null);
    device.setFirmwareId(createFirmware().getId());
    final Device savedDevice = doPost("/api/device", device, Device.class);
    Thread.sleep(1000);
    assertThat(savedDevice).as("saved device").isNotNull();
    assertThat(getDeviceFromAPI(device.getId().getId())).as("fetched device").isEqualTo(savedDevice);
    final List<OtaPackageUpdateStatus> expectedStatuses = Arrays.asList(QUEUED, INITIATED, DOWNLOADING, DOWNLOADED, UPDATING, UPDATED);
    List<TsKvEntry> ts = await("await on timeseries").atMost(30, TimeUnit.SECONDS).until(() -> toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?orderBy=ASC&keys=fw_state&startTs=0&endTs=" + System.currentTimeMillis(), new TypeReference<>() {
    })), hasSize(expectedStatuses.size()));
    List<OtaPackageUpdateStatus> statuses = ts.stream().sorted(Comparator.comparingLong(TsKvEntry::getTs)).map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    Assert.assertEquals(expectedStatuses, statuses);
}
Also used : TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Device(org.thingsboard.server.common.data.Device) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) OtaPackageUpdateStatus(org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus) TsKvEntry(org.thingsboard.server.common.data.kv.TsKvEntry) KvEntry(org.thingsboard.server.common.data.kv.KvEntry) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Aggregations

Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)30 LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)19 Test (org.junit.Test)16 AbstractSecurityLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)13 PrivateKey (java.security.PrivateKey)10 X509Certificate (java.security.cert.X509Certificate)10 Security (org.eclipse.leshan.client.object.Security)8 Device (org.thingsboard.server.common.data.Device)6 X509ClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredential)6 MvcResult (org.springframework.test.web.servlet.MvcResult)5 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)4 Map (java.util.Map)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 PSKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential)3 RPKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential)3 KvEntry (org.thingsboard.server.common.data.kv.KvEntry)3 TsKvEntry (org.thingsboard.server.common.data.kv.TsKvEntry)3 OtaPackageUpdateStatus (org.thingsboard.server.common.data.ota.OtaPackageUpdateStatus)3 AbstractOtaLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)3 Collections (java.util.Collections)2