diff --git a/src/bw.ts b/src/bw.ts index 886b6e6a74..c50b935428 100644 --- a/src/bw.ts +++ b/src/bw.ts @@ -89,6 +89,7 @@ export class Main { this.exportService = new ExportService(this.folderService, this.cipherService); this.authService = new AuthService(this.cryptoService, this.apiService, this.userService, this.tokenService, this.appIdService, this.i18nService, this.platformUtilsService, this.messagingService, true); + this.auditService = new AuditService(this.cryptoFunctionService); this.program = new Program(this); } diff --git a/src/commands/get.command.ts b/src/commands/get.command.ts index 15c26b355c..b15bd562d1 100644 --- a/src/commands/get.command.ts +++ b/src/commands/get.command.ts @@ -2,6 +2,7 @@ import * as program from 'commander'; import { CipherType } from 'jslib/enums/cipherType'; +import { AuditService } from 'jslib/abstractions/audit.service'; import { CipherService } from 'jslib/abstractions/cipher.service'; import { CollectionService } from 'jslib/abstractions/collection.service'; import { FolderService } from 'jslib/abstractions/folder.service'; @@ -32,7 +33,8 @@ import { CliUtils } from '../utils'; export class GetCommand { constructor(private cipherService: CipherService, private folderService: FolderService, - private collectionService: CollectionService, private totpService: TotpService) { } + private collectionService: CollectionService, private totpService: TotpService, + private auditService: AuditService) { } async run(object: string, id: string, cmd: program.Command): Promise { if (id != null) { @@ -50,6 +52,8 @@ export class GetCommand { return await this.getUri(id); case 'totp': return await this.getTotp(id); + case 'exposed': + return await this.getExposed(id); case 'folder': return await this.getFolder(id); case 'collection': @@ -167,6 +171,17 @@ export class GetCommand { return Response.success(res); } + private async getExposed(id: string) { + const passwordResponse = await this.getPassword(id); + if (!passwordResponse.success) { + return passwordResponse; + } + + const exposedNumber = await this.auditService.passwordLeaked((passwordResponse.data as StringResponse).data); + const res = new StringResponse(exposedNumber.toString()); + return Response.success(res); + } + private async getFolder(id: string) { let decFolder: FolderView = null; if (this.isGuid(id)) { diff --git a/src/program.ts b/src/program.ts index 6659c3de1b..0d421e5f60 100644 --- a/src/program.ts +++ b/src/program.ts @@ -233,6 +233,7 @@ export class Program { writeLn(' password'); writeLn(' uri'); writeLn(' totp'); + writeLn(' exposed'); writeLn(' folder'); writeLn(' collection'); writeLn(' template'); @@ -246,6 +247,7 @@ export class Program { writeLn(' bw get item 99ee88d2-6046-4ea7-92c2-acac464b1412'); writeLn(' bw get password https://google.com'); writeLn(' bw get totp google.com'); + writeLn(' bw get exposed yahoo.com'); writeLn(' bw get folder email'); writeLn(' bw get template folder'); writeLn(''); @@ -253,7 +255,7 @@ export class Program { .action(async (object, id, cmd) => { await this.exitIfLocked(); const command = new GetCommand(this.main.cipherService, this.main.folderService, - this.main.collectionService, this.main.totpService); + this.main.collectionService, this.main.totpService, this.main.auditService); const response = await command.run(object, id, cmd); this.processResponse(response); });