Search in sources :

Example 1 with LwM2MBootstrapClientCredentials

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

the class AbstractSecurityLwM2MIntegrationTest method getBootstrapClientCredentialsPsk.

private LwM2MBootstrapClientCredentials getBootstrapClientCredentialsPsk(LwM2MClientCredential clientCredentials) {
    LwM2MBootstrapClientCredentials bootstrapCredentials = new LwM2MBootstrapClientCredentials();
    PSKBootstrapClientCredential serverCredentials = new PSKBootstrapClientCredential();
    if (clientCredentials != null) {
        serverCredentials.setClientSecretKey(((PSKClientCredential) clientCredentials).getKey());
        serverCredentials.setClientPublicKeyOrId(((PSKClientCredential) clientCredentials).getIdentity());
    }
    bootstrapCredentials.setBootstrapServer(serverCredentials);
    bootstrapCredentials.setLwm2mServer(serverCredentials);
    return bootstrapCredentials;
}
Also used : LwM2MBootstrapClientCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials) PSKBootstrapClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.PSKBootstrapClientCredential)

Example 2 with LwM2MBootstrapClientCredentials

use of org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials 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 3 with LwM2MBootstrapClientCredentials

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

the class AbstractSecurityLwM2MIntegrationTest method getBootstrapClientCredentialsRpk.

private LwM2MBootstrapClientCredentials getBootstrapClientCredentialsRpk(X509Certificate certificate, PrivateKey privateKey, boolean privateKeyIsBad) {
    LwM2MBootstrapClientCredentials bootstrapCredentials = new LwM2MBootstrapClientCredentials();
    RPKBootstrapClientCredential serverCredentials = new RPKBootstrapClientCredential();
    if (certificate != null && certificate.getPublicKey() != null && privateKey != null) {
        serverCredentials.setClientPublicKeyOrId(Base64.encodeBase64String(certificate.getPublicKey().getEncoded()));
        if (privateKeyIsBad) {
            serverCredentials.setClientSecretKey(Hex.encodeHexString(privateKey.getEncoded()));
        } else {
            serverCredentials.setClientSecretKey(Base64.encodeBase64String(privateKey.getEncoded()));
        }
    }
    bootstrapCredentials.setBootstrapServer(serverCredentials);
    bootstrapCredentials.setLwm2mServer(serverCredentials);
    return bootstrapCredentials;
}
Also used : RPKBootstrapClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.RPKBootstrapClientCredential) LwM2MBootstrapClientCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials)

Example 4 with LwM2MBootstrapClientCredentials

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

the class AbstractSecurityLwM2MIntegrationTest method getBootstrapClientCredentialsX509.

private LwM2MBootstrapClientCredentials getBootstrapClientCredentialsX509(X509Certificate certificate, PrivateKey privateKey, boolean privateKeyIsBad) {
    LwM2MBootstrapClientCredentials bootstrapCredentials = new LwM2MBootstrapClientCredentials();
    X509BootstrapClientCredential serverCredentials = new X509BootstrapClientCredential();
    if (certificate != null) {
        try {
            serverCredentials.setClientPublicKeyOrId(Base64.encodeBase64String(certificate.getEncoded()));
            if (privateKeyIsBad) {
                serverCredentials.setClientSecretKey(Hex.encodeHexString(privateKey.getEncoded()));
            } else {
                serverCredentials.setClientSecretKey(Base64.encodeBase64String(privateKey.getEncoded()));
            }
        } catch (CertificateEncodingException e) {
            log.error("Client`s certificate [{}] is bad. [{}]", certificate, e.getMessage());
        }
    }
    bootstrapCredentials.setBootstrapServer(serverCredentials);
    bootstrapCredentials.setLwm2mServer(serverCredentials);
    return bootstrapCredentials;
}
Also used : CertificateEncodingException(java.security.cert.CertificateEncodingException) LwM2MBootstrapClientCredentials(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials) X509BootstrapClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.X509BootstrapClientCredential)

Example 5 with LwM2MBootstrapClientCredentials

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

the class AbstractLwM2MIntegrationTest method getDeviceCredentialsNoSec.

protected LwM2MDeviceCredentials getDeviceCredentialsNoSec(LwM2MClientCredential clientCredentials) {
    LwM2MDeviceCredentials credentials = new LwM2MDeviceCredentials();
    credentials.setClient(clientCredentials);
    LwM2MBootstrapClientCredentials bootstrapCredentials = new LwM2MBootstrapClientCredentials();
    NoSecBootstrapClientCredential serverCredentials = new NoSecBootstrapClientCredential();
    bootstrapCredentials.setBootstrapServer(serverCredentials);
    bootstrapCredentials.setLwm2mServer(serverCredentials);
    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) NoSecBootstrapClientCredential(org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecBootstrapClientCredential)

Aggregations

LwM2MBootstrapClientCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredentials)6 LwM2MDeviceCredentials (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MDeviceCredentials)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 LwM2MBootstrapClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MBootstrapClientCredential)1 LwM2MClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MClientCredential)1 NoSecBootstrapClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.NoSecBootstrapClientCredential)1 PSKBootstrapClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.PSKBootstrapClientCredential)1 RPKBootstrapClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.RPKBootstrapClientCredential)1 X509BootstrapClientCredential (org.thingsboard.server.common.data.device.credentials.lwm2m.X509BootstrapClientCredential)1 DeviceCredentialsValidationException (org.thingsboard.server.dao.exception.DeviceCredentialsValidationException)1