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 a40ce4cb69..429a13ddb2 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 @@ -28,27 +28,18 @@ {{ 'device.lwm2m-security-config.client-publicKey-or-id' | translate }} - {{clientPublicKeyOrId.value?.length || 0}}/{{lenMaxClientPublicKeyOrId}} {{ '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-publicKey-or-id-length' | translate: { - count: lenMaxClientPublicKeyOrId - } }} - {{ 'device.lwm2m-security-config.client-secret-key' | translate }} @@ -61,17 +52,18 @@ formControlName="clientSecretKey" required> - {{clientSecretKey.value?.length || 0}}/{{lengthClientSecretKey}} + + {{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: lengthClientSecretKey + 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 267650eef7..7c6ad485f3 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,6 +16,7 @@ import { Component, forwardRef, OnDestroy } from '@angular/core'; import { + AbstractControl, ControlValueAccessor, FormBuilder, FormGroup, @@ -29,8 +30,6 @@ import { KEY_REGEXP_HEX_DEC, LEN_MAX_PRIVATE_KEY, LEN_MAX_PSK, - LEN_MAX_PUBLIC_KEY_RPK, - LEN_MAX_PUBLIC_KEY_X509, Lwm2mSecurityType, Lwm2mSecurityTypeTranslationMap, ServerSecurityConfig @@ -62,9 +61,8 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control securityConfigLwM2MType = Lwm2mSecurityType; securityConfigLwM2MTypes = Object.values(Lwm2mSecurityType); lwm2mSecurityTypeTranslationMap = Lwm2mSecurityTypeTranslationMap; - lenMinClientPublicKeyOrId = 0; - lenMaxClientPublicKeyOrId = LEN_MAX_PUBLIC_KEY_RPK; lengthClientSecretKey = LEN_MAX_PRIVATE_KEY; + allowLengthKey = [32, 64, LEN_MAX_PSK]; private destroy$ = new Subject(); private propagateChange = (v: any) => {}; @@ -134,21 +132,15 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control this.serverFormGroup.get('clientSecretKey').disable(); break; case Lwm2mSecurityType.PSK: - this.lenMinClientPublicKeyOrId = 0; - this.lenMaxClientPublicKeyOrId = LEN_MAX_PUBLIC_KEY_RPK; this.lengthClientSecretKey = LEN_MAX_PSK; this.setValidatorsSecurity(securityMode); break; case Lwm2mSecurityType.RPK: - this.lenMinClientPublicKeyOrId = LEN_MAX_PUBLIC_KEY_RPK; - this.lenMaxClientPublicKeyOrId = LEN_MAX_PUBLIC_KEY_RPK; - this.lengthClientSecretKey = LEN_MAX_PRIVATE_KEY; + this.lengthClientSecretKey = null; this.setValidatorsSecurity(securityMode); break; case Lwm2mSecurityType.X509: - this.lenMinClientPublicKeyOrId = 0; - this.lenMaxClientPublicKeyOrId = LEN_MAX_PUBLIC_KEY_X509; - this.lengthClientSecretKey = LEN_MAX_PRIVATE_KEY; + this.lengthClientSecretKey = null; this.setValidatorsSecurity(securityMode); break; } @@ -157,25 +149,28 @@ export class DeviceCredentialsLwm2mServerComponent implements OnDestroy, Control } private setValidatorsSecurity = (securityMode: Lwm2mSecurityType): void => { + const clientSecretKeyValidators = [Validators.required, Validators.pattern(KEY_REGEXP_HEX_DEC)]; + const clientPublicKeyOrIdValidators = [Validators.required]; if (securityMode === Lwm2mSecurityType.PSK) { - this.serverFormGroup.get('clientPublicKeyOrId').setValidators([Validators.required]); + clientSecretKeyValidators.push(this.maxLength(this.allowLengthKey)); } else { - this.serverFormGroup.get('clientPublicKeyOrId').setValidators([ - Validators.required, - Validators.pattern(KEY_REGEXP_HEX_DEC), - Validators.minLength(this.lenMinClientPublicKeyOrId), - Validators.maxLength(this.lenMaxClientPublicKeyOrId) - ]); + clientPublicKeyOrIdValidators.push(Validators.pattern(KEY_REGEXP_HEX_DEC)); } - this.serverFormGroup.get('clientSecretKey').setValidators([ - Validators.required, - Validators.pattern(KEY_REGEXP_HEX_DEC), - Validators.minLength(this.lengthClientSecretKey), - Validators.maxLength(this.lengthClientSecretKey) - ]); + this.serverFormGroup.get('clientPublicKeyOrId').setValidators(clientPublicKeyOrIdValidators); + this.serverFormGroup.get('clientSecretKey').setValidators(clientSecretKeyValidators); 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 9bc5c799ac..b588f1af72 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 @@ -53,7 +53,8 @@ formControlName="key" required> - {{key.value?.length || 0}}/{{lenMaxKeyClient}} + {{key.value?.length || 0}}/{{lenMaxKeyClient}} {{ 'device.lwm2m-security-config.client-key-required' | translate }} 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 99123a5db3..ff5fba9bdd 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 @@ -31,7 +31,6 @@ import { getDefaultServerSecurityConfig, KEY_REGEXP_HEX_DEC, LEN_MAX_PSK, - LEN_MAX_PUBLIC_KEY_RPK, Lwm2mSecurityConfigModels, Lwm2mSecurityType, Lwm2mSecurityTypeTranslationMap @@ -65,7 +64,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; lenMaxKeyClient = LEN_MAX_PSK; - allowLengthKey: number[]; + allowLengthKey = [32, 64, LEN_MAX_PSK]; private destroy$ = new Subject(); private propagateChange = (v: any) => {}; @@ -137,13 +136,11 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va break; case Lwm2mSecurityType.PSK: this.lenMaxKeyClient = LEN_MAX_PSK; - this.allowLengthKey = [32, 64, LEN_MAX_PSK]; this.setValidatorsPskRpk(mode); this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); break; case Lwm2mSecurityType.RPK: - this.lenMaxKeyClient = LEN_MAX_PUBLIC_KEY_RPK; - this.allowLengthKey = [LEN_MAX_PUBLIC_KEY_RPK]; + this.lenMaxKeyClient = null; this.setValidatorsPskRpk(mode); this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); break; @@ -160,16 +157,14 @@ 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([ - Validators.required, - Validators.pattern(KEY_REGEXP_HEX_DEC), - this.maxLength(this.allowLengthKey) - ]); + this.lwm2mConfigFormGroup.get('client.key').setValidators(keyValidators); this.lwm2mConfigFormGroup.get('client.key').enable({emitEvent: false}); this.lwm2mConfigFormGroup.get('client.cert').disable({emitEvent: false}); } 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 3a8ac64658..b2d69c252f 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 @@ -95,24 +95,17 @@ {{ 'device-profile.lwm2m.server-public-key' | translate }} - {{serverPublicKey.value?.length || 0}}/{{maxLengthPublicKey}} {{ 'device-profile.lwm2m.server-public-key-required' | translate }} {{ 'device-profile.lwm2m.server-public-key-pattern' | translate }} - - {{ 'device-profile.lwm2m.server-public-key-length' | translate: {count: maxLengthPublicKey } }} - 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 d0c51ee847..63cde444ba 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 @@ -29,8 +29,6 @@ import { DEFAULT_PORT_BOOTSTRAP_NO_SEC, DEFAULT_PORT_SERVER_NO_SEC, KEY_REGEXP_HEX_DEC, - LEN_MAX_PUBLIC_KEY_RPK, - LEN_MAX_PUBLIC_KEY_X509, securityConfigMode, securityConfigModeNames, ServerSecurityConfig @@ -68,7 +66,6 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc securityConfigLwM2MType = securityConfigMode; securityConfigLwM2MTypes = Object.keys(securityConfigMode); credentialTypeLwM2MNamesMap = securityConfigModeNames; - maxLengthPublicKey = LEN_MAX_PUBLIC_KEY_RPK; currentSecurityMode = null; @Input() @@ -147,12 +144,10 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc this.clearValidators(); break; case securityConfigMode.RPK: - this.maxLengthPublicKey = LEN_MAX_PUBLIC_KEY_RPK; - this.setValidators(LEN_MAX_PUBLIC_KEY_RPK); + this.setValidators(); break; case securityConfigMode.X509: - this.maxLengthPublicKey = LEN_MAX_PUBLIC_KEY_X509; - this.setValidators(0); + this.setValidators(); break; } this.serverFormGroup.get('serverPublicKey').updateValueAndValidity({emitEvent: false}); @@ -162,12 +157,10 @@ export class Lwm2mDeviceConfigServerComponent implements OnInit, ControlValueAcc this.serverFormGroup.get('serverPublicKey').clearValidators(); } - private setValidators(minLengthKey: number): void { + private setValidators(): void { this.serverFormGroup.get('serverPublicKey').setValidators([ Validators.required, - Validators.pattern(KEY_REGEXP_HEX_DEC), - Validators.minLength(minLengthKey), - Validators.maxLength(this.maxLengthPublicKey) + Validators.pattern(KEY_REGEXP_HEX_DEC) ]); } 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 5e31251786..3be58c7f7f 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,8 +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 LEN_MAX_PUBLIC_KEY_RPK = 182; -export const LEN_MAX_PUBLIC_KEY_X509 = 3000; 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; 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 060e1632f1..3076d5ba3c 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 @@ -16,8 +16,6 @@ export const LEN_MAX_PSK = 128; export const LEN_MAX_PRIVATE_KEY = 134; -export const LEN_MAX_PUBLIC_KEY_RPK = 182; -export const LEN_MAX_PUBLIC_KEY_X509 = 3000; export const KEY_REGEXP_HEX_DEC = /^[-+]?[0-9A-Fa-f]+\.?[0-9A-Fa-f]*?$/; export enum Lwm2mSecurityType { 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 b0fc26abe2..b5a23c0150 100644 --- a/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json +++ b/ui-ngx/src/assets/locale/locale.constant-cs_CZ.json @@ -974,7 +974,6 @@ "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-publicKey-or-id-length": "Veřejný klíč klienta nebo Id musí mít {{ count }} znaků.", "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.", @@ -1301,7 +1300,6 @@ "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.", - "server-public-key-length": "Veřejný klíč serveru musí být {{ count }} znaků.", "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 8d1632a241..bcc13aa024 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -978,7 +978,6 @@ "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-publicKey-or-id-length": "Client Public Key or Id must be {{ count }} characters.", "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.", @@ -1315,7 +1314,6 @@ "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.", - "server-public-key-length": "Server Public Key must be {{ count }} characters.", "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.",