support for otpauth

This commit is contained in:
Kyle Spearrin 2018-07-31 11:26:04 -04:00
parent 8eb48e4311
commit 600218cf7b
2 changed files with 15 additions and 8 deletions

2
jslib

@ -1 +1 @@
Subproject commit 2045e7047a66599b2c8a92b88cd0d1b8bfc5186f Subproject commit 41ab22a82fb5fafcce2e8d1abe86789e152ef1fa

View File

@ -59,10 +59,11 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
if (this.cipher.type === CipherType.Login && this.cipher.login.totp && if (this.cipher.type === CipherType.Login && this.cipher.login.totp &&
(this.cipher.organizationUseTotp || this.isPremium)) { (this.cipher.organizationUseTotp || this.isPremium)) {
await this.totpUpdateCode(); await this.totpUpdateCode();
await this.totpTick(); const interval = this.totpService.getTimeInterval(this.cipher.login.totp);
await this.totpTick(interval);
this.totpInterval = window.setInterval(async () => { this.totpInterval = window.setInterval(async () => {
await this.totpTick(); await this.totpTick(interval);
}, 1000); }, 1000);
} }
} }
@ -132,7 +133,12 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
this.totpCode = await this.totpService.getCode(this.cipher.login.totp); this.totpCode = await this.totpService.getCode(this.cipher.login.totp);
if (this.totpCode != null) { if (this.totpCode != null) {
this.totpCodeFormatted = this.totpCode.substring(0, 3) + ' ' + this.totpCode.substring(3); if (this.totpCode.length > 4) {
const half = Math.floor(this.totpCode.length / 2);
this.totpCodeFormatted = this.totpCode.substring(0, half) + ' ' + this.totpCode.substring(half);
} else {
this.totpCodeFormatted = this.totpCode;
}
} else { } else {
this.totpCodeFormatted = null; this.totpCodeFormatted = null;
if (this.totpInterval) { if (this.totpInterval) {
@ -141,15 +147,16 @@ export class AddEditComponent extends BaseAddEditComponent implements OnInit {
} }
} }
protected async totpTick() { private async totpTick(intervalSeconds: number) {
const epoch = Math.round(new Date().getTime() / 1000.0); const epoch = Math.round(new Date().getTime() / 1000.0);
const mod = epoch % 30; const mod = epoch % intervalSeconds;
this.totpSec = 30 - mod; this.totpSec = intervalSeconds - mod;
this.totpDash = +(Math.round(((2.62 * mod) + 'e+2') as any) + 'e-2'); this.totpDash = +(Math.round((((78.6 / intervalSeconds) * mod) + 'e+2') as any) + 'e-2');
this.totpLow = this.totpSec <= 7; this.totpLow = this.totpSec <= 7;
if (mod === 0) { if (mod === 0) {
await this.totpUpdateCode(); await this.totpUpdateCode();
} }
} }
} }