Commit 84698ad554f555b270214e8b00d20dee86e8f2bb

Authored by nickAS21
1 parent cb3353a3

Lwm2m: front - fix bug /../../

... ... @@ -245,8 +245,7 @@ public class LwM2MTransportBootstrapServerConfiguration {
245 245 }
246 246 if (serverCertificate != null) {
247 247 builder.setCertificateChain(new X509Certificate[]{serverCertificate});
248   - this.contextBs.getCtxBootStrap().setBootstrapCertificate(serverCertificate);
249   - infoParamsX509(serverCertificate);
  248 + this.infoParamsX509(serverCertificate);
250 249 }
251 250 } catch (Exception ex) {
252 251 log.error("[{}] Unable to load KeyStore files server", ex.getMessage());
... ...
... ... @@ -52,6 +52,7 @@ import java.security.KeyFactory;
52 52 import java.security.KeyStoreException;
53 53 import java.security.PrivateKey;
54 54 import java.security.PublicKey;
  55 +import java.security.cert.CertificateEncodingException;
55 56 import java.security.cert.X509Certificate;
56 57 import java.security.interfaces.ECPublicKey;
57 58 import java.security.spec.ECGenParameterSpec;
... ... @@ -306,8 +307,36 @@ public class LwM2MTransportServerConfiguration {
306 307 PrivateKey privateKey = (PrivateKey) this.context.getCtxServer().getKeyStoreValue().getKey(this.context.getCtxServer().getServerAlias(), this.context.getCtxServer().getKeyStorePasswordServer() == null ? null : this.context.getCtxServer().getKeyStorePasswordServer().toCharArray());
307 308 builder.setPrivateKey(privateKey);
308 309 builder.setCertificateChain(new X509Certificate[]{serverCertificate});
  310 + this.infoParamsX509(serverCertificate, privateKey);
309 311 } catch (Exception ex) {
310 312 log.error("[{}] Unable to load KeyStore files server", ex.getMessage());
311 313 }
  314 +// /**
  315 +// * For deb => KeyStorePathFile == yml or commandline: KEY_STORE_PATH_FILE
  316 +// * For idea => KeyStorePathResource == common/transport/lwm2m/src/main/resources/credentials: in LwM2MTransportContextServer: credentials/serverKeyStore.jks
  317 +// */
  318 +// try {
  319 +// X509Certificate serverCertificate = (X509Certificate) this.context.getCtxServer().getKeyStoreValue().getCertificate(this.context.getCtxServer().getServerPrivateS());
  320 +// this.privateKey = (PrivateKey) this.context.getCtxServer().getKeyStoreValue().getKey(this.context.getCtxServer().getServerAlias(), this.context.getCtxServer().getKeyStorePasswordServer() == null ? null : this.context.getCtxServer().getKeyStorePasswordServer().toCharArray());
  321 +// if (this.privateKey != null && this.privateKey.getEncoded().length > 0) {
  322 +// builder.setPrivateKey(this.privateKey);
  323 +// }
  324 +// if (serverCertificate != null) {
  325 +// builder.setCertificateChain(new X509Certificate[]{serverCertificate});
  326 +// this.infoParamsX509(serverCertificate);
  327 +// }
  328 +// } catch (Exception ex) {
  329 +// log.error("[{}] Unable to load KeyStore files server", ex.getMessage());
  330 +// }
  331 + }
  332 +
  333 + private void infoParamsX509(X509Certificate certificate, PrivateKey privateKey) {
  334 + try {
  335 + log.info("Server uses X509 : \n X509 Certificate (Hex): [{}] \n Private Key (Hex): [{}]",
  336 + Hex.encodeHexString(certificate.getEncoded()),
  337 + Hex.encodeHexString(privateKey.getEncoded()));
  338 + } catch (CertificateEncodingException e) {
  339 + log.error("", e);
  340 + }
312 341 }
313 342 }
... ...
... ... @@ -16,6 +16,9 @@
16 16 #
17 17
18 18 # source the properties:
  19 +script_dir=$(dirname $0)
  20 +echo "script_dir: $script_dir"
  21 +cd $script_dir
19 22 . ./lwM2M_keygen.properties
20 23
21 24 # Generation of the keystore.
... ...
... ... @@ -43,7 +43,7 @@ CLIENT_STORE=clientKeyStore.jks
43 43 CLIENT_STORE_PWD=client_ks_password
44 44 CLIENT_ALIAS=client
45 45 #CLIENT_CN=client_lwm2m_x509
46   -CLIENT_CN=mobile_lwm2m_x509
  46 +CLIENT_CN=LwX50900000000
