Search in sources :

Example 1 with AbstractLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class LwM2MBootstrapSecurityStore method getValidatedSecurityMode.

/**
 * Bootstrap security have to sync between (bootstrapServer in credential and  bootstrapServer in profile)
 * and (lwm2mServer  in credential and lwm2mServer  in profile
 *
 * @return false if not sync between SecurityMode of Bootstrap credential and profile
 */
private boolean getValidatedSecurityMode(LwM2MBootstrapConfig lwM2MBootstrapConfig) {
    LwM2MSecurityMode bootstrapServerSecurityMode = lwM2MBootstrapConfig.getBootstrapServer().getSecurityMode();
    LwM2MSecurityMode lwm2mServerSecurityMode = lwM2MBootstrapConfig.getLwm2mServer().getSecurityMode();
    AtomicBoolean validBs = new AtomicBoolean(true);
    AtomicBoolean validLw = new AtomicBoolean(true);
    lwM2MBootstrapConfig.getServerConfiguration().forEach(serverCredential -> {
        if (((AbstractLwM2MBootstrapServerCredential) serverCredential).isBootstrapServerIs()) {
            if (!bootstrapServerSecurityMode.equals(serverCredential.getSecurityMode())) {
                validBs.set(false);
            }
        } else {
            if (!lwm2mServerSecurityMode.equals(serverCredential.getSecurityMode())) {
                validLw.set(false);
            }
        }
    });
    return validBs.get() && validLw.get();
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) LwM2MSecurityMode(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode)

Example 2 with AbstractLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class AbstractLwM2MIntegrationTest method getBootstrapServerCredentialNoSec.

private AbstractLwM2MBootstrapServerCredential getBootstrapServerCredentialNoSec(boolean isBootstrap) {
    AbstractLwM2MBootstrapServerCredential bootstrapServerCredential = new NoSecLwM2MBootstrapServerCredential();
    bootstrapServerCredential.setServerPublicKey("");
    bootstrapServerCredential.setShortServerId(isBootstrap ? shortServerIdBs : shortServerId);
    bootstrapServerCredential.setBootstrapServerIs(isBootstrap);
    bootstrapServerCredential.setHost(isBootstrap ? hostBs : host);
    bootstrapServerCredential.setPort(isBootstrap ? portBs : port);
    return bootstrapServerCredential;
}
Also used : NoSecLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.NoSecLwM2MBootstrapServerCredential) AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential)

Example 3 with AbstractLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class DeviceProfileDataValidator method validateLwm2mServersConfigOfBootstrapForClient.

private void validateLwm2mServersConfigOfBootstrapForClient(List<LwM2MBootstrapServerCredential> lwM2MBootstrapServersConfigurations, boolean isBootstrapServerUpdateEnable) {
    Set<String> uris = new HashSet<>();
    Set<Integer> shortServerIds = new HashSet<>();
    for (LwM2MBootstrapServerCredential bootstrapServerCredential : lwM2MBootstrapServersConfigurations) {
        AbstractLwM2MBootstrapServerCredential serverConfig = (AbstractLwM2MBootstrapServerCredential) bootstrapServerCredential;
        if (!isBootstrapServerUpdateEnable && serverConfig.isBootstrapServerIs()) {
            throw new DeviceCredentialsValidationException("Bootstrap config must not include \"Bootstrap Server\". \"Include Bootstrap Server updates\" is " + isBootstrapServerUpdateEnable + ".");
        }
        String server = serverConfig.isBootstrapServerIs() ? "Bootstrap Server" : "LwM2M Server" + " shortServerId: " + serverConfig.getShortServerId() + ":";
        if (serverConfig.getShortServerId() < 1 || serverConfig.getShortServerId() > 65534) {
            throw new DeviceCredentialsValidationException(server + " ShortServerId must not be less than 1 and more than 65534!");
        }
        if (!shortServerIds.add(serverConfig.getShortServerId())) {
            throw new DeviceCredentialsValidationException(server + " \"Short server Id\" value = " + serverConfig.getShortServerId() + ". This value must be a unique value for all servers!");
        }
        String uri = serverConfig.getHost() + ":" + serverConfig.getPort();
        if (!uris.add(uri)) {
            throw new DeviceCredentialsValidationException(server + " \"Host + port\" value = " + uri + ". This value must be a unique value for all servers!");
        }
        Integer port;
        if (LwM2MSecurityMode.NO_SEC.equals(serverConfig.getSecurityMode())) {
            port = serverConfig.isBootstrapServerIs() ? 5687 : 5685;
        } else {
            port = serverConfig.isBootstrapServerIs() ? 5688 : 5686;
        }
        if (serverConfig.getPort() == null || serverConfig.getPort().intValue() != port) {
            String errMsg = server + " \"Port\" value = " + serverConfig.getPort() + ". This value for security " + serverConfig.getSecurityMode().name() + " must be " + port + "!";
            throw new DeviceCredentialsValidationException(errMsg);
        }
    }
}
Also used : AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) RPKLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential) LwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential) X509LwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential) AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) DeviceCredentialsValidationException(org.thingsboard.server.dao.exception.DeviceCredentialsValidationException) HashSet(java.util.HashSet)

