Search in sources :

Example 6 with TbLwM2MSecurityInfo

use of org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo in project thingsboard by thingsboard.

the class LwM2MBootstrapSecurityStore method getAllByEndpoint.

@Override
public Iterator<SecurityInfo> getAllByEndpoint(String endpoint) {
    TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(endpoint, BOOTSTRAP);
    SecurityInfo securityInfo = this.addValueToStore(store, endpoint);
    return securityInfo == null ? null : Collections.singletonList(store.getSecurityInfo()).iterator();
}
Also used : TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo) SecurityInfo(org.eclipse.leshan.server.security.SecurityInfo) TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo)

Example 7 with TbLwM2MSecurityInfo

use of org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo in project thingsboard by thingsboard.

the class LwM2MBootstrapSecurityStore method getByIdentity.

@Override
public SecurityInfo getByIdentity(String identity) {
    try {
        TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(identity, BOOTSTRAP);
        if (store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) {
            /* add value to store  from BootstrapJson */
            this.setBootstrapConfigSecurityInfo(store);
            BootstrapConfig bsConfig = store.getBootstrapConfig();
            if (bsConfig.security != null) {
                try {
                    bootstrapConfigStore.add(store.getEndpoint(), bsConfig);
                } catch (InvalidConfigurationException e) {
                    log.trace("Invalid Bootstrap Configuration", e);
                    return null;
                }
            }
        }
        return store.getSecurityInfo();
    } catch (LwM2MAuthException e) {
        log.trace("Bootstrap Registration failed: No pre-shared key found for [identity: {}]", identity);
        return null;
    }
}
Also used : TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo) BootstrapConfig(org.eclipse.leshan.server.bootstrap.BootstrapConfig) LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) LwM2MAuthException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException) InvalidConfigurationException(org.eclipse.leshan.server.bootstrap.InvalidConfigurationException)

Example 8 with TbLwM2MSecurityInfo

use of org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo in project thingsboard by thingsboard.

the class LwM2MBootstrapSecurityStore method getX509ByEndpoint.

public TbLwM2MSecurityInfo getX509ByEndpoint(String endPoint) {
    TbLwM2MSecurityInfo store = lwM2MCredentialsSecurityInfoValidator.getEndpointSecurityInfoByCredentialsId(endPoint, BOOTSTRAP);
    this.addValueToStore(store, store.getEndpoint());
    return store;
}
Also used : TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo)

Example 9 with TbLwM2MSecurityInfo

use of org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo in project thingsboard by thingsboard.

the class LwM2MBootstrapSecurityStore method addValueToStore.

