From 06e56f0b57e601b928f54fa17621bec9ba413bb5 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 23 Apr 2018 10:02:30 -0400 Subject: [PATCH] copy totp from each implementation of autofill --- src/background/main.background.ts | 2 +- src/background/runtime.background.ts | 13 ++++++++--- src/popup/vault/current-tab.component.ts | 3 +-- src/services/abstractions/autofill.service.ts | 2 +- src/services/autofill.service.ts | 22 +++++-------------- 5 files changed, 18 insertions(+), 24 deletions(-) diff --git a/src/background/main.background.ts b/src/background/main.background.ts index 064c6c5409..b3bdd30aee 100644 --- a/src/background/main.background.ts +++ b/src/background/main.background.ts @@ -147,7 +147,7 @@ export default class MainBackground { this.passwordGenerationService = new PasswordGenerationService(this.cryptoService, this.storageService); this.totpService = new TotpService(this.storageService, cryptoFunctionService); this.autofillService = new AutofillService(this.cipherService, this.tokenService, - this.totpService, this.utilsService, this.platformUtilsService); + this.totpService); this.containerService = new ContainerService(this.cryptoService, this.platformUtilsService); this.auditService = new AuditService(cryptoFunctionService); this.analytics = new Analytics(window, () => BrowserApi.gaFilter(), this.platformUtilsService, diff --git a/src/background/runtime.background.ts b/src/background/runtime.background.ts index 2523257f80..1b96c8be9b 100644 --- a/src/background/runtime.background.ts +++ b/src/background/runtime.background.ts @@ -136,11 +136,15 @@ export default class RuntimeBackground { break; case 'autofiller': case 'autofill_cmd': - await this.autofillService.doAutoFillForLastUsedLogin([{ + const totpCode = await this.autofillService.doAutoFillForLastUsedLogin([{ frameId: sender.frameId, tab: msg.tab, details: msg.details, }], msg.sender === 'autofill_cmd'); + + if (totpCode !== null && !this.platformUtilsService.isFirefox()) { + this.platformUtilsService.copyToClipboard(totpCode); + } break; case 'contextMenu': clearTimeout(this.autofillTimeout); @@ -161,12 +165,15 @@ export default class RuntimeBackground { } private async autofillPage() { - await this.autofillService.doAutoFill({ + const totpCode = await this.autofillService.doAutoFill({ cipher: this.main.loginToAutoFill, pageDetails: this.pageDetailsToAutoFill, - fromBackground: true, }); + if (totpCode !== null && !this.platformUtilsService.isFirefox()) { + this.platformUtilsService.copyToClipboard(totpCode); + } + // reset this.main.loginToAutoFill = null; this.pageDetailsToAutoFill = []; diff --git a/src/popup/vault/current-tab.component.ts b/src/popup/vault/current-tab.component.ts index 4663812448..d7ad02cd96 100644 --- a/src/popup/vault/current-tab.component.ts +++ b/src/popup/vault/current-tab.component.ts @@ -134,12 +134,11 @@ export class CurrentTabComponent implements OnInit, OnDestroy { const totpCode = await this.autofillService.doAutoFill({ cipher: cipher, pageDetails: this.pageDetails, - fromBackground: false, doc: window.document, }); this.analytics.eventTrack.next({ action: 'Autofilled' }); - if (totpCode != null && this.platformUtilsService.isFirefox()) { + if (totpCode != null) { this.platformUtilsService.copyToClipboard(totpCode, { doc: window.document }); } diff --git a/src/services/abstractions/autofill.service.ts b/src/services/abstractions/autofill.service.ts index 330c2640a7..0b022bc7f1 100644 --- a/src/services/abstractions/autofill.service.ts +++ b/src/services/abstractions/autofill.service.ts @@ -3,5 +3,5 @@ import AutofillPageDetails from '../../models/autofillPageDetails'; export abstract class AutofillService { getFormsWithPasswordFields: (pageDetails: AutofillPageDetails) => any[]; doAutoFill: (options: any) => Promise; - doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise; + doAutoFillForLastUsedLogin: (pageDetails: any, fromCommand: boolean) => Promise; } diff --git a/src/services/autofill.service.ts b/src/services/autofill.service.ts index 0820ac1ae2..ebca28e563 100644 --- a/src/services/autofill.service.ts +++ b/src/services/autofill.service.ts @@ -105,10 +105,8 @@ var IsoProvinces: { [id: string]: string; } = { /* tslint:enable */ export default class AutofillService implements AutofillServiceInterface { - constructor(public cipherService: CipherService, public tokenService: TokenService, - public totpService: TotpService, public utilsService: UtilsServiceAbstraction, - public platformUtilsService: PlatformUtilsService) { - } + constructor(private cipherService: CipherService, private tokenService: TokenService, + private totpService: TotpService) { } getFormsWithPasswordFields(pageDetails: AutofillPageDetails): any[] { const formData: any[] = []; @@ -180,8 +178,7 @@ export default class AutofillService implements AutofillServiceInterface { fillScript: fillScript, }, { frameId: pd.frameId }); - if (options.cipher.type !== CipherType.Login || totpPromise || - (options.fromBackground && this.platformUtilsService.isFirefox()) || options.skipTotp || + if (options.cipher.type !== CipherType.Login || totpPromise || options.skipTotp || !options.cipher.login.totp || !this.tokenService.getPremium()) { return; } @@ -190,21 +187,13 @@ export default class AutofillService implements AutofillServiceInterface { if (enabled) { return this.totpService.getCode(options.cipher.login.totp); } - return null; - }).then((code: string) => { - if (code) { - UtilsService.copyToClipboard(code, options.doc); - } - - return code; }); }); if (didAutofill) { if (totpPromise != null) { - const totpCode = await totpPromise; - return totpCode; + return await totpPromise; } else { return null; } @@ -224,11 +213,10 @@ export default class AutofillService implements AutofillServiceInterface { return; } - await this.doAutoFill({ + return await this.doAutoFill({ cipher: lastUsedCipher, // tslint:disable-next-line pageDetails: pageDetails, - fromBackground: true, skipTotp: !fromCommand, skipLastUsed: true, skipUsernameOnlyFill: !fromCommand,