Commit 17700fe186bed6f24e90d3603804f48208312c11
1 parent
be4475c2
Lwm2m: backEnd: refactoring after update dependencies: <californium.version>2.6.…
…0</californium.version> <leshan-server.version>1.3.0</leshan-server.version> <leshan-core.version>1.3.0</leshan-core.version> <leshan-client.version>1.3.0</leshan-client.version>
Showing
26 changed files
with
417 additions
and
305 deletions
... | ... | @@ -150,53 +150,54 @@ public class LwM2MModelsRepository { |
150 | 150 | */ |
151 | 151 | private ServerSecurityConfig getBootstrapServer(boolean bootstrapServerIs, LwM2MSecurityMode mode) { |
152 | 152 | ServerSecurityConfig bsServ = new ServerSecurityConfig(); |
153 | + bsServ.setBootstrapServerIs(bootstrapServerIs); | |
153 | 154 | if (bootstrapServerIs) { |
155 | + bsServ.setServerId(contextBootStrap.getBootstrapServerId()); | |
154 | 156 | switch (mode) { |
155 | 157 | case NO_SEC: |
156 | 158 | bsServ.setHost(contextBootStrap.getBootstrapHost()); |
157 | - bsServ.setPort(contextBootStrap.getBootstrapPort()); | |
159 | + bsServ.setPort(contextBootStrap.getBootstrapPortNoSecPsk()); | |
158 | 160 | bsServ.setServerPublicKey(""); |
159 | 161 | break; |
160 | 162 | case PSK: |
161 | 163 | bsServ.setHost(contextBootStrap.getBootstrapSecureHost()); |
162 | - bsServ.setPort(contextBootStrap.getBootstrapSecurePort()); | |
164 | + bsServ.setPort(contextBootStrap.getBootstrapSecurePortPsk()); | |
163 | 165 | bsServ.setServerPublicKey(""); |
164 | 166 | break; |
165 | 167 | case RPK: |
166 | 168 | bsServ.setHost(contextBootStrap.getBootstrapSecureHost()); |
167 | - bsServ.setPort(contextBootStrap.getBootstrapSecurePort()); | |
169 | + bsServ.setPort(contextBootStrap.getBootstrapSecurePortRpk()); | |
168 | 170 | bsServ.setServerPublicKey(getRPKPublicKey(this.contextBootStrap.getBootstrapPublicX(), this.contextBootStrap.getBootstrapPublicY())); |
169 | 171 | break; |
170 | 172 | case X509: |
171 | 173 | bsServ.setHost(contextBootStrap.getBootstrapSecureHost()); |
172 | - bsServ.setPort(contextBootStrap.getBootstrapSecurePortCert()); | |
174 | + bsServ.setPort(contextBootStrap.getBootstrapSecurePortX509()); | |
173 | 175 | bsServ.setServerPublicKey(getServerPublicKeyX509(contextBootStrap.getBootstrapAlias())); |
174 | 176 | break; |
175 | 177 | default: |
176 | 178 | break; |
177 | 179 | } |
178 | 180 | } else { |
179 | - bsServ.setBootstrapServerIs(bootstrapServerIs); | |
180 | - bsServ.setServerId(123); | |
181 | + bsServ.setServerId(contextServer.getServerId()); | |
181 | 182 | switch (mode) { |
182 | 183 | case NO_SEC: |
183 | 184 | bsServ.setHost(contextServer.getServerHost()); |
184 | - bsServ.setPort(contextServer.getServerPort()); | |
185 | + bsServ.setPort(contextServer.getServerPortNoSecPsk()); | |
185 | 186 | bsServ.setServerPublicKey(""); |
186 | 187 | break; |
187 | 188 | case PSK: |
188 | 189 | bsServ.setHost(contextServer.getServerSecureHost()); |
189 | - bsServ.setPort(contextServer.getServerSecurePort()); | |
190 | + bsServ.setPort(contextServer.getServerPortPsk()); | |
190 | 191 | bsServ.setServerPublicKey(""); |
191 | 192 | break; |
192 | 193 | case RPK: |
193 | 194 | bsServ.setHost(contextServer.getServerSecureHost()); |
194 | - bsServ.setPort(contextServer.getServerSecurePort()); | |
195 | + bsServ.setPort(contextServer.getServerPortRpk()); | |
195 | 196 | bsServ.setServerPublicKey(getRPKPublicKey(this.contextServer.getServerPublicX(), this.contextServer.getServerPublicY())); |
196 | 197 | break; |
197 | 198 | case X509: |
198 | 199 | bsServ.setHost(contextServer.getServerSecureHost()); |
199 | - bsServ.setPort(contextServer.getServerSecurePortCert()); | |
200 | + bsServ.setPort(contextServer.getServerPortX509()); | |
200 | 201 | bsServ.setServerPublicKey(getServerPublicKeyX509(contextServer.getServerAlias())); |
201 | 202 | break; |
202 | 203 | default: | ... | ... |
... | ... | @@ -575,7 +575,13 @@ transport: |
575 | 575 | timeout: "${LWM2M_TIMEOUT:120000}" |
576 | 576 | # model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}" |
577 | 577 | model_path_file: "${LWM2M_MODEL_PATH_FILE:}" |
578 | - support_deprecated_ciphers_enable: "${LWM2M_SUPPORT_DEPRECATED_CIPHERS_ENABLED:true}" | |
578 | + recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}" | |
579 | + recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:false}" | |
580 | + request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}" | |
581 | + request_error_pool_size: "${LWM2M_REQUEST_ERROR_POOL_SIZE:10}" | |
582 | + registered_pool_size: "${LWM2M_REGISTERED_POOL_SIZE:10}" | |
583 | + update_registered_pool_size: "${LWM2M_UPDATE_REGISTERED_POOL_SIZE:10}" | |
584 | + un_registered_pool_size: "${LWM2M_UN_REGISTERED_POOL_SIZE:10}" | |
579 | 585 | secure: |
580 | 586 | # Only Certificate_x509: |
581 | 587 | # To get helps about files format and how to generate it, see: https://github.com/eclipse/leshan/wiki/Credential-files-format |
... | ... | @@ -588,24 +594,19 @@ transport: |
588 | 594 | root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}" |
589 | 595 | enable_gen_psk_rpk: "${ENABLE_GEN_PSK_RPK:true}" |
590 | 596 | server: |
597 | + id: "${LWM2M_SERVER_ID:123}" | |
591 | 598 | bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" |
592 | - bind_port: "${LWM2M_BIND_PORT:5685}" | |
593 | - bind_port_cert: "${LWM2M_BIND_PORT_CERT:5687}" | |
599 | + bind_port_no_sec_psk: "${LWM2M_BIND_PORT_NO_SEC_PSK:5685}" | |
600 | + bind_port_no_sec_rpk: "${LWM2M_BIND_PORT_NO_SEC_RPK:5687}" | |
601 | + bind_port_no_sec_x509: "${LWM2M_BIND_PORT_NO_SEC_X509:5689}" | |
594 | 602 | secure: |
595 | - start_all: "${START_SERVER_ALL:true}" | |
596 | - #leshan.core (V1_1) | |
597 | - #DTLS security modes: | |
598 | - #0: Pre-Shared Key mode | |
599 | - #1: Raw Public Key mode | |
600 | - #2: Certificate mode X509 | |
601 | - #3: NoSec mode * | |
602 | - #OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A (add) | |
603 | - #4: Certificate mode X509 with EST | |
604 | - # If only startAll == false | |
605 | - dtls_mode: "${LWM2M_SECURITY_MODE:1}" | |
606 | 603 | bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" |
607 | - bind_port: "${LWM2M_BIND_PORT_SEC:5686}" | |
608 | - bind_port_cert: "${LWM2M_BIND_PORT_SEC_CERT:5688}" | |
604 | + start_psk: "${START_SERVER_PSK:true}" | |
605 | + start_rpk: "${START_SERVER_RPK:true}" | |
606 | + start_x509: "${START_SERVER_X509:true}" | |
607 | + bind_port_psk: "${LWM2M_BIND_PORT_SEC_PSK:5686}" | |
608 | + bind_port_rpk: "${LWM2M_BIND_PORT_SEC_RPK:5688}" | |
609 | + bind_port_x509: "${LWM2M_BIND_PORT_SEC_X509:5690}" | |
609 | 610 | # Only RPK: Public & Private Key |
610 | 611 | # create_rpk: "${CREATE_RPK:}" |
611 | 612 | public_x: "${LWM2M_SERVER_PUBLIC_X:405354ea8893471d9296afbc8b020a5c6201b0bb25812a53b849d4480fa5f069}" |
... | ... | @@ -615,16 +616,19 @@ transport: |
615 | 616 | alias: "${LWM2M_KEYSTORE_ALIAS_SERVER:server}" |
616 | 617 | bootstrap: |
617 | 618 | enable: "${BOOTSTRAP:true}" |
619 | + id: "${LWM2M_SERVER_ID:111}" | |
618 | 620 | bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}" |
619 | - bind_port: "${LWM2M_BIND_PORT_BS:5689}" | |
620 | - bind_port_cert: "${LWM2M_BIND_PORT_SER_BS:5691}" | |
621 | + bind_port_no_sec_psk: "${LWM2M_BIND_PORT_NO_SEC_BS:5691}" | |
622 | + bind_port_no_sec_rpk: "${LWM2M_BIND_PORT_NO_SEC_BS:5693}" | |
623 | + bind_port_no_sec_x509: "${LWM2M_BIND_PORT_NO_SEC_BS:5695}" | |
621 | 624 | secure: |
622 | - start_all: "${START_BOOTSTRAP_ALL:true}" | |
623 | - # If only startAll == false | |
624 | - dtls_mode: "${LWM2M_SECURITY_MODE_BS:1}" | |
625 | 625 | bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}" |
626 | - bind_port: "${LWM2M_BIND_PORT_SEC_BS:5690}" | |
627 | - bind_port_cert: "${LWM2M_BIND_PORT_SEC_CERT_BS:5692}" | |
626 | + start_psk: "${START_SERVER_PSK_BS:true}" | |
627 | + start_rpk: "${START_SERVER_RPK_BS:true}" | |
628 | + start_x509: "${START_SERVER_X509_BS:true}" | |
629 | + bind_port_psk: "${LWM2M_BIND_PORT_SEC_PSK_BS:5692}" | |
630 | + bind_port_rpk: "${LWM2M_BIND_PORT_SER_RPK_BS:5694}" | |
631 | + bind_port_x509: "${LWM2M_BIND_PORT_SEC_X509_BS:5696}" | |
628 | 632 | # Only RPK: Public & Private Key |
629 | 633 | public_x: "${LWM2M_SERVER_PUBLIC_X_BS:993ef2b698c6a9c0c1d8be78b13a9383c0854c7c7c7a504d289b403794648183}" |
630 | 634 | public_y: "${LWM2M_SERVER_PUBLIC_Y_BS:267412d5fc4e5ceb2257cb7fd7f76ebdac2fa9aa100afb162e990074cc0bfaa2}" | ... | ... |
... | ... | @@ -101,6 +101,14 @@ |
101 | 101 | </dependency> |
102 | 102 | <dependency> |
103 | 103 | <groupId>org.eclipse.californium</groupId> |
104 | + <artifactId>californium-core</artifactId> | |
105 | + </dependency> | |
106 | +<!-- <dependency>--> | |
107 | +<!-- <groupId>org.eclipse.californium</groupId>--> | |
108 | +<!-- <artifactId>scandium</artifactId>--> | |
109 | +<!-- </dependency>--> | |
110 | + <dependency> | |
111 | + <groupId>org.eclipse.californium</groupId> | |
104 | 112 | <artifactId>element-connector</artifactId> |
105 | 113 | <type>test-jar</type> |
106 | 114 | <scope>test</scope> | ... | ... |
... | ... | @@ -52,7 +52,9 @@ import java.security.spec.ECPublicKeySpec; |
52 | 52 | import java.security.spec.KeySpec; |
53 | 53 | import java.util.Arrays; |
54 | 54 | |
55 | +import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256; | |
55 | 56 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.NO_SEC; |
57 | +import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.PSK; | |
56 | 58 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.RPK; |
57 | 59 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.X509; |
58 | 60 | import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.getCoapConfig; |
... | ... | @@ -76,27 +78,32 @@ public class LwM2MTransportBootstrapServerConfiguration { |
76 | 78 | @Autowired |
77 | 79 | private LwM2MInMemoryBootstrapConfigStore lwM2MInMemoryBootstrapConfigStore; |
78 | 80 | |
79 | - | |
80 | 81 | @Primary |
81 | - @Bean(name = "leshanBootstrapCert") | |
82 | - public LeshanBootstrapServer getLeshanBootstrapServerCert() { | |
83 | - log.info("Prepare and start BootstrapServerCert... PostConstruct"); | |
84 | - return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortCert(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortCert(), X509); | |
82 | + @Bean(name = "leshanBootstrapX509") | |
83 | + public LeshanBootstrapServer getLeshanBootstrapServerX509() { | |
84 | + log.info("Prepare and start BootstrapServerX509... PostConstruct"); | |
85 | + return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecX509(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortX509(), X509); | |
86 | + } | |
87 | + | |
88 | + @Bean(name = "leshanBootstrapPsk") | |
89 | + public LeshanBootstrapServer getLeshanBootstrapServerPsk() { | |
90 | + log.info("Prepare and start BootstrapServerRsk... PostConstruct"); | |
91 | + return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecPsk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortPsk(), PSK); | |
85 | 92 | } |
86 | 93 | |
87 | - @Bean(name = "leshanBootstrapRPK") | |
88 | - public LeshanBootstrapServer getLeshanBootstrapServerRPK() { | |
89 | - log.info("Prepare and start BootstrapServerRPK... PostConstruct"); | |
90 | - return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPort(), this.contextBs.getCtxBootStrap().getBootstrapSecurePort(), RPK); | |
94 | + @Bean(name = "leshanBootstrapRpk") | |
95 | + public LeshanBootstrapServer getLeshanBootstrapServerRpk() { | |
96 | + log.info("Prepare and start BootstrapServerRpk... PostConstruct"); | |
97 | + return getLeshanBootstrapServer(this.contextBs.getCtxBootStrap().getBootstrapPortNoSecRpk(), this.contextBs.getCtxBootStrap().getBootstrapSecurePortRpk(), RPK); | |
91 | 98 | } |
92 | 99 | |
93 | - public LeshanBootstrapServer getLeshanBootstrapServer(Integer bootstrapPort, Integer bootstrapSecurePort, LwM2MSecurityMode dtlsMode) { | |
100 | + public LeshanBootstrapServer getLeshanBootstrapServer(Integer bootstrapPortNoSec, Integer bootstrapSecurePort, LwM2MSecurityMode dtlsMode) { | |
94 | 101 | LeshanBootstrapServerBuilder builder = new LeshanBootstrapServerBuilder(); |
95 | - builder.setLocalAddress(this.contextBs.getCtxBootStrap().getBootstrapHost(), bootstrapPort); | |
102 | + builder.setLocalAddress(this.contextBs.getCtxBootStrap().getBootstrapHost(), bootstrapPortNoSec); | |
96 | 103 | builder.setLocalSecureAddress(this.contextBs.getCtxBootStrap().getBootstrapSecureHost(), bootstrapSecurePort); |
97 | 104 | |
98 | 105 | /** Create CoAP Config */ |
99 | - builder.setCoapConfig(getCoapConfig ()); | |
106 | + builder.setCoapConfig(getCoapConfig (bootstrapPortNoSec, bootstrapSecurePort)); | |
100 | 107 | |
101 | 108 | /** ConfigStore */ |
102 | 109 | builder.setConfigStore(lwM2MInMemoryBootstrapConfigStore); |
... | ... | @@ -107,13 +114,22 @@ public class LwM2MTransportBootstrapServerConfiguration { |
107 | 114 | /** Define model provider (Create Models )*/ |
108 | 115 | builder.setModel(new StaticModel(contextS.getCtxServer().getModelsValue())); |
109 | 116 | |
117 | + /** Create credentials */ | |
118 | + LwM2MSetSecurityStoreBootstrap(builder, dtlsMode); | |
119 | + | |
110 | 120 | /** Create and Set DTLS Config */ |
111 | 121 | DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); |
112 | - dtlsConfig.setRecommendedCipherSuitesOnly(contextS.getCtxServer().isSupportDeprecatedCiphersEnable()); | |
122 | + if (dtlsMode==PSK) { | |
123 | + dtlsConfig.setRecommendedCipherSuitesOnly(this.contextS.getCtxServer().isRecommendedCiphers()); | |
124 | + dtlsConfig.setRecommendedSupportedGroupsOnly(this.contextS.getCtxServer().isRecommendedSupportedGroups()); | |
125 | + dtlsConfig.setSupportedCipherSuites(TLS_PSK_WITH_AES_128_CBC_SHA256); | |
126 | + } | |
127 | + else { | |
128 | + dtlsConfig.setRecommendedCipherSuitesOnly(this.contextS.getCtxServer().isRecommendedCiphers()); | |
129 | +// dtlsConfig.setRecommendedSupportedGroupsOnly(false); | |
130 | + } | |
113 | 131 | builder.setDtlsConfig(dtlsConfig); |
114 | 132 | |
115 | - /** Create credentials */ | |
116 | - LwM2MSetSecurityStoreBootstrap(builder, dtlsMode); | |
117 | 133 | |
118 | 134 | BootstrapSessionManager sessionManager = new LwM2mDefaultBootstrapSessionManager(lwM2MBootstrapSecurityStore); |
119 | 135 | builder.setSessionManager(sessionManager); |
... | ... | @@ -133,6 +149,7 @@ public class LwM2MTransportBootstrapServerConfiguration { |
133 | 149 | break; |
134 | 150 | /** Use PSK/RPK */ |
135 | 151 | case PSK: |
152 | + break; | |
136 | 153 | case RPK: |
137 | 154 | setRPK(builder); |
138 | 155 | break; | ... | ... |
... | ... | @@ -14,13 +14,13 @@ |
14 | 14 | * limitations under the License. |
15 | 15 | */ |
16 | 16 | package org.thingsboard.server.transport.lwm2m.bootstrap; |
17 | + | |
17 | 18 | import lombok.extern.slf4j.Slf4j; |
18 | 19 | import org.eclipse.leshan.server.californium.bootstrap.LeshanBootstrapServer; |
19 | 20 | import org.springframework.beans.factory.annotation.Autowired; |
20 | 21 | import org.springframework.beans.factory.annotation.Qualifier; |
21 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
22 | 23 | import org.springframework.stereotype.Service; |
23 | -import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; | |
24 | 24 | |
25 | 25 | import javax.annotation.PostConstruct; |
26 | 26 | import javax.annotation.PreDestroy; |
... | ... | @@ -31,40 +31,39 @@ import javax.annotation.PreDestroy; |
31 | 31 | public class LwM2MTransportBootstrapServerInitializer { |
32 | 32 | |
33 | 33 | @Autowired |
34 | - @Qualifier("leshanBootstrapCert") | |
34 | + @Qualifier("leshanBootstrapX509") | |
35 | 35 | private LeshanBootstrapServer lhBServerCert; |
36 | 36 | |
37 | 37 | @Autowired |
38 | - @Qualifier("leshanBootstrapRPK") | |
39 | - private LeshanBootstrapServer lhBServerRPK; | |
38 | + @Qualifier("leshanBootstrapPsk") | |
39 | + private LeshanBootstrapServer lhBServerPsk; | |
40 | + | |
41 | + @Autowired | |
42 | + @Qualifier("leshanBootstrapRpk") | |
43 | + private LeshanBootstrapServer lhBServerRpk; | |
40 | 44 | |
41 | 45 | @Autowired |
42 | 46 | private LwM2MTransportContextBootstrap contextBS; |
43 | 47 | |
44 | 48 | @PostConstruct |
45 | 49 | public void init() { |
46 | - if (this.contextBS.getCtxBootStrap().isBootstrapStartAll()) { | |
47 | - this.lhBServerCert.start(); | |
48 | - this.lhBServerRPK.start(); | |
50 | + if (this.contextBS.getCtxBootStrap().getBootstrapStartPsk()) { | |
51 | + this.lhBServerPsk.start(); | |
49 | 52 | } |
50 | - else { | |
51 | - if (this.contextBS.getCtxBootStrap().getBootStrapDtlsMode() == LwM2MSecurityMode.X509.code) { | |
52 | - this.lhBServerCert.start(); | |
53 | - } | |
54 | - else { | |
55 | - this.lhBServerRPK.start(); | |
56 | - } | |
53 | + if (this.contextBS.getCtxBootStrap().getBootstrapStartRpk()) { | |
54 | + this.lhBServerRpk.start(); | |
55 | + } | |
56 | + if (this.contextBS.getCtxBootStrap().getBootstrapStartX509()) { | |
57 | + this.lhBServerCert.start(); | |
57 | 58 | } |
58 | 59 | } |
59 | 60 | |
60 | 61 | @PreDestroy |
61 | 62 | public void shutdown() throws InterruptedException { |
62 | 63 | log.info("Stopping LwM2M transport Bootstrap Server!"); |
63 | - try { | |
64 | - lhBServerCert.destroy(); | |
65 | - lhBServerRPK.destroy(); | |
66 | - } finally { | |
67 | - } | |
64 | + lhBServerPsk.destroy(); | |
65 | + lhBServerRpk.destroy(); | |
66 | + lhBServerCert.destroy(); | |
68 | 67 | log.info("LwM2M transport Bootstrap Server stopped!"); |
69 | 68 | } |
70 | 69 | } | ... | ... |
... | ... | @@ -49,7 +49,6 @@ public class LwM2mDefaultBootstrapSessionManager extends DefaultBootstrapSession |
49 | 49 | this.securityChecker = securityChecker; |
50 | 50 | } |
51 | 51 | |
52 | - @Override | |
53 | 52 | public BootstrapSession begin(String endpoint, Identity clientIdentity) { |
54 | 53 | boolean authorized; |
55 | 54 | if (bsSecurityStore != null) { | ... | ... |
... | ... | @@ -141,7 +141,7 @@ public class LwM2MTransportHandler { |
141 | 141 | // } |
142 | 142 | // } |
143 | 143 | |
144 | - public static NetworkConfig getCoapConfig() { | |
144 | + public static NetworkConfig getCoapConfig(Integer serverPortNoSec, Integer serverSecurePort) { | |
145 | 145 | NetworkConfig coapConfig; |
146 | 146 | File configFile = new File(NetworkConfig.DEFAULT_FILE_NAME); |
147 | 147 | if (configFile.isFile()) { |
... | ... | @@ -151,6 +151,8 @@ public class LwM2MTransportHandler { |
151 | 151 | coapConfig = LeshanServerBuilder.createDefaultNetworkConfig(); |
152 | 152 | coapConfig.store(configFile); |
153 | 153 | } |
154 | + coapConfig.setString("COAP_PORT", Integer.toString(serverPortNoSec)); | |
155 | + coapConfig.setString("COAP_SECURE_PORT", Integer.toString(serverSecurePort)); | |
154 | 156 | return coapConfig; |
155 | 157 | } |
156 | 158 | ... | ... |
... | ... | @@ -88,12 +88,15 @@ public class LwM2MTransportRequest { |
88 | 88 | @Autowired |
89 | 89 | LwM2MTransportServiceImpl service; |
90 | 90 | |
91 | + @Autowired | |
92 | + public LwM2MTransportContextServer context; | |
93 | + | |
91 | 94 | @PostConstruct |
92 | 95 | public void init() { |
93 | 96 | this.converter = LwM2mValueConverterImpl.getInstance(); |
94 | - executorResponse = Executors.newFixedThreadPool(10, | |
97 | + executorResponse = Executors.newFixedThreadPool(this.context.getCtxServer().getRequestPoolSize(), | |
95 | 98 | new NamedThreadFactory(String.format("LwM2M %s channel response", RESPONSE_CHANNEL))); |
96 | - executorResponseError = Executors.newFixedThreadPool(10, | |
99 | + executorResponseError = Executors.newFixedThreadPool(this.context.getCtxServer().getRequestErrorPoolSize(), | |
97 | 100 | new NamedThreadFactory(String.format("LwM2M %s channel response Error", RESPONSE_CHANNEL))); |
98 | 101 | } |
99 | 102 | ... | ... |
... | ... | @@ -62,6 +62,8 @@ import java.security.spec.ECPublicKeySpec; |
62 | 62 | import java.security.spec.KeySpec; |
63 | 63 | import java.util.Arrays; |
64 | 64 | |
65 | +import static org.eclipse.californium.scandium.dtls.cipher.CipherSuite.TLS_PSK_WITH_AES_128_CBC_SHA256; | |
66 | +import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.PSK; | |
65 | 67 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.RPK; |
66 | 68 | import static org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode.X509; |
67 | 69 | import static org.thingsboard.server.transport.lwm2m.server.LwM2MTransportHandler.getCoapConfig; |
... | ... | @@ -83,24 +85,27 @@ public class LwM2MTransportServerConfiguration { |
83 | 85 | private LwM2mInMemorySecurityStore lwM2mInMemorySecurityStore; |
84 | 86 | |
85 | 87 | @Primary |
86 | - @Bean(name = "LeshanServerCert") | |
87 | - public LeshanServer getLeshanServerCert() { | |
88 | - log.info("Starting LwM2M transport ServerCert... PostConstruct"); | |
89 | - LeshanServer leshanServerCert = getLeshanServer(this.context.getCtxServer().getServerPortCert(), this.context.getCtxServer().getServerSecurePortCert(), X509); | |
90 | - | |
91 | - return leshanServerCert; | |
88 | + @Bean(name = "leshanServerX509") | |
89 | + public LeshanServer getLeshanServerX509() { | |
90 | + log.info("Starting LwM2M transport ServerX509... PostConstruct"); | |
91 | + return getLeshanServer(this.context.getCtxServer().getServerPortNoSecX509(), this.context.getCtxServer().getServerPortX509(), X509); | |
92 | 92 | } |
93 | 93 | |
94 | - @Bean(name = "LeshanServerNoSecPskRpk") | |
95 | - public LeshanServer getLeshanServerNoSecPskRpk() { | |
96 | - log.info("Starting LwM2M transport ServerNoSecPskRpk... PostConstruct"); | |
97 | - return getLeshanServer(this.context.getCtxServer().getServerPort(), this.context.getCtxServer().getServerSecurePort(), RPK); | |
94 | + @Bean(name = "leshanServerPsk") | |
95 | + public LeshanServer getLeshanServerPsk() { | |
96 | + log.info("Starting LwM2M transport ServerPsk... PostConstruct"); | |
97 | + return getLeshanServer(this.context.getCtxServer().getServerPortNoSecPsk(), this.context.getCtxServer().getServerPortPsk(), PSK); | |
98 | 98 | } |
99 | 99 | |
100 | - private LeshanServer getLeshanServer(Integer serverPort, Integer serverSecurePort, LwM2MSecurityMode dtlsMode) { | |
100 | + @Bean(name = "leshanServerRpk") | |
101 | + public LeshanServer getLeshanServerRpk() { | |
102 | + log.info("Starting LwM2M transport ServerRpk... PostConstruct"); | |
103 | + return getLeshanServer(this.context.getCtxServer().getServerPortNoSecRpk(), this.context.getCtxServer().getServerPortRpk(), RPK); | |
104 | + } | |
101 | 105 | |
106 | + private LeshanServer getLeshanServer(Integer serverPortNoSec, Integer serverSecurePort, LwM2MSecurityMode dtlsMode) { | |
102 | 107 | LeshanServerBuilder builder = new LeshanServerBuilder(); |
103 | - builder.setLocalAddress(this.context.getCtxServer().getServerHost(), serverPort); | |
108 | + builder.setLocalAddress(this.context.getCtxServer().getServerHost(), serverPortNoSec); | |
104 | 109 | builder.setLocalSecureAddress(this.context.getCtxServer().getServerSecureHost(), serverSecurePort); |
105 | 110 | builder.setEncoder(new DefaultLwM2mNodeEncoder()); |
106 | 111 | LwM2mNodeDecoder decoder = new DefaultLwM2mNodeDecoder(); |
... | ... | @@ -108,43 +113,47 @@ public class LwM2MTransportServerConfiguration { |
108 | 113 | builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance())); |
109 | 114 | |
110 | 115 | /** Create CoAP Config */ |
111 | - builder.setCoapConfig(getCoapConfig()); | |
116 | + builder.setCoapConfig(getCoapConfig(serverPortNoSec, serverSecurePort)); | |
112 | 117 | |
113 | 118 | /** Define model provider (Create Models )*/ |
114 | 119 | LwM2mModelProvider modelProvider = new VersionedModelProvider(this.context.getCtxServer().getModelsValue()); |
115 | 120 | builder.setObjectModelProvider(modelProvider); |
116 | 121 | |
122 | + /** Create DTLS security mode | |
123 | + * There can be only one DTLS security mode | |
124 | + */ | |
125 | + this.LwM2MSetSecurityStoreServer(builder, dtlsMode); | |
126 | + | |
117 | 127 | /** Create DTLS Config */ |
118 | 128 | DtlsConnectorConfig.Builder dtlsConfig = new DtlsConnectorConfig.Builder(); |
119 | - dtlsConfig.setRecommendedCipherSuitesOnly(this.context.getCtxServer().isSupportDeprecatedCiphersEnable()); | |
129 | + if (dtlsMode==PSK) { | |
130 | + dtlsConfig.setRecommendedCipherSuitesOnly(this.context.getCtxServer().isRecommendedCiphers()); | |
131 | + dtlsConfig.setRecommendedSupportedGroupsOnly(this.context.getCtxServer().isRecommendedSupportedGroups()); | |
132 | + dtlsConfig.setSupportedCipherSuites(TLS_PSK_WITH_AES_128_CBC_SHA256); | |
133 | + } | |
134 | + else { | |
135 | + dtlsConfig.setRecommendedSupportedGroupsOnly(!this.context.getCtxServer().isRecommendedSupportedGroups()); | |
136 | + dtlsConfig.setRecommendedCipherSuitesOnly(!this.context.getCtxServer().isRecommendedCiphers()); | |
137 | + } | |
120 | 138 | /** Set DTLS Config */ |
121 | 139 | builder.setDtlsConfig(dtlsConfig); |
122 | 140 | |
123 | 141 | /** Use a magic converter to support bad type send by the UI. */ |
124 | 142 | builder.setEncoder(new DefaultLwM2mNodeEncoder(LwM2mValueConverterImpl.getInstance())); |
125 | 143 | |
126 | - /** Create DTLS security mode | |
127 | - * There can be only one DTLS security mode | |
128 | - */ | |
129 | - this.LwM2MSetSecurityStoreServer(builder, dtlsMode); | |
130 | 144 | |
131 | 145 | /** Create LWM2M server */ |
132 | 146 | return builder.build(); |
133 | 147 | } |
134 | 148 | |
135 | - private void LwM2MSetSecurityStoreServer(LeshanServerBuilder builder, LwM2MSecurityMode dtlsMode) { | |
149 | + private void LwM2MSetSecurityStoreServer(LeshanServerBuilder builder, LwM2MSecurityMode dtlsMode) { | |
136 | 150 | /** Set securityStore with new registrationStore */ |
137 | 151 | EditableSecurityStore securityStore = lwM2mInMemorySecurityStore; |
138 | - | |
139 | 152 | switch (dtlsMode) { |
140 | 153 | /** Use PSK only */ |
141 | 154 | case PSK: |
142 | 155 | generatePSK_RPK(); |
143 | - if (this.privateKey != null && this.privateKey.getEncoded().length > 0) { | |
144 | - builder.setPrivateKey(this.privateKey); | |
145 | - builder.setPublicKey(null); | |
146 | - infoParamsPSK(); | |
147 | - } | |
156 | + infoParamsPSK(); | |
148 | 157 | break; |
149 | 158 | /** Use RPK only */ |
150 | 159 | case RPK: |
... | ... | @@ -233,7 +242,7 @@ public class LwM2MTransportServerConfiguration { |
233 | 242 | private void infoParamsPSK() { |
234 | 243 | log.info("\nServer uses PSK -> private key : \n security key : [{}] \n serverSecureURI : [{}]", |
235 | 244 | Hex.encodeHexString(this.privateKey.getEncoded()), |
236 | - this.context.getCtxServer().getServerSecureHost() + ":" + Integer.toString(this.context.getCtxServer().getServerSecurePort())); | |
245 | + this.context.getCtxServer().getServerSecureHost() + ":" + Integer.toString(this.context.getCtxServer().getServerPortPsk())); | |
237 | 246 | } |
238 | 247 | |
239 | 248 | private void infoParamsRPK() { |
... | ... | @@ -298,6 +307,4 @@ public class LwM2MTransportServerConfiguration { |
298 | 307 | log.error("[{}] Unable to load KeyStore files server", ex.getMessage()); |
299 | 308 | } |
300 | 309 | } |
301 | - | |
302 | - | |
303 | 310 | } | ... | ... |
... | ... | @@ -22,7 +22,6 @@ import org.springframework.beans.factory.annotation.Qualifier; |
22 | 22 | import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression; |
23 | 23 | import org.springframework.stereotype.Component; |
24 | 24 | import org.thingsboard.server.transport.lwm2m.secure.LWM2MGenerationPSkRPkECC; |
25 | -import org.thingsboard.server.transport.lwm2m.secure.LwM2MSecurityMode; | |
26 | 25 | |
27 | 26 | import javax.annotation.PostConstruct; |
28 | 27 | import javax.annotation.PreDestroy; |
... | ... | @@ -37,12 +36,16 @@ public class LwM2MTransportServerInitializer { |
37 | 36 | private LwM2MTransportServiceImpl service; |
38 | 37 | |
39 | 38 | @Autowired |
40 | - @Qualifier("LeshanServerCert") | |
41 | - private LeshanServer lhServerCert; | |
39 | + @Qualifier("leshanServerX509") | |
40 | + private LeshanServer lhServerX509; | |
42 | 41 | |
43 | 42 | @Autowired |
44 | - @Qualifier("LeshanServerNoSecPskRpk") | |
45 | - private LeshanServer lhServerNoSecPskRpk; | |
43 | + @Qualifier("leshanServerPsk") | |
44 | + private LeshanServer lhServerPsk; | |
45 | + | |
46 | + @Autowired | |
47 | + @Qualifier("leshanServerRpk") | |
48 | + private LeshanServer lhServerRpk; | |
46 | 49 | |
47 | 50 | @Autowired |
48 | 51 | private LwM2MTransportContextServer context; |
... | ... | @@ -50,39 +53,47 @@ public class LwM2MTransportServerInitializer { |
50 | 53 | @PostConstruct |
51 | 54 | public void init() { |
52 | 55 | if (this.context.getCtxServer().getEnableGenPskRpk()) new LWM2MGenerationPSkRPkECC(); |
53 | - if (this.context.getCtxServer().isServerStartAll()) { | |
54 | - this.startLhServerCert(); | |
55 | - this.startLhServerNoSecPskRpk(); | |
56 | - } else { | |
57 | - if (this.context.getCtxServer().getServerDtlsMode() == LwM2MSecurityMode.X509.code) { | |
58 | - this.startLhServerCert(); | |
59 | - } else { | |
60 | - this.startLhServerNoSecPskRpk(); | |
61 | - } | |
56 | + if (this.context.getCtxServer().isServerStartPsk()) { | |
57 | + this.startLhServerPsk(); | |
58 | + } | |
59 | + if (this.context.getCtxServer().isServerStartRpk()) { | |
60 | + this.startLhServerRpk(); | |
62 | 61 | } |
62 | + if (this.context.getCtxServer().isServerStartX509()) { | |
63 | + this.startLhServerX509(); | |
64 | + } | |
65 | + } | |
66 | + | |
67 | + private void startLhServerPsk() { | |
68 | + this.lhServerPsk.start(); | |
69 | + LwM2mServerListener lhServerPskListener = new LwM2mServerListener(this.lhServerPsk, service); | |
70 | + this.lhServerPsk.getRegistrationService().addListener(lhServerPskListener.registrationListener); | |
71 | + this.lhServerPsk.getPresenceService().addListener(lhServerPskListener.presenceListener); | |
72 | + this.lhServerPsk.getObservationService().addListener(lhServerPskListener.observationListener); | |
63 | 73 | } |
64 | 74 | |
65 | - private void startLhServerCert() { | |
66 | - this.lhServerCert.start(); | |
67 | - LwM2mServerListener lhServerCertListener = new LwM2mServerListener(this.lhServerCert, service); | |
68 | - this.lhServerCert.getRegistrationService().addListener(lhServerCertListener.registrationListener); | |
69 | - this.lhServerCert.getPresenceService().addListener(lhServerCertListener.presenceListener); | |
70 | - this.lhServerCert.getObservationService().addListener(lhServerCertListener.observationListener); | |
75 | + private void startLhServerRpk() { | |
76 | + this.lhServerRpk.start(); | |
77 | + LwM2mServerListener lhServerRpkListener = new LwM2mServerListener(this.lhServerRpk, service); | |
78 | + this.lhServerRpk.getRegistrationService().addListener(lhServerRpkListener.registrationListener); | |
79 | + this.lhServerRpk.getPresenceService().addListener(lhServerRpkListener.presenceListener); | |
80 | + this.lhServerRpk.getObservationService().addListener(lhServerRpkListener.observationListener); | |
71 | 81 | } |
72 | 82 | |
73 | - private void startLhServerNoSecPskRpk() { | |
74 | - this.lhServerNoSecPskRpk.start(); | |
75 | - LwM2mServerListener lhServerNoSecPskRpkListener = new LwM2mServerListener(this.lhServerNoSecPskRpk, service); | |
76 | - this.lhServerNoSecPskRpk.getRegistrationService().addListener(lhServerNoSecPskRpkListener.registrationListener); | |
77 | - this.lhServerNoSecPskRpk.getPresenceService().addListener(lhServerNoSecPskRpkListener.presenceListener); | |
78 | - this.lhServerNoSecPskRpk.getObservationService().addListener(lhServerNoSecPskRpkListener.observationListener); | |
83 | + private void startLhServerX509() { | |
84 | + this.lhServerX509.start(); | |
85 | + LwM2mServerListener lhServerCertListener = new LwM2mServerListener(this.lhServerX509, service); | |
86 | + this.lhServerX509.getRegistrationService().addListener(lhServerCertListener.registrationListener); | |
87 | + this.lhServerX509.getPresenceService().addListener(lhServerCertListener.presenceListener); | |
88 | + this.lhServerX509.getObservationService().addListener(lhServerCertListener.observationListener); | |
79 | 89 | } |
80 | 90 | |
81 | 91 | @PreDestroy |
82 | 92 | public void shutdown() { |
83 | 93 | log.info("Stopping LwM2M transport Server!"); |
84 | - lhServerCert.destroy(); | |
85 | - lhServerNoSecPskRpk.destroy(); | |
94 | + lhServerPsk.destroy(); | |
95 | + lhServerRpk.destroy(); | |
96 | + lhServerX509.destroy(); | |
86 | 97 | log.info("LwM2M transport Server stopped!"); |
87 | 98 | } |
88 | 99 | } | ... | ... |
... | ... | @@ -32,7 +32,7 @@ public interface LwM2MTransportService { |
32 | 32 | |
33 | 33 | void updatedReg(LeshanServer lwServer, Registration registration); |
34 | 34 | |
35 | - void unReg(Registration registration, Collection<Observation> observations); | |
35 | + void unReg(LeshanServer lwServer, Registration registration, Collection<Observation> observations); | |
36 | 36 | |
37 | 37 | void onSleepingDev(Registration registration); |
38 | 38 | ... | ... |
... | ... | @@ -20,7 +20,6 @@ import com.google.gson.JsonArray; |
20 | 20 | import com.google.gson.JsonElement; |
21 | 21 | import com.google.gson.JsonObject; |
22 | 22 | import lombok.extern.slf4j.Slf4j; |
23 | -import org.eclipse.leshan.core.Link; | |
24 | 23 | import org.eclipse.leshan.core.model.ResourceModel; |
25 | 24 | import org.eclipse.leshan.core.node.LwM2mMultipleResource; |
26 | 25 | import org.eclipse.leshan.core.node.LwM2mObject; |
... | ... | @@ -57,6 +56,7 @@ import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; |
57 | 56 | |
58 | 57 | import javax.annotation.PostConstruct; |
59 | 58 | import java.util.ArrayList; |
59 | +import java.util.Arrays; | |
60 | 60 | import java.util.Collection; |
61 | 61 | import java.util.HashSet; |
62 | 62 | import java.util.LinkedHashSet; |
... | ... | @@ -120,11 +120,11 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
120 | 120 | @PostConstruct |
121 | 121 | public void init() { |
122 | 122 | this.context.getScheduler().scheduleAtFixedRate(this::checkInactivityAndReportActivity, new Random().nextInt((int) context.getCtxServer().getSessionReportTimeout()), context.getCtxServer().getSessionReportTimeout(), TimeUnit.MILLISECONDS); |
123 | - this.executorRegistered = Executors.newFixedThreadPool(10, | |
123 | + this.executorRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getRegisteredPoolSize(), | |
124 | 124 | new NamedThreadFactory(String.format("LwM2M %s channel registered", SERVICE_CHANNEL))); |
125 | - this.executorUpdateRegistered = Executors.newFixedThreadPool(10, | |
125 | + this.executorUpdateRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUpdateRegisteredPoolSize(), | |
126 | 126 | new NamedThreadFactory(String.format("LwM2M %s channel update registered", SERVICE_CHANNEL))); |
127 | - this.executorUnRegistered = Executors.newFixedThreadPool(10, | |
127 | + this.executorUnRegistered = Executors.newFixedThreadPool(this.context.getCtxServer().getUnRegisteredPoolSize(), | |
128 | 128 | new NamedThreadFactory(String.format("LwM2M %s channel un registered", SERVICE_CHANNEL))); |
129 | 129 | this.converter = LwM2mValueConverterImpl.getInstance(); |
130 | 130 | } |
... | ... | @@ -147,13 +147,13 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
147 | 147 | public void onRegistered(LeshanServer lwServer, Registration registration, Collection<Observation> previousObsersations) { |
148 | 148 | executorRegistered.submit(() -> { |
149 | 149 | try { |
150 | - log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); | |
150 | +// log.warn("[{}] [{{}] Client: create after Registration", registration.getEndpoint(), registration.getId()); | |
151 | 151 | LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.updateInSessionsLwM2MClient(lwServer, registration); |
152 | 152 | if (lwM2MClient != null) { |
153 | 153 | lwM2MClient.setLwM2MTransportServiceImpl(this); |
154 | 154 | lwM2MClient.setSessionUuid(UUID.randomUUID()); |
155 | 155 | this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client Registered", registration); |
156 | - this.setLwM2MClient(lwServer, registration, lwM2MClient); | |
156 | +// this.setLwM2MClient(lwServer, registration, lwM2MClient); | |
157 | 157 | SessionInfoProto sessionInfo = this.getValidateSessionInfo(registration); |
158 | 158 | if (sessionInfo != null) { |
159 | 159 | lwM2MClient.setDeviceUuid(new UUID(sessionInfo.getDeviceIdMSB(), sessionInfo.getDeviceIdLSB())); |
... | ... | @@ -204,9 +204,10 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
204 | 204 | * @param observations - All paths observations before unReg |
205 | 205 | * !!! Warn: if have not finishing unReg, then this operation will be finished on next Client`s connect |
206 | 206 | */ |
207 | - public void unReg(Registration registration, Collection<Observation> observations) { | |
207 | + public void unReg(LeshanServer lwServer, Registration registration, Collection<Observation> observations) { | |
208 | 208 | executorUnRegistered.submit(() -> { |
209 | 209 | try { |
210 | + this.setCancelObservations(lwServer, registration); | |
210 | 211 | this.sentLogsToThingsboard(LOG_LW2M_INFO + ": Client unRegistration", registration); |
211 | 212 | this.closeClientSession(registration); |
212 | 213 | } catch (Throwable t) { |
... | ... | @@ -279,38 +280,49 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
279 | 280 | * @param lwM2MClient - object with All parameters off client |
280 | 281 | */ |
281 | 282 | private void setLwM2MClient(LeshanServer lwServer, Registration registration, LwM2MClient lwM2MClient) { |
282 | - // #1 | |
283 | - for (Link url : registration.getObjectLinks()) { | |
284 | - LwM2mPath pathIds = new LwM2mPath(url.getUrl()); | |
285 | - if (pathIds.isObjectInstance() && !pathIds.isResource()) { | |
286 | - lwM2MClient.getPendingRequests().add(url.getUrl()); | |
287 | - } | |
288 | - } | |
289 | - // #2 | |
290 | - for (Link url : registration.getObjectLinks()) { | |
291 | - LwM2mPath pathIds = new LwM2mPath(url.getUrl()); | |
292 | - if (pathIds.isObjectInstance() && !pathIds.isResource()) { | |
293 | - lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), | |
294 | - lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); | |
295 | - } | |
296 | - } | |
297 | - | |
298 | - // #1 | |
299 | 283 | // Arrays.stream(registration.getObjectLinks()).forEach(url -> { |
300 | 284 | // LwM2mPath pathIds = new LwM2mPath(url.getUrl()); |
301 | 285 | // if (pathIds.isObjectInstance() && !pathIds.isResource()) { |
286 | +// // #1 | |
302 | 287 | // lwM2MClient.getPendingRequests().add(url.getUrl()); |
288 | +// // #2 | |
289 | +// lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), | |
290 | +// lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); | |
303 | 291 | // } |
304 | 292 | // }); |
305 | - // #2 | |
306 | 293 | |
307 | -// Arrays.stream(registration.getObjectLinks()).forEach(url -> { | |
294 | +// // #1 | |
295 | +// for (Link url : registration.getObjectLinks()) { | |
296 | +// LwM2mPath pathIds = new LwM2mPath(url.getUrl()); | |
297 | +// if (pathIds.isObjectInstance() && !pathIds.isResource()) { | |
298 | +// lwM2MClient.getPendingRequests().add(url.getUrl()); | |
299 | +// } | |
300 | +// } | |
301 | +// // #2 | |
302 | +// for (Link url : registration.getObjectLinks()) { | |
308 | 303 | // LwM2mPath pathIds = new LwM2mPath(url.getUrl()); |
309 | 304 | // if (pathIds.isObjectInstance() && !pathIds.isResource()) { |
310 | 305 | // lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), |
311 | 306 | // lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); |
312 | 307 | // } |
313 | -// }); | |
308 | +// } | |
309 | + | |
310 | + // #1 | |
311 | + Arrays.stream(registration.getObjectLinks()).forEach(url -> { | |
312 | + LwM2mPath pathIds = new LwM2mPath(url.getUrl()); | |
313 | + if (pathIds.isObjectInstance() && !pathIds.isResource()) { | |
314 | + lwM2MClient.getPendingRequests().add(url.getUrl()); | |
315 | + } | |
316 | + }); | |
317 | + | |
318 | + // #2 | |
319 | + Arrays.stream(registration.getObjectLinks()).forEach(url -> { | |
320 | + LwM2mPath pathIds = new LwM2mPath(url.getUrl()); | |
321 | + if (pathIds.isObjectInstance() && !pathIds.isResource()) { | |
322 | + lwM2MTransportRequest.sendAllRequest(lwServer, registration, url.getUrl(), GET_TYPE_OPER_READ, ContentFormat.TLV.getName(), | |
323 | + lwM2MClient, null, null, this.context.getCtxServer().getTimeout(), false); | |
324 | + } | |
325 | + }); | |
314 | 326 | } |
315 | 327 | |
316 | 328 | /** |
... | ... | @@ -691,24 +703,29 @@ public class LwM2MTransportServiceImpl implements LwM2MTransportService { |
691 | 703 | * @param values - LwM2mSingleResource response.getContent() |
692 | 704 | * @param path - resource |
693 | 705 | */ |
694 | - private void onObservationSetResourcesValue(Registration registration, Object value, Map<Integer, ?> values, String path) { | |
706 | + private void onObservationSetResourcesValue(Registration registration, Object value, Map<Integer, ?> values, String path) { | |
695 | 707 | boolean isChange = false; |
696 | 708 | try { |
697 | 709 | writeLock.lock(); |
698 | 710 | // #1 |
699 | 711 | LwM2MClient lwM2MClient = lwM2mInMemorySecurityStore.getLwM2MClientWithReg(registration, null); |
700 | 712 | LwM2mPath pathIds = new LwM2mPath(path); |
701 | - log.warn("#0 nameDevice: [{}] resultIds: [{}] value: [{}], values: [{}] ", lwM2MClient.getDeviceName(), pathIds, value, values); | |
713 | +// log.warn("#0 nameDevice: [{}] resultIds: [{}] value: [{}], values: [{}] ", lwM2MClient.getDeviceName(), pathIds, value, values); | |
702 | 714 | ResourceModel.Type resModelType = context.getCtxServer().getResourceModelType(registration, pathIds); |
703 | 715 | ResourceValue resValueOld = lwM2MClient.getResources().get(path); |
704 | 716 | // #2 |
705 | 717 | if (resValueOld.isMultiInstances() && !values.toString().equals(resValueOld.getResourceValue().toString())) { |
706 | - ResourceValue resourceValue = new ResourceValue(values, null, true); | |
707 | - lwM2MClient.getResources().put(path, resourceValue); | |
718 | + lwM2MClient.getResources().get(path).setValues(values); | |
719 | +// ResourceValue resourceValue = new ResourceValue(values, null, true); | |
720 | +// lwM2MClient.getResources().put(path, resourceValue); | |
708 | 721 | isChange = true; |
709 | 722 | } else if (!LwM2MTransportHandler.equalsResourceValue(resValueOld.getValue(), value, resModelType, pathIds)) { |
710 | - ResourceValue resourceValue = new ResourceValue(null, value, false); | |
711 | - lwM2MClient.getResources().put(path, resourceValue); | |
723 | + lwM2MClient.getResources().get(path).setValue(value); | |
724 | +// ResourceValue resourceValueOld = lwM2MClient.getResources().get(path); | |
725 | +// lwM2MClient.getResources().remove(resourceValueOld); | |
726 | +// ResourceValue resourceValue = new ResourceValue(null, value, false); | |
727 | +// lwM2MClient.getResources().put(path, resourceValue); | |
728 | + log.warn("upDateResize: [{}] [{}] [{}] [{}]", lwM2MClient.getEndPoint(), lwM2MClient.getResources().size(), value, path); | |
712 | 729 | isChange = true; |
713 | 730 | } |
714 | 731 | } catch (Exception e) { | ... | ... |
... | ... | @@ -54,7 +54,6 @@ public class LwM2mServerListener { |
54 | 54 | @Override |
55 | 55 | public void updated(RegistrationUpdate update, Registration updatedRegistration, |
56 | 56 | Registration previousRegistration) { |
57 | - log.info("updated"); | |
58 | 57 | service.updatedReg(lhServer, updatedRegistration); |
59 | 58 | } |
60 | 59 | |
... | ... | @@ -64,8 +63,7 @@ public class LwM2mServerListener { |
64 | 63 | @Override |
65 | 64 | public void unregistered(Registration registration, Collection<Observation> observations, boolean expired, |
66 | 65 | Registration newReg) { |
67 | - log.info("unregistered"); | |
68 | - service.unReg(registration, observations); | |
66 | + service.unReg(lhServer, registration, observations); | |
69 | 67 | } |
70 | 68 | |
71 | 69 | }; | ... | ... |
... | ... | @@ -18,6 +18,7 @@ package org.thingsboard.server.transport.lwm2m.server.client; |
18 | 18 | import lombok.Data; |
19 | 19 | import lombok.extern.slf4j.Slf4j; |
20 | 20 | import org.eclipse.leshan.core.model.ObjectModel; |
21 | +import org.eclipse.leshan.core.node.LwM2mMultipleResource; | |
21 | 22 | import org.eclipse.leshan.core.node.LwM2mObjectInstance; |
22 | 23 | import org.eclipse.leshan.core.node.LwM2mPath; |
23 | 24 | import org.eclipse.leshan.core.response.LwM2mResponse; |
... | ... | @@ -104,8 +105,8 @@ public class LwM2MClient implements Cloneable { |
104 | 105 | if (objectModel != null) { |
105 | 106 | ((LwM2mObjectInstance)((ReadResponse)resp).getContent()).getResources().forEach((k, v) -> { |
106 | 107 | String rez = pathIds.toString() + "/" + k; |
107 | - if (objectModel.resources.get(k).multiple){ | |
108 | - this.resources.put(rez, new ResourceValue(v.getValues(), null, true)); | |
108 | + if (((LwM2mObjectInstance) ((ReadResponse) resp).getContent()).getResource(k) instanceof LwM2mMultipleResource){ | |
109 | +// this.resources.put(rez, new ResourceValue(v.getInstances().values(), null, true)); | |
109 | 110 | } |
110 | 111 | else { |
111 | 112 | this.resources.put(rez, new ResourceValue(null, v.getValue(), false)); |
... | ... | @@ -114,6 +115,7 @@ public class LwM2MClient implements Cloneable { |
114 | 115 | } |
115 | 116 | } |
116 | 117 | }); |
118 | + if (this.responses.size() == 0) this.responses = new ConcurrentHashMap<>(); | |
117 | 119 | } |
118 | 120 | |
119 | 121 | /** | ... | ... |
... | ... | @@ -32,39 +32,57 @@ import java.util.Map; |
32 | 32 | @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") |
33 | 33 | public class LwM2MTransportConfigBootstrap { |
34 | 34 | |
35 | - | |
36 | 35 | @Getter |
37 | - @Value("${transport.lwm2m.bootstrap.bind_address:}") | |
38 | - private String bootstrapHost; | |
36 | + @Value("${transport.lwm2m.bootstrap.enable:}") | |
37 | + private Boolean bootstrapEnable; | |
39 | 38 | |
40 | 39 | @Getter |
41 | - @Value("${transport.lwm2m.bootstrap.bind_port:}") | |
42 | - private Integer bootstrapPort; | |
40 | + @Value("${transport.lwm2m.bootstrap.id:}") | |
41 | + private Integer bootstrapServerId; | |
43 | 42 | |
44 | 43 | @Getter |
45 | - @Value("${transport.lwm2m.bootstrap.bind_port_cert:}") | |
46 | - private Integer bootstrapPortCert; | |
44 | + @Value("${transport.lwm2m.bootstrap.secure.start_psk:}") | |
45 | + private Boolean bootstrapStartPsk; | |
47 | 46 | |
47 | + @Getter | |
48 | + @Value("${transport.lwm2m.bootstrap.secure.start_rpk:}") | |
49 | + private Boolean bootstrapStartRpk; | |
48 | 50 | |
49 | 51 | @Getter |
50 | - @Value("${transport.lwm2m.bootstrap.secure.start_all:}") | |
51 | - private boolean bootstrapStartAll; | |
52 | + @Value("${transport.lwm2m.bootstrap.secure.start_x509:}") | |
53 | + private Boolean bootstrapStartX509; | |
52 | 54 | |
53 | 55 | @Getter |
54 | - @Value("${transport.lwm2m.bootstrap.secure.dtls_mode:}") | |
55 | - private Integer bootStrapDtlsMode; | |
56 | + @Value("${transport.lwm2m.bootstrap.bind_address:}") | |
57 | + private String bootstrapHost; | |
56 | 58 | |
57 | 59 | @Getter |
58 | 60 | @Value("${transport.lwm2m.bootstrap.secure.bind_address:}") |
59 | 61 | private String bootstrapSecureHost; |
60 | 62 | |
61 | 63 | @Getter |
62 | - @Value("${transport.lwm2m.bootstrap.secure.bind_port:}") | |
63 | - private Integer bootstrapSecurePort; | |
64 | + @Value("${transport.lwm2m.bootstrap.bind_port_no_sec_psk:}") | |
65 | + private Integer bootstrapPortNoSecPsk; | |
66 | + | |
67 | + @Getter | |
68 | + @Value("${transport.lwm2m.bootstrap.bind_port_no_sec_rpk:}") | |
69 | + private Integer bootstrapPortNoSecRpk; | |
70 | + | |
71 | + @Getter | |
72 | + @Value("${transport.lwm2m.bootstrap.bind_port_no_sec_x509:}") | |
73 | + private Integer bootstrapPortNoSecX509; | |
74 | + | |
75 | + @Getter | |
76 | + @Value("${transport.lwm2m.bootstrap.secure.bind_port_psk:}") | |
77 | + private Integer bootstrapSecurePortPsk; | |
78 | + | |
79 | + @Getter | |
80 | + @Value("${transport.lwm2m.bootstrap.secure.bind_port_rpk:}") | |
81 | + private Integer bootstrapSecurePortRpk; | |
64 | 82 | |
65 | 83 | @Getter |
66 | - @Value("${transport.lwm2m.bootstrap.secure.bind_port_cert:}") | |
67 | - private Integer bootstrapSecurePortCert; | |
84 | + @Value("${transport.lwm2m.bootstrap.secure.bind_port_x509:}") | |
85 | + private Integer bootstrapSecurePortX509; | |
68 | 86 | |
69 | 87 | @Getter |
70 | 88 | @Value("${transport.lwm2m.bootstrap.secure.public_x:}") | ... | ... |
... | ... | @@ -47,13 +47,6 @@ import java.util.stream.Collectors; |
47 | 47 | @ConditionalOnExpression("('${service.type:null}'=='tb-transport' && '${transport.lwm2m.enabled:false}'=='true') || '${service.type:null}'=='monolith' || '${service.type:null}'=='tb-core'") |
48 | 48 | public class LwM2MTransportConfigServer { |
49 | 49 | |
50 | - @Getter | |
51 | - @Value("${transport.lwm2m.timeout:}") | |
52 | - private Long timeout; | |
53 | - | |
54 | - @Getter | |
55 | - @Value("${transport.sessions.report_timeout}") | |
56 | - private long sessionReportTimeout; | |
57 | 50 | |
58 | 51 | @Getter |
59 | 52 | private String MODEL_PATH_DEFAULT = "models"; |
... | ... | @@ -86,10 +79,6 @@ public class LwM2MTransportConfigServer { |
86 | 79 | private String BASE_DIR_PATH = System.getProperty("user.dir"); |
87 | 80 | |
88 | 81 | @Getter |
89 | - @Value("${transport.lwm2m.model_path_file:}") | |
90 | - private String modelPathFile; | |
91 | - | |
92 | - @Getter | |
93 | 82 | // private String PATH_DATA_MICROSERVICE = "/usr/share/tb-lwm2m-transport/data$"; |
94 | 83 | private String PATH_DATA = "data"; |
95 | 84 | |
... | ... | @@ -98,8 +87,44 @@ public class LwM2MTransportConfigServer { |
98 | 87 | private List<ObjectModel> modelsValue; |
99 | 88 | |
100 | 89 | @Getter |
101 | - @Value("${transport.lwm2m.support_deprecated_ciphers_enable:}") | |
102 | - private boolean supportDeprecatedCiphersEnable; | |
90 | + @Value("${transport.lwm2m.timeout:}") | |
91 | + private Long timeout; | |
92 | + | |
93 | + @Getter | |
94 | + @Value("${transport.sessions.report_timeout}") | |
95 | + private long sessionReportTimeout; | |
96 | + | |
97 | + @Getter | |
98 | + @Value("${transport.lwm2m.model_path_file:}") | |
99 | + private String modelPathFile; | |
100 | + | |
101 | + @Getter | |
102 | + @Value("${transport.lwm2m.recommended_ciphers:}") | |
103 | + private boolean recommendedCiphers; | |
104 | + | |
105 | + @Getter | |
106 | + @Value("${transport.lwm2m.recommended_supported_groups:}") | |
107 | + private boolean recommendedSupportedGroups; | |
108 | + | |
109 | + @Getter | |
110 | + @Value("${transport.lwm2m.request_pool_size:}") | |
111 | + private int requestPoolSize; | |
112 | + | |
113 | + @Getter | |
114 | + @Value("${transport.lwm2m.request_error_pool_size:}") | |
115 | + private int requestErrorPoolSize; | |
116 | + | |
117 | + @Getter | |
118 | + @Value("${transport.lwm2m.registered_pool_size:}") | |
119 | + private int registeredPoolSize; | |
120 | + | |
121 | + @Getter | |
122 | + @Value("${transport.lwm2m.update_registered_pool_size:}") | |
123 | + private int updateRegisteredPoolSize; | |
124 | + | |
125 | + @Getter | |
126 | + @Value("${transport.lwm2m.un_registered_pool_size:}") | |
127 | + private int unRegisteredPoolSize; | |
103 | 128 | |
104 | 129 | @Getter |
105 | 130 | @Value("${transport.lwm2m.secure.key_store_type:}") |
... | ... | @@ -122,6 +147,18 @@ public class LwM2MTransportConfigServer { |
122 | 147 | private String rootAlias; |
123 | 148 | |
124 | 149 | @Getter |
150 | + @Value("${transport.lwm2m.server.secure.start_psk:}") | |
151 | + private boolean serverStartPsk; | |
152 | + | |
153 | + @Getter | |
154 | + @Value("${transport.lwm2m.server.secure.start_rpk:}") | |
155 | + private boolean serverStartRpk; | |
156 | + | |
157 | + @Getter | |
158 | + @Value("${transport.lwm2m.server.secure.start_x509:}") | |
159 | + private boolean serverStartX509; | |
160 | + | |
161 | + @Getter | |
125 | 162 | @Value("${transport.lwm2m.secure.enable_gen_psk_rpk:}") |
126 | 163 | private Boolean enableGenPskRpk; |
127 | 164 | |
... | ... | @@ -130,32 +167,37 @@ public class LwM2MTransportConfigServer { |
130 | 167 | private String serverHost; |
131 | 168 | |
132 | 169 | @Getter |
133 | - @Value("${transport.lwm2m.server.bind_port:}") | |
134 | - private Integer serverPort; | |
170 | + @Value("${transport.lwm2m.server.id:}") | |
171 | + private Integer serverId; | |
172 | + | |
173 | + @Getter | |
174 | + @Value("${transport.lwm2m.server.secure.bind_address:}") | |
175 | + private String serverSecureHost; | |
176 | + | |
135 | 177 | |
136 | 178 | @Getter |
137 | - @Value("${transport.lwm2m.server.bind_port_cert:}") | |
138 | - private Integer serverPortCert; | |
179 | + @Value("${transport.lwm2m.server.bind_port_no_sec_psk:}") | |
180 | + private Integer serverPortNoSecPsk; | |
139 | 181 | |
140 | 182 | @Getter |
141 | - @Value("${transport.lwm2m.server.secure.start_all:}") | |
142 | - private boolean serverStartAll; | |
183 | + @Value("${transport.lwm2m.server.bind_port_no_sec_rpk:}") | |
184 | + private Integer serverPortNoSecRpk; | |
143 | 185 | |
144 | 186 | @Getter |
145 | - @Value("${transport.lwm2m.server.secure.dtls_mode:}") | |
146 | - private Integer serverDtlsMode; | |
187 | + @Value("${transport.lwm2m.server.bind_port_no_sec_x509:}") | |
188 | + private Integer serverPortNoSecX509; | |
147 | 189 | |
148 | 190 | @Getter |
149 | - @Value("${transport.lwm2m.server.secure.bind_address:}") | |
150 | - private String serverSecureHost; | |
191 | + @Value("${transport.lwm2m.server.secure.bind_port_psk:}") | |
192 | + private Integer serverPortPsk; | |
151 | 193 | |
152 | 194 | @Getter |
153 | - @Value("${transport.lwm2m.server.secure.bind_port:}") | |
154 | - private Integer serverSecurePort; | |
195 | + @Value("${transport.lwm2m.server.secure.bind_port_rpk:}") | |
196 | + private Integer serverPortRpk; | |
155 | 197 | |
156 | 198 | @Getter |
157 | - @Value("${transport.lwm2m.server.secure.bind_port_cert:}") | |
158 | - private Integer serverSecurePortCert; | |
199 | + @Value("${transport.lwm2m.server.secure.bind_port_x509:}") | |
200 | + private Integer serverPortX509; | |
159 | 201 | |
160 | 202 | @Getter |
161 | 203 | @Value("${transport.lwm2m.server.secure.public_x:}") |
... | ... | @@ -174,10 +216,6 @@ public class LwM2MTransportConfigServer { |
174 | 216 | private String serverAlias; |
175 | 217 | |
176 | 218 | @Getter |
177 | - @Value("${transport.lwm2m.bootstrap.enable:}") | |
178 | - private Boolean bootstrapEnable; | |
179 | - | |
180 | - @Getter | |
181 | 219 | @Value("${transport.lwm2m.secure.redis_url:}") |
182 | 220 | private String redisUrl; |
183 | 221 | ... | ... |
... | ... | @@ -62,10 +62,10 @@ |
62 | 62 | <jackson-annotations.version>2.11.3</jackson-annotations.version> |
63 | 63 | <jackson-core.version>2.11.3</jackson-core.version> |
64 | 64 | <json-schema-validator.version>2.2.6</json-schema-validator.version> |
65 | - <californium.version>2.2.3</californium.version> | |
66 | - <leshan-server.version>1.0.1</leshan-server.version> | |
67 | - <leshan-core.version>1.0.1</leshan-core.version> | |
68 | - <leshan-client.version>1.0.0</leshan-client.version> | |
65 | + <californium.version>2.6.0</californium.version> | |
66 | + <leshan-server.version>1.3.0</leshan-server.version> | |
67 | + <leshan-core.version>1.3.0</leshan-core.version> | |
68 | + <leshan-client.version>1.3.0</leshan-client.version> | |
69 | 69 | <gson.version>2.6.2</gson.version> |
70 | 70 | <freemarker.version>2.3.30</freemarker.version> |
71 | 71 | <mail.version>1.6.2</mail.version> |
... | ... | @@ -1170,11 +1170,6 @@ |
1170 | 1170 | <groupId>org.eclipse.californium</groupId> |
1171 | 1171 | <artifactId>californium-core</artifactId> |
1172 | 1172 | <version>${californium.version}</version> |
1173 | - </dependency> | |
1174 | - <dependency> | |
1175 | - <groupId>org.eclipse.californium</groupId> | |
1176 | - <artifactId>californium-core</artifactId> | |
1177 | - <version>${californium.version}</version> | |
1178 | 1173 | <type>test-jar</type> |
1179 | 1174 | <scope>test</scope> |
1180 | 1175 | </dependency> | ... | ... |
... | ... | @@ -46,10 +46,37 @@ |
46 | 46 | |
47 | 47 | <dependencies> |
48 | 48 | <dependency> |
49 | + <groupId>org.thingsboard.common.transport</groupId> | |
50 | + <artifactId>transport-api</artifactId> | |
51 | + </dependency> | |
52 | + <dependency> | |
53 | + <groupId>org.springframework</groupId> | |
54 | + <artifactId>spring-context-support</artifactId> | |
55 | + </dependency> | |
56 | + <dependency> | |
57 | + <groupId>org.springframework</groupId> | |
58 | + <artifactId>spring-context</artifactId> | |
59 | + </dependency> | |
60 | + <dependency> | |
61 | + <groupId>org.slf4j</groupId> | |
62 | + <artifactId>slf4j-api</artifactId> | |
63 | + </dependency> | |
64 | + <dependency> | |
65 | + <groupId>org.slf4j</groupId> | |
66 | + <artifactId>log4j-over-slf4j</artifactId> | |
67 | + </dependency> | |
68 | + <dependency> | |
69 | + <groupId>ch.qos.logback</groupId> | |
70 | + <artifactId>logback-core</artifactId> | |
71 | + </dependency> | |
72 | + <dependency> | |
73 | + <groupId>ch.qos.logback</groupId> | |
74 | + <artifactId>logback-classic</artifactId> | |
75 | + </dependency> | |
76 | + <dependency> | |
49 | 77 | <groupId>org.eclipse.leshan</groupId> |
50 | 78 | <artifactId>leshan-server-cf</artifactId> |
51 | 79 | </dependency> |
52 | - | |
53 | 80 | <dependency> |
54 | 81 | <groupId>org.eclipse.leshan</groupId> |
55 | 82 | <artifactId>leshan-client-cf</artifactId> |
... | ... | @@ -59,7 +86,6 @@ |
59 | 86 | <groupId>org.eclipse.leshan</groupId> |
60 | 87 | <artifactId>leshan-server-redis</artifactId> |
61 | 88 | </dependency> |
62 | - | |
63 | 89 | <dependency> |
64 | 90 | <groupId>org.springframework.boot</groupId> |
65 | 91 | <artifactId>spring-boot-starter-test</artifactId> |
... | ... | @@ -78,32 +104,22 @@ |
78 | 104 | <dependency> |
79 | 105 | <groupId>org.eclipse.californium</groupId> |
80 | 106 | <artifactId>californium-core</artifactId> |
81 | - </dependency> | |
82 | - <dependency> | |
83 | - <groupId>org.eclipse.californium</groupId> | |
84 | - <artifactId>element-connector</artifactId> | |
85 | 107 | <type>test-jar</type> |
86 | 108 | <scope>test</scope> |
87 | 109 | </dependency> |
88 | - | |
89 | 110 | <dependency> |
90 | - <groupId>org.thingsboard.common.transport</groupId> | |
91 | - <artifactId>lwm2m</artifactId> | |
92 | - </dependency> | |
93 | - <dependency> | |
94 | - <groupId>org.thingsboard.common</groupId> | |
95 | - <artifactId>queue</artifactId> | |
96 | - </dependency> | |
97 | - <dependency> | |
98 | - <groupId>org.springframework.boot</groupId> | |
99 | - <artifactId>spring-boot-starter-web</artifactId> | |
111 | + <groupId>org.eclipse.californium</groupId> | |
112 | + <artifactId>californium-core</artifactId> | |
100 | 113 | </dependency> |
114 | +<!-- <dependency>--> | |
115 | +<!-- <groupId>org.eclipse.californium</groupId>--> | |
116 | +<!-- <artifactId>scandium</artifactId>--> | |
117 | +<!-- </dependency>--> | |
101 | 118 | <dependency> |
102 | - <groupId>com.sun.winsw</groupId> | |
103 | - <artifactId>winsw</artifactId> | |
104 | - <classifier>bin</classifier> | |
105 | - <type>exe</type> | |
106 | - <scope>provided</scope> | |
119 | + <groupId>org.eclipse.californium</groupId> | |
120 | + <artifactId>element-connector</artifactId> | |
121 | + <type>test-jar</type> | |
122 | + <scope>test</scope> | |
107 | 123 | </dependency> |
108 | 124 | </dependencies> |
109 | 125 | ... | ... |
... | ... | @@ -42,6 +42,7 @@ zk: |
42 | 42 | |
43 | 43 | # LWM2M server parameters |
44 | 44 | transport: |
45 | + # Local LwM2M transport parameters | |
45 | 46 | lwm2m: |
46 | 47 | # Enable/disable lvm2m transport protocol. |
47 | 48 | enabled: "${LWM2M_ENABLED:true}" |
... | ... | @@ -51,7 +52,13 @@ transport: |
51 | 52 | timeout: "${LWM2M_TIMEOUT:120000}" |
52 | 53 | # model_path_file: "${LWM2M_MODEL_PATH_FILE:./common/transport/lwm2m/src/main/resources/models/}" |
53 | 54 | model_path_file: "${LWM2M_MODEL_PATH_FILE:}" |
54 | - support_deprecated_ciphers_enable: "${LWM2M_SUPPORT_DEPRECATED_CIPHERS_ENABLED:true}" | |
55 | + recommended_ciphers: "${LWM2M_RECOMMENDED_CIPHERS:false}" | |
56 | + recommended_supported_groups: "${LWM2M_RECOMMENDED_SUPPORTED_GROUPS:false}" | |
57 | + request_pool_size: "${LWM2M_REQUEST_POOL_SIZE:100}" | |
58 | + request_error_pool_size: "${LWM2M_REQUEST_ERROR_POOL_SIZE:10}" | |
59 | + registered_pool_size: "${LWM2M_REGISTERED_POOL_SIZE:10}" | |
60 | + update_registered_pool_size: "${LWM2M_UPDATE_REGISTERED_POOL_SIZE:10}" | |
61 | + un_registered_pool_size: "${LWM2M_UN_REGISTERED_POOL_SIZE:10}" | |
55 | 62 | secure: |
56 | 63 | # Only Certificate_x509: |
57 | 64 | # To get helps about files format and how to generate it, see: https://github.com/eclipse/leshan/wiki/Credential-files-format |
... | ... | @@ -64,24 +71,19 @@ transport: |
64 | 71 | root_alias: "${LWM2M_SERVER_ROOT_CA:rootca}" |
65 | 72 | enable_gen_psk_rpk: "${ENABLE_GEN_PSK_RPK:true}" |
66 | 73 | server: |
74 | + id: "${LWM2M_SERVER_ID:123}" | |
67 | 75 | bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" |
68 | - bind_port: "${LWM2M_BIND_PORT:5685}" | |
69 | - bind_port_cert: "${LWM2M_BIND_PORT_CERT:5687}" | |
76 | + bind_port_no_sec_psk: "${LWM2M_BIND_PORT_NO_SEC_PSK:5685}" | |
77 | + bind_port_no_sec_rpk: "${LWM2M_BIND_PORT_NO_SEC_RPK:5687}" | |
78 | + bind_port_no_sec_x509: "${LWM2M_BIND_PORT_NO_SEC_X509:5689}" | |
70 | 79 | secure: |
71 | - start_all: "${START_SERVER_ALL:true}" | |
72 | - #leshan.core (V1_1) | |
73 | - #DTLS security modes: | |
74 | - #0: Pre-Shared Key mode | |
75 | - #1: Raw Public Key mode | |
76 | - #2: Certificate mode X509 | |
77 | - #3: NoSec mode * | |
78 | - #OMA-TS-LightweightM2M_Core-V1_1_1-20190617-A (add) | |
79 | - #4: Certificate mode X509 with EST | |
80 | - # If only startAll == false | |
81 | - dtls_mode: "${LWM2M_SECURITY_MODE:1}" | |
82 | 80 | bind_address: "${LWM2M_BIND_ADDRESS:0.0.0.0}" |
83 | - bind_port: "${LWM2M_BIND_PORT_SEC:5686}" | |
84 | - bind_port_cert: "${LWM2M_BIND_PORT_SEC_CERT:5688}" | |
81 | + start_psk: "${START_SERVER_PSK:true}" | |
82 | + start_rpk: "${START_SERVER_RPK:true}" | |
83 | + start_x509: "${START_SERVER_X509:true}" | |
84 | + bind_port_psk: "${LWM2M_BIND_PORT_SEC_PSK:5686}" | |
85 | + bind_port_rpk: "${LWM2M_BIND_PORT_SEC_RPK:5688}" | |
86 | + bind_port_x509: "${LWM2M_BIND_PORT_SEC_X509:5690}" | |
85 | 87 | # Only RPK: Public & Private Key |
86 | 88 | # create_rpk: "${CREATE_RPK:}" |
87 | 89 | public_x: "${LWM2M_SERVER_PUBLIC_X:405354ea8893471d9296afbc8b020a5c6201b0bb25812a53b849d4480fa5f069}" |
... | ... | @@ -91,16 +93,19 @@ transport: |
91 | 93 | alias: "${LWM2M_KEYSTORE_ALIAS_SERVER:server}" |
92 | 94 | bootstrap: |
93 | 95 | enable: "${BOOTSTRAP:true}" |
96 | + id: "${LWM2M_SERVER_ID:111}" | |
94 | 97 | bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}" |
95 | - bind_port: "${LWM2M_BIND_PORT_BS:5689}" | |
96 | - bind_port_cert: "${LWM2M_BIND_PORT_SER_BS:5691}" | |
98 | + bind_port_no_sec_psk: "${LWM2M_BIND_PORT_NO_SEC_BS:5691}" | |
99 | + bind_port_no_sec_rpk: "${LWM2M_BIND_PORT_NO_SEC_BS:5693}" | |
100 | + bind_port_no_sec_x509: "${LWM2M_BIND_PORT_NO_SEC_BS:5695}" | |
97 | 101 | secure: |
98 | - start_all: "${START_BOOTSTRAP_ALL:true}" | |
99 | - # If only startAll == false | |
100 | - dtls_mode: "${LWM2M_SECURITY_MODE_BS:1}" | |
101 | 102 | bind_address: "${LWM2M_BIND_ADDRESS_BS:0.0.0.0}" |
102 | - bind_port: "${LWM2M_BIND_PORT_SEC_BS:5690}" | |
103 | - bind_port_cert: "${LWM2M_BIND_PORT_SEC_CERT_BS:5692}" | |
103 | + start_psk: "${START_SERVER_PSK_BS:true}" | |
104 | + start_rpk: "${START_SERVER_RPK_BS:true}" | |
105 | + start_x509: "${START_SERVER_X509_BS:true}" | |
106 | + bind_port_psk: "${LWM2M_BIND_PORT_SEC_PSK_BS:5692}" | |
107 | + bind_port_rpk: "${LWM2M_BIND_PORT_SER_RPK_BS:5694}" | |
108 | + bind_port_x509: "${LWM2M_BIND_PORT_SEC_X509_BS:5696}" | |
104 | 109 | # Only RPK: Public & Private Key |
105 | 110 | public_x: "${LWM2M_SERVER_PUBLIC_X_BS:993ef2b698c6a9c0c1d8be78b13a9383c0854c7c7c7a504d289b403794648183}" |
106 | 111 | public_y: "${LWM2M_SERVER_PUBLIC_Y_BS:267412d5fc4e5ceb2257cb7fd7f76ebdac2fa9aa100afb162e990074cc0bfaa2}" | ... | ... |
... | ... | @@ -16,12 +16,11 @@ |
16 | 16 | |
17 | 17 | import { Component, Inject, OnInit } from '@angular/core'; |
18 | 18 | import { DialogComponent } from '@shared/components/dialog.component'; |
19 | -import { ControlValueAccessor, FormBuilder, FormGroup } from '@angular/forms'; | |
19 | +import { FormBuilder, FormGroup } from '@angular/forms'; | |
20 | 20 | import { Store } from '@ngrx/store'; |
21 | 21 | import { AppState } from '@core/core.state'; |
22 | 22 | import { Router } from '@angular/router'; |
23 | 23 | import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; |
24 | -import { TranslateService } from '@ngx-translate/core'; | |
25 | 24 | |
26 | 25 | export interface Lwm2mObjectAddInstancesData { |
27 | 26 | instancesIds: Set<number>; | ... | ... |
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -import { Component, EventEmitter, forwardRef, Input, OnInit, Output, ViewChild } from "@angular/core"; | |
17 | +import { Component, forwardRef, Input, OnInit } from "@angular/core"; | |
18 | 18 | import { |
19 | 19 | ControlValueAccessor, |
20 | 20 | FormArray, FormBuilder, |
... | ... | @@ -27,7 +27,7 @@ import { |
27 | 27 | } from '@home/components/profile/device/lwm2m/profile-config.models'; |
28 | 28 | import { Store } from '@ngrx/store'; |
29 | 29 | import { AppState } from '@core/core.state'; |
30 | -import { deepClone, isUndefined } from '@core/utils'; | |
30 | +import { deepClone } from '@core/utils'; | |
31 | 31 | import { coerceBooleanProperty } from '@angular/cdk/coercion'; |
32 | 32 | |
33 | 33 | @Component({ | ... | ... |
... | ... | @@ -44,7 +44,6 @@ import { |
44 | 44 | Lwm2mObjectAddInstancesComponent, |
45 | 45 | Lwm2mObjectAddInstancesData |
46 | 46 | } from '@home/components/profile/device/lwm2m/lwm2m-object-add-instances.component'; |
47 | -import { Control } from 'leaflet'; | |
48 | 47 | |
49 | 48 | @Component({ |
50 | 49 | selector: 'tb-profile-lwm2m-observe-attr-telemetry', | ... | ... |
... | ... | @@ -25,11 +25,7 @@ export const DEFAULT_ID_SERVER = 123; |
25 | 25 | export const DEFAULT_ID_BOOTSTRAP = 111; |
26 | 26 | export const DEFAULT_HOST_NAME = "localhost"; |
27 | 27 | export const DEFAULT_PORT_SERVER_NO_SEC = 5685; |
28 | -export const DEFAULT_PORT_SERVER_SEC = 5686; | |
29 | -export const DEFAULT_PORT_SERVER_SEC_CERT = 5688; | |
30 | -export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5689; | |
31 | -export const DEFAULT_PORT_BOOTSTRAP_SEC = 5690; | |
32 | -export const DEFAULT_PORT_BOOTSTRAP_SEC_CERT = 5692; | |
28 | +export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5691; | |
33 | 29 | export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1; |
34 | 30 | export const DEFAULT_LIFE_TIME = 300; |
35 | 31 | export const DEFAULT_DEFAULT_MIN_PERIOD = 1; |
... | ... | @@ -118,7 +114,7 @@ export function getDefaultBootstrapServersSecurityConfig(): BootstrapServersSecu |
118 | 114 | export function getDefaultBootstrapServerSecurityConfig(hostname: any): ServerSecurityConfig { |
119 | 115 | return { |
120 | 116 | host: hostname, |
121 | - port: getDefaultPortBootstrap(), | |
117 | + port: DEFAULT_PORT_BOOTSTRAP_NO_SEC, | |
122 | 118 | bootstrapServerIs: true, |
123 | 119 | securityMode: SECURITY_CONFIG_MODE.NO_SEC.toString(), |
124 | 120 | serverPublicKey: '', |
... | ... | @@ -131,20 +127,10 @@ export function getDefaultBootstrapServerSecurityConfig(hostname: any): ServerSe |
131 | 127 | export function getDefaultLwM2MServerSecurityConfig(hostname): ServerSecurityConfig { |
132 | 128 | const DefaultLwM2MServerSecurityConfig = getDefaultBootstrapServerSecurityConfig(hostname); |
133 | 129 | DefaultLwM2MServerSecurityConfig.bootstrapServerIs = false; |
134 | - DefaultLwM2MServerSecurityConfig.port = getDefaultPortServer(); | |
130 | + DefaultLwM2MServerSecurityConfig.port = DEFAULT_PORT_SERVER_NO_SEC; | |
135 | 131 | DefaultLwM2MServerSecurityConfig.serverId = DEFAULT_ID_SERVER; |
136 | 132 | return DefaultLwM2MServerSecurityConfig; |
137 | 133 | } |
138 | -//ok | |
139 | -export function getDefaultPortBootstrap(securityMode?: string): number { | |
140 | - return (!securityMode || securityMode === SECURITY_CONFIG_MODE.NO_SEC.toString()) ? DEFAULT_PORT_BOOTSTRAP_NO_SEC : | |
141 | - (securityMode === SECURITY_CONFIG_MODE.X509.toString()) ? DEFAULT_PORT_BOOTSTRAP_SEC_CERT : DEFAULT_PORT_BOOTSTRAP_SEC; | |
142 | -} | |
143 | -//ok | |
144 | -export function getDefaultPortServer(securityMode?: string): number { | |
145 | - return (!securityMode || securityMode === SECURITY_CONFIG_MODE.NO_SEC.toString()) ? DEFAULT_PORT_SERVER_NO_SEC : | |
146 | - (securityMode === SECURITY_CONFIG_MODE.X509.toString()) ? DEFAULT_PORT_SERVER_SEC_CERT : DEFAULT_PORT_SERVER_SEC; | |
147 | -} | |
148 | 134 | |
149 | 135 | //ok |
150 | 136 | function getDefaultProfileBootstrapSecurityConfig(hostname: any): BootstrapSecurityConfig { |
... | ... | @@ -197,16 +183,3 @@ export interface ObjectLwM2M { |
197 | 183 | instances?: Instance [] |
198 | 184 | } |
199 | 185 | |
200 | -export function getChangeInstancesIds (): ChangeInstancesIds { | |
201 | - let changeInstancesIds: ChangeInstancesIds; | |
202 | - changeInstancesIds.add = new Set<number>(); | |
203 | - changeInstancesIds.del = new Set<number>(); | |
204 | - return changeInstancesIds; | |
205 | - | |
206 | -} | |
207 | - | |
208 | -export interface ChangeInstancesIds { | |
209 | - add: Set<number>, | |
210 | - del: Set<number> | |
211 | -} | |
212 | - | ... | ... |