Commit a5b001bf6785cadc85c53054294532421b147e75
Committed by
Andrew Shvayka
1 parent
a60913af
UI: Change LwM2M DTLS PSK key length allow length 32, 64, 128
Showing
3 changed files
with
19 additions
and
7 deletions
... | ... | @@ -60,10 +60,9 @@ |
60 | 60 | <mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('pattern')"> |
61 | 61 | {{ 'device.lwm2m-security-config.client-key-pattern' | translate }} |
62 | 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 | 64 | {{ 'device.lwm2m-security-config.client-key-length' | translate: { |
66 | - count: lenMaxKeyClient | |
65 | + count: allowLengthKey.join(', ') | |
67 | 66 | } }} |
68 | 67 | </mat-error> |
69 | 68 | </mat-form-field> | ... | ... |
... | ... | @@ -16,6 +16,7 @@ |
16 | 16 | |
17 | 17 | import { Component, forwardRef, OnDestroy } from '@angular/core'; |
18 | 18 | import { |
19 | + AbstractControl, | |
19 | 20 | ControlValueAccessor, |
20 | 21 | FormBuilder, |
21 | 22 | FormGroup, |
... | ... | @@ -64,6 +65,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
64 | 65 | securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); |
65 | 66 | credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; |
66 | 67 | lenMaxKeyClient = LEN_MAX_PSK; |
68 | + allowLengthKey: number[]; | |
67 | 69 | |
68 | 70 | private destroy$ = new Subject(); |
69 | 71 | private propagateChange = (v: any) => {}; |
... | ... | @@ -119,7 +121,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
119 | 121 | config.key = this.lwm2mConfigFormGroup.get('client.key').value; |
120 | 122 | break; |
121 | 123 | } |
122 | - this.lwm2mConfigFormGroup.get('client').patchValue(config, {emitEvent: false}); | |
124 | + this.lwm2mConfigFormGroup.get('client').reset(config, {emitEvent: false}); | |
123 | 125 | this.securityConfigClientUpdateValidators(type); |
124 | 126 | } |
125 | 127 | |
... | ... | @@ -135,11 +137,13 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
135 | 137 | break; |
136 | 138 | case Lwm2mSecurityType.PSK: |
137 | 139 | this.lenMaxKeyClient = LEN_MAX_PSK; |
140 | + this.allowLengthKey = [32, 64, LEN_MAX_PSK]; | |
138 | 141 | this.setValidatorsPskRpk(mode); |
139 | 142 | this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); |
140 | 143 | break; |
141 | 144 | case Lwm2mSecurityType.RPK: |
142 | 145 | this.lenMaxKeyClient = LEN_MAX_PUBLIC_KEY_RPK; |
146 | + this.allowLengthKey = [LEN_MAX_PUBLIC_KEY_RPK]; | |
143 | 147 | this.setValidatorsPskRpk(mode); |
144 | 148 | this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); |
145 | 149 | break; |
... | ... | @@ -164,13 +168,22 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
164 | 168 | this.lwm2mConfigFormGroup.get('client.key').setValidators([ |
165 | 169 | Validators.required, |
166 | 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 | 173 | this.lwm2mConfigFormGroup.get('client.key').enable({emitEvent: false}); |
171 | 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 | 187 | private initLwm2mConfigForm = (): FormGroup => { |
175 | 188 | const formGroup = this.fb.group({ |
176 | 189 | client: this.fb.group({ | ... | ... |
... | ... | @@ -14,7 +14,7 @@ |
14 | 14 | /// limitations under the License. |
15 | 15 | /// |
16 | 16 | |
17 | -export const LEN_MAX_PSK = 32; | |
17 | +export const LEN_MAX_PSK = 128; | |
18 | 18 | export const LEN_MAX_PRIVATE_KEY = 134; |
19 | 19 | export const LEN_MAX_PUBLIC_KEY_RPK = 182; |
20 | 20 | export const LEN_MAX_PUBLIC_KEY_X509 = 3000; | ... | ... |