Browse Source

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

pull/4992/head
Vladyslav_Prykhodko 5 years ago
committed by Andrew Shvayka
parent
commit
a5b001bf67
  1. 5
      ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html
  2. 19
      ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts
  3. 2
      ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts

5
ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.html

@ -60,10 +60,9 @@
<mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('pattern')">
{{ 'device.lwm2m-security-config.client-key-pattern' | translate }}
</mat-error>
<mat-error *ngIf="(lwm2mConfigFormGroup.get('client.key').hasError('maxlength') ||
lwm2mConfigFormGroup.get('client.key').hasError('minlength'))">
<mat-error *ngIf="lwm2mConfigFormGroup.get('client.key').hasError('length')">
{{ 'device.lwm2m-security-config.client-key-length' | translate: {
count: lenMaxKeyClient
count: allowLengthKey.join(', ')
} }}
</mat-error>
</mat-form-field>

19
ui-ngx/src/app/modules/home/components/device/device-credentials-lwm2m.component.ts

@ -16,6 +16,7 @@
import { Component, forwardRef, OnDestroy } from '@angular/core';
import {
AbstractControl,
ControlValueAccessor,
FormBuilder,
FormGroup,
@ -64,6 +65,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType);
credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap;
lenMaxKeyClient = LEN_MAX_PSK;
allowLengthKey: number[];
private destroy$ = new Subject();
private propagateChange = (v: any) => {};
@ -119,7 +121,7 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
config.key = this.lwm2mConfigFormGroup.get('client.key').value;
break;
}
this.lwm2mConfigFormGroup.get('client').patchValue(config, {emitEvent: false});
this.lwm2mConfigFormGroup.get('client').reset(config, {emitEvent: false});
this.securityConfigClientUpdateValidators(type);
}
@ -135,11 +137,13 @@ 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.setValidatorsPskRpk(mode);
this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false});
break;
@ -164,13 +168,22 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va
this.lwm2mConfigFormGroup.get('client.key').setValidators([
Validators.required,
Validators.pattern(KEY_REGEXP_HEX_DEC),
Validators.maxLength(this.lenMaxKeyClient),
Validators.minLength(this.lenMaxKeyClient)
this.maxLength(this.allowLengthKey)
]);
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({

2
ui-ngx/src/app/shared/models/lwm2m-security-config.models.ts

@ -14,7 +14,7 @@
/// limitations under the License.
///
export const LEN_MAX_PSK = 32;
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;

Loading…
Cancel
Save