diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts b/ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts index c051af11eb..fb4e81653e 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials.component.ts @@ -41,7 +41,7 @@ import { DeviceCredentialsDialogLwm2mData, END_POINT, getDefaultSecurityConfig, - JSON_ALL_CONFIG + JSON_ALL_CONFIG, SecurityConfigModels, validateSecurityConfig } from '@home/pages/device/lwm2m/security-config.models'; import {TranslateService} from '@ngx-translate/core'; import {MatDialog} from '@angular/material/dialog'; @@ -285,15 +285,6 @@ export class DeviceCredentialsComponent implements ControlValueAccessor, OnInit, } private jsonValidator(control: FormControl) { - try { - JSON.parse(control.value); - return null - } catch (e) { - return { - jsonError: { - parsedJson: "error" - } - } - } + return validateSecurityConfig(control.value) ? null: {jsonError: {parsedJson: "error"}}; } } diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts index f097d9fb23..40ba18ebe9 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-profile-transport-configuration.component.ts @@ -395,21 +395,4 @@ export class Lwm2mDeviceProfileTransportConfigurationComponent implements Contro } }); } - - isPathInJson(path: string): boolean { - let isPath = this.findPathInJson(path, ATTRIBUTE); - if (!isPath) { - isPath = this.findPathInJson(path, TELEMETRY); - } - return !!isPath; - } - - private findPathInJson = (path: string, side: string): string => { - if (this.configurationValue.observeAttr) { - if (this.configurationValue.observeAttr[side]) { - return this.configurationValue.bootstrap[side].find( - pathJs => pathJs === path); - } - } - } } diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts index 51d7735dd7..7142648061 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/profile-config.models.ts @@ -27,7 +27,7 @@ export const DEFAULT_ID_SERVER = 123; export const DEFAULT_ID_BOOTSTRAP = 111; export const DEFAULT_HOST_NAME = 'localhost'; export const DEFAULT_PORT_SERVER_NO_SEC = 5685; -export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5686; +export const DEFAULT_PORT_BOOTSTRAP_NO_SEC = 5687; export const DEFAULT_CLIENT_HOLD_OFF_TIME = 1; export const DEFAULT_LIFE_TIME = 300; export const DEFAULT_MIN_PERIOD = 1; diff --git a/ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts b/ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts index 37720d93a4..a42757d326 100644 --- a/ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts +++ b/ui-ngx/src/app/modules/home/pages/device/lwm2m/security-config.models.ts @@ -20,7 +20,6 @@ export const DEFAULT_END_POINT = 'default_client_lwm2m_end_point_no_sec'; export const BOOTSTRAP_SERVERS = 'servers'; export const BOOTSTRAP_SERVER = 'bootstrapServer'; export const LWM2M_SERVER = 'lwm2mServer'; -export const JSON_OBSERVE = 'jsonObserve'; export const LEN_MAX_PSK = 64; export const LEN_MAX_PRIVATE_KEY = 134; export const LEN_MAX_PUBLIC_KEY_RPK = 182; @@ -148,4 +147,41 @@ export function getDefaultSecurityConfig(): SecurityConfigModels { return securityConfigModels; } +const isSecurityConfigModels = (p: any): p is SecurityConfigModels => + p.hasOwnProperty('client') && + isClientSecurityConfigType(p['client']) && + p.hasOwnProperty('bootstrap') && + isBootstrapSecurityConfig(p['bootstrap']); + +const isClientSecurityConfigType = (p: any): p is ClientSecurityConfigType => + p.hasOwnProperty('securityConfigClientMode') && + p.hasOwnProperty('endpoint') && + p.hasOwnProperty('identity') && + p.hasOwnProperty('key') && + p.hasOwnProperty('x509'); + +const isBootstrapSecurityConfig = (p: any): p is BootstrapSecurityConfig => + p.hasOwnProperty('bootstrapServer') && + isServerSecurityConfig(p['bootstrapServer']) && + p.hasOwnProperty('lwm2mServer') && + isServerSecurityConfig(p['lwm2mServer']); + +const isServerSecurityConfig = (p: any): p is ServerSecurityConfig => + p.hasOwnProperty('securityMode') && + p.hasOwnProperty('clientPublicKeyOrId') && + p.hasOwnProperty('clientSecretKey'); + +export function validateSecurityConfig(config: string): boolean { + try { + const securityConfig= JSON.parse(config); + if (isSecurityConfigModels(securityConfig)) { + return true; + } else { + return false; + } + } catch (e) { + return false; + } +} +