Example 4 with AbstractLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class AbstractSecurityLwM2MIntegrationTest method getBootstrapServerCredential.

private AbstractLwM2MBootstrapServerCredential getBootstrapServerCredential(LwM2MSecurityMode mode, boolean isBootstrap) {
    AbstractLwM2MBootstrapServerCredential bootstrapServerCredential;
    switch(mode) {
        case PSK:
            bootstrapServerCredential = new PSKLwM2MBootstrapServerCredential();
            bootstrapServerCredential.setServerPublicKey("");
            break;
        case RPK:
            bootstrapServerCredential = new RPKLwM2MBootstrapServerCredential();
            if (isBootstrap) {
                bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCertBs.getEncoded()));
            } else {
                bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverPublicKeyFromCert.getEncoded()));
            }
            break;
        case X509:
            bootstrapServerCredential = new X509LwM2MBootstrapServerCredential();
            try {
                if (isBootstrap) {
                    bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509CertBs.getEncoded()));
                } else {
                    bootstrapServerCredential.setServerPublicKey(Base64.encodeBase64String(serverX509Cert.getEncoded()));
                }
            } catch (CertificateEncodingException e) {
                e.printStackTrace();
            }
            break;
        default:
            throw new IllegalStateException("Unexpected value: " + mode);
    }
    bootstrapServerCredential.setShortServerId(isBootstrap ? shortServerIdBs : shortServerId);
    bootstrapServerCredential.setBootstrapServerIs(isBootstrap);
    bootstrapServerCredential.setHost(isBootstrap ? hostBs : host);
    bootstrapServerCredential.setPort(isBootstrap ? securityPortBs : securityPort);
    return bootstrapServerCredential;
}
Also used : PSKLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.PSKLwM2MBootstrapServerCredential) X509LwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential) AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) RPKLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential) CertificateEncodingException(java.security.cert.CertificateEncodingException)

Example 5 with AbstractLwM2MBootstrapServerCredential

use of org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential in project thingsboard by thingsboard.

the class LwM2MBootstrapConfig method getLwM2MBootstrapConfig.

@JsonIgnore
public BootstrapConfig getLwM2MBootstrapConfig() {
    BootstrapConfig configBs = new BootstrapConfig();
    configBs.autoIdForSecurityObject = true;
    int id = 0;
    for (LwM2MBootstrapServerCredential serverCredential : serverConfiguration) {
        BootstrapConfig.ServerConfig serverConfig = setServerConfig((AbstractLwM2MBootstrapServerCredential) serverCredential);
        configBs.servers.put(id, serverConfig);
        BootstrapConfig.ServerSecurity serverSecurity = setServerSecurity((AbstractLwM2MBootstrapServerCredential) serverCredential, serverCredential.getSecurityMode());
        configBs.security.put(id, serverSecurity);
        id++;
    }
    return configBs;
}
Also used : AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) LwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential) BootstrapConfig(org.eclipse.leshan.server.bootstrap.BootstrapConfig) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore)

Aggregations

AbstractLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential)5 LwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MBootstrapServerCredential)2 RPKLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.RPKLwM2MBootstrapServerCredential)2 X509LwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.X509LwM2MBootstrapServerCredential)2 JsonIgnore (com.fasterxml.jackson.annotation.JsonIgnore)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 HashSet (java.util.HashSet)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BootstrapConfig (org.eclipse.leshan.server.bootstrap.BootstrapConfig)1 LwM2MSecurityMode (org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode)1 NoSecLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.NoSecLwM2MBootstrapServerCredential)1 PSKLwM2MBootstrapServerCredential (org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.PSKLwM2MBootstrapServerCredential)1 DeviceCredentialsValidationException (org.thingsboard.server.dao.exception.DeviceCredentialsValidationException)1