public SecurityInfo addValueToStore(TbLwM2MSecurityInfo store, String endpoint) {
    /* add value to store  from BootstrapJson */
    SecurityInfo securityInfo = null;
    if (store != null && store.getBootstrapCredentialConfig() != null && store.getSecurityMode() != null) {
        securityInfo = store.getSecurityInfo();
        this.setBootstrapConfigSecurityInfo(store);
        BootstrapConfig bsConfigNew = store.getBootstrapConfig();
        if (bsConfigNew != null) {
            try {
                boolean bootstrapServerUpdateEnable = ((Lwm2mDeviceProfileTransportConfiguration) store.getDeviceProfile().getProfileData().getTransportConfiguration()).isBootstrapServerUpdateEnable();
                if (!bootstrapServerUpdateEnable) {
                    Optional<Map.Entry<Integer, BootstrapConfig.ServerSecurity>> securities = bsConfigNew.security.entrySet().stream().filter(sec -> sec.getValue().bootstrapServer).findAny();
                    if (securities.isPresent()) {
                        bsConfigNew.security.entrySet().remove(securities.get());
                        int serverSortId = securities.get().getValue().serverId;
                        Optional<Map.Entry<Integer, BootstrapConfig.ServerConfig>> serverConfigs = bsConfigNew.servers.entrySet().stream().filter(serv -> (serv.getValue()).shortId == serverSortId).findAny();
                        if (serverConfigs.isPresent()) {
                            bsConfigNew.servers.entrySet().remove(serverConfigs.get());
                        }
                    }
                }
                for (String config : bootstrapConfigStore.getAll().keySet()) {
                    if (config.equals(endpoint)) {
                        bootstrapConfigStore.remove(config);
                    }
                }
                bootstrapConfigStore.add(endpoint, bsConfigNew);
            } catch (InvalidConfigurationException e) {
                if (e.getMessage().contains("Psk identity") && e.getMessage().contains("already used for this bootstrap server")) {
                    log.trace("Invalid Bootstrap Configuration", e);
                } else {
                    log.error("Invalid Bootstrap Configuration", e);
                }
            }
        }
    }
    return securityInfo;
}
Also used : AbstractLwM2MBootstrapServerCredential(org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.AbstractLwM2MBootstrapServerCredential) LwM2mSessionMsgListener(org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener) LwM2MSecurityMode(org.thingsboard.server.common.data.device.credentials.lwm2m.LwM2MSecurityMode) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) SecurityInfo(org.eclipse.leshan.server.security.SecurityInfo) LwM2mTransportContext(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContext) InvalidConfigurationException(org.eclipse.leshan.server.bootstrap.InvalidConfigurationException) Service(org.springframework.stereotype.Service) BootstrapConfig(org.eclipse.leshan.server.bootstrap.BootstrapConfig) Map(java.util.Map) TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo) TbLwM2mBootstrapTransportComponent(org.thingsboard.server.queue.util.TbLwM2mBootstrapTransportComponent) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) LOG_LWM2M_ERROR(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_ERROR) EditableBootstrapConfigStore(org.eclipse.leshan.server.bootstrap.EditableBootstrapConfigStore) Iterator(java.util.Iterator) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) LwM2MAuthException(org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException) UUID(java.util.UUID) BOOTSTRAP(org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.BOOTSTRAP) Slf4j(lombok.extern.slf4j.Slf4j) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) LwM2mCredentialsSecurityInfoValidator(org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator) LwM2mTransportServerHelper(org.thingsboard.server.transport.lwm2m.server.LwM2mTransportServerHelper) Optional(java.util.Optional) BootstrapSecurityStore(org.eclipse.leshan.server.security.BootstrapSecurityStore) Collections(java.util.Collections) LOG_LWM2M_TELEMETRY(org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.LOG_LWM2M_TELEMETRY) BootstrapConfig(org.eclipse.leshan.server.bootstrap.BootstrapConfig) LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) Lwm2mDeviceProfileTransportConfiguration(org.thingsboard.server.common.data.device.profile.Lwm2mDeviceProfileTransportConfiguration) SecurityInfo(org.eclipse.leshan.server.security.SecurityInfo) TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo) InvalidConfigurationException(org.eclipse.leshan.server.bootstrap.InvalidConfigurationException)

Example 10 with TbLwM2MSecurityInfo

use of org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo in project thingsboard by thingsboard.

the class TbLwM2mSecurityStore method fetchAndPutSecurityInfo.

@Nullable
public SecurityInfo fetchAndPutSecurityInfo(String credentialsId) {
    TbLwM2MSecurityInfo securityInfo = validator.getEndpointSecurityInfoByCredentialsId(credentialsId, CLIENT);
    doPut(securityInfo);
    return securityInfo != null ? securityInfo.getSecurityInfo() : null;
}
Also used : TbLwM2MSecurityInfo(org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

TbLwM2MSecurityInfo (org.thingsboard.server.transport.lwm2m.secure.TbLwM2MSecurityInfo)13 Lock (java.util.concurrent.locks.Lock)5 SecurityInfo (org.eclipse.leshan.server.security.SecurityInfo)4 LwM2MAuthException (org.thingsboard.server.transport.lwm2m.server.client.LwM2MAuthException)3 BootstrapConfig (org.eclipse.leshan.server.bootstrap.BootstrapConfig)2 InvalidConfigurationException (org.eclipse.leshan.server.bootstrap.InvalidConfigurationException)2 NonUniqueSecurityInfoException (org.eclipse.leshan.server.security.NonUniqueSecurityInfoException)2 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)2 LwM2MBootstrapConfig (org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig)2 PublicKey (java.security.PublicKey)1 CertPath (java.security.cert.CertPath)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 CertificateExpiredException (java.security.cert.CertificateExpiredException)1 CertificateNotYetValidException (java.security.cert.CertificateNotYetValidException)1 X509Certificate (java.security.cert.X509Certificate)1 Collections (java.util.Collections)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1