Commit a5b001bf6785cadc85c53054294532421b147e75

Authored by Vladyslav_Prykhodko
Committed by Andrew Shvayka
1 parent a60913af

UI: Change LwM2M DTLS PSK key length allow length 32, 64, 128

@@ -60,10 +60,9 @@ @@ -60,10 +60,9 @@
60 <mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('pattern')"> 60 <mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('pattern')">
61 {{ 'device.lwm2m-security-config.client-key-pattern' | translate }} 61 {{ 'device.lwm2m-security-config.client-key-pattern' | translate }}
62 </mat-error> 62 </mat-error>
63 - <mat-error *ngIf="(lwm2mConfigFormGroup.get('client.key').hasError('maxlength') ||  
64 - lwm2mConfigFormGroup.get('client.key').hasError('minlength'))"> 63 + <mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('length')">
65 {{ 'device.lwm2m-security-config.client-key-length' | translate: { 64 {{ 'device.lwm2m-security-config.client-key-length' | translate: {
66 - count: lenMaxKeyClient 65 + count: allowLengthKey.join(', ')
67 } }} 66 } }}
68 </mat-error> 67 </mat-error>
69 </mat-form-field> 68 </mat-form-field>
@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 16
17 import { Component, forwardRef, OnDestroy } from '@angular/core'; 17 import { Component, forwardRef, OnDestroy } from '@angular/core';
18 import { 18 import {
  19 + AbstractControl,
19 ControlValueAccessor, 20 ControlValueAccessor,
20 FormBuilder, 21 FormBuilder,
21 FormGroup, 22 FormGroup,
@@ -64,6 +65,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va @@ -64,6 +65,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
64 securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); 65 securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType);
65 credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; 66 credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap;
66 lenMaxKeyClient = LEN_MAX_PSK; 67 lenMaxKeyClient = LEN_MAX_PSK;
  68 + allowLengthKey: number[];
67 69
68 private destroy$ = new Subject(); 70 private destroy$ = new Subject();
69 private propagateChange = (v: any) => {}; 71 private propagateChange = (v: any) => {};
@@ -119,7 +121,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va @@ -119,7 +121,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
119 config.key = this.lwm2mConfigFormGroup.get('client.key').value; 121 config.key = this.lwm2mConfigFormGroup.get('client.key').value;
120 break; 122 break;
121 } 123 }
122 - this.lwm2mConfigFormGroup.get('client').patchValue(config, {emitEvent: false}); 124 + this.lwm2mConfigFormGroup.get('client').reset(config, {emitEvent: false});
123 this.securityConfigClientUpdateValidators(type); 125 this.securityConfigClientUpdateValidators(type);
124 } 126 }
125 127
@@ -135,11 +137,13 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va @@ -135,11 +137,13 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
135 break; 137 break;
136 case Lwm2mSecurityType.PSK: 138 case Lwm2mSecurityType.PSK:
137 this.lenMaxKeyClient = LEN_MAX_PSK; 139 this.lenMaxKeyClient = LEN_MAX_PSK;
  140 + this.allowLengthKey = [32, 64, LEN_MAX_PSK];
138 this.setValidatorsPskRpk(mode); 141 this.setValidatorsPskRpk(mode);
139 this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); 142 this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false});
140 break; 143 break;
141 case Lwm2mSecurityType.RPK: 144 case Lwm2mSecurityType.RPK:
142 this.lenMaxKeyClient = LEN_MAX_PUBLIC_KEY_RPK; 145 this.lenMaxKeyClient = LEN_MAX_PUBLIC_KEY_RPK;
  146 + this.allowLengthKey = [LEN_MAX_PUBLIC_KEY_RPK];
143 this.setValidatorsPskRpk(mode); 147 this.setValidatorsPskRpk(mode);
144 this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); 148 this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false});
145 break; 149 break;
@@ -164,13 +168,22 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va @@ -164,13 +168,22 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
164 this.lwm2mConfigFormGroup.get('client.key').setValidators([ 168 this.lwm2mConfigFormGroup.get('client.key').setValidators([
165 Validators.required, 169 Validators.required,
166 Validators.pattern(KEY_REGEXP_HEX_DEC), 170 Validators.pattern(KEY_REGEXP_HEX_DEC),
167 - Validators.maxLength(this.lenMaxKeyClient),  
168 - Validators.minLength(this.lenMaxKeyClient) 171 + this.maxLength(this.allowLengthKey)
169 ]); 172 ]);
170 this.lwm2mConfigFormGroup.get('client.key').enable({emitEvent: false}); 173 this.lwm2mConfigFormGroup.get('client.key').enable({emitEvent: false});
171 this.lwm2mConfigFormGroup.get('client.cert').disable({emitEvent: false}); 174 this.lwm2mConfigFormGroup.get('client.cert').disable({emitEvent: false});
172 } 175 }
173 176
  177 + private maxLength(keyLengths: number[]) {
  178 + return (control: AbstractControl): ValidationErrors | null => {
  179 + const value = control.value;
  180 + if (keyLengths.some(len => value.length === len)) {
  181 + return null;
  182 + }
  183 + return {length: true};
  184 + };
  185 + }
  186 +
174 private initLwm2mConfigForm = (): FormGroup => { 187 private initLwm2mConfigForm = (): FormGroup => {
175 const formGroup = this.fb.group({ 188 const formGroup = this.fb.group({
176 client: this.fb.group({ 189 client: this.fb.group({
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 /// limitations under the License. 14 /// limitations under the License.
15 /// 15 ///
16 16
17 -export const LEN_MAX_PSK = 32; 17 +export const LEN_MAX_PSK = 128;
18 export const LEN_MAX_PRIVATE_KEY = 134; 18 export const LEN_MAX_PRIVATE_KEY = 134;
19 export const LEN_MAX_PUBLIC_KEY_RPK = 182; 19 export const LEN_MAX_PUBLIC_KEY_RPK = 182;
20 export const LEN_MAX_PUBLIC_KEY_X509 = 3000; 20 export const LEN_MAX_PUBLIC_KEY_X509 = 3000;