Search in sources :

Example 1 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class OtaLwM2MIntegrationTest method testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile.

@Test
public void testFirmwareUpdateWithClientWithoutFirmwareOtaInfoFromProfile() throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITH_PARAMS, getBootstrapServerCredentialsNoSec(NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(this.CLIENT_ENDPOINT_WITHOUT_FW_INFO));
    final Device device = createDevice(deviceCredentials, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO);
    createNewClient(SECURITY_NO_SEC, COAP_CONFIG, false, this.CLIENT_ENDPOINT_WITHOUT_FW_INFO, 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);
    List<TsKvEntry> ts = toTimeseries(doGetAsyncTyped("/api/plugins/telemetry/DEVICE/" + savedDevice.getId().getId() + "/values/timeseries?keys=fw_state", new TypeReference<>() {
    }));
    List<OtaPackageUpdateStatus> statuses = ts.stream().map(KvEntry::getValueAsString).map(OtaPackageUpdateStatus::valueOf).collect(Collectors.toList());
    List<OtaPackageUpdateStatus> expectedStatuses = Collections.singletonList(FAILED);
    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) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Test(org.junit.Test) AbstractOtaLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.ota.AbstractOtaLwM2MIntegrationTest)

Example 2 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method createDeviceWithMvcResult.

protected MvcResult createDeviceWithMvcResult(LwM2MDeviceCredentials credentials, String endpoint) throws Exception {
    Device device = new Device();
    device.setName(endpoint);
    device.setDeviceProfileId(deviceProfile.getId());
    device.setTenantId(tenantId);
    device = doPost("/api/device", device, Device.class);
    Assert.assertNotNull(device);
    DeviceCredentials deviceCredentials = doGet("/api/device/" + device.getId().getId().toString() + "/credentials", DeviceCredentials.class);
    Assert.assertEquals(device.getId(), deviceCredentials.getDeviceId());
    deviceCredentials.setCredentialsType(DeviceCredentialsType.LWM2M_CREDENTIALS);
    deviceCredentials.setCredentialsValue(JacksonUtil.toString(credentials));
    return doPost("/api/device/credentials", deviceCredentials).andReturn();
}
Also used : Device(org.thingsboard.server.common.data.Device) LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) DeviceCredentials(org.thingsboard.server.common.data.security.DeviceCredentials)

Example 3 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method getDeviceCredentialsSecure.

protected LwM2MDeviceCredentials getDeviceCredentialsSecure(LwM2MClientCredential clientCredentials, PrivateKey privateKey, X509Certificate certificate, LwM2MSecurityMode mode, boolean privateKeyIsBad) {
    LwM2MDeviceCredentials credentials = new LwM2MDeviceCredentials();
    credentials.setClient(clientCredentials);
    LwM2MBootstrapClientCredentials bootstrapCredentials;
    switch(mode) {
        case PSK:
            bootstrapCredentials = getBootstrapClientCredentialsPsk(clientCredentials);
            break;
        case RPK:
            bootstrapCredentials = getBootstrapClientCredentialsRpk(certificate, privateKey, privateKeyIsBad);
            break;
        case X509:
            bootstrapCredentials = getBootstrapClientCredentialsX509(certificate, privateKey, privateKeyIsBad);
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + mode);
    }
    credentials.setBootstrap(bootstrapCredentials);
    return credentials;
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) LwM2MBootstrapClientCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials)

Example 4 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method basicTestConnectionBefore.

public void basicTestConnectionBefore(String clientEndpoint, String awaitAlias, LwM2MProfileBootstrapConfigType type, Set<LwM2MClientState> expectedStatuses, LwM2MClientState finishState) throws Exception {
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsNoSec(type));
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsNoSec(createNoSecClientCredentials(clientEndpoint));
    this.basicTestConnection(noSecBootstap(URI_BS), deviceCredentials, COAP_CONFIG_BS, clientEndpoint, transportConfiguration, awaitAlias, expectedStatuses, true, finishState, false);
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)

Example 5 with LwM2MDeviceCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials in project thingsboard by thingsboard.

the class PskLwm2mIntegrationTest method testWithPskConnectLwm2mBadPskKeyByLength_BAD_REQUEST.

@Test
public void testWithPskConnectLwm2mBadPskKeyByLength_BAD_REQUEST() throws Exception {
    String clientEndpoint = CLIENT_ENDPOINT_PSK;
    String identity = CLIENT_PSK_IDENTITY + "_BadLength";
    String keyPsk = CLIENT_PSK_KEY + "05AC";
    PSKClientCredential clientCredentials = new PSKClientCredential();
    clientCredentials.setEndpoint(clientEndpoint);
    clientCredentials.setIdentity(identity);
    clientCredentials.setKey(keyPsk);
    Lwm2mDeviceProfileTransportConfiguration transportConfiguration = getTransportConfiguration(OBSERVE_ATTRIBUTES_WITHOUT_PARAMS, getBootstrapServerCredentialsSecure(PSK, NONE));
    createDeviceProfile(transportConfiguration);
    LwM2MDeviceCredentials deviceCredentials = getDeviceCredentialsSecure(clientCredentials, null, null, PSK, false);
    MvcResult result = createDeviceWithMvcResult(deviceCredentials, clientEndpoint);
    assertEquals(HttpServletResponse.SC_BAD_REQUEST, result.getResponse().getStatus());
    String msgExpected = "Key must be HexDec format: 32, 64, 128 characters!";
    assertTrue(result.getResponse().getContentAsString().contains(msgExpected));
}
Also used : LwM2MDeviceCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) PSKClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.Test) AbstractSecurityLwM2MIntegrationTest(org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)

Aggregations

LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)25 Lwm2mDeviceProfileTransportConfiguration (org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration)19 Test (org.junit.Test)17 AbstractSecurityLwM2MIntegrationTest (org.thingsboard.server.transport.lwm2m.security.AbstractSecurityLwM2MIntegrationTest)14 PrivateKey (java.security.PrivateKey)10 X509Certificate (java.security.cert.X509Certificate)10 Security (org.eclipse.leshan.client.object.Security)8 X509ClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.X509ClientCredential)7 Device (org.thingsboard.server.common.data.Device)6 MvcResult (org.springframework.test.web.servlet.MvcResult)5 RPKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.RPKClientCredential)4 PSKClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.PSKClientCredential)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 LwM2MBootstrapClientCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials)2 DeviceCredentials (org.thingsboard.server.common.data.security.DeviceCredentials)2 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 LwM2MClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredential)1