|
|
@ -18,38 +18,46 @@ package org.thingsboard.server.service.lwm2m; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.RequiredArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
import org.apache.commons.codec.binary.Base64; |
|
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
|
|
|
|
|
import org.springframework.stereotype.Service; |
|
|
import org.springframework.stereotype.Service; |
|
|
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; |
|
|
import org.thingsboard.server.common.data.device.profile.lwm2m.bootstrap.LwM2MServerSecurityConfigDefault; |
|
|
import org.thingsboard.server.common.transport.config.ssl.SslCredentials; |
|
|
import org.thingsboard.server.common.transport.config.ssl.SslCredentials; |
|
|
|
|
|
import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|
|
import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig; |
|
|
|
|
|
|
|
|
|
|
|
import java.util.Optional; |
|
|
|
|
|
|
|
|
@Slf4j |
|
|
@Slf4j |
|
|
@Service |
|
|
@Service |
|
|
@RequiredArgsConstructor |
|
|
@RequiredArgsConstructor |
|
|
@ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") |
|
|
@TbLwM2mTransportComponent |
|
|
public class LwM2MServiceImpl implements LwM2MService { |
|
|
public class LwM2MServiceImpl implements LwM2MService { |
|
|
|
|
|
|
|
|
private final LwM2MTransportServerConfig serverConfig; |
|
|
private final LwM2MTransportServerConfig serverConfig; |
|
|
private final LwM2MTransportBootstrapConfig bootstrapConfig; |
|
|
private final Optional<LwM2MTransportBootstrapConfig> bootstrapConfig; |
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public LwM2MServerSecurityConfigDefault getServerSecurityInfo(boolean bootstrapServer) { |
|
|
public LwM2MServerSecurityConfigDefault getServerSecurityInfo(boolean bootstrapServer) { |
|
|
LwM2MServerSecurityConfigDefault result = getServerSecurityConfig(bootstrapServer ? bootstrapConfig : serverConfig); |
|
|
LwM2MSecureServerConfig bsServerConfig = bootstrapServer ? bootstrapConfig.isPresent() ? bootstrapConfig.get() : null : serverConfig; |
|
|
result.setBootstrapServerIs(bootstrapServer); |
|
|
if (bsServerConfig!= null) { |
|
|
return result; |
|
|
LwM2MServerSecurityConfigDefault result = getServerSecurityConfig(bsServerConfig); |
|
|
|
|
|
result.setBootstrapServerIs(bootstrapServer); |
|
|
|
|
|
return result; |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
return null; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private LwM2MServerSecurityConfigDefault getServerSecurityConfig(LwM2MSecureServerConfig serverConfig) { |
|
|
private LwM2MServerSecurityConfigDefault getServerSecurityConfig(LwM2MSecureServerConfig bsServerConfig) { |
|
|
LwM2MServerSecurityConfigDefault bsServ = new LwM2MServerSecurityConfigDefault(); |
|
|
LwM2MServerSecurityConfigDefault bsServ = new LwM2MServerSecurityConfigDefault(); |
|
|
bsServ.setShortServerId(serverConfig.getId()); |
|
|
bsServ.setShortServerId(bsServerConfig.getId()); |
|
|
bsServ.setHost(serverConfig.getHost()); |
|
|
bsServ.setHost(bsServerConfig.getHost()); |
|
|
bsServ.setPort(serverConfig.getPort()); |
|
|
bsServ.setPort(bsServerConfig.getPort()); |
|
|
bsServ.setSecurityHost(serverConfig.getSecureHost()); |
|
|
bsServ.setSecurityHost(bsServerConfig.getSecureHost()); |
|
|
bsServ.setSecurityPort(serverConfig.getSecurePort()); |
|
|
bsServ.setSecurityPort(bsServerConfig.getSecurePort()); |
|
|
byte[] publicKeyBase64 = getPublicKey(serverConfig); |
|
|
byte[] publicKeyBase64 = getPublicKey(bsServerConfig); |
|
|
if (publicKeyBase64 == null) { |
|
|
if (publicKeyBase64 == null) { |
|
|
bsServ.setServerPublicKey(""); |
|
|
bsServ.setServerPublicKey(""); |
|
|
} else { |
|
|
} else { |
|
|
|