mirror of
https://github.com/bitwarden/browser.git
synced 2025-01-30 22:41:33 +01:00
[Reset Password] Update Crypto and Policy services (#387)
This commit is contained in:
parent
5f1ad85dd1
commit
395ded02aa
@ -43,7 +43,7 @@ export abstract class CryptoService {
|
|||||||
encrypt: (plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey) => Promise<EncString>;
|
encrypt: (plainValue: string | ArrayBuffer, key?: SymmetricCryptoKey) => Promise<EncString>;
|
||||||
encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<EncArrayBuffer>;
|
encryptToBytes: (plainValue: ArrayBuffer, key?: SymmetricCryptoKey) => Promise<EncArrayBuffer>;
|
||||||
rsaEncrypt: (data: ArrayBuffer, publicKey?: ArrayBuffer) => Promise<EncString>;
|
rsaEncrypt: (data: ArrayBuffer, publicKey?: ArrayBuffer) => Promise<EncString>;
|
||||||
rsaDecrypt: (encValue: string) => Promise<ArrayBuffer>;
|
rsaDecrypt: (encValue: string, privateKeyValue?: ArrayBuffer) => Promise<ArrayBuffer>;
|
||||||
decryptToBytes: (encString: EncString, key?: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
decryptToBytes: (encString: EncString, key?: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
||||||
decryptToUtf8: (encString: EncString, key?: SymmetricCryptoKey) => Promise<string>;
|
decryptToUtf8: (encString: EncString, key?: SymmetricCryptoKey) => Promise<string>;
|
||||||
decryptFromBytes: (encBuf: ArrayBuffer, key: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
decryptFromBytes: (encBuf: ArrayBuffer, key: SymmetricCryptoKey) => Promise<ArrayBuffer>;
|
||||||
|
@ -6,6 +6,9 @@ import { ResetPasswordPolicyOptions } from '../models/domain/resetPasswordPolicy
|
|||||||
|
|
||||||
import { PolicyType } from '../enums/policyType';
|
import { PolicyType } from '../enums/policyType';
|
||||||
|
|
||||||
|
import { ListResponse } from '../models/response/listResponse';
|
||||||
|
import { PolicyResponse } from '../models/response/policyResponse';
|
||||||
|
|
||||||
export abstract class PolicyService {
|
export abstract class PolicyService {
|
||||||
policyCache: Policy[];
|
policyCache: Policy[];
|
||||||
|
|
||||||
@ -16,5 +19,6 @@ export abstract class PolicyService {
|
|||||||
getMasterPasswordPolicyOptions: (policies?: Policy[]) => Promise<MasterPasswordPolicyOptions>;
|
getMasterPasswordPolicyOptions: (policies?: Policy[]) => Promise<MasterPasswordPolicyOptions>;
|
||||||
evaluateMasterPassword: (passwordStrength: number, newPassword: string,
|
evaluateMasterPassword: (passwordStrength: number, newPassword: string,
|
||||||
enforcedPolicyOptions?: MasterPasswordPolicyOptions) => boolean;
|
enforcedPolicyOptions?: MasterPasswordPolicyOptions) => boolean;
|
||||||
getResetPasswordPolicyOptions: (policy: Policy) => ResetPasswordPolicyOptions;
|
getResetPasswordPolicyOptions: (policies: Policy[], orgId: string) => [ResetPasswordPolicyOptions, boolean];
|
||||||
|
mapPoliciesFromToken: (policiesResponse: ListResponse<PolicyResponse>) => Policy[];
|
||||||
}
|
}
|
||||||
|
@ -446,7 +446,7 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
return new EncString(EncryptionType.Rsa2048_OaepSha1_B64, Utils.fromBufferToB64(encBytes));
|
return new EncString(EncryptionType.Rsa2048_OaepSha1_B64, Utils.fromBufferToB64(encBytes));
|
||||||
}
|
}
|
||||||
|
|
||||||
async rsaDecrypt(encValue: string): Promise<ArrayBuffer> {
|
async rsaDecrypt(encValue: string, privateKeyValue?: ArrayBuffer): Promise<ArrayBuffer> {
|
||||||
const headerPieces = encValue.split('.');
|
const headerPieces = encValue.split('.');
|
||||||
let encType: EncryptionType = null;
|
let encType: EncryptionType = null;
|
||||||
let encPieces: string[];
|
let encPieces: string[];
|
||||||
@ -477,7 +477,7 @@ export class CryptoService implements CryptoServiceAbstraction {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const data = Utils.fromB64ToArray(encPieces[0]).buffer;
|
const data = Utils.fromB64ToArray(encPieces[0]).buffer;
|
||||||
const privateKey = await this.getPrivateKey();
|
const privateKey = privateKeyValue ?? await this.getPrivateKey();
|
||||||
if (privateKey == null) {
|
if (privateKey == null) {
|
||||||
throw new Error('No private key.');
|
throw new Error('No private key.');
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,12 @@ import { PolicyData } from '../models/data/policyData';
|
|||||||
|
|
||||||
import { MasterPasswordPolicyOptions } from '../models/domain/masterPasswordPolicyOptions';
|
import { MasterPasswordPolicyOptions } from '../models/domain/masterPasswordPolicyOptions';
|
||||||
import { Policy } from '../models/domain/policy';
|
import { Policy } from '../models/domain/policy';
|
||||||
|
import { ResetPasswordPolicyOptions } from '../models/domain/resetPasswordPolicyOptions';
|
||||||
|
|
||||||
import { PolicyType } from '../enums/policyType';
|
import { PolicyType } from '../enums/policyType';
|
||||||
import { ResetPasswordPolicyOptions } from '../models/domain/resetPasswordPolicyOptions';
|
|
||||||
|
import { ListResponse } from '../models/response/listResponse';
|
||||||
|
import { PolicyResponse } from '../models/response/policyResponse';
|
||||||
|
|
||||||
const Keys = {
|
const Keys = {
|
||||||
policiesPrefix: 'policies_',
|
policiesPrefix: 'policies_',
|
||||||
@ -140,13 +143,25 @@ export class PolicyService implements PolicyServiceAbstraction {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
getResetPasswordPolicyOptions(policy: Policy): ResetPasswordPolicyOptions {
|
getResetPasswordPolicyOptions(policies: Policy[], orgId: string): [ResetPasswordPolicyOptions, boolean] {
|
||||||
const resetPasswordPolicyOptions = new ResetPasswordPolicyOptions();
|
const resetPasswordPolicyOptions = new ResetPasswordPolicyOptions();
|
||||||
|
|
||||||
if (policy != null && policy.enabled && policy.data != null) {
|
if (policies == null || orgId == null) {
|
||||||
resetPasswordPolicyOptions.autoEnrollEnabled = policy.data.autoEnrollEnabled;
|
return [resetPasswordPolicyOptions, false];
|
||||||
}
|
}
|
||||||
|
|
||||||
return resetPasswordPolicyOptions;
|
const policy = policies.find(p => p.organizationId === orgId && p.type === PolicyType.ResetPassword && p.enabled);
|
||||||
|
resetPasswordPolicyOptions.autoEnrollEnabled = policy?.data?.autoEnrollEnabled ?? false;
|
||||||
|
|
||||||
|
return [resetPasswordPolicyOptions, policy?.enabled ?? false];
|
||||||
|
}
|
||||||
|
|
||||||
|
mapPoliciesFromToken(policiesResponse: ListResponse<PolicyResponse>): Policy[] {
|
||||||
|
if (policiesResponse == null || policiesResponse.data == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const policiesData = policiesResponse.data.map(p => new PolicyData(p));
|
||||||
|
return policiesData.map(p => new Policy(p));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user