Commit a787ca9d5d933277760dd86d63defed0c8520be8

Authored by Andrii Shvaika
1 parent ff334b54

Refactoring of the lwm2m yml configuration

Showing 24 changed files with 315 additions and 415 deletions
@@ -132,7 +132,7 @@ import org.thingsboard.server.service.firmware.FirmwareStateService; @@ -132,7 +132,7 @@ import org.thingsboard.server.service.firmware.FirmwareStateService;
132 import org.thingsboard.server.service.edge.EdgeNotificationService; 132 import org.thingsboard.server.service.edge.EdgeNotificationService;
133 import org.thingsboard.server.service.edge.rpc.EdgeGrpcService; 133 import org.thingsboard.server.service.edge.rpc.EdgeGrpcService;
134 import org.thingsboard.server.service.edge.rpc.init.SyncEdgeService; 134 import org.thingsboard.server.service.edge.rpc.init.SyncEdgeService;
135 -import org.thingsboard.server.service.lwm2m.LwM2MModelsRepository; 135 +import org.thingsboard.server.service.lwm2m.LwM2MServerSecurityInfoRepository;
136 import org.thingsboard.server.service.profile.TbDeviceProfileCache; 136 import org.thingsboard.server.service.profile.TbDeviceProfileCache;
137 import org.thingsboard.server.service.queue.TbClusterService; 137 import org.thingsboard.server.service.queue.TbClusterService;
138 import org.thingsboard.server.service.resource.TbResourceService; 138 import org.thingsboard.server.service.resource.TbResourceService;
@@ -267,7 +267,7 @@ public abstract class BaseController { @@ -267,7 +267,7 @@ public abstract class BaseController {
267 protected TbDeviceProfileCache deviceProfileCache; 267 protected TbDeviceProfileCache deviceProfileCache;
268 268
269 @Autowired 269 @Autowired
270 - protected LwM2MModelsRepository lwM2MModelsRepository; 270 + protected LwM2MServerSecurityInfoRepository lwM2MServerSecurityInfoRepository;
271 271
272 @Autowired(required = false) 272 @Autowired(required = false)
273 protected EdgeService edgeService; 273 protected EdgeService edgeService;
@@ -47,9 +47,9 @@ public class Lwm2mController extends BaseController { @@ -47,9 +47,9 @@ public class Lwm2mController extends BaseController {
47 @RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{securityMode}/{bootstrapServerIs}", method = RequestMethod.GET) 47 @RequestMapping(value = "/lwm2m/deviceProfile/bootstrap/{securityMode}/{bootstrapServerIs}", method = RequestMethod.GET)
48 @ResponseBody 48 @ResponseBody
49 public ServerSecurityConfig getLwm2mBootstrapSecurityInfo(@PathVariable("securityMode") String securityMode, 49 public ServerSecurityConfig getLwm2mBootstrapSecurityInfo(@PathVariable("securityMode") String securityMode,
50 - @PathVariable("bootstrapServerIs") boolean bootstrapServerIs) throws ThingsboardException { 50 + @PathVariable("bootstrapServerIs") boolean bootstrapServer) throws ThingsboardException {
51 try { 51 try {
52 - return lwM2MModelsRepository.getBootstrapSecurityInfo(securityMode, bootstrapServerIs); 52 + return lwM2MServerSecurityInfoRepository.getServerSecurityInfo(securityMode, bootstrapServer);
53 } catch (Exception e) { 53 } catch (Exception e) {
54 throw handleException(e); 54 throw handleException(e);
55 } 55 }
application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MServerSecurityInfoRepository.java renamed from application/src/main/java/org/thingsboard/server/service/lwm2m/LwM2MModelsRepository.java
@@ -16,14 +16,15 @@ @@ -16,14 +16,15 @@
16 package org.thingsboard.server.service.lwm2m; 16 package org.thingsboard.server.service.lwm2m;
17 17
18 18
  19 +import lombok.RequiredArgsConstructor;
19 import lombok.extern.slf4j.Slf4j; 20 import lombok.extern.slf4j.Slf4j;
20 import org.eclipse.leshan.core.util.Hex; 21 import org.eclipse.leshan.core.util.Hex;
21 -import org.springframework.beans.factory.annotation.Autowired;  
22 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 22 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
23 import org.springframework.stereotype.Service; 23 import org.springframework.stereotype.Service;
24 import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig; 24 import org.thingsboard.server.common.data.lwm2m.ServerSecurityConfig;
25 -import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstrap;  
26 -import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer; 25 +import org.thingsboard.server.transport.lwm2m.config.LwM2MSecureServerConfig;
  26 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig;
  27 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
27 import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; 28 import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
28 29
29 import java.math.BigInteger; 30 import java.math.BigInteger;
@@ -42,96 +43,59 @@ import java.security.spec.KeySpec; @@ -42,96 +43,59 @@ import java.security.spec.KeySpec;
42 43
43 @Slf4j 44 @Slf4j
44 @Service 45 @Service
  46 +@RequiredArgsConstructor
45 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") 47 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
46 -public class LwM2MModelsRepository { 48 +public class LwM2MServerSecurityInfoRepository {
47 49
48 - private static final String INCORRECT_TENANT_ID = "Incorrect tenantId ";  
49 -  
50 - @Autowired  
51 - LwM2MTransportConfigServer contextServer;  
52 -  
53 -  
54 - @Autowired  
55 - LwM2MTransportConfigBootstrap contextBootStrap; 50 + private final LwM2MTransportServerConfig serverConfig;
  51 + private final LwM2MTransportBootstrapConfig bootstrapConfig;
56 52
57 /** 53 /**
58 * @param securityMode 54 * @param securityMode
59 - * @param bootstrapServerIs 55 + * @param bootstrapServer
60 * @return ServerSecurityConfig more value is default: Important - port, host, publicKey 56 * @return ServerSecurityConfig more value is default: Important - port, host, publicKey
61 */ 57 */
62 - public ServerSecurityConfig getBootstrapSecurityInfo(String securityMode, boolean bootstrapServerIs) { 58 + public ServerSecurityConfig getServerSecurityInfo(String securityMode, boolean bootstrapServer) {
63 LwM2MSecurityMode lwM2MSecurityMode = LwM2MSecurityMode.fromSecurityMode(securityMode.toLowerCase()); 59 LwM2MSecurityMode lwM2MSecurityMode = LwM2MSecurityMode.fromSecurityMode(securityMode.toLowerCase());
64 - return getBootstrapServer(bootstrapServerIs, lwM2MSecurityMode); 60 + ServerSecurityConfig result = getServerSecurityConfig(bootstrapServer ? bootstrapConfig : serverConfig, lwM2MSecurityMode);
  61 + result.setBootstrapServerIs(bootstrapServer);
  62 + return result;
65 } 63 }
66 64
67 - /**  
68 - * @param bootstrapServerIs  
69 - * @param mode  
70 - * @return ServerSecurityConfig more value is default: Important - port, host, publicKey  
71 - */  
72 - private ServerSecurityConfig getBootstrapServer(boolean bootstrapServerIs, LwM2MSecurityMode mode) { 65 + private ServerSecurityConfig getServerSecurityConfig(LwM2MSecureServerConfig serverConfig, LwM2MSecurityMode mode) {
73 ServerSecurityConfig bsServ = new ServerSecurityConfig(); 66 ServerSecurityConfig bsServ = new ServerSecurityConfig();
74 - bsServ.setBootstrapServerIs(bootstrapServerIs);  
75 - if (bootstrapServerIs) {  
76 - bsServ.setServerId(contextBootStrap.getBootstrapServerId());  
77 - switch (mode) {  
78 - case NO_SEC:  
79 - bsServ.setHost(contextBootStrap.getBootstrapHost());  
80 - bsServ.setPort(contextBootStrap.getBootstrapPortNoSec());  
81 - bsServ.setServerPublicKey("");  
82 - break;  
83 - case PSK:  
84 - bsServ.setHost(contextBootStrap.getBootstrapHostSecurity());  
85 - bsServ.setPort(contextBootStrap.getBootstrapPortSecurity());  
86 - bsServ.setServerPublicKey("");  
87 - break;  
88 - case RPK:  
89 - case X509:  
90 - bsServ.setHost(contextBootStrap.getBootstrapHostSecurity());  
91 - bsServ.setPort(contextBootStrap.getBootstrapPortSecurity());  
92 - bsServ.setServerPublicKey(getPublicKey (contextBootStrap.getBootstrapAlias(), this.contextBootStrap.getBootstrapPublicX(), this.contextBootStrap.getBootstrapPublicY()));  
93 - break;  
94 - default:  
95 - break;  
96 - }  
97 - } else {  
98 - bsServ.setServerId(contextServer.getServerId());  
99 - switch (mode) {  
100 - case NO_SEC:  
101 - bsServ.setHost(contextServer.getServerHost());  
102 - bsServ.setPort(contextServer.getServerPortNoSec());  
103 - bsServ.setServerPublicKey("");  
104 - break;  
105 - case PSK:  
106 - bsServ.setHost(contextServer.getServerHostSecurity());  
107 - bsServ.setPort(contextServer.getServerPortSecurity());  
108 - bsServ.setServerPublicKey("");  
109 - break;  
110 - case RPK:  
111 - case X509:  
112 - bsServ.setHost(contextServer.getServerHostSecurity());  
113 - bsServ.setPort(contextServer.getServerPortSecurity());  
114 - bsServ.setServerPublicKey(getPublicKey (contextServer.getServerAlias(), this.contextServer.getServerPublicX(), this.contextServer.getServerPublicY()));  
115 - break;  
116 - default:  
117 - break;  
118 - } 67 + bsServ.setServerId(serverConfig.getId());
  68 + switch (mode) {
  69 + case NO_SEC:
  70 + bsServ.setHost(serverConfig.getHost());
  71 + bsServ.setPort(serverConfig.getPort());
  72 + bsServ.setServerPublicKey("");
  73 + break;
  74 + case PSK:
  75 + bsServ.setHost(serverConfig.getSecureHost());
  76 + bsServ.setPort(serverConfig.getSecurePort());
  77 + bsServ.setServerPublicKey("");
  78 + break;
  79 + case RPK:
  80 + case X509:
  81 + bsServ.setHost(serverConfig.getSecureHost());
  82 + bsServ.setPort(serverConfig.getSecurePort());
  83 + bsServ.setServerPublicKey(getPublicKey(serverConfig.getCertificateAlias(), this.serverConfig.getPublicX(), this.serverConfig.getPublicY()));
  84 + break;
  85 + default:
  86 + break;
119 } 87 }
120 return bsServ; 88 return bsServ;
121 } 89 }
122 90
123 - private String getPublicKey (String alias, String publicServerX, String publicServerY) { 91 + private String getPublicKey(String alias, String publicServerX, String publicServerY) {
124 String publicKey = getServerPublicKeyX509(alias); 92 String publicKey = getServerPublicKeyX509(alias);
125 return publicKey != null ? publicKey : getRPKPublicKey(publicServerX, publicServerY); 93 return publicKey != null ? publicKey : getRPKPublicKey(publicServerX, publicServerY);
126 } 94 }
127 95
128 - /**  
129 - * @param alias  
130 - * @return PublicKey format HexString or null  
131 - */  
132 private String getServerPublicKeyX509(String alias) { 96 private String getServerPublicKeyX509(String alias) {
133 try { 97 try {
134 - X509Certificate serverCertificate = (X509Certificate) contextServer.getKeyStoreValue().getCertificate(alias); 98 + X509Certificate serverCertificate = (X509Certificate) serverConfig.getKeyStoreValue().getCertificate(alias);
135 return Hex.encodeHexString(serverCertificate.getEncoded()); 99 return Hex.encodeHexString(serverCertificate.getEncoded());
136 } catch (CertificateEncodingException | KeyStoreException e) { 100 } catch (CertificateEncodingException | KeyStoreException e) {
137 e.printStackTrace(); 101 e.printStackTrace();
@@ -139,11 +103,6 @@ public class LwM2MModelsRepository { @@ -139,11 +103,6 @@ public class LwM2MModelsRepository {
139 return null; 103 return null;
140 } 104 }
141 105
142 - /**  
143 - * @param publicServerX  
144 - * @param publicServerY  
145 - * @return PublicKey format HexString or null  
146 - */  
147 private String getRPKPublicKey(String publicServerX, String publicServerY) { 106 private String getRPKPublicKey(String publicServerX, String publicServerY) {
148 try { 107 try {
149 /** Get Elliptic Curve Parameter spec for secp256r1 */ 108 /** Get Elliptic Curve Parameter spec for secp256r1 */
@@ -630,38 +630,14 @@ transport: @@ -630,38 +630,14 @@ transport:
630 lwm2m: 630 lwm2m:
631 # Enable/disable lvm2m transport protocol. 631 # Enable/disable lvm2m transport protocol.
632 enabled: "${LWM2M_ENABLED:true}" 632 enabled: "${LWM2M_ENABLED:true}"
633 - # We choose a default timeout a bit higher to the MAX_TRANSMIT_WAIT(62-93s) which is the time from starting to  
634 - # send a Confirmable message to the time when an acknowledgement is no longer expected.  
635 - # DEFAULT_TIMEOUT = 2 * 60 * 1000l; 2 min in ms  
636 - timeout: "${LWM2M_TIMEOUT:120000}"  
637 - recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"  
638 - recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"  
639 - response_pool_size: "${LWM2M_RESPONSE_POOL_SIZE:100}"  
640 - registered_pool_size: "${LWM2M_REGISTERED_POOL_SIZE:10}"  
641 - update_registered_pool_size: "${LWM2M_UPDATE_REGISTERED_POOL_SIZE:10}"  
642 - un_registered_pool_size: "${LWM2M_UN_REGISTERED_POOL_SIZE:10}"  
643 - secure:  
644 - # Certificate_x509:  
645 - # To get helps about files format and how to generate it, see: https://github.com/eclipse/leshan/wiki/Credential-files-format  
646 - # Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh  
647 - key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"  
648 - # key_store_path_file: "${KEY_STORE_PATH_FILE:/common/transport/lwm2m/src/main/resources/credentials/serverKeyStore.jks"  
649 - key_store_path_file: "${KEY_STORE_PATH_FILE:}"  
650 - key_store_password: "${LWM2M_KEYSTORE_PASSWORD_SERVER:server_ks_password}"  
651 - root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"  
652 - enable_gen_new_key_psk_rpk: "${ENABLE_GEN_NEW_KEY_PSK_RPK:false}"  
653 server: 633 server:
654 id: "${LWM2M_SERVER_ID:123}" 634 id: "${LWM2M_SERVER_ID:123}"
655 bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" 635 bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}"
656 - bind_port_no_sec: "${LWM2M_BIND_PORT_NO_SEC:5685}"  
657 - secure:  
658 - bind_address_security: "${LWM2M_BIND_ADDRESS_SECURITY:0.0.0.0}"  
659 - bind_port_security: "${LWM2M_BIND_PORT_SECURITY:5686}"  
660 - # create_rpk: "${CREATE_RPK:}" 636 + bind_port: "${LWM2M_BIND_PORT:5685}"
  637 + security:
  638 + bind_address: "${LWM2M_BIND_ADDRESS_SECURITY:0.0.0.0}"
  639 + bind_port: "${LWM2M_BIND_PORT_SECURITY:5686}"
661 # Only for RPK: Public & Private Key. If the keystore file is missing or not working 640 # Only for RPK: Public & Private Key. If the keystore file is missing or not working
662 - # - Public Key (Hex): [3059301306072a8648ce3d020106082a8648ce3d0301070342000405064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f3585eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b]  
663 - # - Private Key (Hex): [308193020100301306072a8648ce3d020106082a8648ce3d030107047930770201010420dc774b309e547ceb48fee547e104ce201a9c48c449dc5414cd04e7f5cf05f67ba00a06082a8648ce3d030107a1440342000405064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f3585eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b],  
664 - # - Elliptic Curve parameters : [secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)]  
665 public_x: "${LWM2M_SERVER_PUBLIC_X:05064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f358}" 641 public_x: "${LWM2M_SERVER_PUBLIC_X:05064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f358}"
666 public_y: "${LWM2M_SERVER_PUBLIC_Y:5eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b}" 642 public_y: "${LWM2M_SERVER_PUBLIC_Y:5eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b}"
667 private_encoded: "${LWM2M_SERVER_PRIVATE_ENCODED:308193020100301306072a8648ce3d020106082a8648ce3d030107047930770201010420dc774b309e547ceb48fee547e104ce201a9c48c449dc5414cd04e7f5cf05f67ba00a06082a8648ce3d030107a1440342000405064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f3585eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b}" 643 private_encoded: "${LWM2M_SERVER_PRIVATE_ENCODED:308193020100301306072a8648ce3d020106082a8648ce3d030107047930770201010420dc774b309e547ceb48fee547e104ce201a9c48c449dc5414cd04e7f5cf05f67ba00a06082a8648ce3d030107a1440342000405064b9e6762dd8d8b8a52355d7b4d8b9a3d64e6d2ee277d76c248861353f3585eeb1838e4f9e37b31fa347aef5ce3431eb54e0a2506910c5e0298817445721b}"
@@ -671,19 +647,33 @@ transport: @@ -671,19 +647,33 @@ transport:
671 enable: "${LWM2M_ENABLED_BS:true}" 647 enable: "${LWM2M_ENABLED_BS:true}"
672 id: "${LWM2M_SERVER_ID_BS:111}" 648 id: "${LWM2M_SERVER_ID_BS:111}"
673 bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}" 649 bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}"
674 - bind_port_no_sec: "${LWM2M_BIND_PORT_NO_SEC_BS:5687}"  
675 - secure:  
676 - bind_address_security: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}"  
677 - bind_port_security: "${LWM2M_BIND_PORT_SECURITY_BS:5688}" 650 + bind_port: "${LWM2M_BIND_PORT_BS:5687}"
  651 + security:
  652 + bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}"
  653 + bind_port: "${LWM2M_BIND_PORT_SECURITY_BS:5688}"
678 # Only for RPK: Public & Private Key. If the keystore file is missing or not working 654 # Only for RPK: Public & Private Key. If the keystore file is missing or not working
679 - # - Elliptic Curve parameters : [secp256r1 [NIST P-256, X9.62 prime256v1] (1.2.840.10045.3.1.7)]  
680 - # - Public Key (Hex): [3059301306072a8648ce3d020106082a8648ce3d030107034200045017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f913fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34]  
681 - # - Private Key (Hex): [308193020100301306072a8648ce3d020106082a8648ce3d0301070479307702010104205ecafd90caa7be45c42e1f3f32571632b8409e6e6249d7124f4ba56fab3c8083a00a06082a8648ce3d030107a144034200045017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f913fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34],  
682 public_x: "${LWM2M_SERVER_PUBLIC_X_BS:5017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f91}" 655 public_x: "${LWM2M_SERVER_PUBLIC_X_BS:5017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f91}"
683 public_y: "${LWM2M_SERVER_PUBLIC_Y_BS:3fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34}" 656 public_y: "${LWM2M_SERVER_PUBLIC_Y_BS:3fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34}"
684 private_encoded: "${LWM2M_SERVER_PRIVATE_ENCODED_BS:308193020100301306072a8648ce3d020106082a8648ce3d0301070479307702010104205ecafd90caa7be45c42e1f3f32571632b8409e6e6249d7124f4ba56fab3c8083a00a06082a8648ce3d030107a144034200045017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f913fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34}" 657 private_encoded: "${LWM2M_SERVER_PRIVATE_ENCODED_BS:308193020100301306072a8648ce3d020106082a8648ce3d0301070479307702010104205ecafd90caa7be45c42e1f3f32571632b8409e6e6249d7124f4ba56fab3c8083a00a06082a8648ce3d030107a144034200045017c87a1c1768264656b3b355434b0def6edb8b9bf166a4762d9930cd730f913fc4e61bcd8901ec27c424114c3e887ed372497f0c2cf85839b8443e76988b34}"
685 # Only Certificate_x509: 658 # Only Certificate_x509:
686 alias: "${LWM2M_KEYSTORE_ALIAS_BS:bootstrap}" 659 alias: "${LWM2M_KEYSTORE_ALIAS_BS:bootstrap}"
  660 + security:
  661 + # Certificate_x509:
  662 + # To get helps about files format and how to generate it, see: https://github.com/eclipse/leshan/wiki/Credential-files-format
  663 + # Create new X509 Certificates: common/transport/lwm2m/src/main/resources/credentials/shell/lwM2M_credentials.sh
  664 + key_store_type: "${LWM2M_KEYSTORE_TYPE:JKS}"
  665 + # key_store_path_file: "${KEY_STORE_PATH_FILE:/common/transport/lwm2m/src/main/resources/credentials/serverKeyStore.jks"
  666 + key_store: "${LWM2M_KEY_STORE:lwm2mserver.jks}"
  667 + key_store_password: "${LWM2M_KEY_STORE_PASSWORD:server_ks_password}"
  668 + root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}"
  669 + enable_gen_new_key_psk_rpk: "${ENABLE_GEN_NEW_KEY_PSK_RPK:false}"
  670 + timeout: "${LWM2M_TIMEOUT:120000}"
  671 + recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}"
  672 + recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:true}"
  673 + response_pool_size: "${LWM2M_RESPONSE_POOL_SIZE:100}"
  674 + registered_pool_size: "${LWM2M_REGISTERED_POOL_SIZE:10}"
  675 + update_registered_pool_size: "${LWM2M_UPDATE_REGISTERED_POOL_SIZE:10}"
  676 + un_registered_pool_size: "${LWM2M_UN_REGISTERED_POOL_SIZE:10}"
687 # Use redis for Security and Registration stores 677 # Use redis for Security and Registration stores
688 redis.enabled: "${LWM2M_REDIS_ENABLED:false}" 678 redis.enabled: "${LWM2M_REDIS_ENABLED:false}"
689 snmp: 679 snmp:
@@ -25,9 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired; @@ -25,9 +25,11 @@ import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 25 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
26 import org.springframework.context.annotation.Bean; 26 import org.springframework.context.annotation.Bean;
27 import org.springframework.stereotype.Component; 27 import org.springframework.stereotype.Component;
  28 +import org.thingsboard.server.common.data.StringUtils;
28 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapSecurityStore; 29 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MBootstrapSecurityStore;
29 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MInMemoryBootstrapConfigStore; 30 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2MInMemoryBootstrapConfigStore;
30 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2mDefaultBootstrapSessionManager; 31 import org.thingsboard.server.transport.lwm2m.bootstrap.secure.LwM2mDefaultBootstrapSessionManager;
  32 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig;
31 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer; 33 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer;
32 34
33 import java.math.BigInteger; 35 import java.math.BigInteger;
@@ -81,13 +83,13 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -81,13 +83,13 @@ public class LwM2MTransportBootstrapServerConfiguration {
81 @Bean 83 @Bean
82 public LeshanBootstrapServer getLeshanBootstrapServer() { 84 public LeshanBootstrapServer getLeshanBootstrapServer() {
83 log.info("Prepare and start BootstrapServer... PostConstruct"); 85 log.info("Prepare and start BootstrapServer... PostConstruct");
84 - return this.getLhBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSec(), this.contextBs.getCtxBootStrap().getBootstrapPortSecurity()); 86 + return this.getLhBootstrapServer(this.contextBs.getCtxBootStrap().getPort(), this.contextBs.getCtxBootStrap().getSecurePort());
85 } 87 }
86 88
87 public LeshanBootstrapServer getLhBootstrapServer(Integer bootstrapPortNoSec, Integer bootstrapSecurePort) { 89 public LeshanBootstrapServer getLhBootstrapServer(Integer bootstrapPortNoSec, Integer bootstrapSecurePort) {
88 LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder(); 90 LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder();
89 - builder.setLocalAddress(this.contextBs.getCtxBootStrap().getBootstrapHost(), bootstrapPortNoSec);  
90 - builder.setLocalSecureAddress(this.contextBs.getCtxBootStrap().getBootstrapHostSecurity(), bootstrapSecurePort); 91 + builder.setLocalAddress(this.contextBs.getCtxBootStrap().getHost(), bootstrapPortNoSec);
  92 + builder.setLocalSecureAddress(this.contextBs.getCtxBootStrap().getSecureHost(), bootstrapSecurePort);
91 93
92 /** Create CoAP Config */ 94 /** Create CoAP Config */
93 builder.setCoapConfig(getCoapConfig(bootstrapPortNoSec, bootstrapSecurePort)); 95 builder.setCoapConfig(getCoapConfig(bootstrapPortNoSec, bootstrapSecurePort));
@@ -106,14 +108,13 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -106,14 +108,13 @@ public class LwM2MTransportBootstrapServerConfiguration {
106 108
107 /** Create and Set DTLS Config */ 109 /** Create and Set DTLS Config */
108 DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); 110 DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
109 - dtlsConfig.setRecommendedSupportedGroupsOnly(this.contextS.getLwM2MTransportConfigServer().isRecommendedSupportedGroups());  
110 - dtlsConfig.setRecommendedCipherSuitesOnly(this.contextS.getLwM2MTransportConfigServer().isRecommendedCiphers()); 111 + dtlsConfig.setRecommendedSupportedGroupsOnly(this.contextS.getLwM2MTransportServerConfig().isRecommendedSupportedGroups());
  112 + dtlsConfig.setRecommendedCipherSuitesOnly(this.contextS.getLwM2MTransportServerConfig().isRecommendedCiphers());
111 if (this.pskMode) { 113 if (this.pskMode) {
112 dtlsConfig.setSupportedCipherSuites( 114 dtlsConfig.setSupportedCipherSuites(
113 TLS_PSK_WITH_AES_128_CCM_8, 115 TLS_PSK_WITH_AES_128_CCM_8,
114 TLS_PSK_WITH_AES_128_CBC_SHA256); 116 TLS_PSK_WITH_AES_128_CBC_SHA256);
115 - }  
116 - else { 117 + } else {
117 dtlsConfig.setSupportedCipherSuites( 118 dtlsConfig.setSupportedCipherSuites(
118 TLS_PSK_WITH_AES_128_CCM_8, 119 TLS_PSK_WITH_AES_128_CCM_8,
119 TLS_PSK_WITH_AES_128_CBC_SHA256, 120 TLS_PSK_WITH_AES_128_CBC_SHA256,
@@ -133,10 +134,10 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -133,10 +134,10 @@ public class LwM2MTransportBootstrapServerConfiguration {
133 134
134 private void setServerWithCredentials(LeshanBootstrapServerBuilder builder) { 135 private void setServerWithCredentials(LeshanBootstrapServerBuilder builder) {
135 try { 136 try {
136 - if (this.contextS.getLwM2MTransportConfigServer().getKeyStoreValue() != null) {  
137 - KeyStore keyStoreServer = this.contextS.getLwM2MTransportConfigServer().getKeyStoreValue(); 137 + if (this.contextS.getLwM2MTransportServerConfig().getKeyStoreValue() != null) {
  138 + KeyStore keyStoreServer = this.contextS.getLwM2MTransportServerConfig().getKeyStoreValue();
138 if (this.setBuilderX509(builder)) { 139 if (this.setBuilderX509(builder)) {
139 - X509Certificate rootCAX509Cert = (X509Certificate) keyStoreServer.getCertificate(this.contextS.getLwM2MTransportConfigServer().getRootAlias()); 140 + X509Certificate rootCAX509Cert = (X509Certificate) keyStoreServer.getCertificate(this.contextS.getLwM2MTransportServerConfig().getRootCertificateAlias());
140 if (rootCAX509Cert != null) { 141 if (rootCAX509Cert != null) {
141 X509Certificate[] trustedCertificates = new X509Certificate[1]; 142 X509Certificate[] trustedCertificates = new X509Certificate[1];
142 trustedCertificates[0] = rootCAX509Cert; 143 trustedCertificates[0] = rootCAX509Cert;
@@ -167,12 +168,10 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -167,12 +168,10 @@ public class LwM2MTransportBootstrapServerConfiguration {
167 * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks 168 * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks
168 */ 169 */
169 try { 170 try {
170 - X509Certificate serverCertificate = (X509Certificate) this.contextS.getLwM2MTransportConfigServer().getKeyStoreValue().getCertificate(this.contextBs.getCtxBootStrap().getBootstrapAlias());  
171 - PrivateKey privateKey = (PrivateKey) this.contextS.getLwM2MTransportConfigServer().getKeyStoreValue().getKey(this.contextBs.getCtxBootStrap().getBootstrapAlias(), this.contextS.getLwM2MTransportConfigServer().getKeyStorePasswordServer() == null ? null : this.contextS.getLwM2MTransportConfigServer().getKeyStorePasswordServer().toCharArray()); 171 + X509Certificate serverCertificate = (X509Certificate) this.contextS.getLwM2MTransportServerConfig().getKeyStoreValue().getCertificate(this.contextBs.getCtxBootStrap().getCertificateAlias());
  172 + PrivateKey privateKey = (PrivateKey) this.contextS.getLwM2MTransportServerConfig().getKeyStoreValue().getKey(this.contextBs.getCtxBootStrap().getCertificateAlias(), this.contextS.getLwM2MTransportServerConfig().getKeyStorePassword() == null ? null : this.contextS.getLwM2MTransportServerConfig().getKeyStorePassword().toCharArray());
172 PublicKey publicKey = serverCertificate.getPublicKey(); 173 PublicKey publicKey = serverCertificate.getPublicKey();
173 - if (serverCertificate != null &&  
174 - privateKey != null && privateKey.getEncoded().length > 0 &&  
175 - publicKey != null && publicKey.getEncoded().length > 0) { 174 + if (privateKey != null && privateKey.getEncoded().length > 0 && publicKey != null && publicKey.getEncoded().length > 0) {
176 builder.setPublicKey(serverCertificate.getPublicKey()); 175 builder.setPublicKey(serverCertificate.getPublicKey());
177 builder.setPrivateKey(privateKey); 176 builder.setPrivateKey(privateKey);
178 builder.setCertificateChain(new X509Certificate[]{serverCertificate}); 177 builder.setCertificateChain(new X509Certificate[]{serverCertificate});
@@ -199,10 +198,12 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -199,10 +198,12 @@ public class LwM2MTransportBootstrapServerConfiguration {
199 } 198 }
200 199
201 private void infoPramsUri(String mode) { 200 private void infoPramsUri(String mode) {
202 - log.info("Bootstrap Server uses [{}]: serverNoSecureURI : [{}], serverSecureURI : [{}]", 201 + log.info("Bootstrap Server uses [{}]: serverNoSecureURI : [{}:{}], serverSecureURI : [{}:{}]",
203 mode, 202 mode,
204 - this.contextBs.getCtxBootStrap().getBootstrapHost() + ":" + this.contextBs.getCtxBootStrap().getBootstrapPortNoSec(),  
205 - this.contextBs.getCtxBootStrap().getBootstrapHostSecurity() + ":" + this.contextBs.getCtxBootStrap().getBootstrapPortSecurity()); 203 + this.contextBs.getCtxBootStrap().getHost(),
  204 + this.contextBs.getCtxBootStrap().getPort(),
  205 + this.contextBs.getCtxBootStrap().getSecureHost(),
  206 + this.contextBs.getCtxBootStrap().getSecurePort());
206 } 207 }
207 208
208 209
@@ -236,23 +237,25 @@ public class LwM2MTransportBootstrapServerConfiguration { @@ -236,23 +237,25 @@ public class LwM2MTransportBootstrapServerConfiguration {
236 AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); 237 AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC");
237 algoParameters.init(new ECGenParameterSpec("secp256r1")); 238 algoParameters.init(new ECGenParameterSpec("secp256r1"));
238 ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); 239 ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class);
239 - if (this.contextBs.getCtxBootStrap().getBootstrapPublicX() != null && !this.contextBs.getCtxBootStrap().getBootstrapPublicX().isEmpty() && this.contextBs.getCtxBootStrap().getBootstrapPublicY() != null && !this.contextBs.getCtxBootStrap().getBootstrapPublicY().isEmpty()) { 240 + LwM2MTransportBootstrapConfig serverConfig = this.contextBs.getCtxBootStrap();
  241 + if (StringUtils.isNotEmpty(serverConfig.getPublicX()) && StringUtils.isNotEmpty(serverConfig.getPublicY())) {
240 /** Get point values */ 242 /** Get point values */
241 - byte[] publicX = Hex.decodeHex(this.contextBs.getCtxBootStrap().getBootstrapPublicX().toCharArray());  
242 - byte[] publicY = Hex.decodeHex(this.contextBs.getCtxBootStrap().getBootstrapPublicY().toCharArray()); 243 + byte[] publicX = Hex.decodeHex(serverConfig.getPublicX().toCharArray());
  244 + byte[] publicY = Hex.decodeHex(serverConfig.getPublicY().toCharArray());
243 /** Create key specs */ 245 /** Create key specs */
244 KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)), 246 KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)),
245 parameterSpec); 247 parameterSpec);
246 /** Get public key */ 248 /** Get public key */
247 this.publicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec); 249 this.publicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec);
248 } 250 }
249 - if (this.contextBs.getCtxBootStrap().getBootstrapPrivateEncoded() != null && !this.contextBs.getCtxBootStrap().getBootstrapPrivateEncoded().isEmpty()) { 251 + String privateEncodedKey = serverConfig.getPrivateEncoded();
  252 + if (StringUtils.isNotEmpty(privateEncodedKey)) {
250 /** Get private key */ 253 /** Get private key */
251 - byte[] privateS = Hex.decodeHex(this.contextBs.getCtxBootStrap().getBootstrapPrivateEncoded().toCharArray()); 254 + byte[] privateS = Hex.decodeHex(privateEncodedKey.toCharArray());
252 try { 255 try {
253 this.privateKey = KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(privateS)); 256 this.privateKey = KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(privateS));
254 } catch (InvalidKeySpecException ignore2) { 257 } catch (InvalidKeySpecException ignore2) {
255 - log.error("Invalid Bootstrap Server rpk.PrivateKey.getEncoded () [{}}]. PrivateKey has no EC algorithm", this.contextBs.getCtxBootStrap().getBootstrapPrivateEncoded()); 258 + log.error("Invalid Bootstrap Server rpk.PrivateKey.getEncoded () [{}}]. PrivateKey has no EC algorithm", privateEncodedKey);
256 } 259 }
257 } 260 }
258 } 261 }
@@ -34,7 +34,7 @@ import lombok.extern.slf4j.Slf4j; @@ -34,7 +34,7 @@ import lombok.extern.slf4j.Slf4j;
34 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; 34 import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
35 import org.springframework.stereotype.Component; 35 import org.springframework.stereotype.Component;
36 import org.thingsboard.server.common.transport.TransportContext; 36 import org.thingsboard.server.common.transport.TransportContext;
37 -import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstrap; 37 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportBootstrapConfig;
38 38
39 39
40 @Slf4j 40 @Slf4j
@@ -42,13 +42,13 @@ import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstr @@ -42,13 +42,13 @@ import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigBootstr
42 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith'") 42 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith'")
43 public class LwM2MTransportContextBootstrap extends TransportContext { 43 public class LwM2MTransportContextBootstrap extends TransportContext {
44 44
45 - private final LwM2MTransportConfigBootstrap lwM2MTransportConfigBootstrap; 45 + private final LwM2MTransportBootstrapConfig lwM2MTransportBootstrapConfig;
46 46
47 - public LwM2MTransportContextBootstrap(LwM2MTransportConfigBootstrap ctxBootStrap) {  
48 - this.lwM2MTransportConfigBootstrap = ctxBootStrap; 47 + public LwM2MTransportContextBootstrap(LwM2MTransportBootstrapConfig ctxBootStrap) {
  48 + this.lwM2MTransportBootstrapConfig = ctxBootStrap;
49 } 49 }
50 50
51 - public LwM2MTransportConfigBootstrap getCtxBootStrap() {  
52 - return this.lwM2MTransportConfigBootstrap; 51 + public LwM2MTransportBootstrapConfig getCtxBootStrap() {
  52 + return this.lwM2MTransportBootstrapConfig;
53 } 53 }
54 } 54 }
@@ -35,7 +35,7 @@ import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInf @@ -35,7 +35,7 @@ import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInf
35 import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; 35 import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore;
36 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener; 36 import org.thingsboard.server.transport.lwm2m.server.LwM2mSessionMsgListener;
37 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer; 37 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer;
38 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler; 38 +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil;
39 39
40 import java.io.IOException; 40 import java.io.IOException;
41 import java.security.GeneralSecurityException; 41 import java.security.GeneralSecurityException;
@@ -43,12 +43,12 @@ import java.util.Collections; @@ -43,12 +43,12 @@ import java.util.Collections;
43 import java.util.List; 43 import java.util.List;
44 import java.util.UUID; 44 import java.util.UUID;
45 45
46 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.BOOTSTRAP_SERVER;  
47 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_ERROR;  
48 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_INFO;  
49 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LWM2M_SERVER;  
50 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.SERVERS;  
51 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.getBootstrapParametersFromThingsboard; 46 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.BOOTSTRAP_SERVER;
  47 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR;
  48 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
  49 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_SERVER;
  50 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.SERVERS;
  51 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getBootstrapParametersFromThingsboard;
52 52
53 @Slf4j 53 @Slf4j
54 @Service("LwM2MBootstrapSecurityStore") 54 @Service("LwM2MBootstrapSecurityStore")
@@ -69,7 +69,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { @@ -69,7 +69,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
69 69
70 @Override 70 @Override
71 public List<SecurityInfo> getAllByEndpoint(String endPoint) { 71 public List<SecurityInfo> getAllByEndpoint(String endPoint) {
72 - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(endPoint, LwM2mTransportHandler.LwM2mTypeServer.BOOTSTRAP); 72 + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(endPoint, LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP);
73 if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { 73 if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) {
74 /** add value to store from BootstrapJson */ 74 /** add value to store from BootstrapJson */
75 this.setBootstrapConfigScurityInfo(store); 75 this.setBootstrapConfigScurityInfo(store);
@@ -93,7 +93,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore { @@ -93,7 +93,7 @@ public class LwM2MBootstrapSecurityStore implements BootstrapSecurityStore {
93 93
94 @Override 94 @Override
95 public SecurityInfo getByIdentity(String identity) { 95 public SecurityInfo getByIdentity(String identity) {
96 - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandler.LwM2mTypeServer.BOOTSTRAP); 96 + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP);
97 if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { 97 if (store.getBootstrapJsonCredential() != null && store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) {
98 /** add value to store from BootstrapJson */ 98 /** add value to store from BootstrapJson */
99 this.setBootstrapConfigScurityInfo(store); 99 this.setBootstrapConfigScurityInfo(store);
  1 +/**
  2 + * Copyright © 2016-2021 The Thingsboard Authors
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License");
  5 + * you may not use this file except in compliance with the License.
  6 + * You may obtain a copy of the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS,
  12 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13 + * See the License for the specific language governing permissions and
  14 + * limitations under the License.
  15 + */
  16 +package org.thingsboard.server.transport.lwm2m.config;
  17 +
  18 +public interface LwM2MSecureServerConfig {
  19 +
  20 + Integer getId();
  21 +
  22 + String getHost();
  23 +
  24 + Integer getPort();
  25 +
  26 + String getSecureHost();
  27 +
  28 + Integer getSecurePort();
  29 +
  30 + String getPublicX();
  31 +
  32 + String getPublicY();
  33 +
  34 + String getPrivateEncoded();
  35 +
  36 + String getCertificateAlias();
  37 +
  38 +}
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportBootstrapConfig.java renamed from common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/lwm2m/LwM2MTransportConfigBootstrap.java
@@ -13,7 +13,7 @@ @@ -13,7 +13,7 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.common.transport.lwm2m; 16 +package org.thingsboard.server.transport.lwm2m.config;
17 17
18 import lombok.Getter; 18 import lombok.Getter;
19 import lombok.Setter; 19 import lombok.Setter;
@@ -29,53 +29,42 @@ import java.util.Map; @@ -29,53 +29,42 @@ import java.util.Map;
29 @Slf4j 29 @Slf4j
30 @Component 30 @Component
31 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") 31 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
32 -public class LwM2MTransportConfigBootstrap {  
33 -  
34 - @Getter  
35 - @Value("${transport.lwm2m.bootstrap.enable:}")  
36 - private Boolean bootstrapEnable; 32 +public class LwM2MTransportBootstrapConfig implements LwM2MSecureServerConfig {
37 33
38 @Getter 34 @Getter
39 @Value("${transport.lwm2m.bootstrap.id:}") 35 @Value("${transport.lwm2m.bootstrap.id:}")
40 - private Integer bootstrapServerId; 36 + private Integer id;
41 37
42 @Getter 38 @Getter
43 @Value("${transport.lwm2m.bootstrap.bind_address:}") 39 @Value("${transport.lwm2m.bootstrap.bind_address:}")
44 - private String bootstrapHost; 40 + private String host;
45 41
46 @Getter 42 @Getter
47 - @Value("${transport.lwm2m.bootstrap.bind_port_no_sec:}")  
48 - private Integer bootstrapPortNoSec; 43 + @Value("${transport.lwm2m.bootstrap.bind_port:}")
  44 + private Integer port;
49 45
50 @Getter 46 @Getter
51 - @Value("${transport.lwm2m.bootstrap.secure.bind_address_security:}")  
52 - private String bootstrapHostSecurity; 47 + @Value("${transport.lwm2m.bootstrap.security.bind_address:}")
  48 + private String secureHost;
53 49
54 @Getter 50 @Getter
55 - @Value("${transport.lwm2m.bootstrap.secure.bind_port_security:}")  
56 - private Integer bootstrapPortSecurity; 51 + @Value("${transport.lwm2m.bootstrap.security.bind_port:}")
  52 + private Integer securePort;
57 53
58 @Getter 54 @Getter
59 - @Value("${transport.lwm2m.bootstrap.secure.public_x:}")  
60 - private String bootstrapPublicX; 55 + @Value("${transport.lwm2m.bootstrap.security.public_x:}")
  56 + private String publicX;
61 57
62 @Getter 58 @Getter
63 - @Value("${transport.lwm2m.bootstrap.secure.public_y:}")  
64 - private String bootstrapPublicY; 59 + @Value("${transport.lwm2m.bootstrap.security.public_y:}")
  60 + private String publicY;
65 61
66 @Getter 62 @Getter
67 - @Setter  
68 - private PublicKey bootstrapPublicKey; 63 + @Value("${transport.lwm2m.bootstrap.security.private_encoded:}")
  64 + private String privateEncoded;
69 65
70 @Getter 66 @Getter
71 - @Value("${transport.lwm2m.bootstrap.secure.private_encoded:}")  
72 - private String bootstrapPrivateEncoded; 67 + @Value("${transport.lwm2m.bootstrap.security.alias:}")
  68 + private String certificateAlias;
73 69
74 - @Getter  
75 - @Value("${transport.lwm2m.bootstrap.secure.alias:}")  
76 - private String bootstrapAlias;  
77 -  
78 - @Getter  
79 - @Setter  
80 - private Map<String /** clientEndPoint */, TransportProtos.ValidateDeviceCredentialsResponseMsg> sessions;  
81 } 70 }
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/config/LwM2MTransportServerConfig.java renamed from common/transport/transport-api/src/main/java/org/thingsboard/server/common/transport/lwm2m/LwM2MTransportConfigServer.java
@@ -13,8 +13,9 @@ @@ -13,8 +13,9 @@
13 * See the License for the specific language governing permissions and 13 * See the License for the specific language governing permissions and
14 * limitations under the License. 14 * limitations under the License.
15 */ 15 */
16 -package org.thingsboard.server.common.transport.lwm2m; 16 +package org.thingsboard.server.transport.lwm2m.config;
17 17
  18 +import com.google.common.io.Resources;
18 import lombok.Getter; 19 import lombok.Getter;
19 import lombok.Setter; 20 import lombok.Setter;
20 import lombok.extern.slf4j.Slf4j; 21 import lombok.extern.slf4j.Slf4j;
@@ -38,38 +39,7 @@ import java.security.cert.CertificateException; @@ -38,38 +39,7 @@ import java.security.cert.CertificateException;
38 @Slf4j 39 @Slf4j
39 @Component 40 @Component
40 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") 41 @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'")
41 -public class LwM2MTransportConfigServer {  
42 -  
43 - @Getter  
44 - private String KEY_STORE_DEFAULT_RESOURCE_PATH = "credentials";  
45 -  
46 - @Getter  
47 - private String KEY_STORE_DEFAULT_FILE = "serverKeyStore.jks";  
48 -  
49 - @Getter  
50 - private String APP_DIR = "common";  
51 -  
52 - @Getter  
53 - private String TRANSPORT_DIR = "transport";  
54 -  
55 - @Getter  
56 - private String LWM2M_DIR = "lwm2m";  
57 -  
58 - @Getter  
59 - private String SRC_DIR = "src";  
60 -  
61 - @Getter  
62 - private String MAIN_DIR = "main";  
63 -  
64 - @Getter  
65 - private String RESOURCES_DIR = "resources";  
66 -  
67 - @Getter  
68 - private String BASE_DIR_PATH = System.getProperty("user.dir");  
69 -  
70 - @Getter  
71 - // private String PATH_DATA_MICROSERVICE = "/usr/share/tb-lwm2m-transport/data$";  
72 - private String PATH_DATA = "data"; 42 +public class LwM2MTransportServerConfig implements LwM2MSecureServerConfig {
73 43
74 @Getter 44 @Getter
75 @Setter 45 @Setter
@@ -108,11 +78,11 @@ public class LwM2MTransportConfigServer { @@ -108,11 +78,11 @@ public class LwM2MTransportConfigServer {
108 private int unRegisteredPoolSize; 78 private int unRegisteredPoolSize;
109 79
110 @Getter 80 @Getter
111 - @Value("${transport.lwm2m.secure.key_store_type:}") 81 + @Value("${transport.lwm2m.security.key_store_type:}")
112 private String keyStoreType; 82 private String keyStoreType;
113 83
114 @Getter 84 @Getter
115 - @Value("${transport.lwm2m.secure.key_store_path_file:}") 85 + @Value("${transport.lwm2m.security.key_store:}")
116 private String keyStorePathFile; 86 private String keyStorePathFile;
117 87
118 @Getter 88 @Getter
@@ -120,98 +90,64 @@ public class LwM2MTransportConfigServer { @@ -120,98 +90,64 @@ public class LwM2MTransportConfigServer {
120 private KeyStore keyStoreValue; 90 private KeyStore keyStoreValue;
121 91
122 @Getter 92 @Getter
123 - @Value("${transport.lwm2m.secure.key_store_password:}")  
124 - private String keyStorePasswordServer; 93 + @Value("${transport.lwm2m.security.key_store_password:}")
  94 + private String keyStorePassword;
125 95
126 @Getter 96 @Getter
127 - @Value("${transport.lwm2m.secure.root_alias:}")  
128 - private String rootAlias; 97 + @Value("${transport.lwm2m.security.root_alias:}")
  98 + private String rootCertificateAlias;
129 99
130 @Getter 100 @Getter
131 - @Value("${transport.lwm2m.secure.enable_gen_new_key_psk_rpk:}") 101 + @Value("${transport.lwm2m.security.enable_gen_new_key_psk_rpk:}")
132 private Boolean enableGenNewKeyPskRpk; 102 private Boolean enableGenNewKeyPskRpk;
133 103
134 @Getter 104 @Getter
135 @Value("${transport.lwm2m.server.id:}") 105 @Value("${transport.lwm2m.server.id:}")
136 - private Integer serverId; 106 + private Integer id;
137 107
138 @Getter 108 @Getter
139 @Value("${transport.lwm2m.server.bind_address:}") 109 @Value("${transport.lwm2m.server.bind_address:}")
140 - private String serverHost; 110 + private String host;
141 111
142 @Getter 112 @Getter
143 - @Value("${transport.lwm2m.server.secure.bind_address_security:}")  
144 - private String serverHostSecurity; 113 + @Value("${transport.lwm2m.server.bind_port:}")
  114 + private Integer port;
145 115
146 @Getter 116 @Getter
147 - @Value("${transport.lwm2m.server.bind_port_no_sec:}")  
148 - private Integer serverPortNoSec; 117 + @Value("${transport.lwm2m.server.security.bind_address:}")
  118 + private String secureHost;
149 119
150 @Getter 120 @Getter
151 - @Value("${transport.lwm2m.server.secure.bind_port_security:}")  
152 - private Integer serverPortSecurity; 121 + @Value("${transport.lwm2m.server.security.bind_port:}")
  122 + private Integer securePort;
153 123
154 @Getter 124 @Getter
155 - @Value("${transport.lwm2m.server.secure.public_x:}")  
156 - private String serverPublicX; 125 + @Value("${transport.lwm2m.server.security.public_x:}")
  126 + private String publicX;
157 127
158 @Getter 128 @Getter
159 - @Value("${transport.lwm2m.server.secure.public_y:}")  
160 - private String serverPublicY; 129 + @Value("${transport.lwm2m.server.security.public_y:}")
  130 + private String publicY;
161 131
162 @Getter 132 @Getter
163 - @Value("${transport.lwm2m.server.secure.private_encoded:}")  
164 - private String serverPrivateEncoded; 133 + @Value("${transport.lwm2m.server.security.private_encoded:}")
  134 + private String privateEncoded;
165 135
166 @Getter 136 @Getter
167 - @Value("${transport.lwm2m.server.secure.alias:}")  
168 - private String serverAlias;  
169 - 137 + @Value("${transport.lwm2m.server.security.alias:}")
  138 + private String certificateAlias;
  139 +
  140 +
170 @PostConstruct 141 @PostConstruct
171 public void init() { 142 public void init() {
172 - this.getInKeyStore();  
173 - }  
174 -  
175 - private KeyStore getInKeyStore() {  
176 try { 143 try {
177 - if (keyStoreValue != null && keyStoreValue.size() > 0)  
178 - return keyStoreValue;  
179 - } catch (KeyStoreException e) {  
180 - log.error("Uninitialized keystore [{}]", keyStoreValue.toString());  
181 - }  
182 - Path keyStorePath = (keyStorePathFile != null && !keyStorePathFile.isEmpty()) ? Paths.get(keyStorePathFile) :  
183 - (new File(Paths.get(getBaseDirPath(), PATH_DATA, KEY_STORE_DEFAULT_RESOURCE_PATH, KEY_STORE_DEFAULT_FILE).toUri()).isFile()) ?  
184 - Paths.get(getBaseDirPath(), PATH_DATA, KEY_STORE_DEFAULT_RESOURCE_PATH, KEY_STORE_DEFAULT_FILE) :  
185 - Paths.get(getBaseDirPath(), APP_DIR, TRANSPORT_DIR, LWM2M_DIR, SRC_DIR, MAIN_DIR, RESOURCES_DIR, KEY_STORE_DEFAULT_RESOURCE_PATH, KEY_STORE_DEFAULT_FILE);  
186 - File keyStoreFile = new File(keyStorePath.toUri());  
187 - if (keyStoreFile.isFile()) {  
188 - try {  
189 - InputStream inKeyStore = new FileInputStream(keyStoreFile);  
190 - keyStoreValue = KeyStore.getInstance(keyStoreType);  
191 - keyStoreValue.load(inKeyStore, keyStorePasswordServer == null ? null : keyStorePasswordServer.toCharArray());  
192 - } catch (CertificateException | NoSuchAlgorithmException | IOException | KeyStoreException e) {  
193 - log.error("[{}] Unable to load KeyStore files server, folder is not a directory", e.getMessage());  
194 - keyStoreValue = null;  
195 - }  
196 - log.info("[{}] Load KeyStore files server, folder is a directory", keyStoreFile.getAbsoluteFile());  
197 - } else {  
198 - log.error("[{}] Unable to load KeyStore files server, is not a file", keyStoreFile.getAbsoluteFile());  
199 - keyStoreValue = null;  
200 - }  
201 - return keyStoreValue;  
202 - }  
203 -  
204 - private String getBaseDirPath() {  
205 - Path FULL_FILE_PATH;  
206 - if (BASE_DIR_PATH.endsWith("bin")) {  
207 - FULL_FILE_PATH = Paths.get(BASE_DIR_PATH.replaceAll("bin$", ""));  
208 - } else if (BASE_DIR_PATH.endsWith("conf")) {  
209 - FULL_FILE_PATH = Paths.get(BASE_DIR_PATH.replaceAll("conf$", ""));  
210 - } else if (BASE_DIR_PATH.endsWith("application")) {  
211 - FULL_FILE_PATH = Paths.get(BASE_DIR_PATH.substring(0, BASE_DIR_PATH.length() - "application".length()));  
212 - } else {  
213 - FULL_FILE_PATH = Paths.get(BASE_DIR_PATH); 144 + File keyStoreFile = new File(Resources.getResource(keyStorePathFile).toURI());
  145 + InputStream inKeyStore = new FileInputStream(keyStoreFile);
  146 + keyStoreValue = KeyStore.getInstance(keyStoreType);
  147 + keyStoreValue.load(inKeyStore, keyStorePassword == null ? null : keyStorePassword.toCharArray());
  148 + } catch (Exception e) {
  149 + log.error("Unable to lookup LwM2M keystore. Reason: " + e.getMessage(), e);
  150 + throw new RuntimeException("Failed to lookup LwM2M keystore", e);
214 } 151 }
215 - return FULL_FILE_PATH.toUri().getPath();  
216 } 152 }
217 } 153 }
@@ -27,7 +27,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCreden @@ -27,7 +27,7 @@ import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceCreden
27 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg; 27 import org.thingsboard.server.gen.transport.TransportProtos.ValidateDeviceLwM2MCredentialsRequestMsg;
28 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 28 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
29 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer; 29 import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportContextServer;
30 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler; 30 +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil;
31 31
32 import java.io.IOException; 32 import java.io.IOException;
33 import java.security.GeneralSecurityException; 33 import java.security.GeneralSecurityException;
@@ -58,7 +58,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -58,7 +58,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
58 * @param keyValue - 58 * @param keyValue -
59 * @return ValidateDeviceCredentialsResponseMsg and SecurityInfo 59 * @return ValidateDeviceCredentialsResponseMsg and SecurityInfo
60 */ 60 */
61 - public ReadResultSecurityStore createAndValidateCredentialsSecurityInfo(String endpoint, LwM2mTransportHandler.LwM2mTypeServer keyValue) { 61 + public ReadResultSecurityStore createAndValidateCredentialsSecurityInfo(String endpoint, LwM2mTransportHandlerUtil.LwM2mTypeServer keyValue) {
62 CountDownLatch latch = new CountDownLatch(1); 62 CountDownLatch latch = new CountDownLatch(1);
63 final ReadResultSecurityStore[] resultSecurityStore = new ReadResultSecurityStore[1]; 63 final ReadResultSecurityStore[] resultSecurityStore = new ReadResultSecurityStore[1];
64 contextS.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(endpoint).build(), 64 contextS.getTransportService().process(ValidateDeviceLwM2MCredentialsRequestMsg.newBuilder().setCredentialsId(endpoint).build(),
@@ -68,7 +68,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -68,7 +68,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
68 String credentialsBody = msg.getCredentialsBody(); 68 String credentialsBody = msg.getCredentialsBody();
69 resultSecurityStore[0] = createSecurityInfo(endpoint, credentialsBody, keyValue); 69 resultSecurityStore[0] = createSecurityInfo(endpoint, credentialsBody, keyValue);
70 resultSecurityStore[0].setMsg(msg); 70 resultSecurityStore[0].setMsg(msg);
71 - Optional<DeviceProfile> deviceProfileOpt = LwM2mTransportHandler.decode(msg.getProfileBody().toByteArray()); 71 + Optional<DeviceProfile> deviceProfileOpt = LwM2mTransportHandlerUtil.decode(msg.getProfileBody().toByteArray());
72 deviceProfileOpt.ifPresent(profile -> resultSecurityStore[0].setDeviceProfile(profile)); 72 deviceProfileOpt.ifPresent(profile -> resultSecurityStore[0].setDeviceProfile(profile));
73 latch.countDown(); 73 latch.countDown();
74 } 74 }
@@ -81,7 +81,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -81,7 +81,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
81 } 81 }
82 }); 82 });
83 try { 83 try {
84 - latch.await(contextS.getLwM2MTransportConfigServer().getTimeout(), TimeUnit.MILLISECONDS); 84 + latch.await(contextS.getLwM2MTransportServerConfig().getTimeout(), TimeUnit.MILLISECONDS);
85 } catch (InterruptedException e) { 85 } catch (InterruptedException e) {
86 log.error("Failed to await credentials!", e); 86 log.error("Failed to await credentials!", e);
87 } 87 }
@@ -95,9 +95,9 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -95,9 +95,9 @@ public class LwM2mCredentialsSecurityInfoValidator {
95 * @param keyValue - 95 * @param keyValue -
96 * @return SecurityInfo 96 * @return SecurityInfo
97 */ 97 */
98 - private ReadResultSecurityStore createSecurityInfo(String endPoint, String jsonStr, LwM2mTransportHandler.LwM2mTypeServer keyValue) { 98 + private ReadResultSecurityStore createSecurityInfo(String endPoint, String jsonStr, LwM2mTransportHandlerUtil.LwM2mTypeServer keyValue) {
99 ReadResultSecurityStore result = new ReadResultSecurityStore(); 99 ReadResultSecurityStore result = new ReadResultSecurityStore();
100 - JsonObject objectMsg = LwM2mTransportHandler.validateJson(jsonStr); 100 + JsonObject objectMsg = LwM2mTransportHandlerUtil.validateJson(jsonStr);
101 if (objectMsg != null && !objectMsg.isJsonNull()) { 101 if (objectMsg != null && !objectMsg.isJsonNull()) {
102 JsonObject object = (objectMsg.has(keyValue.type) && !objectMsg.get(keyValue.type).isJsonNull()) ? objectMsg.get(keyValue.type).getAsJsonObject() : null; 102 JsonObject object = (objectMsg.has(keyValue.type) && !objectMsg.get(keyValue.type).isJsonNull()) ? objectMsg.get(keyValue.type).getAsJsonObject() : null;
103 /** 103 /**
@@ -108,7 +108,7 @@ public class LwM2mCredentialsSecurityInfoValidator { @@ -108,7 +108,7 @@ public class LwM2mCredentialsSecurityInfoValidator {
108 && objectMsg.get("client").getAsJsonObject().get("endpoint").isJsonPrimitive()) ? objectMsg.get("client").getAsJsonObject().get("endpoint").getAsString() : null; 108 && objectMsg.get("client").getAsJsonObject().get("endpoint").isJsonPrimitive()) ? objectMsg.get("client").getAsJsonObject().get("endpoint").getAsString() : null;
109 endPoint = (endPointPsk == null || endPointPsk.isEmpty()) ? endPoint : endPointPsk; 109 endPoint = (endPointPsk == null || endPointPsk.isEmpty()) ? endPoint : endPointPsk;
110 if (object != null && !object.isJsonNull()) { 110 if (object != null && !object.isJsonNull()) {
111 - if (keyValue.equals(LwM2mTransportHandler.LwM2mTypeServer.BOOTSTRAP)) { 111 + if (keyValue.equals(LwM2mTransportHandlerUtil.LwM2mTypeServer.BOOTSTRAP)) {
112 result.setBootstrapJsonCredential(object); 112 result.setBootstrapJsonCredential(object);
113 result.setEndPoint(endPoint); 113 result.setEndPoint(endPoint);
114 result.setSecurityMode(LwM2MSecurityMode.fromSecurityMode(object.get("bootstrapServer").getAsJsonObject().get("securityMode").getAsString().toLowerCase()).code); 114 result.setSecurityMode(LwM2MSecurityMode.fromSecurityMode(object.get("bootstrapServer").getAsJsonObject().get("securityMode").getAsString().toLowerCase()).code);
@@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.RegistrationUpdate; @@ -26,8 +26,8 @@ import org.eclipse.leshan.server.registration.RegistrationUpdate;
26 26
27 import java.util.Collection; 27 import java.util.Collection;
28 28
29 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_INFO;  
30 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromObjectIdToIdVer; 29 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
  30 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer;
31 31
32 @Slf4j 32 @Slf4j
33 public class LwM2mServerListener { 33 public class LwM2mServerListener {
@@ -43,7 +43,7 @@ import org.thingsboard.server.common.transport.TransportContext; @@ -43,7 +43,7 @@ import org.thingsboard.server.common.transport.TransportContext;
43 import org.thingsboard.server.common.transport.TransportResourceCache; 43 import org.thingsboard.server.common.transport.TransportResourceCache;
44 import org.thingsboard.server.common.transport.TransportService; 44 import org.thingsboard.server.common.transport.TransportService;
45 import org.thingsboard.server.common.transport.TransportServiceCallback; 45 import org.thingsboard.server.common.transport.TransportServiceCallback;
46 -import org.thingsboard.server.common.transport.lwm2m.LwM2MTransportConfigServer; 46 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
47 import org.thingsboard.server.gen.transport.TransportProtos; 47 import org.thingsboard.server.gen.transport.TransportProtos;
48 import org.thingsboard.server.gen.transport.TransportProtos.PostAttributeMsg; 48 import org.thingsboard.server.gen.transport.TransportProtos.PostAttributeMsg;
49 import org.thingsboard.server.gen.transport.TransportProtos.PostTelemetryMsg; 49 import org.thingsboard.server.gen.transport.TransportProtos.PostTelemetryMsg;
@@ -57,7 +57,7 @@ import java.util.ArrayList; @@ -57,7 +57,7 @@ import java.util.ArrayList;
57 import java.util.List; 57 import java.util.List;
58 58
59 import static org.thingsboard.server.gen.transport.TransportProtos.KeyValueType.BOOLEAN_V; 59 import static org.thingsboard.server.gen.transport.TransportProtos.KeyValueType.BOOLEAN_V;
60 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_TELEMETRY; 60 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_TELEMETRY;
61 61
62 @Slf4j 62 @Slf4j
63 @Component 63 @Component
@@ -65,7 +65,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle @@ -65,7 +65,7 @@ import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandle
65 public class LwM2mTransportContextServer extends TransportContext { 65 public class LwM2mTransportContextServer extends TransportContext {
66 66
67 67
68 - private final LwM2MTransportConfigServer lwM2MTransportConfigServer; 68 + private final LwM2MTransportServerConfig lwM2MTransportServerConfig;
69 69
70 private final TransportService transportService; 70 private final TransportService transportService;
71 71
@@ -75,15 +75,15 @@ public class LwM2mTransportContextServer extends TransportContext { @@ -75,15 +75,15 @@ public class LwM2mTransportContextServer extends TransportContext {
75 @Getter 75 @Getter
76 private final LwM2MJsonAdaptor adaptor; 76 private final LwM2MJsonAdaptor adaptor;
77 77
78 - public LwM2mTransportContextServer(LwM2MTransportConfigServer lwM2MTransportConfigServer, TransportService transportService, TransportResourceCache transportResourceCache, LwM2MJsonAdaptor adaptor) {  
79 - this.lwM2MTransportConfigServer = lwM2MTransportConfigServer; 78 + public LwM2mTransportContextServer(LwM2MTransportServerConfig lwM2MTransportServerConfig, TransportService transportService, TransportResourceCache transportResourceCache, LwM2MJsonAdaptor adaptor) {
  79 + this.lwM2MTransportServerConfig = lwM2MTransportServerConfig;
80 this.transportService = transportService; 80 this.transportService = transportService;
81 this.transportResourceCache = transportResourceCache; 81 this.transportResourceCache = transportResourceCache;
82 this.adaptor = adaptor; 82 this.adaptor = adaptor;
83 } 83 }
84 84
85 - public LwM2MTransportConfigServer getLwM2MTransportConfigServer() {  
86 - return this.lwM2MTransportConfigServer; 85 + public LwM2MTransportServerConfig getLwM2MTransportServerConfig() {
  86 + return this.lwM2MTransportServerConfig;
87 } 87 }
88 88
89 public TransportResourceCache getTransportResourceCache() { 89 public TransportResourceCache getTransportResourceCache() {
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportHandlerUtil.java renamed from common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/LwM2mTransportHandler.java
@@ -67,7 +67,7 @@ import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPA @@ -67,7 +67,7 @@ import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPA
67 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 67 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
68 68
69 @Slf4j 69 @Slf4j
70 -public class LwM2mTransportHandler { 70 +public class LwM2mTransportHandlerUtil {
71 71
72 public static final String TRANSPORT_DEFAULT_LWM2M_VERSION = "1.0"; 72 public static final String TRANSPORT_DEFAULT_LWM2M_VERSION = "1.0";
73 public static final String CLIENT_LWM2M_SETTINGS = "clientLwM2mSettings"; 73 public static final String CLIENT_LWM2M_SETTINGS = "clientLwM2mSettings";
@@ -256,7 +256,7 @@ public class LwM2mTransportHandler { @@ -256,7 +256,7 @@ public class LwM2mTransportHandler {
256 ObjectMapper mapper = new ObjectMapper(); 256 ObjectMapper mapper = new ObjectMapper();
257 String profileStr = mapper.writeValueAsString(profile); 257 String profileStr = mapper.writeValueAsString(profile);
258 JsonObject profileJson = (profileStr != null) ? validateJson(profileStr) : null; 258 JsonObject profileJson = (profileStr != null) ? validateJson(profileStr) : null;
259 - return getValidateCredentialsBodyFromThingsboard(profileJson) ? LwM2mTransportHandler.getNewProfileParameters(profileJson, deviceProfile.getTenantId()) : null; 259 + return getValidateCredentialsBodyFromThingsboard(profileJson) ? LwM2mTransportHandlerUtil.getNewProfileParameters(profileJson, deviceProfile.getTenantId()) : null;
260 } catch (IOException e) { 260 } catch (IOException e) {
261 log.error("", e); 261 log.error("", e);
262 } 262 }
@@ -66,18 +66,18 @@ import java.util.stream.Collectors; @@ -66,18 +66,18 @@ import java.util.stream.Collectors;
66 import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT; 66 import static org.eclipse.californium.core.coap.CoAP.ResponseCode.CONTENT;
67 import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST; 67 import static org.eclipse.leshan.core.ResponseCode.BAD_REQUEST;
68 import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND; 68 import static org.eclipse.leshan.core.ResponseCode.NOT_FOUND;
69 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.DEFAULT_TIMEOUT;  
70 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.FR_PATH_RESOURCE_VER_ID;  
71 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_ERROR;  
72 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_INFO;  
73 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_VALUE;  
74 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper;  
75 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.OBSERVE_CANCEL;  
76 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.OBSERVE_READ_ALL;  
77 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.RESPONSE_CHANNEL;  
78 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromIdVerToObjectId;  
79 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromObjectIdToIdVer;  
80 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.createWriteAttributeRequest; 69 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.DEFAULT_TIMEOUT;
  70 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.FR_PATH_RESOURCE_VER_ID;
  71 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR;
  72 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
  73 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE;
  74 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper;
  75 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_CANCEL;
  76 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_READ_ALL;
  77 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.RESPONSE_CHANNEL;
  78 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId;
  79 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer;
  80 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.createWriteAttributeRequest;
81 81
82 @Slf4j 82 @Slf4j
83 @Service 83 @Service
@@ -110,7 +110,7 @@ public class LwM2mTransportRequest { @@ -110,7 +110,7 @@ public class LwM2mTransportRequest {
110 @PostConstruct 110 @PostConstruct
111 public void init() { 111 public void init() {
112 this.converter = LwM2mValueConverterImpl.getInstance(); 112 this.converter = LwM2mValueConverterImpl.getInstance();
113 - executorResponse = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getResponsePoolSize(), 113 + executorResponse = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getResponsePoolSize(),
114 new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL))); 114 new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL)));
115 } 115 }
116 116
@@ -161,7 +161,7 @@ public class LwM2mTransportRequest { @@ -161,7 +161,7 @@ public class LwM2mTransportRequest {
161 leshanServer.getObservationService().cancelObservations(registration, target); 161 leshanServer.getObservationService().cancelObservations(registration, target);
162 break; 162 break;
163 case EXECUTE: 163 case EXECUTE:
164 - resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer() 164 + resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig()
165 .getModelProvider()); 165 .getModelProvider());
166 if (params != null && !resourceModel.multiple) { 166 if (params != null && !resourceModel.multiple) {
167 request = new ExecuteRequest(target, (String) this.converter.convertValue(params, resourceModel.type, ResourceModel.Type.STRING, resultIds)); 167 request = new ExecuteRequest(target, (String) this.converter.convertValue(params, resourceModel.type, ResourceModel.Type.STRING, resultIds));
@@ -171,7 +171,7 @@ public class LwM2mTransportRequest { @@ -171,7 +171,7 @@ public class LwM2mTransportRequest {
171 break; 171 break;
172 case WRITE_REPLACE: 172 case WRITE_REPLACE:
173 // Request to write a <b>String Single-Instance Resource</b> using the TLV content format. 173 // Request to write a <b>String Single-Instance Resource</b> using the TLV content format.
174 - resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer() 174 + resourceModel = lwM2MClient.getResourceModel(targetIdVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig()
175 .getModelProvider()); 175 .getModelProvider());
176 if (contentFormat.equals(ContentFormat.TLV)) { 176 if (contentFormat.equals(ContentFormat.TLV)) {
177 request = this.getWriteRequestSingleResource(null, resultIds.getObjectId(), 177 request = this.getWriteRequestSingleResource(null, resultIds.getObjectId(),
@@ -31,7 +31,9 @@ import org.eclipse.leshan.server.security.EditableSecurityStore; @@ -31,7 +31,9 @@ import org.eclipse.leshan.server.security.EditableSecurityStore;
31 import org.eclipse.leshan.server.security.SecurityChecker; 31 import org.eclipse.leshan.server.security.SecurityChecker;
32 import org.springframework.context.annotation.Bean; 32 import org.springframework.context.annotation.Bean;
33 import org.springframework.stereotype.Component; 33 import org.springframework.stereotype.Component;
  34 +import org.thingsboard.server.common.data.StringUtils;
34 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; 35 import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
  36 +import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
35 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; 37 import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
36 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; 38 import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
37 39
@@ -83,13 +85,13 @@ public class LwM2mTransportServerConfiguration { @@ -83,13 +85,13 @@ public class LwM2mTransportServerConfiguration {
83 @Bean 85 @Bean
84 public LeshanServer getLeshanServer() { 86 public LeshanServer getLeshanServer() {
85 log.info("Starting LwM2M transport Server... PostConstruct"); 87 log.info("Starting LwM2M transport Server... PostConstruct");
86 - return this.getLhServer(this.context.getLwM2MTransportConfigServer().getServerPortNoSec(), this.context.getLwM2MTransportConfigServer().getServerPortSecurity()); 88 + return this.getLhServer(this.context.getLwM2MTransportServerConfig().getPort(), this.context.getLwM2MTransportServerConfig().getSecurePort());
87 } 89 }
88 90
89 private LeshanServer getLhServer(Integer serverPortNoSec, Integer serverSecurePort) { 91 private LeshanServer getLhServer(Integer serverPortNoSec, Integer serverSecurePort) {
90 LeshanServerBuilder builder = new LeshanServerBuilder(); 92 LeshanServerBuilder builder = new LeshanServerBuilder();
91 - builder.setLocalAddress(this.context.getLwM2MTransportConfigServer().getServerHost(), serverPortNoSec);  
92 - builder.setLocalSecureAddress(this.context.getLwM2MTransportConfigServer().getServerHostSecurity(), serverSecurePort); 93 + builder.setLocalAddress(this.context.getLwM2MTransportServerConfig().getHost(), serverPortNoSec);
  94 + builder.setLocalSecureAddress(this.context.getLwM2MTransportServerConfig().getSecureHost(), serverSecurePort);
93 builder.setDecoder(new DefaultLwM2mNodeDecoder()); 95 builder.setDecoder(new DefaultLwM2mNodeDecoder());
94 /** Use a magic converter to support bad type send by the UI. */ 96 /** Use a magic converter to support bad type send by the UI. */
95 builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance())); 97 builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance()));
@@ -102,7 +104,7 @@ public class LwM2mTransportServerConfiguration { @@ -102,7 +104,7 @@ public class LwM2mTransportServerConfiguration {
102 104
103 /** Define model provider (Create Models )*/ 105 /** Define model provider (Create Models )*/
104 LwM2mModelProvider modelProvider = new LwM2mVersionedModelProvider(this.lwM2mClientContext, this.context); 106 LwM2mModelProvider modelProvider = new LwM2mVersionedModelProvider(this.lwM2mClientContext, this.context);
105 - this.context.getLwM2MTransportConfigServer().setModelProvider(modelProvider); 107 + this.context.getLwM2MTransportServerConfig().setModelProvider(modelProvider);
106 builder.setObjectModelProvider(modelProvider); 108 builder.setObjectModelProvider(modelProvider);
107 109
108 /** Create credentials */ 110 /** Create credentials */
@@ -116,8 +118,8 @@ public class LwM2mTransportServerConfiguration { @@ -116,8 +118,8 @@ public class LwM2mTransportServerConfiguration {
116 /** Create DTLS Config */ 118 /** Create DTLS Config */
117 DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); 119 DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder();
118 dtlsConfig.setServerOnly(true); 120 dtlsConfig.setServerOnly(true);
119 - dtlsConfig.setRecommendedSupportedGroupsOnly(this.context.getLwM2MTransportConfigServer().isRecommendedSupportedGroups());  
120 - dtlsConfig.setRecommendedCipherSuitesOnly(this.context.getLwM2MTransportConfigServer().isRecommendedCiphers()); 121 + dtlsConfig.setRecommendedSupportedGroupsOnly(this.context.getLwM2MTransportServerConfig().isRecommendedSupportedGroups());
  122 + dtlsConfig.setRecommendedCipherSuitesOnly(this.context.getLwM2MTransportServerConfig().isRecommendedCiphers());
121 if (this.pskMode) { 123 if (this.pskMode) {
122 dtlsConfig.setSupportedCipherSuites( 124 dtlsConfig.setSupportedCipherSuites(
123 TLS_PSK_WITH_AES_128_CCM_8, 125 TLS_PSK_WITH_AES_128_CCM_8,
@@ -139,9 +141,9 @@ public class LwM2mTransportServerConfiguration { @@ -139,9 +141,9 @@ public class LwM2mTransportServerConfiguration {
139 141
140 private void setServerWithCredentials(LeshanServerBuilder builder) { 142 private void setServerWithCredentials(LeshanServerBuilder builder) {
141 try { 143 try {
142 - if (this.context.getLwM2MTransportConfigServer().getKeyStoreValue() != null) { 144 + if (this.context.getLwM2MTransportServerConfig().getKeyStoreValue() != null) {
143 if (this.setBuilderX509(builder)) { 145 if (this.setBuilderX509(builder)) {
144 - X509Certificate rootCAX509Cert = (X509Certificate) this.context.getLwM2MTransportConfigServer().getKeyStoreValue().getCertificate(this.context.getLwM2MTransportConfigServer().getRootAlias()); 146 + X509Certificate rootCAX509Cert = (X509Certificate) this.context.getLwM2MTransportServerConfig().getKeyStoreValue().getCertificate(this.context.getLwM2MTransportServerConfig().getRootCertificateAlias());
145 if (rootCAX509Cert != null) { 147 if (rootCAX509Cert != null) {
146 X509Certificate[] trustedCertificates = new X509Certificate[1]; 148 X509Certificate[] trustedCertificates = new X509Certificate[1];
147 trustedCertificates[0] = rootCAX509Cert; 149 trustedCertificates[0] = rootCAX509Cert;
@@ -175,17 +177,11 @@ public class LwM2mTransportServerConfiguration { @@ -175,17 +177,11 @@ public class LwM2mTransportServerConfiguration {
175 } 177 }
176 178
177 private boolean setBuilderX509(LeshanServerBuilder builder) { 179 private boolean setBuilderX509(LeshanServerBuilder builder) {
178 - /**  
179 - * For deb => KeyStorePathFile == yml or commandline: KEY_STORE_PATH_FILE  
180 - * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks  
181 - */  
182 try { 180 try {
183 - X509Certificate serverCertificate = (X509Certificate) this.context.getLwM2MTransportConfigServer().getKeyStoreValue().getCertificate(this.context.getLwM2MTransportConfigServer().getServerAlias());  
184 - PrivateKey privateKey = (PrivateKey) this.context.getLwM2MTransportConfigServer().getKeyStoreValue().getKey(this.context.getLwM2MTransportConfigServer().getServerAlias(), this.context.getLwM2MTransportConfigServer().getKeyStorePasswordServer() == null ? null : this.context.getLwM2MTransportConfigServer().getKeyStorePasswordServer().toCharArray()); 181 + X509Certificate serverCertificate = (X509Certificate) this.context.getLwM2MTransportServerConfig().getKeyStoreValue().getCertificate(this.context.getLwM2MTransportServerConfig().getCertificateAlias());
  182 + PrivateKey privateKey = (PrivateKey) this.context.getLwM2MTransportServerConfig().getKeyStoreValue().getKey(this.context.getLwM2MTransportServerConfig().getCertificateAlias(), this.context.getLwM2MTransportServerConfig().getKeyStorePassword() == null ? null : this.context.getLwM2MTransportServerConfig().getKeyStorePassword().toCharArray());
185 PublicKey publicKey = serverCertificate.getPublicKey(); 183 PublicKey publicKey = serverCertificate.getPublicKey();
186 - if (serverCertificate != null &&  
187 - privateKey != null && privateKey.getEncoded().length > 0 &&  
188 - publicKey != null && publicKey.getEncoded().length > 0) { 184 + if (privateKey != null && privateKey.getEncoded().length > 0 && publicKey != null && publicKey.getEncoded().length > 0) {
189 builder.setPublicKey(serverCertificate.getPublicKey()); 185 builder.setPublicKey(serverCertificate.getPublicKey());
190 builder.setPrivateKey(privateKey); 186 builder.setPrivateKey(privateKey);
191 builder.setCertificateChain(new X509Certificate[]{serverCertificate}); 187 builder.setCertificateChain(new X509Certificate[]{serverCertificate});
@@ -212,10 +208,12 @@ public class LwM2mTransportServerConfiguration { @@ -212,10 +208,12 @@ public class LwM2mTransportServerConfiguration {
212 } 208 }
213 209
214 private void infoPramsUri(String mode) { 210 private void infoPramsUri(String mode) {
215 - log.info("Server uses [{}]: serverNoSecureURI : [{}], serverSecureURI : [{}]",  
216 - mode,  
217 - this.context.getLwM2MTransportConfigServer().getServerHost() + ":" + this.context.getLwM2MTransportConfigServer().getServerPortNoSec(),  
218 - this.context.getLwM2MTransportConfigServer().getServerHostSecurity() + ":" + this.context.getLwM2MTransportConfigServer().getServerPortSecurity()); 211 + LwM2MTransportServerConfig lwM2MTransportServerConfig = this.context.getLwM2MTransportServerConfig();
  212 + log.info("Server uses [{}]: serverNoSecureURI : [{}:{}], serverSecureURI : [{}:{}]", mode,
  213 + lwM2MTransportServerConfig.getHost(),
  214 + lwM2MTransportServerConfig.getPort(),
  215 + lwM2MTransportServerConfig.getSecureHost(),
  216 + lwM2MTransportServerConfig.getSecurePort());
219 } 217 }
220 218
221 private boolean setServerRPK(LeshanServerBuilder builder) { 219 private boolean setServerRPK(LeshanServerBuilder builder) {
@@ -233,39 +231,26 @@ public class LwM2mTransportServerConfiguration { @@ -233,39 +231,26 @@ public class LwM2mTransportServerConfiguration {
233 return false; 231 return false;
234 } 232 }
235 233
236 -  
237 - /**  
238 - * From yml: server  
239 - * public_x: "${LWM2M_SERVER_PUBLIC_X:405354ea8893471d9296afbc8b020a5c6201b0bb25812a53b849d4480fa5f069}"  
240 - * public_y: "${LWM2M_SERVER_PUBLIC_Y:30c9237e946a3a1692c1cafaa01a238a077f632c99371348337512363f28212b}"  
241 - * private_encoded: "${LWM2M_SERVER_PRIVATE_ENCODED:274671fe40ce937b8a6352cf0a418e8a39e4bf0bb9bf74c910db953c20c73802}"  
242 - */  
243 private void generateKeyForRPK() throws NoSuchAlgorithmException, InvalidParameterSpecException, InvalidKeySpecException { 234 private void generateKeyForRPK() throws NoSuchAlgorithmException, InvalidParameterSpecException, InvalidKeySpecException {
244 /** Get Elliptic Curve Parameter spec for secp256r1 */ 235 /** Get Elliptic Curve Parameter spec for secp256r1 */
245 AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC"); 236 AlgorithmParameters algoParameters = AlgorithmParameters.getInstance("EC");
246 algoParameters.init(new ECGenParameterSpec("secp256r1")); 237 algoParameters.init(new ECGenParameterSpec("secp256r1"));
247 ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class); 238 ECParameterSpec parameterSpec = algoParameters.getParameterSpec(ECParameterSpec.class);
248 - if (this.context.getLwM2MTransportConfigServer().getServerPublicX() != null &&  
249 - !this.context.getLwM2MTransportConfigServer().getServerPublicX().isEmpty() &&  
250 - this.context.getLwM2MTransportConfigServer().getServerPublicY() != null &&  
251 - !this.context.getLwM2MTransportConfigServer().getServerPublicY().isEmpty()) {  
252 - /** Get point values */  
253 - byte[] publicX = Hex.decodeHex(this.context.getLwM2MTransportConfigServer().getServerPublicX().toCharArray());  
254 - byte[] publicY = Hex.decodeHex(this.context.getLwM2MTransportConfigServer().getServerPublicY().toCharArray());  
255 - /** Create key specs */ 239 + LwM2MTransportServerConfig serverConfig = this.context.getLwM2MTransportServerConfig();
  240 + if (StringUtils.isNotEmpty(serverConfig.getPublicX()) && StringUtils.isNotEmpty(serverConfig.getPublicY())) {
  241 + byte[] publicX = Hex.decodeHex(serverConfig.getPublicX().toCharArray());
  242 + byte[] publicY = Hex.decodeHex(serverConfig.getPublicY().toCharArray());
256 KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)), 243 KeySpec publicKeySpec = new ECPublicKeySpec(new ECPoint(new BigInteger(publicX), new BigInteger(publicY)),
257 parameterSpec); 244 parameterSpec);
258 - /** Get keys */  
259 this.publicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec); 245 this.publicKey = KeyFactory.getInstance("EC").generatePublic(publicKeySpec);
260 } 246 }
261 - if (this.context.getLwM2MTransportConfigServer().getServerPrivateEncoded() != null &&  
262 - !this.context.getLwM2MTransportConfigServer().getServerPrivateEncoded().isEmpty()) {  
263 - /** Get private key */  
264 - byte[] privateS = Hex.decodeHex(this.context.getLwM2MTransportConfigServer().getServerPrivateEncoded().toCharArray()); 247 + String privateEncodedKey = serverConfig.getPrivateEncoded();
  248 + if (StringUtils.isNotEmpty(privateEncodedKey)) {
  249 + byte[] privateS = Hex.decodeHex(privateEncodedKey.toCharArray());
265 try { 250 try {
266 this.privateKey = KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(privateS)); 251 this.privateKey = KeyFactory.getInstance("EC").generatePrivate(new PKCS8EncodedKeySpec(privateS));
267 } catch (InvalidKeySpecException ignore2) { 252 } catch (InvalidKeySpecException ignore2) {
268 - log.error("Invalid Server rpk.PrivateKey.getEncoded () [{}}]. PrivateKey has no EC algorithm", this.context.getLwM2MTransportConfigServer().getServerPrivateEncoded()); 253 + log.error("Invalid Server rpk.PrivateKey.getEncoded () [{}}]. PrivateKey has no EC algorithm", privateEncodedKey);
269 } 254 }
270 } 255 }
271 } 256 }
@@ -41,7 +41,7 @@ public class LwM2mTransportServerInitializer { @@ -41,7 +41,7 @@ public class LwM2mTransportServerInitializer {
41 41
42 @PostConstruct 42 @PostConstruct
43 public void init() { 43 public void init() {
44 - if (this.context.getLwM2MTransportConfigServer().getEnableGenNewKeyPskRpk()) { 44 + if (this.context.getLwM2MTransportServerConfig().getEnableGenNewKeyPskRpk()) {
45 new LWM2MGenerationPSkRPkECC(); 45 new LWM2MGenerationPSkRPkECC();
46 } 46 }
47 this.startLhServer(); 47 this.startLhServer();
@@ -84,29 +84,29 @@ import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST; @@ -84,29 +84,29 @@ import static org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST;
84 import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION; 84 import static org.eclipse.leshan.core.attributes.Attribute.OBJECT_VERSION;
85 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY; 85 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_KEY;
86 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 86 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
87 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.CLIENT_NOT_AUTHORIZED;  
88 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.DEVICE_ATTRIBUTES_REQUEST;  
89 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.FR_PATH_RESOURCE_VER_ID;  
90 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_ERROR;  
91 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_INFO;  
92 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LOG_LW2M_VALUE;  
93 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LWM2M_STRATEGY_2;  
94 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper;  
95 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.DISCOVER;  
96 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.EXECUTE;  
97 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.OBSERVE;  
98 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.OBSERVE_CANCEL;  
99 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.OBSERVE_READ_ALL;  
100 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.READ;  
101 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.WRITE_ATTRIBUTES;  
102 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.WRITE_REPLACE;  
103 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper.WRITE_UPDATE;  
104 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.SERVICE_CHANNEL;  
105 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertJsonArrayToSet;  
106 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromIdVerToObjectId;  
107 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromObjectIdToIdVer;  
108 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.getAckCallback;  
109 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.validateObjectVerFromKey; 87 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.CLIENT_NOT_AUTHORIZED;
  88 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.DEVICE_ATTRIBUTES_REQUEST;
  89 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.FR_PATH_RESOURCE_VER_ID;
  90 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_ERROR;
  91 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_INFO;
  92 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LOG_LW2M_VALUE;
  93 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LWM2M_STRATEGY_2;
  94 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper;
  95 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.DISCOVER;
  96 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.EXECUTE;
  97 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE;
  98 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_CANCEL;
  99 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.OBSERVE_READ_ALL;
  100 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.READ;
  101 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_ATTRIBUTES;
  102 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_REPLACE;
  103 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper.WRITE_UPDATE;
  104 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.SERVICE_CHANNEL;
  105 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertJsonArrayToSet;
  106 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId;
  107 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer;
  108 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getAckCallback;
  109 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.validateObjectVerFromKey;
110 110
111 @Slf4j 111 @Slf4j
112 @Service 112 @Service
@@ -143,12 +143,12 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -143,12 +143,12 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
143 143
144 @PostConstruct 144 @PostConstruct
145 public void init() { 145 public void init() {
146 - this.lwM2mTransportContextServer.getScheduler().scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) lwM2mTransportContextServer.getLwM2MTransportConfigServer().getSessionReportTimeout()), lwM2mTransportContextServer.getLwM2MTransportConfigServer().getSessionReportTimeout(), TimeUnit.MILLISECONDS);  
147 - this.executorRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getRegisteredPoolSize(), 146 + this.lwM2mTransportContextServer.getScheduler().scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) lwM2mTransportContextServer.getLwM2MTransportServerConfig().getSessionReportTimeout()), lwM2mTransportContextServer.getLwM2MTransportServerConfig().getSessionReportTimeout(), TimeUnit.MILLISECONDS);
  147 + this.executorRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getRegisteredPoolSize(),
148 new NamedThreadFactory(String.format("LwM2M %s channel registered", SERVICE_CHANNEL))); 148 new NamedThreadFactory(String.format("LwM2M %s channel registered", SERVICE_CHANNEL)));
149 - this.executorUpdateRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getUpdateRegisteredPoolSize(), 149 + this.executorUpdateRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getUpdateRegisteredPoolSize(),
150 new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL))); 150 new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL)));
151 - this.executorUnRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getUnRegisteredPoolSize(), 151 + this.executorUnRegistered = Executors.newFixedThreadPool(this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getUnRegisteredPoolSize(),
152 new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL))); 152 new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL)));
153 this.converter = LwM2mValueConverterImpl.getInstance(); 153 this.converter = LwM2mValueConverterImpl.getInstance();
154 } 154 }
@@ -281,7 +281,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -281,7 +281,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
281 Set<Observation> observations = leshanServer.getObservationService().getObservations(registration); 281 Set<Observation> observations = leshanServer.getObservationService().getObservations(registration);
282 observations.forEach(observation -> lwM2mTransportRequest.sendAllRequest(registration, 282 observations.forEach(observation -> lwM2mTransportRequest.sendAllRequest(registration,
283 convertPathFromObjectIdToIdVer(observation.getPath().toString(), registration), OBSERVE_CANCEL, 283 convertPathFromObjectIdToIdVer(observation.getPath().toString(), registration), OBSERVE_CANCEL,
284 - null, null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null)); 284 + null, null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null));
285 } 285 }
286 } 286 }
287 287
@@ -339,7 +339,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -339,7 +339,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
339 this.getInfoFirmwareUpdate(lwM2MClient); 339 this.getInfoFirmwareUpdate(lwM2MClient);
340 } 340 }
341 if (pathIdVer != null) { 341 if (pathIdVer != null) {
342 - ResourceModel resourceModel = lwM2MClient.getResourceModel(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer() 342 + ResourceModel resourceModel = lwM2MClient.getResourceModel(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig()
343 .getModelProvider()); 343 .getModelProvider());
344 if (resourceModel != null && resourceModel.operations.isWritable()) { 344 if (resourceModel != null && resourceModel.operations.isWritable()) {
345 this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer), valueNew, pathIdVer); 345 this.updateResourcesValueToClient(lwM2MClient, this.getResourceValueFormatKv(lwM2MClient, pathIdVer), valueNew, pathIdVer);
@@ -404,7 +404,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -404,7 +404,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
404 @Override 404 @Override
405 public void onResourceUpdate(Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) { 405 public void onResourceUpdate(Optional<TransportProtos.ResourceUpdateMsg> resourceUpdateMsgOpt) {
406 String idVer = resourceUpdateMsgOpt.get().getResourceKey(); 406 String idVer = resourceUpdateMsgOpt.get().getResourceKey();
407 - lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.updateResourceModel(idVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider())); 407 + lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.updateResourceModel(idVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getModelProvider()));
408 } 408 }
409 409
410 /** 410 /**
@@ -413,7 +413,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -413,7 +413,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
413 @Override 413 @Override
414 public void onResourceDelete(Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) { 414 public void onResourceDelete(Optional<TransportProtos.ResourceDeleteMsg> resourceDeleteMsgOpt) {
415 String pathIdVer = resourceDeleteMsgOpt.get().getResourceKey(); 415 String pathIdVer = resourceDeleteMsgOpt.get().getResourceKey();
416 - lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.deleteResources(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getModelProvider())); 416 + lwM2mClientContext.getLwM2mClients().values().stream().forEach(e -> e.deleteResources(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getModelProvider()));
417 } 417 }
418 418
419 @Override 419 @Override
@@ -429,7 +429,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -429,7 +429,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
429 } else { 429 } else {
430 lwM2mTransportRequest.sendAllRequest(registration, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(), lwm2mClientRpcRequest.getContentFormatName(), 430 lwM2mTransportRequest.sendAllRequest(registration, lwm2mClientRpcRequest.getTargetIdVer(), lwm2mClientRpcRequest.getTypeOper(), lwm2mClientRpcRequest.getContentFormatName(),
431 lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(), 431 lwm2mClientRpcRequest.getValue() == null ? lwm2mClientRpcRequest.getParams() : lwm2mClientRpcRequest.getValue(),
432 - this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), lwm2mClientRpcRequest); 432 + this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), lwm2mClientRpcRequest);
433 } 433 }
434 } catch (Exception e) { 434 } catch (Exception e) {
435 if (lwm2mClientRpcRequest == null) { 435 if (lwm2mClientRpcRequest == null) {
@@ -457,7 +457,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -457,7 +457,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
457 lwm2mClientRpcRequest.setRequestId(toDeviceRequest.getRequestId()); 457 lwm2mClientRpcRequest.setRequestId(toDeviceRequest.getRequestId());
458 lwm2mClientRpcRequest.setSessionInfo(sessionInfo); 458 lwm2mClientRpcRequest.setSessionInfo(sessionInfo);
459 lwm2mClientRpcRequest.setValidTypeOper(toDeviceRequest.getMethodName()); 459 lwm2mClientRpcRequest.setValidTypeOper(toDeviceRequest.getMethodName());
460 - JsonObject rpcRequest = LwM2mTransportHandler.validateJson(toDeviceRequest.getParams()); 460 + JsonObject rpcRequest = LwM2mTransportHandlerUtil.validateJson(toDeviceRequest.getParams());
461 if (rpcRequest != null) { 461 if (rpcRequest != null) {
462 if (rpcRequest.has(lwm2mClientRpcRequest.keyNameKey)) { 462 if (rpcRequest.has(lwm2mClientRpcRequest.keyNameKey)) {
463 String targetIdVer = this.getPresentPathIntoProfile(sessionInfo, 463 String targetIdVer = this.getPresentPathIntoProfile(sessionInfo,
@@ -546,7 +546,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -546,7 +546,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
546 @Override 546 @Override
547 public void doTrigger(Registration registration, String path) { 547 public void doTrigger(Registration registration, String path) {
548 lwM2mTransportRequest.sendAllRequest(registration, path, EXECUTE, 548 lwM2mTransportRequest.sendAllRequest(registration, path, EXECUTE,
549 - ContentFormat.TLV.getName(), null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 549 + ContentFormat.TLV.getName(), null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
550 } 550 }
551 551
552 /** 552 /**
@@ -636,11 +636,11 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -636,11 +636,11 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
636 LwM2mClientProfile lwM2MClientProfile = lwM2mClientContext.getProfile(registration); 636 LwM2mClientProfile lwM2MClientProfile = lwM2mClientContext.getProfile(registration);
637 Set<String> clientObjects = lwM2mClientContext.getSupportedIdVerInClient(registration); 637 Set<String> clientObjects = lwM2mClientContext.getSupportedIdVerInClient(registration);
638 if (clientObjects != null && clientObjects.size() > 0) { 638 if (clientObjects != null && clientObjects.size() > 0) {
639 - if (LWM2M_STRATEGY_2 == LwM2mTransportHandler.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) { 639 + if (LWM2M_STRATEGY_2 == LwM2mTransportHandlerUtil.getClientOnlyObserveAfterConnect(lwM2MClientProfile)) {
640 // #2 640 // #2
641 lwM2MClient.getPendingReadRequests().addAll(clientObjects); 641 lwM2MClient.getPendingReadRequests().addAll(clientObjects);
642 clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(), 642 clientObjects.forEach(path -> lwM2mTransportRequest.sendAllRequest(registration, path, READ, ContentFormat.TLV.getName(),
643 - null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null)); 643 + null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null));
644 } 644 }
645 // #1 645 // #1
646 this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, READ, clientObjects); 646 this.initReadAttrTelemetryObserveToClient(registration, lwM2MClient, READ, clientObjects);
@@ -689,7 +689,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -689,7 +689,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
689 */ 689 */
690 private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) { 690 private void updateResourcesValue(Registration registration, LwM2mResource lwM2mResource, String path) {
691 LwM2mClient lwM2MClient = lwM2mClientContext.getLwM2mClientWithReg(registration, null); 691 LwM2mClient lwM2MClient = lwM2mClientContext.getLwM2mClientWithReg(registration, null);
692 - if (lwM2MClient.saveResourceValue(path, lwM2mResource, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer() 692 + if (lwM2MClient.saveResourceValue(path, lwM2mResource, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig()
693 .getModelProvider())) { 693 .getModelProvider())) {
694 if (FR_PATH_RESOURCE_VER_ID.equals(convertPathFromIdVerToObjectId(path)) && 694 if (FR_PATH_RESOURCE_VER_ID.equals(convertPathFromIdVerToObjectId(path)) &&
695 lwM2MClient.getFrUpdate().getCurrentFwVersion() != null 695 lwM2MClient.getFrUpdate().getCurrentFwVersion() != null
@@ -780,7 +780,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -780,7 +780,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
780 ConcurrentHashMap<String, Object> finalParams = params; 780 ConcurrentHashMap<String, Object> finalParams = params;
781 pathSend.forEach(target -> { 781 pathSend.forEach(target -> {
782 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(), 782 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, ContentFormat.TLV.getName(),
783 - finalParams != null ? finalParams.get(target) : null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 783 + finalParams != null ? finalParams.get(target) : null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
784 }); 784 });
785 if (OBSERVE.equals(typeOper)) { 785 if (OBSERVE.equals(typeOper)) {
786 lwM2MClient.initReadValue(this, null); 786 lwM2MClient.initReadValue(this, null);
@@ -1094,10 +1094,10 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1094,10 +1094,10 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1094 if (pathIds.isResource()) { 1094 if (pathIds.isResource()) {
1095 if (READ.equals(typeOper)) { 1095 if (READ.equals(typeOper)) {
1096 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, 1096 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,
1097 - ContentFormat.TLV.getName(), null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1097 + ContentFormat.TLV.getName(), null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1098 } else if (OBSERVE.equals(typeOper)) { 1098 } else if (OBSERVE.equals(typeOper)) {
1099 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper, 1099 lwM2mTransportRequest.sendAllRequest(registration, target, typeOper,
1100 - null, null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1100 + null, null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1101 } 1101 }
1102 } 1102 }
1103 }); 1103 });
@@ -1153,7 +1153,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1153,7 +1153,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1153 if (!pathSend.isEmpty()) { 1153 if (!pathSend.isEmpty()) {
1154 ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew; 1154 ConcurrentHashMap<String, Object> finalParams = lwm2mAttributesNew;
1155 pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(), 1155 pathSend.forEach(target -> lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(),
1156 - finalParams.get(target), this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null)); 1156 + finalParams.get(target), this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null));
1157 } 1157 }
1158 }); 1158 });
1159 } 1159 }
@@ -1170,7 +1170,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1170,7 +1170,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1170 params.clear(); 1170 params.clear();
1171 params.put(OBJECT_VERSION, ""); 1171 params.put(OBJECT_VERSION, "");
1172 lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(), 1172 lwM2mTransportRequest.sendAllRequest(registration, target, WRITE_ATTRIBUTES, ContentFormat.TLV.getName(),
1173 - params, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1173 + params, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1174 }); 1174 });
1175 } 1175 }
1176 }); 1176 });
@@ -1183,7 +1183,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1183,7 +1183,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1183 paramAnallyzer.forEach(pathIdVer -> { 1183 paramAnallyzer.forEach(pathIdVer -> {
1184 if (this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer) != null) { 1184 if (this.getResourceValueFromLwM2MClient(lwM2MClient, pathIdVer) != null) {
1185 lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, OBSERVE_CANCEL, null, 1185 lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, OBSERVE_CANCEL, null,
1186 - null, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1186 + null, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1187 } 1187 }
1188 } 1188 }
1189 ); 1189 );
@@ -1193,7 +1193,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1193,7 +1193,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1193 if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) { 1193 if (valueNew != null && (valueOld == null || !valueNew.toString().equals(valueOld.toString()))) {
1194 lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), path, WRITE_REPLACE, 1194 lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), path, WRITE_REPLACE,
1195 ContentFormat.TLV.getName(), valueNew, 1195 ContentFormat.TLV.getName(), valueNew,
1196 - this.lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1196 + this.lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1197 } else { 1197 } else {
1198 log.error("Failed update resource [{}] [{}]", path, valueNew); 1198 log.error("Failed update resource [{}] [{}]", path, valueNew);
1199 String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad", 1199 String logMsg = String.format("%s: Failed update resource path - %s value - %s. Value is not changed or bad",
@@ -1406,7 +1406,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1406,7 +1406,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1406 public void readRequestToClientFirmwareVer(Registration registration) { 1406 public void readRequestToClientFirmwareVer(Registration registration) {
1407 String pathIdVer = convertPathFromObjectIdToIdVer(FR_PATH_RESOURCE_VER_ID, registration); 1407 String pathIdVer = convertPathFromObjectIdToIdVer(FR_PATH_RESOURCE_VER_ID, registration);
1408 lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, READ, ContentFormat.TLV.getName(), 1408 lwM2mTransportRequest.sendAllRequest(registration, pathIdVer, READ, ContentFormat.TLV.getName(),
1409 - null, lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1409 + null, lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1410 } 1410 }
1411 1411
1412 /** 1412 /**
@@ -1422,7 +1422,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1422,7 +1422,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1422 String verSupportedObject = lwM2MClient.getRegistration().getSupportedObject().get(objectId); 1422 String verSupportedObject = lwM2MClient.getRegistration().getSupportedObject().get(objectId);
1423 String targetIdVer = LWM2M_SEPARATOR_PATH + objectId + LWM2M_SEPARATOR_KEY + verSupportedObject + LWM2M_SEPARATOR_PATH + 0 + LWM2M_SEPARATOR_PATH + 0; 1423 String targetIdVer = LWM2M_SEPARATOR_PATH + objectId + LWM2M_SEPARATOR_KEY + verSupportedObject + LWM2M_SEPARATOR_PATH + 0 + LWM2M_SEPARATOR_PATH + 0;
1424 lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(), 1424 lwM2mTransportRequest.sendAllRequest(lwM2MClient.getRegistration(), targetIdVer, WRITE_REPLACE, ContentFormat.OPAQUE.getName(),
1425 - firmwareChunk, lwM2mTransportContextServer.getLwM2MTransportConfigServer().getTimeout(), null); 1425 + firmwareChunk, lwM2mTransportContextServer.getLwM2MTransportServerConfig().getTimeout(), null);
1426 log.warn("updateFirmwareClient [{}] [{}]", lwM2MClient.getFrUpdate().getCurrentFwVersion(), lwM2MClient.getFrUpdate().getClientFwVersion()); 1426 log.warn("updateFirmwareClient [{}] [{}]", lwM2MClient.getFrUpdate().getCurrentFwVersion(), lwM2MClient.getFrUpdate().getClientFwVersion());
1427 } 1427 }
1428 } 1428 }
@@ -1444,7 +1444,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService { @@ -1444,7 +1444,7 @@ public class LwM2mTransportServiceImpl implements LwM2mTransportService {
1444 } 1444 }
1445 1445
1446 private boolean validateResourceInModel(LwM2mClient lwM2mClient, String pathIdVer, boolean isWritableNotOptional) { 1446 private boolean validateResourceInModel(LwM2mClient lwM2mClient, String pathIdVer, boolean isWritableNotOptional) {
1447 - ResourceModel resourceModel = lwM2mClient.getResourceModel(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportConfigServer() 1447 + ResourceModel resourceModel = lwM2mClient.getResourceModel(pathIdVer, this.lwM2mTransportContextServer.getLwM2MTransportServerConfig()
1448 .getModelProvider()); 1448 .getModelProvider());
1449 Integer objectId = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)).getObjectId(); 1449 Integer objectId = new LwM2mPath(convertPathFromIdVerToObjectId(pathIdVer)).getObjectId();
1450 String objectVer = validateObjectVerFromKey(pathIdVer); 1450 String objectVer = validateObjectVerFromKey(pathIdVer);
@@ -42,9 +42,9 @@ import java.util.concurrent.CopyOnWriteArrayList; @@ -42,9 +42,9 @@ import java.util.concurrent.CopyOnWriteArrayList;
42 import java.util.stream.Collectors; 42 import java.util.stream.Collectors;
43 43
44 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH; 44 import static org.thingsboard.server.common.data.lwm2m.LwM2mConstants.LWM2M_SEPARATOR_PATH;
45 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.TRANSPORT_DEFAULT_LWM2M_VERSION;  
46 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromIdVerToObjectId;  
47 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.getVerFromPathIdVerOrId; 45 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.TRANSPORT_DEFAULT_LWM2M_VERSION;
  46 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromIdVerToObjectId;
  47 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.getVerFromPathIdVerOrId;
48 48
49 @Slf4j 49 @Slf4j
50 @Data 50 @Data
@@ -25,7 +25,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent; @@ -25,7 +25,7 @@ import org.thingsboard.server.queue.util.TbLwM2mTransportComponent;
25 import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; 25 import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode;
26 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator; 26 import org.thingsboard.server.transport.lwm2m.secure.LwM2mCredentialsSecurityInfoValidator;
27 import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore; 27 import org.thingsboard.server.transport.lwm2m.secure.ReadResultSecurityStore;
28 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler; 28 +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil;
29 29
30 import java.util.Arrays; 30 import java.util.Arrays;
31 import java.util.Map; 31 import java.util.Map;
@@ -34,7 +34,7 @@ import java.util.UUID; @@ -34,7 +34,7 @@ import java.util.UUID;
34 import java.util.concurrent.ConcurrentHashMap; 34 import java.util.concurrent.ConcurrentHashMap;
35 35
36 import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO_SEC; 36 import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO_SEC;
37 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.convertPathFromObjectIdToIdVer; 37 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.convertPathFromObjectIdToIdVer;
38 38
39 @Service 39 @Service
40 @TbLwM2mTransportComponent 40 @TbLwM2mTransportComponent
@@ -118,7 +118,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { @@ -118,7 +118,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
118 */ 118 */
119 @Override 119 @Override
120 public LwM2mClient addLwM2mClientToSession(String identity) { 120 public LwM2mClient addLwM2mClientToSession(String identity) {
121 - ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandler.LwM2mTypeServer.CLIENT); 121 + ReadResultSecurityStore store = lwM2MCredentialsSecurityInfoValidator.createAndValidateCredentialsSecurityInfo(identity, LwM2mTransportHandlerUtil.LwM2mTypeServer.CLIENT);
122 if (store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) { 122 if (store.getSecurityMode() < LwM2MSecurityMode.DEFAULT_MODE.code) {
123 UUID profileUuid = (store.getDeviceProfile() != null && addUpdateProfileParameters(store.getDeviceProfile())) ? store.getDeviceProfile().getUuidId() : null; 123 UUID profileUuid = (store.getDeviceProfile() != null && addUpdateProfileParameters(store.getDeviceProfile())) ? store.getDeviceProfile().getUuidId() : null;
124 LwM2mClient client; 124 LwM2mClient client;
@@ -165,7 +165,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext { @@ -165,7 +165,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
165 165
166 @Override 166 @Override
167 public boolean addUpdateProfileParameters(DeviceProfile deviceProfile) { 167 public boolean addUpdateProfileParameters(DeviceProfile deviceProfile) {
168 - LwM2mClientProfile lwM2MClientProfile = LwM2mTransportHandler.getLwM2MClientProfileFromThingsboard(deviceProfile); 168 + LwM2mClientProfile lwM2MClientProfile = LwM2mTransportHandlerUtil.getLwM2MClientProfileFromThingsboard(deviceProfile);
169 if (lwM2MClientProfile != null) { 169 if (lwM2MClientProfile != null) {
170 profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile); 170 profiles.put(deviceProfile.getUuidId(), lwM2MClientProfile);
171 return true; 171 return true;
@@ -21,11 +21,11 @@ import org.eclipse.leshan.core.request.ContentFormat; @@ -21,11 +21,11 @@ import org.eclipse.leshan.core.request.ContentFormat;
21 import org.eclipse.leshan.server.registration.Registration; 21 import org.eclipse.leshan.server.registration.Registration;
22 import org.thingsboard.server.gen.transport.TransportProtos; 22 import org.thingsboard.server.gen.transport.TransportProtos;
23 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto; 23 import org.thingsboard.server.gen.transport.TransportProtos.SessionInfoProto;
24 -import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.LwM2mTypeOper; 24 +import org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.LwM2mTypeOper;
25 25
26 import java.util.concurrent.ConcurrentHashMap; 26 import java.util.concurrent.ConcurrentHashMap;
27 27
28 -import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandler.validPathIdVer; 28 +import static org.thingsboard.server.transport.lwm2m.server.LwM2mTransportHandlerUtil.validPathIdVer;
29 29
30 @Data 30 @Data
31 public class Lwm2mClientRpcRequest { 31 public class Lwm2mClientRpcRequest {
common/transport/lwm2m/src/main/resources/lwm2mserver.jks renamed from common/transport/lwm2m/src/main/resources/credentials/serverKeyStore.jks
No preview for this file type
transport/lwm2m/src/main/data/lwm2mserver.jks renamed from transport/lwm2m/src/main/data/credentials/serverKeyStore.jks
No preview for this file type