support for uri matching types to cipher service
This commit is contained in:
parent
dc0befc9be
commit
ad4c81ed84
|
@ -20,8 +20,8 @@ export abstract class CipherService {
|
|||
getAll: () => Promise<Cipher[]>;
|
||||
getAllDecrypted: () => Promise<CipherView[]>;
|
||||
getAllDecryptedForGrouping: (groupingId: string, folder?: boolean) => Promise<CipherView[]>;
|
||||
getAllDecryptedForDomain: (domain: string, includeOtherTypes?: CipherType[]) => Promise<CipherView[]>;
|
||||
getLastUsedForDomain: (domain: string) => Promise<CipherView>;
|
||||
getAllDecryptedForUrl: (url: string, includeOtherTypes?: CipherType[]) => Promise<CipherView[]>;
|
||||
getLastUsedForUrl: (url: string) => Promise<CipherView>;
|
||||
updateLastUsedDate: (id: string) => Promise<void>;
|
||||
saveNeverDomain: (domain: string) => Promise<void>;
|
||||
saveWithServer: (cipher: Cipher) => Promise<any>;
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
export abstract class UtilsService {
|
||||
copyToClipboard: (text: string, doc?: Document) => void;
|
||||
getHostname: (uriString: string) => string;
|
||||
getHost: (uriString: string) => string;
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export enum UriMatchType {
|
||||
BaseDomain = 0,
|
||||
FullHostname = 1,
|
||||
Host = 1,
|
||||
StartsWith = 2,
|
||||
Exact = 3,
|
||||
RegularExpression = 4,
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
import { CipherType } from '../enums/cipherType';
|
||||
import { UriMatchType } from '../enums/uriMatchType';
|
||||
|
||||
import { CipherData } from '../models/data/cipherData';
|
||||
|
||||
|
@ -31,9 +32,11 @@ import { ApiService } from '../abstractions/api.service';
|
|||
import { CipherService as CipherServiceAbstraction } from '../abstractions/cipher.service';
|
||||
import { CryptoService } from '../abstractions/crypto.service';
|
||||
import { I18nService } from '../abstractions/i18n.service';
|
||||
import { PlatformUtilsService } from '../abstractions/platformUtils.service';
|
||||
import { SettingsService } from '../abstractions/settings.service';
|
||||
import { StorageService } from '../abstractions/storage.service';
|
||||
import { UserService } from '../abstractions/user.service';
|
||||
import { UtilsService } from '../abstractions/utils.service';
|
||||
|
||||
const Keys = {
|
||||
ciphersPrefix: 'ciphers_',
|
||||
|
@ -46,7 +49,8 @@ export class CipherService implements CipherServiceAbstraction {
|
|||
|
||||
constructor(private cryptoService: CryptoService, private userService: UserService,
|
||||
private settingsService: SettingsService, private apiService: ApiService,
|
||||
private storageService: StorageService, private i18nService: I18nService) {
|
||||
private storageService: StorageService, private i18nService: I18nService,
|
||||
private platformUtilsService: PlatformUtilsService, private utilsService: UtilsService) {
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
|
@ -170,11 +174,12 @@ export class CipherService implements CipherServiceAbstraction {
|
|||
});
|
||||
}
|
||||
|
||||
async getAllDecryptedForDomain(domain: string, includeOtherTypes?: CipherType[]): Promise<CipherView[]> {
|
||||
if (domain == null && !includeOtherTypes) {
|
||||
async getAllDecryptedForUrl(url: string, includeOtherTypes?: CipherType[]): Promise<CipherView[]> {
|
||||
if (url == null && !includeOtherTypes) {
|
||||
return Promise.resolve([]);
|
||||
}
|
||||
|
||||
const domain = this.platformUtilsService.getDomain(url);
|
||||
const eqDomainsPromise = domain == null ? Promise.resolve([]) :
|
||||
this.settingsService.getEquivalentDomains().then((eqDomains: any[][]) => {
|
||||
let matches: any[] = [];
|
||||
|
@ -196,20 +201,55 @@ export class CipherService implements CipherServiceAbstraction {
|
|||
const ciphers = result[1];
|
||||
|
||||
return ciphers.filter((cipher) => {
|
||||
// TODO: uris
|
||||
//if (domain && cipher.type === CipherType.Login && cipher.login.domain &&
|
||||
// matchingDomains.indexOf(cipher.login.domain) > -1) {
|
||||
// return true;
|
||||
//} else if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) {
|
||||
// return true;
|
||||
//}
|
||||
if (includeOtherTypes && includeOtherTypes.indexOf(cipher.type) > -1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (url != null && cipher.type === CipherType.Login && cipher.login.uris != null) {
|
||||
for (let i = 0; i < cipher.login.uris.length; i++) {
|
||||
const u = cipher.login.uris[i];
|
||||
if (u.uri == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (u.match) {
|
||||
case null:
|
||||
case undefined:
|
||||
case UriMatchType.BaseDomain:
|
||||
if (domain != null && u.domain != null && matchingDomains.indexOf(u.domain) > -1) {
|
||||
return true;
|
||||
}
|
||||
case UriMatchType.Host:
|
||||
const urlHost = this.utilsService.getHost(url);
|
||||
if (urlHost != null && urlHost === this.utilsService.getHost(u.uri)) {
|
||||
return true;
|
||||
}
|
||||
case UriMatchType.Exact:
|
||||
if (url === u.uri) {
|
||||
return true;
|
||||
}
|
||||
case UriMatchType.StartsWith:
|
||||
if (url.startsWith(u.uri)) {
|
||||
return true;
|
||||
}
|
||||
case UriMatchType.RegularExpression:
|
||||
const regex = new RegExp(u.uri, 'i');
|
||||
if (regex.test(url)) {
|
||||
return true;
|
||||
}
|
||||
case UriMatchType.Never:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
async getLastUsedForDomain(domain: string): Promise<CipherView> {
|
||||
const ciphers = await this.getAllDecryptedForDomain(domain);
|
||||
async getLastUsedForUrl(url: string): Promise<CipherView> {
|
||||
const ciphers = await this.getAllDecryptedForUrl(url);
|
||||
if (ciphers.length === 0) {
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -53,7 +53,7 @@ export class SearchService implements SearchServiceAbstraction {
|
|||
|
||||
private transformQuery(query: string) {
|
||||
if (query.indexOf('>') === 0) {
|
||||
return query.substr(1).trimLeft();
|
||||
return query.substr(1);
|
||||
}
|
||||
return '*' + query + '*';
|
||||
}
|
||||
|
|
|
@ -132,6 +132,16 @@ export class UtilsService implements UtilsServiceAbstraction {
|
|||
}
|
||||
|
||||
static getHostname(uriString: string): string {
|
||||
const url = UtilsService.getUrl(uriString);
|
||||
return url != null ? url.hostname : null;
|
||||
}
|
||||
|
||||
static getHost(uriString: string): string {
|
||||
const url = UtilsService.getUrl(uriString);
|
||||
return url != null ? url.host : null;
|
||||
}
|
||||
|
||||
private static getUrl(uriString: string): URL {
|
||||
if (uriString == null) {
|
||||
return null;
|
||||
}
|
||||
|
@ -143,8 +153,7 @@ export class UtilsService implements UtilsServiceAbstraction {
|
|||
|
||||
if (uriString.startsWith('http://') || uriString.startsWith('https://')) {
|
||||
try {
|
||||
const url = new URL(uriString);
|
||||
return url.hostname;
|
||||
return new URL(uriString);
|
||||
} catch (e) { }
|
||||
}
|
||||
|
||||
|
@ -155,6 +164,10 @@ export class UtilsService implements UtilsServiceAbstraction {
|
|||
return UtilsService.getHostname(uriString);
|
||||
}
|
||||
|
||||
getHost(uriString: string): string {
|
||||
return UtilsService.getHost(uriString);
|
||||
}
|
||||
|
||||
copyToClipboard(text: string, doc?: Document) {
|
||||
UtilsService.copyToClipboard(text, doc);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue