2018-12-12 05:25:05 +01:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
ComponentFactoryResolver,
|
|
|
|
OnInit,
|
|
|
|
} from '@angular/core';
|
|
|
|
|
|
|
|
import { CipherService } from 'jslib/abstractions/cipher.service';
|
2018-12-12 15:29:51 +01:00
|
|
|
import { MessagingService } from 'jslib/abstractions/messaging.service';
|
|
|
|
import { UserService } from 'jslib/abstractions/user.service';
|
2018-12-12 05:25:05 +01:00
|
|
|
|
|
|
|
import { CipherView } from 'jslib/models/view/cipherView';
|
|
|
|
|
|
|
|
import { CipherType } from 'jslib/enums/cipherType';
|
|
|
|
|
|
|
|
import { Utils } from 'jslib/misc/utils';
|
|
|
|
|
2018-12-12 15:11:10 +01:00
|
|
|
import { CipherReportComponent } from './cipher-report.component';
|
|
|
|
|
2018-12-12 05:25:05 +01:00
|
|
|
@Component({
|
|
|
|
selector: 'app-inactive-two-factor-report',
|
|
|
|
templateUrl: 'inactive-two-factor-report.component.html',
|
|
|
|
})
|
2018-12-12 15:11:10 +01:00
|
|
|
export class InactiveTwoFactorReportComponent extends CipherReportComponent implements OnInit {
|
2018-12-12 05:25:05 +01:00
|
|
|
services = new Map<string, string>();
|
|
|
|
cipherDocs = new Map<string, string>();
|
|
|
|
|
2018-12-14 20:22:30 +01:00
|
|
|
constructor(protected cipherService: CipherService, componentFactoryResolver: ComponentFactoryResolver,
|
2018-12-12 15:29:51 +01:00
|
|
|
messagingService: MessagingService, userService: UserService) {
|
|
|
|
super(componentFactoryResolver, userService, messagingService, true);
|
2018-12-12 15:11:10 +01:00
|
|
|
}
|
2018-12-12 05:25:05 +01:00
|
|
|
|
2018-12-12 15:29:51 +01:00
|
|
|
async ngOnInit() {
|
2018-12-14 19:56:01 +01:00
|
|
|
if (await this.checkAccess()) {
|
2018-12-12 15:29:51 +01:00
|
|
|
await super.load();
|
|
|
|
}
|
2018-12-12 05:25:05 +01:00
|
|
|
}
|
|
|
|
|
2018-12-12 15:11:10 +01:00
|
|
|
async setCiphers() {
|
2018-12-12 05:25:05 +01:00
|
|
|
try {
|
|
|
|
await this.load2fa();
|
|
|
|
} catch { }
|
|
|
|
if (this.services.size > 0) {
|
2018-12-14 20:22:30 +01:00
|
|
|
const allCiphers = await this.getAllCiphers();
|
2018-12-12 05:25:05 +01:00
|
|
|
const inactive2faCiphers: CipherView[] = [];
|
2020-08-12 21:43:26 +02:00
|
|
|
const promises: Promise<void>[] = [];
|
2018-12-12 05:25:05 +01:00
|
|
|
const docs = new Map<string, string>();
|
|
|
|
allCiphers.forEach((c) => {
|
|
|
|
if (c.type !== CipherType.Login || (c.login.totp != null && c.login.totp !== '') || !c.login.hasUris) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (let i = 0; i < c.login.uris.length; i++) {
|
|
|
|
const u = c.login.uris[i];
|
|
|
|
if (u.uri != null && u.uri !== '') {
|
|
|
|
const hostname = Utils.getHostname(u.uri);
|
|
|
|
if (hostname != null && this.services.has(hostname)) {
|
|
|
|
if (this.services.get(hostname) != null) {
|
|
|
|
docs.set(c.id, this.services.get(hostname));
|
|
|
|
}
|
|
|
|
inactive2faCiphers.push(c);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
await Promise.all(promises);
|
|
|
|
this.ciphers = inactive2faCiphers;
|
|
|
|
this.cipherDocs = docs;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-14 20:22:30 +01:00
|
|
|
protected getAllCiphers(): Promise<CipherView[]> {
|
|
|
|
return this.cipherService.getAllDecrypted();
|
|
|
|
}
|
|
|
|
|
2018-12-12 05:25:05 +01:00
|
|
|
private async load2fa() {
|
|
|
|
if (this.services.size > 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-10-29 13:04:09 +01:00
|
|
|
const response = await fetch(new Request('https://twofactorauth.org/api/v1/data.json'));
|
2018-12-12 05:25:05 +01:00
|
|
|
if (response.status !== 200) {
|
|
|
|
throw new Error();
|
|
|
|
}
|
|
|
|
const responseJson = await response.json();
|
|
|
|
for (const categoryName in responseJson) {
|
|
|
|
if (responseJson.hasOwnProperty(categoryName)) {
|
|
|
|
const category = responseJson[categoryName];
|
|
|
|
for (const serviceName in category) {
|
|
|
|
if (category.hasOwnProperty(serviceName)) {
|
|
|
|
const service = category[serviceName];
|
2019-05-27 14:15:02 +02:00
|
|
|
if (service.tfa && service.software && service.url != null) {
|
2018-12-12 05:25:05 +01:00
|
|
|
const hostname = Utils.getHostname(service.url);
|
|
|
|
if (hostname != null) {
|
|
|
|
this.services.set(hostname, service.doc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|