From bb2efb145bd4e848ef33b6b85bbfd95bebe9096e Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 23 Sep 2021 13:24:48 +0300 Subject: [PATCH] UI: Remove HEX and length validations in device lwm2m credentials --- ...ce-credentials-lwm2m-server.component.html | 16 --------- ...vice-credentials-lwm2m-server.component.ts | 34 ++----------------- .../device-credentials-lwm2m.component.html | 12 ------- .../device-credentials-lwm2m.component.ts | 21 +----------- .../lwm2m-device-config-server.component.html | 3 -- .../lwm2m-device-config-server.component.ts | 6 +--- .../lwm2m/lwm2m-profile-config.models.ts | 1 - .../models/lwm2m-security-config.models.ts | 4 --- .../assets/locale/locale.constant-cs_CZ.json | 6 ---- .../assets/locale/locale.constant-en_US.json | 6 ---- .../assets/locale/locale.constant-tr_TR.json | 6 ---- 11 files changed, 5 insertions(+), 110 deletions(-) diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.html b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.html index 429a13ddb2..3c3806882f 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.html +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.html @@ -37,35 +37,19 @@ {{ 'device.lwm2m-security-config.client-publicKey-or-id-required' | translate }} - - {{ 'device.lwm2m-security-config.client-publicKey-or-id-pattern' | translate }} - {{ 'device.lwm2m-security-config.client-secret-key' | translate }} - - {{clientSecretKey.value?.length || 0}}/{{lengthClientSecretKey}} - {{ 'device.lwm2m-security-config.client-secret-key-required' | translate }} - - {{ 'device.lwm2m-security-config.client-secret-key-pattern' | translate }} - - - {{ 'device.lwm2m-security-config.client-secret-key-length' | translate: { - count: allowLengthKey.join(', ') - } }} - diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.ts b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.ts index 7c6ad485f3..96b1e74fb9 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.ts +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m-server.component.ts @@ -16,7 +16,6 @@ import { Component, forwardRef, OnDestroy } from '@angular/core'; import { - AbstractControl, ControlValueAccessor, FormBuilder, FormGroup, @@ -27,9 +26,6 @@ import { Validators } from '@angular/forms'; import { - KEY_REGEXP_HEX_DEC, - LEN_MAX_PRIVATE_KEY, - LEN_MAX_PSK, Lwm2mSecurityType, Lwm2mSecurityTypeTranslationMap, ServerSecurityConfig @@ -61,8 +57,6 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control securityConfigLwM2MType = Lwm2mSecurityType; securityConfigLwM2MTypes = Object.values(Lwm2mSecurityType); lwm2mSecurityTypeTranslationMap = Lwm2mSecurityTypeTranslationMap; - lengthClientSecretKey = LEN_MAX_PRIVATE_KEY; - allowLengthKey = [32, 64, LEN_MAX_PSK]; private destroy$ = new Subject(); private propagateChange = (v: any) => {}; @@ -132,30 +126,18 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control this.serverFormGroup.get('clientSecretKey').disable(); break; case Lwm2mSecurityType.PSK: - this.lengthClientSecretKey = LEN_MAX_PSK; - this.setValidatorsSecurity(securityMode); - break; case Lwm2mSecurityType.RPK: - this.lengthClientSecretKey = null; - this.setValidatorsSecurity(securityMode); - break; case Lwm2mSecurityType.X509: - this.lengthClientSecretKey = null; - this.setValidatorsSecurity(securityMode); + this.setValidatorsSecurity(); break; } this.serverFormGroup.get('clientPublicKeyOrId').updateValueAndValidity({emitEvent: false}); this.serverFormGroup.get('clientSecretKey').updateValueAndValidity({emitEvent: !initValue}); } - private setValidatorsSecurity = (securityMode: Lwm2mSecurityType): void => { - const clientSecretKeyValidators = [Validators.required, Validators.pattern(KEY_REGEXP_HEX_DEC)]; + private setValidatorsSecurity = (): void => { + const clientSecretKeyValidators = [Validators.required]; const clientPublicKeyOrIdValidators = [Validators.required]; - if (securityMode === Lwm2mSecurityType.PSK) { - clientSecretKeyValidators.push(this.maxLength(this.allowLengthKey)); - } else { - clientPublicKeyOrIdValidators.push(Validators.pattern(KEY_REGEXP_HEX_DEC)); - } this.serverFormGroup.get('clientPublicKeyOrId').setValidators(clientPublicKeyOrIdValidators); this.serverFormGroup.get('clientSecretKey').setValidators(clientSecretKeyValidators); @@ -163,14 +145,4 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control this.serverFormGroup.get('clientPublicKeyOrId').enable({emitEvent: false}); this.serverFormGroup.get('clientSecretKey').enable(); } - - private maxLength(keyLengths: number[]) { - return (control: AbstractControl): ValidationErrors | null => { - const value = control.value; - if (keyLengths.some(len => value.length === len)) { - return null; - } - return {length: true}; - }; - } } diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html index b588f1af72..b10eaf68ae 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html @@ -45,27 +45,15 @@ lwm2mConfigFormGroup.get('client.securityConfigClientMode').value === securityConfigLwM2MType.PSK"> {{ 'device.lwm2m-security-config.client-key' | translate }} - {{key.value?.length || 0}}/{{lenMaxKeyClient}} {{ 'device.lwm2m-security-config.client-key-required' | translate }} - - {{ 'device.lwm2m-security-config.client-key-pattern' | translate }} - - - {{ 'device.lwm2m-security-config.client-key-length' | translate: { - count: allowLengthKey.join(', ') - } }} - device.lwm2m-security-config.client-public-key diff --git a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts index ff5fba9bdd..1645d3317d 100644 --- a/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts +++ b/ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts @@ -16,7 +16,6 @@ import { Component, forwardRef, OnDestroy } from '@angular/core'; import { - AbstractControl, ControlValueAccessor, FormBuilder, FormGroup, @@ -29,8 +28,6 @@ import { import { getDefaultClientSecurityConfig, getDefaultServerSecurityConfig, - KEY_REGEXP_HEX_DEC, - LEN_MAX_PSK, Lwm2mSecurityConfigModels, Lwm2mSecurityType, Lwm2mSecurityTypeTranslationMap @@ -63,8 +60,6 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va securityConfigLwM2MType = Lwm2mSecurityType; securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; - lenMaxKeyClient = LEN_MAX_PSK; - allowLengthKey = [32, 64, LEN_MAX_PSK]; private destroy$ = new Subject(); private propagateChange = (v: any) => {}; @@ -135,12 +130,10 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va this.lwm2mConfigFormGroup.get('client.cert').enable({emitEvent: false}); break; case Lwm2mSecurityType.PSK: - this.lenMaxKeyClient = LEN_MAX_PSK; this.setValidatorsPskRpk(mode); this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); break; case Lwm2mSecurityType.RPK: - this.lenMaxKeyClient = null; this.setValidatorsPskRpk(mode); this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); break; @@ -157,28 +150,16 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va } private setValidatorsPskRpk = (mode: Lwm2mSecurityType): void => { - const keyValidators = [Validators.required, Validators.pattern(KEY_REGEXP_HEX_DEC)]; if (mode === Lwm2mSecurityType.PSK) { this.lwm2mConfigFormGroup.get('client.identity').setValidators([Validators.required]); - keyValidators.push(this.maxLength(this.allowLengthKey)); } else { this.lwm2mConfigFormGroup.get('client.identity').clearValidators(); } - this.lwm2mConfigFormGroup.get('client.key').setValidators(keyValidators); + this.lwm2mConfigFormGroup.get('client.key').setValidators([Validators.required]); this.lwm2mConfigFormGroup.get('client.key').enable({emitEvent: false}); this.lwm2mConfigFormGroup.get('client.cert').disable({emitEvent: false}); } - private maxLength(keyLengths: number[]) { - return (control: AbstractControl): ValidationErrors | null => { - const value = control.value; - if (keyLengths.some(len => value.length === len)) { - return null; - } - return {length: true}; - }; - } - private initLwm2mConfigForm = (): FormGroup => { const formGroup = this.fb.group({ client: this.fb.group({ diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.html b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.html index b2d69c252f..9c2ce132d8 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.html +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.html @@ -103,9 +103,6 @@ {{ 'device-profile.lwm2m.server-public-key-required' | translate }} - - {{ 'device-profile.lwm2m.server-public-key-pattern' | translate }} - diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts index 63cde444ba..93c22d44b1 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-device-config-server.component.ts @@ -28,7 +28,6 @@ import { import { DEFAULT_PORT_BOOTSTRAP_NO_SEC, DEFAULT_PORT_SERVER_NO_SEC, - KEY_REGEXP_HEX_DEC, securityConfigMode, securityConfigModeNames, ServerSecurityConfig @@ -158,10 +157,7 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc } private setValidators(): void { - this.serverFormGroup.get('serverPublicKey').setValidators([ - Validators.required, - Validators.pattern(KEY_REGEXP_HEX_DEC) - ]); + this.serverFormGroup.get('serverPublicKey').setValidators([Validators.required]); } private propagateChangeState = (value: ServerSecurityConfig): void => { diff --git a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts index 3be58c7f7f..2845ad75b3 100644 --- a/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts +++ b/ui-ngx/src/app/modules/home/components/profile/device/lwm2m/lwm2m-profile-config.models.ts @@ -34,7 +34,6 @@ export const DEFAULT_MIN_PERIOD = 1; export const DEFAULT_NOTIF_IF_DESIBLED = true; export const DEFAULT_BINDING = 'UQ'; export const DEFAULT_BOOTSTRAP_SERVER_ACCOUNT_TIME_OUT = 0; -export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/; export const INSTANCES_ID_VALUE_MIN = 0; export const INSTANCES_ID_VALUE_MAX = 65535; export const DEFAULT_OTA_UPDATE_PROTOCOL = 'coap://'; diff --git a/ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts b/ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts index d18ea56644..d3b4171b80 100644 --- a/ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts +++ b/ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts @@ -14,10 +14,6 @@ /// limitations under the License. /// -export const LEN_MAX_PSK = 128; -export const LEN_MAX_PRIVATE_KEY = 134; -export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/; - export enum Lwm2mSecurityType { PSK = 'PSK', RPK = 'RPK', diff --git a/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json b/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json index b5a23c0150..4e1ec64412 100644 --- a/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json +++ b/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json @@ -961,8 +961,6 @@ "identity-required": "Identita klienta je povinná.", "client-key": "Klíč klienta", "client-key-required": "Klíč klienta je povinný.", - "client-key-pattern": "Klíč klienta musí být v hexadecimálním formátu.", - "client-key-length": "Klíč klienta musí mít {{ count }} znaků.", "endpoint": "Název endpointu klienta", "endpoint-required": "Název endpointu klienta je povinný.", "mode": "Režim konfigurace bezpečnosti", @@ -973,11 +971,8 @@ "lwm2m-server": "LwM2M server", "client-publicKey-or-id": "Veřejný klíč nebo Id klienta", "client-publicKey-or-id-required": "Veřejný klíč nebo Id klienta jsou povinné.", - "client-publicKey-or-id-pattern": "Veřejný klíč klienta nebo Id musí být v hexadecimálním formátu.", "client-secret-key": "Tajný klíč klienta", "client-secret-key-required": "Tajný klíč klienta je povinný.", - "client-secret-key-pattern": "Tajný klíč klienta musí být v hexadecimálním formátu.", - "client-secret-key-length": "Tajný klíč klienta musí mít {{ count }} znaků.", "client-public-key": "Veřejný klíč klienta", "client-public-key-hint": "Jestliže je veřejný klíč klienta prázdný, bude použit důvěryhodný certifikát" }, @@ -1299,7 +1294,6 @@ "server-port-range": "Port by měl být v rozsahu od 1 do 65535.", "server-public-key": "Veřejný klíč serveru", "server-public-key-required": "Veřejný klíč serveru je povinný.", - "server-public-key-pattern": "Veřejný klíč serveru musí být v hexadecimálním formátu.", "client-hold-off-time": "Čas odložení", "client-hold-off-time-required": "Čas odloženíje povinný.", "client-hold-off-time-pattern": "Čas odložení musí být kladné celé číslo.", diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 7bea6e6097..4bbde6c029 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -965,8 +965,6 @@ "identity-required": "Client Identity is required.", "client-key": "Client Key", "client-key-required": "Client Key is required.", - "client-key-pattern": "Client Key must be hexadecimal format.", - "client-key-length": "Client Key must be {{ count }} characters.", "endpoint": "Endpoint Client Name", "endpoint-required": "Endpoint Client Name is required.", "mode": "Security config mode", @@ -977,11 +975,8 @@ "lwm2m-server": "LwM2M Server", "client-publicKey-or-id": "Client Public Key or Id", "client-publicKey-or-id-required": "Client Public Key or Id is required.", - "client-publicKey-or-id-pattern": "Client Public Key or Id must be hexadecimal format.", "client-secret-key": "Client Secret Key", "client-secret-key-required": "Client Secret Key is required.", - "client-secret-key-pattern": "Client Secret Key must be hexadecimal format.", - "client-secret-key-length": "Client Secret Key must be {{ count }} characters.", "client-public-key": "Client public key", "client-public-key-hint": "If client public key is empty, the trusted certificate will be used" }, @@ -1313,7 +1308,6 @@ "server-port-range": "Port should be in a range from 1 to 65535.", "server-public-key": "Server Public Key", "server-public-key-required": "Server Public Key is required.", - "server-public-key-pattern": "Server Public Key must be hex decimal format.", "client-hold-off-time": "Hold Off Time", "client-hold-off-time-required": "Hold Off Time is required.", "client-hold-off-time-pattern": "Hold Off Time must be a positive integer.", diff --git a/ui-ngx/src/assets/locale/locale.constant-tr_TR.json b/ui-ngx/src/assets/locale/locale.constant-tr_TR.json index 087060361b..c600cb0c9a 100644 --- a/ui-ngx/src/assets/locale/locale.constant-tr_TR.json +++ b/ui-ngx/src/assets/locale/locale.constant-tr_TR.json @@ -964,8 +964,6 @@ "identity-required": "İstemci Kimliği gerekli.", "client-key": "İstemci Anahtarı", "client-key-required": "İstemci Anahtarı gerekli.", - "client-key-pattern": "İstemci Anahtarı onaltılık biçimde olmalıdır.", - "client-key-length": "İstemci Anahtarı {{ sayı }} karakter olmalıdır.", "endpoint": "Uç Nokta İstemci Adı", "endpoint-required": "Uç Nokta İstemci Adı gerekli.", "mode": "Güvenlik yapılandırma modu", @@ -976,11 +974,8 @@ "lwm2m-server": "LwM2M Sunucusu", "client-publicKey-or-id": "İstemci Genel Anahtarı veya Kimliği", "client-publicKey-or-id-required": "İstemci Genel Anahtarı veya Kimliği gerekli.", - "client-publicKey-or-id-pattern": "İstemci Genel Anahtarı veya Kimliği onaltılık biçimde olmalıdır.", "client-secret-key": "İstemci Gizli Anahtarı", "client-secret-key-required": "İstemci Gizli Anahtarı gerekli.", - "client-secret-key-pattern": "İstemci Gizli Anahtarı onaltılık biçimde olmalıdır.", - "client-secret-key-length": "İstemci Gizli Anahtarı {{ sayı }} karakter olmalıdır.", "client-public-key": "İstemci açık anahtarı", "client-public-key-hint": "İstemci açık anahtarı boşsa, güvenilen sertifika kullanılacaktır." }, @@ -1312,7 +1307,6 @@ "server-port-range": "Port 1 ila 65535 aralığında olmalıdır.", "server-public-key": "Sunucu Açık Anahtarı", "server-public-key-required": "Sunucu Açık Anahtarı gerekli.", - "server-public-key-pattern": "Sunucu Açık Anahtarı onaltılık biçimde olmalıdır.", "client-hold-off-time": "Bekleme Süresi", "client-hold-off-time-required": "Bekleme Süresi gerekli.", "client-hold-off-time-pattern": "Bekleme Süresi pozitif bir tam sayı olmalıdır.",