Поиск сертификата в объеденённом списке сертификатов из личного хранилища и из закрытого ключа

This commit is contained in:
Artem Vasilev 2022-06-23 11:58:48 +03:00
parent 33f5941e58
commit 937da83bb4

View File

@ -1,20 +1,29 @@
import { Certificate } from './certificate'; import {Certificate} from './certificate';
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; import {_afterPluginsLoaded} from '../helpers/_afterPluginsLoaded';
import { getUserCertificates } from './getUserCertificates'; import {getCertificates} from "./getCertificates";
import {getAllCertificates} from "./getAllCertificates";
/** /**
* Возвращает сертификат по отпечатку * Возвращает сертификат по отпечатку
* *
* @param thumbprint - отпечаток сертификата * @param thumbprint - отпечаток сертификата
* @param validOnly - проверять сертификаты по дате и наличию приватного ключа
* @returns сертификат * @returns сертификат
*/ */
export const getCertificate = _afterPluginsLoaded( export const getCertificate = _afterPluginsLoaded(
async (thumbprint: string): Promise<Certificate> => { async (thumbprint: string, validOnly: boolean = true): Promise<Certificate> => {
if (!thumbprint) { if (!thumbprint) {
throw new Error('Отпечаток не указан'); throw new Error('Отпечаток не указан');
} }
const availableCertificates: Certificate[] = await getUserCertificates(); let availableCertificates: Certificate[];
if (validOnly) {
availableCertificates = await getCertificates();
} else {
availableCertificates = await getAllCertificates();
}
const foundCertificate: Certificate = availableCertificates.find((cert) => cert.thumbprint === thumbprint); const foundCertificate: Certificate = availableCertificates.find((cert) => cert.thumbprint === thumbprint);
if (!foundCertificate) { if (!foundCertificate) {