Search in sources :

Example 1 with LwM2MBootstrapConfig

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

the class LwM2MBootstrapSecurityStore method getParametersBootstrap.

private LwM2MBootstrapConfig getParametersBootstrap(TbLwM2MSecurityInfo store) {
    LwM2MBootstrapConfig lwM2MBootstrapConfig = store.getBootstrapCredentialConfig();
    if (lwM2MBootstrapConfig != null) {
        UUID sessionUUiD = UUID.randomUUID();
        TransportProtos.SessionInfoProto sessionInfo = helper.getValidateSessionInfo(store.getMsg(), sessionUUiD.getMostSignificantBits(), sessionUUiD.getLeastSignificantBits());
        bsSessions.put(store.getEndpoint(), sessionInfo);
        context.getTransportService().registerAsyncSession(sessionInfo, new LwM2mSessionMsgListener(null, null, null, sessionInfo, context.getTransportService()));
        if (this.getValidatedSecurityMode(lwM2MBootstrapConfig)) {
            return lwM2MBootstrapConfig;
        } else {
            log.error(" [{}] Different values SecurityMode between of client and profile.", store.getEndpoint());
            log.error("{} getParametersBootstrap: [{}] Different values SecurityMode between of client and profile.", LOG_LWM2M_ERROR, store.getEndpoint());
            String logMsg = String.format("%s: Different values SecurityMode between of client and profile.", LOG_LWM2M_ERROR);
            helper.sendParametersOnThingsboardTelemetry(helper.getKvStringtoThingsboard(LOG_LWM2M_TELEMETRY, logMsg), sessionInfo);
            return null;
        }
    }
    log.error("Unable to decode Json or Certificate for [{}]", store.getEndpoint());
    return null;
}
Also used : LwM2mSessionMsgListener(org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener) LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) TransportProtos(org.thingsboard.server.gen.transport.TransportProtos) UUID(java.util.UUID)

Example 2 with LwM2MBootstrapConfig

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

the class LwM2mCredentialsSecurityInfoValidator method createSecurityInfo.

/**
 * Create new SecurityInfo
 *
 * @return SecurityInfo
 */
private TbLwM2MSecurityInfo createSecurityInfo(String endpoint, ValidateDeviceCredentialsResponse msg, LwM2mTypeServer keyValue) {
    TbLwM2MSecurityInfo result = new TbLwM2MSecurityInfo();
    LwM2MClientCredentials credentials = JacksonUtil.fromString(msg.getCredentials(), LwM2MClientCredentials.class);
    if (credentials != null) {
        result.setMsg(msg);
        result.setDeviceProfile(msg.getDeviceProfile());
        result.setEndpoint(credentials.getClient().getEndpoint());
        // if ((keyValue.equals(CLIENT))) {
        switch(credentials.getClient().getSecurityConfigClientMode()) {
            case NO_SEC:
                createClientSecurityInfoNoSec(result);
                break;
            case PSK:
                createClientSecurityInfoPSK(result, endpoint, credentials.getClient());
                break;
            case RPK:
                createClientSecurityInfoRPK(result, endpoint, credentials.getClient());
                break;
            case X509:
                createClientSecurityInfoX509(result, endpoint);
                break;
            default:
                break;
        }
        if (keyValue.equals(BOOTSTRAP)) {
            LwM2MBootstrapConfig bootstrapCredentialConfig = new LwM2MBootstrapConfig(((Lwm2mDeviceProfileTransportConfiguration) msg.getDeviceProfile().getProfileData().getTransportConfiguration()).getBootstrap(), credentials.getBootstrap().getBootstrapServer(), credentials.getBootstrap().getLwm2mServer());
            result.setBootstrapCredentialConfig(bootstrapCredentialConfig);
        }
    }
    return result;
}
Also used : LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) LwM2MClientCredentials(org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MClientCredentials)

Example 3 with LwM2MBootstrapConfig

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

the class LwM2MBootstrapSecurityStore method setBootstrapConfigSecurityInfo.

private void setBootstrapConfigSecurityInfo(TbLwM2MSecurityInfo store) {
    /* BootstrapConfig */
    LwM2MBootstrapConfig lwM2MBootstrapConfig = this.getParametersBootstrap(store);
    if (lwM2MBootstrapConfig != null) {
        BootstrapConfig bootstrapConfig = lwM2MBootstrapConfig.getLwM2MBootstrapConfig();
        store.setBootstrapConfig(bootstrapConfig);
    }
}
Also used : LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig) BootstrapConfig(org.eclipse.leshan.server.bootstrap.BootstrapConfig) LwM2MBootstrapConfig(org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig)

Aggregations

LwM2MBootstrapConfig (org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapConfig)3 UUID (java.util.UUID)1 BootstrapConfig (org.eclipse.leshan.server.bootstrap.BootstrapConfig)1 TransportProtos (org.thingsboard.server.gen.transport.TransportProtos)1 LwM2MClientCredentials (org.thingsboard.server.transport.lwm2m.secure.credentials.LwM2MClientCredentials)1 LwM2mSessionMsgListener (org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener)1