Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 | import { zxcvbn, zxcvbnOptions } from '@zxcvbn-ts/core';
import * as zxcvbnEnPackage from "@zxcvbn-ts/language-en";
import * as zxcvbnCommonPackage from "@zxcvbn-ts/language-common";
export var FILTERS;
(function (FILTERS) {
FILTERS[FILTERS["SHOW_ALL"] = 0] = "SHOW_ALL";
FILTERS[FILTERS["COMPROMISED"] = 1] = "COMPROMISED";
FILTERS[FILTERS["STRENGTH_LOW"] = 2] = "STRENGTH_LOW";
FILTERS[FILTERS["STRENGTH_MEDIUM"] = 3] = "STRENGTH_MEDIUM";
FILTERS[FILTERS["STRENGTH_GOOD"] = 4] = "STRENGTH_GOOD";
FILTERS[FILTERS["EXPIRED"] = 5] = "EXPIRED";
FILTERS[FILTERS["DELETED"] = 6] = "DELETED";
FILTERS[FILTERS["ENCRYPTION_BROKEN"] = 7] = "ENCRYPTION_BROKEN"; // use FILTERS.ENCRYPTION_BROKEN only when you really know what you are doing
})(FILTERS || (FILTERS = {}));
export class CredentialFilterService {
static getFilteredCredentials = (allCredentials, filter, additionalFilterText = undefined, additionalFilterTags = undefined) => {
let filtered = [];
for (const credential of allCredentials) {
if (filter === FILTERS.ENCRYPTION_BROKEN) {
// do not care about other major categories (like hidden / deleted / text) for this filter option
if (credential.hasUnspecifiedEncryptionError()) {
filtered.push(credential);
}
continue;
}
if (CredentialFilterService.isHidden(credential)) {
// hidden credentials are never shown in the list
// matches usually only the (required) first test credential
continue;
}
const additionalTextFilterEnabled = additionalFilterText !== undefined && additionalFilterText !== '';
const additionalTagsFilterEnabled = additionalFilterTags !== undefined && additionalFilterTags.length > 0;
// filter text if possible, otherwise ignore filter and proceed
if ((!additionalTextFilterEnabled || (additionalTextFilterEnabled && CredentialFilterService.matchesFilterText(credential, additionalFilterText))) &&
(!additionalTagsFilterEnabled || (additionalTagsFilterEnabled && CredentialFilterService.matchesFilterTags(credential, additionalFilterTags)))) {
if (filter === FILTERS.DELETED) {
// deleted credentials will not match any other category
if (CredentialFilterService.isDeleted(credential)) {
filtered.push(credential);
}
}
else {
if (CredentialFilterService.isDeleted(credential)) {
// deleted credentials will not match any other category
continue;
}
if (filter === FILTERS.SHOW_ALL) {
filtered.push(credential);
}
else if (filter === FILTERS.COMPROMISED) {
if (CredentialFilterService.isCompromised(credential)) {
filtered.push(credential);
}
}
else if (filter === FILTERS.STRENGTH_LOW) {
if (CredentialFilterService.hasLowStrength(credential)) {
filtered.push(credential);
}
}
else if (filter === FILTERS.STRENGTH_MEDIUM) {
if (CredentialFilterService.hasMediumStrength(credential)) {
filtered.push(credential);
}
}
else if (filter === FILTERS.STRENGTH_GOOD) {
if (CredentialFilterService.hasGoodStrength(credential)) {
filtered.push(credential);
}
}
else if (filter === FILTERS.EXPIRED) {
if (CredentialFilterService.isExpired(credential)) {
filtered.push(credential);
}
}
}
}
}
return filtered;
};
static getFilterStats = (allCredentials) => {
const stats = {
allVisible: 0,
compromised: 0,
strengthLow: 0,
strengthMedium: 0,
strengthGood: 0,
expired: 0,
deleted: 0,
encryptionBroken: 0
};
const options = {
translations: zxcvbnEnPackage.translations,
graphs: zxcvbnCommonPackage.adjacencyGraphs,
dictionary: {}, // do not use dictionaries for a faster evaluation
};
zxcvbnOptions.setOptions(options);
const now = Date.now();
for (const credential of allCredentials) {
if (!CredentialFilterService.isHidden(credential)) {
if (CredentialFilterService.isDeleted(credential)) {
stats.deleted++;
}
else {
stats.allVisible++;
if (CredentialFilterService.isCompromised(credential)) {
stats.compromised++;
}
if (CredentialFilterService.isExpired(credential, now)) {
stats.expired++;
}
if (credential.password != null) {
// do not categorize credential by strength if it has no primary password set
// zxcvbn will fail for credential.password = null
const zxcvbnResult = zxcvbn(credential.password);
if (zxcvbnResult.score >= 3) {
stats.strengthGood++;
}
else if (zxcvbnResult.score == 2) {
stats.strengthMedium++;
}
else {
// use strength low also as fallback, if zxcvbnResult is < 0
stats.strengthLow++;
}
}
}
}
// count all types of credentials (also hidden), if its encryption is broken
if (credential.hasUnspecifiedEncryptionError()) {
stats.encryptionBroken++;
}
}
return stats;
};
static isHidden(credential) {
return credential.hidden;
}
static isDeleted(credential) {
return credential.delete_time !== null && credential.delete_time > 0;
}
static isCompromised(credential) {
return credential.compromised !== null && credential.compromised != false;
}
static isExpired(credential, now = undefined) {
if (now === undefined) {
now = Date.now();
}
return credential.expire_time !== 0 && credential.expire_time * 1000 <= now;
}
static hasLowStrength(credential) {
if (credential.password == null) {
// do not categorize credential by strength if it has no primary password set
return false;
}
const zxcvbnResult = zxcvbn(credential.password);
return zxcvbnResult.score <= 1;
}
static hasMediumStrength(credential) {
if (credential.password == null) {
// do not categorize credential by strength if it has no primary password set
return false;
}
const zxcvbnResult = zxcvbn(credential.password);
return zxcvbnResult.score == 2;
}
static hasGoodStrength(credential) {
if (credential.password == null) {
// do not categorize credential by strength if it has no primary password set
return false;
}
const zxcvbnResult = zxcvbn(credential.password);
return zxcvbnResult.score >= 3;
}
static matchesFilterText(credential, filterText) {
filterText = filterText.toLowerCase();
if (credential.label != null && credential.label.toLowerCase().indexOf(filterText) > -1) {
return true;
}
else if (credential.description != null && credential.description.toLowerCase().indexOf(filterText) > -1) {
return true;
}
return false;
}
static matchesFilterTags(credential, filterTags) {
return credential.tags && credential.tags.filter(tag => filterTags.includes(tag.text)).length > 0;
}
}
|