|
|
@ -16,7 +16,6 @@ |
|
|
|
|
|
|
|
|
import { Component, forwardRef, OnDestroy } from '@angular/core'; |
|
|
import { Component, forwardRef, OnDestroy } from '@angular/core'; |
|
|
import { |
|
|
import { |
|
|
AbstractControl, |
|
|
|
|
|
ControlValueAccessor, |
|
|
ControlValueAccessor, |
|
|
FormBuilder, |
|
|
FormBuilder, |
|
|
FormGroup, |
|
|
FormGroup, |
|
|
@ -29,8 +28,6 @@ import { |
|
|
import { |
|
|
import { |
|
|
getDefaultClientSecurityConfig, |
|
|
getDefaultClientSecurityConfig, |
|
|
getDefaultServerSecurityConfig, |
|
|
getDefaultServerSecurityConfig, |
|
|
KEY_REGEXP_HEX_DEC, |
|
|
|
|
|
LEN_MAX_PSK, |
|
|
|
|
|
Lwm2mSecurityConfigModels, |
|
|
Lwm2mSecurityConfigModels, |
|
|
Lwm2mSecurityType, |
|
|
Lwm2mSecurityType, |
|
|
Lwm2mSecurityTypeTranslationMap |
|
|
Lwm2mSecurityTypeTranslationMap |
|
|
@ -63,8 +60,6 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
|
|
securityConfigLwM2MType = Lwm2mSecurityType; |
|
|
securityConfigLwM2MType = Lwm2mSecurityType; |
|
|
securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); |
|
|
securityConfigLwM2MTypes = Object.keys(Lwm2mSecurityType); |
|
|
credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; |
|
|
credentialTypeLwM2MNamesMap = Lwm2mSecurityTypeTranslationMap; |
|
|
lenMaxKeyClient = LEN_MAX_PSK; |
|
|
|
|
|
allowLengthKey = [32, 64, LEN_MAX_PSK]; |
|
|
|
|
|
|
|
|
|
|
|
private destroy$ = new Subject(); |
|
|
private destroy$ = new Subject(); |
|
|
private propagateChange = (v: any) => {}; |
|
|
private propagateChange = (v: any) => {}; |
|
|
@ -135,12 +130,10 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
|
|
this.lwm2mConfigFormGroup.get('client.cert').enable({emitEvent: false}); |
|
|
this.lwm2mConfigFormGroup.get('client.cert').enable({emitEvent: false}); |
|
|
break; |
|
|
break; |
|
|
case Lwm2mSecurityType.PSK: |
|
|
case Lwm2mSecurityType.PSK: |
|
|
this.lenMaxKeyClient = LEN_MAX_PSK; |
|
|
|
|
|
this.setValidatorsPskRpk(mode); |
|
|
this.setValidatorsPskRpk(mode); |
|
|
this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); |
|
|
this.lwm2mConfigFormGroup.get('client.identity').enable({emitEvent: false}); |
|
|
break; |
|
|
break; |
|
|
case Lwm2mSecurityType.RPK: |
|
|
case Lwm2mSecurityType.RPK: |
|
|
this.lenMaxKeyClient = null; |
|
|
|
|
|
this.setValidatorsPskRpk(mode); |
|
|
this.setValidatorsPskRpk(mode); |
|
|
this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); |
|
|
this.lwm2mConfigFormGroup.get('client.identity').disable({emitEvent: false}); |
|
|
break; |
|
|
break; |
|
|
@ -157,28 +150,16 @@ export class DeviceCredentialsLwm2mComponent implements ControlValueAccessor, Va |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
private setValidatorsPskRpk = (mode: Lwm2mSecurityType): void => { |
|
|
private setValidatorsPskRpk = (mode: Lwm2mSecurityType): void => { |
|
|
const keyValidators = [Validators.required, Validators.pattern(KEY_REGEXP_HEX_DEC)]; |
|
|
|
|
|
if (mode === Lwm2mSecurityType.PSK) { |
|
|
if (mode === Lwm2mSecurityType.PSK) { |
|
|
this.lwm2mConfigFormGroup.get('client.identity').setValidators([Validators.required]); |
|
|
this.lwm2mConfigFormGroup.get('client.identity').setValidators([Validators.required]); |
|
|
keyValidators.push(this.maxLength(this.allowLengthKey)); |
|
|
|
|
|
} else { |
|
|
} else { |
|
|
this.lwm2mConfigFormGroup.get('client.identity').clearValidators(); |
|
|
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.key').enable({emitEvent: false}); |
|
|
this.lwm2mConfigFormGroup.get('client.cert').disable({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 => { |
|
|
private initLwm2mConfigForm = (): FormGroup => { |
|
|
const formGroup = this.fb.group({ |
|
|
const formGroup = this.fb.group({ |
|
|
client: this.fb.group({ |
|
|
client: this.fb.group({ |
|
|
|