@ -43,11 +43,11 @@ import java.util.Map;
import java.util.UUID ;
import java.util.concurrent.ConcurrentHashMap ;
import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.BOOTSTRAP ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2mTransportUtil.LOG_LWM2M_ERROR ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2mTransportUtil.LOG_LWM2M_INFO ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2mTransportUtil.LOG_LWM2M_TELEMETRY ;
import static org.thingsboard.server.transport.lwm2m.utils.LwM2mTransportUtil.getBootstrapParametersFromThingsboard ;
import static org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mTypeServer.BOOTSTRAP ;
@Slf4j
@Service ( "LwM2MBootstrapSecurityStore" )
@ -86,10 +86,10 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
bootstrapConfigStore . add ( endPoint , bsConfigNew ) ;
} catch ( InvalidConfigurationException e ) {
if ( e . getMessage ( ) . contains ( "Psk identity" ) & & e . getMessage ( ) . contains ( "already used for this bootstrap server" ) ) {
log . trace ( "" , e ) ;
log . trace ( "Invalid Bootstrap Configuration " , e ) ;
}
else {
log . error ( "" , e ) ;
log . error ( "Invalid Bootstrap Configuration " , e ) ;
}
}
return store . getSecurityInfo ( ) = = null ? null : Collections . singletonList ( store . getSecurityInfo ( ) ) . iterator ( ) ;
@ -109,7 +109,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
try {
bootstrapConfigStore . add ( store . getEndpoint ( ) , bsConfig ) ;
} catch ( InvalidConfigurationException e ) {
log . error ( "" , e ) ;
log . error ( "Invalid Bootstrap Configuration " , e ) ;
}
return store . getSecurityInfo ( ) ;
}
@ -158,11 +158,11 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
LwM2MBootstrapConfig lwM2MBootstrapConfig = store . getBootstrapCredentialConfig ( ) ;
if ( lwM2MBootstrapConfig ! = null ) {
BootstrapConfiguration bootstrapObject = getBootstrapParametersFromThingsboard ( store . getDeviceProfile ( ) ) ;
lwM2MBootstrapConfig . servers = JacksonUtil . fromString ( JacksonUtil . toString ( bootstrapObject . getServers ( ) ) , LwM2MBootstrapServers . class ) ;
LwM2MServerBootstrap profileServerBootstrap = JacksonUtil . fromString ( JacksonUtil . toString ( bootstrapObject . getBootstrapServer ( ) ) , LwM2MServerBootstrap . class ) ;
if ( SecurityMode . NO_SEC ! = profileServerBootstrap . getSecurityMode ( ) & & profileServerBootstrap ! = null ) {
profileServerBootstrap . setSecurityHost ( profileServerBootstrap . getHost ( ) ) ;
profileServerBootstrap . setSecurityPort ( profileServerBootstrap . getPort ( ) ) ;
lwM2MBootstrapConfig . setServers ( JacksonUtil . fromString ( JacksonUtil . toString ( bootstrapObject . getServers ( ) ) , LwM2MBootstrapServers . class ) ) ;
LwM2MServerBootstrap bootstrapServerProfile = JacksonUtil . fromString ( JacksonUtil . toString ( bootstrapObject . getBootstrapServer ( ) ) , LwM2MServerBootstrap . class ) ;
if ( SecurityMode . NO_SEC ! = bootstrapServerProfile . getSecurityMode ( ) & & bootstrapServerProfile ! = null ) {
bootstrapServerProfile . setSecurityHost ( bootstrapServerProfile . getHost ( ) ) ;
bootstrapServerProfile . setSecurityPort ( bootstrapServerProfile . getPort ( ) ) ;
}
LwM2MServerBootstrap profileLwm2mServer = JacksonUtil . fromString ( JacksonUtil . toString ( bootstrapObject . getLwm2mServer ( ) ) , LwM2MServerBootstrap . class ) ;
if ( SecurityMode . NO_SEC ! = profileLwm2mServer . getSecurityMode ( ) & & profileLwm2mServer ! = null ) {
@ -173,9 +173,9 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
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 . bootstrapServer , profileServerBootstrap , lwM2MBootstrapConfig . lwm2mServer , profileLwm2mServer ) ) {
lwM2MBootstrapConfig . bootstrapServer = new LwM2MServerBootstrap ( lwM2MBootstrapConfig . bootstrapServer , profileServerBootstrap ) ;
lwM2MBootstrapConfig . lwm2mServer = new LwM2MServerBootstrap ( lwM2MBootstrapConfig . lwm2mServer , profileLwm2mServer ) ;
if ( this . getValidatedSecurityMode ( lwM2MBootstrapConfig . getBootstrapServer ( ) , bootstrapServerProfile , lwM2MBootstrapConfig . getLwm2mServer ( ) , profileLwm2mServer ) ) {
lwM2MBootstrapConfig . setBootstrapServer ( new LwM2MServerBootstrap ( lwM2MBootstrapConfig . getBootstrapServer ( ) , bootstrapServerProfile ) ) ;
lwM2MBootstrapConfig . setLwm2mServer ( new LwM2MServerBootstrap ( lwM2MBootstrapConfig . getLwm2mServer ( ) , profileLwm2mServer ) ) ;
String logMsg = String . format ( "%s: getParametersBootstrap: %s Access connect client with bootstrap server." , LOG_LWM2M_INFO , store . getEndpoint ( ) ) ;
helper . sendParametersOnThingsboardTelemetry ( helper . getKvStringtoThingsboard ( LOG_LWM2M_TELEMETRY , logMsg ) , sessionInfo ) ;
return lwM2MBootstrapConfig ;
@ -187,7 +187,6 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
return null ;
}
}
log . error ( "Unable to decode Json or Certificate for [{}]" , store . getEndpoint ( ) ) ;
return null ;
}
@ -197,13 +196,13 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
* and ( lwm2mServer in credential and lwm2mServer in profile
*
* @param bootstrapFromCredential - Bootstrap - > Security of bootstrapServer in credential
* @param profileServerBootstrap - Bootstrap - > Security of bootstrapServer in profile
* @param bootstrapServerProfile - Bootstrap - > Security of bootstrapServer in profile
* @param lwm2mFromCredential - Bootstrap - > Security of lwm2mServer in credential
* @param profileLwm2mServer - Bootstrap - > Security of lwm2mServer in profile
* @return false if not sync between SecurityMode of Bootstrap credential and profile
* /
private boolean getValidatedSecurityMode ( LwM2MServerBootstrap bootstrapFromCredential , LwM2MServerBootstrap profileServerBootstrap , LwM2MServerBootstrap lwm2mFromCredential , LwM2MServerBootstrap profileLwm2mServer ) {
return ( bootstrapFromCredential . getSecurityMode ( ) . equals ( profileServerBootstrap . getSecurityMode ( ) ) & &
private boolean getValidatedSecurityMode ( LwM2MServerBootstrap bootstrapFromCredential , LwM2MServerBootstrap bootstrapServerProfile , LwM2MServerBootstrap lwm2mFromCredential , LwM2MServerBootstrap profileLwm2mServer ) {
return ( bootstrapFromCredential . getSecurityMode ( ) . equals ( bootstrapServerProfile . getSecurityMode ( ) ) & &
lwm2mFromCredential . getSecurityMode ( ) . equals ( profileLwm2mServer . getSecurityMode ( ) ) ) ;
}