Fixes, if "Change Master" is empty

This commit is contained in:
Sergej Schwabauer 2022-03-22 12:57:42 +01:00
parent 406f2de7ec
commit 6f0d6d747b
2 changed files with 13 additions and 6 deletions

View File

@ -5,7 +5,7 @@ import { IVaultData } from '@src/interfaces/IVaultData';
export interface IPasswordVaultService { export interface IPasswordVaultService {
encryptData(plainData: IVaultData): IVaultData; encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData;
decryptData(encryptedData: IVaultData): IVaultData; decryptData(encryptedData: IVaultData): IVaultData;
open(masterPW: string, encryptedMasterPW: string): boolean; open(masterPW: string, encryptedMasterPW: string): boolean;
isOpen(): boolean; isOpen(): boolean;
@ -72,9 +72,15 @@ export class PasswordVaultService implements IPasswordVaultService {
this.isVaultOpen = toBoolean(this.cache.get(this.encryptedInstanceId)); this.isVaultOpen = toBoolean(this.cache.get(this.encryptedInstanceId));
let pwFromCache = this.cache.get(this.encryptedMasterPWInstanceId); let pwFromCache = this.cache.get(this.encryptedMasterPWInstanceId);
this.encryptedMasterPw = isNullOrEmpty(pwFromCache) ? "" : pwFromCache; this.encryptedMasterPw = isNullOrEmpty(pwFromCache) ? "" : pwFromCache;
if(!isNullOrEmpty(this.encryptedMasterPw)) {
const plainPassword: string = this.decrypt(this.encryptedMasterPw, this.masterSecretKey);
this.hashedMasterPw = CryptoJS.HmacSHA256(plainPassword, this.masterSecretKey).toString();
}
} }
public encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData { public encryptData(plainData: Omit<IVaultData, "masterPW">): IVaultData {
return { return {
masterPW: this.hashedMasterPw, masterPW: this.hashedMasterPw,
username: this.encryptUsername(plainData.username), username: this.encryptUsername(plainData.username),

View File

@ -324,13 +324,15 @@ export default class PasswordVault extends SPFxAppDevWebPartComponent<PasswordVa
<PrimaryButton disabled={this.state.isSaveButtonDisabled} onClick={() => { <PrimaryButton disabled={this.state.isSaveButtonDisabled} onClick={() => {
this.isNewVault = false; this.isNewVault = false;
let encryptedMaster = this.currentMasterPW; let encryptedMaster = this.currentMasterPW;
if(!this.enteredMasterPW.IsEmpty()) { if(!this.enteredMasterPW.IsEmpty()) {
encryptedMaster = this.props.passwordVaultService.setMasterPassword(this.enteredMasterPW); encryptedMaster = this.props.passwordVaultService.setMasterPassword(this.enteredMasterPW);
this.currentMasterPW = encryptedMaster; this.currentMasterPW = encryptedMaster;
} }
this.encryptedData = this.props.passwordVaultService.encryptData({ this.encryptedData = this.props.passwordVaultService.encryptData({
masterPW: encryptedMaster,
note: this.editModeNote, note: this.editModeNote,
password: this.editModePw, password: this.editModePw,
username: this.editModeUsername username: this.editModeUsername
@ -435,12 +437,11 @@ export default class PasswordVault extends SPFxAppDevWebPartComponent<PasswordVa
if(isCorrectPW) { if(isCorrectPW) {
this.decryptedData = props.passwordVaultService.decryptData(this.encryptedData); this.decryptedData = props.passwordVaultService.decryptData(this.encryptedData);
this.editModeNote = this.decryptedData.note;
this.editModePw = this.decryptedData.password;
this.editModeUsername = this.decryptedData.username;
} }
this.editModeNote = this.decryptedData.note;
this.editModePw = this.decryptedData.password;
this.editModeUsername = this.decryptedData.username;
this.setState({ this.setState({
isVaultOpen: isCorrectPW, isVaultOpen: isCorrectPW,
showWrongMasterInfo: !isCorrectPW showWrongMasterInfo: !isCorrectPW