47 47 CLIENT_SELF_ALIAS=client_self_signed
48 48 CLIENT_SELF_CN="$DOMAIN_SUFFIX client LwM2M self-signed"
49 49
... ...
... ... @@ -24,7 +24,6 @@ import org.springframework.stereotype.Component;
24 24 import org.thingsboard.server.gen.transport.TransportProtos;
25 25
26 26 import java.security.PublicKey;
27   -import java.security.cert.X509Certificate;
28 27 import java.util.Map;
29 28
30 29 @Slf4j
... ... @@ -106,9 +105,5 @@ public class LwM2MTransportConfigBootstrap {
106 105
107 106 @Getter
108 107 @Setter
109   - private X509Certificate bootstrapCertificate;
110   -
111   - @Getter
112   - @Setter
113 108 private Map<String /** clientEndPoint */, TransportProtos.ValidateDeviceCredentialsResponseMsg> sessions;
114 109 }
... ...
... ... @@ -233,7 +233,7 @@ public class LwM2MTransportConfigServer {
233 233 } else {
234 234 log.error(" [{}] Read Models", path.getAbsoluteFile());
235 235 }
236   - getInKeyStore();
  236 + this.getInKeyStore();
237 237 }
238 238
239 239 private File getPathModels() {
... ...
... ... @@ -36,7 +36,7 @@ import {
36 36 import { Store } from "@ngrx/store";
37 37 import { AppState } from "@core/core.state";
38 38 import { coerceBooleanProperty } from "@angular/cdk/coercion";
39   -import { WINDOW } from "../../../../../../core/services/window.service";
  39 +import { WINDOW } from "@core/services/window.service";
40 40 import { pairwise, startWith } from 'rxjs/operators';
41 41 import { DeviceProfileService } from '@core/http/device-profile.service';
42 42
... ...
... ... @@ -35,9 +35,9 @@ import {
35 35 TELEMETRY,
36 36 ObjectLwM2M, getDefaultProfileConfig, KEY_NAME, Instance
37 37 } from "./profile-config.models";
38   -import { DeviceProfileService } from "../../../../../../core/http/device-profile.service";
39   -import { deepClone, isUndefined } from "../../../../../../core/utils";
40   -import { WINDOW } from "../../../../../../core/services/window.service";
  38 +import { DeviceProfileService } from "@core/http/device-profile.service";
  39 +import { deepClone, isUndefined } from "@core/utils";
  40 +import { WINDOW } from "@core/services/window.service";
41 41 import { JsonObject } from '@angular/compiler-cli/ngcc/src/packages/entry_point';
42 42 import { isNotNullOrUndefined } from 'codelyzer/util/isNotNullOrUndefined';
43 43
... ...
... ... @@ -30,14 +30,14 @@ import {
30 30 } from "@angular/forms";
31 31 import { coerceBooleanProperty } from "@angular/cdk/coercion";
32 32 import { Store } from "@ngrx/store";
33   -import { AppState } from "../../../../../../core/core.state";
  33 +import { AppState } from "@core/core.state";
34 34 import { MatChipList } from '@angular/material/chips';
35 35 import {
36 36 INSTANCES_ID_VALUE_MAX,
37 37 INSTANCES_ID_VALUE_MIN
38 38 } from "./profile-config.models";
39 39 import { TranslateService } from "@ngx-translate/core";
40   -import { DeviceProfileService } from "../../../../../../core/http/device-profile.service";
  40 +import { DeviceProfileService } from "@core/http/device-profile.service";
41 41
42 42 @Component({
43 43 selector: 'tb-profile-lwm2m-object-add-instances-list',
... ...
... ... @@ -32,16 +32,16 @@ import {
32 32 } from "@angular/forms";
33 33 import {coerceBooleanProperty} from "@angular/cdk/coercion";
34 34 import {Store} from "@ngrx/store";
35   -import {AppState} from "../../../../../../core/core.state";
  35 +import {AppState} from "@core/core.state";
36 36 import {MatChipList} from '@angular/material/chips';
37 37 import {MatAutocomplete} from "@angular/material/autocomplete";
38 38 import {Observable} from "rxjs";
39 39 import {filter, map, mergeMap, share, tap} from 'rxjs/operators';
40 40 import {ObjectLwM2M} from "./profile-config.models";
41 41 import {TranslateService} from "@ngx-translate/core";
42   -import {DeviceProfileService} from "../../../../../../core/http/device-profile.service";
43   -import {PageLink} from "../../../../../../shared/models/page/page-link";
44   -import {Direction} from "../../../../../../shared/models/page/sort-order";
  42 +import {DeviceProfileService} from "@core/http/device-profile.service";
  43 +import {PageLink} from "@shared/models/page/page-link";
  44 +import {Direction} from "@shared/models/page/sort-order";
45 45
46 46 @Component({
47 47 selector: 'tb-profile-lwm2m-object-list',
... ...