mirror of
https://github.com/bitwarden/browser.git
synced 2024-11-30 13:03:53 +01:00
breach report audit api
This commit is contained in:
parent
569ad25208
commit
a097ef9bea
@ -1,3 +1,6 @@
|
|||||||
|
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
|
||||||
|
|
||||||
export abstract class AuditService {
|
export abstract class AuditService {
|
||||||
passwordLeaked: (password: string) => Promise<number>;
|
passwordLeaked: (password: string) => Promise<number>;
|
||||||
|
breachedAccounts: (email: string) => Promise<BreachAccountResponse[]>;
|
||||||
}
|
}
|
||||||
|
29
src/models/response/breachAccountResponse.ts
Normal file
29
src/models/response/breachAccountResponse.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
export class BreachAccountResponse {
|
||||||
|
addedDate: Date;
|
||||||
|
breachDate: Date;
|
||||||
|
dataClasses: string[];
|
||||||
|
description: string;
|
||||||
|
domain: string;
|
||||||
|
isActive: boolean;
|
||||||
|
isVerified: boolean;
|
||||||
|
logoType: string;
|
||||||
|
modifiedDate: Date;
|
||||||
|
name: string;
|
||||||
|
pwnCount: number;
|
||||||
|
title: string;
|
||||||
|
|
||||||
|
constructor(response: any) {
|
||||||
|
this.addedDate = response.AddedDate;
|
||||||
|
this.breachDate = response.BreachDate;
|
||||||
|
this.dataClasses = response.DataClasses;
|
||||||
|
this.description = response.Description;
|
||||||
|
this.domain = response.Domain;
|
||||||
|
this.isActive = response.IsActive;
|
||||||
|
this.isVerified = response.IsVerified;
|
||||||
|
this.logoType = response.LogoType;
|
||||||
|
this.modifiedDate = response.ModifiedDate;
|
||||||
|
this.name = response.Name;
|
||||||
|
this.pwnCount = response.PwnCount;
|
||||||
|
this.title = response.Title;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,12 @@
|
|||||||
import { AuditService as AuditServiceAbstraction } from '../abstractions/audit.service';
|
import { AuditService as AuditServiceAbstraction } from '../abstractions/audit.service';
|
||||||
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
|
import { CryptoFunctionService } from '../abstractions/cryptoFunction.service';
|
||||||
|
|
||||||
import { Utils } from '../misc/utils';
|
import { Utils } from '../misc/utils';
|
||||||
|
|
||||||
|
import { BreachAccountResponse } from '../models/response/breachAccountResponse';
|
||||||
|
|
||||||
const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/';
|
const PwnedPasswordsApi = 'https://api.pwnedpasswords.com/range/';
|
||||||
|
const HibpBreachApi = 'https://haveibeenpwned.com/api/v2/breachedaccount/';
|
||||||
|
|
||||||
export class AuditService implements AuditServiceAbstraction {
|
export class AuditService implements AuditServiceAbstraction {
|
||||||
constructor(private cryptoFunctionService: CryptoFunctionService) { }
|
constructor(private cryptoFunctionService: CryptoFunctionService) { }
|
||||||
@ -21,4 +25,15 @@ export class AuditService implements AuditServiceAbstraction {
|
|||||||
|
|
||||||
return match != null ? parseInt(match.split(':')[1], 10) : 0;
|
return match != null ? parseInt(match.split(':')[1], 10) : 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async breachedAccounts(email: string): Promise<BreachAccountResponse[]> {
|
||||||
|
const response = await fetch(HibpBreachApi + email);
|
||||||
|
if (response.status === 404) {
|
||||||
|
return [];
|
||||||
|
} else if (response.status !== 200) {
|
||||||
|
throw new Error();
|
||||||
|
}
|
||||||
|
const responseJson = await response.json();
|
||||||
|
return responseJson.map((a) => new BreachAccountResponse(a));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user