mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2025-04-18 19:43:12 +03:00
Методы загрузки объеденённого списка сертификатов из личного хранилища и из закрытого ключа
This commit is contained in:
parent
af76d5cc7a
commit
33f5941e58
62
src/api/getAllCertificates.ts
Executable file
62
src/api/getAllCertificates.ts
Executable file
@ -0,0 +1,62 @@
|
||||
import {Certificate} from './certificate';
|
||||
import {_afterPluginsLoaded} from '../helpers/_afterPluginsLoaded';
|
||||
import {getAllUserCertificates} from './getAllUserCertificates';
|
||||
import {getAllContainerCertificates} from './getAllContainerCertificates';
|
||||
|
||||
let certificatesCache: Certificate[];
|
||||
/**
|
||||
* Возвращает список сертификатов, доступных пользователю из пользовательского хранилища и закрытых ключей, не установленных в системе, без фильтрации по дате и наличию приватного ключа
|
||||
*
|
||||
* @param resetCache = false - позволяет сбросить кэш ранее полученных сертификатов
|
||||
* @returns список сертификатов
|
||||
*/
|
||||
export const getAllCertificates = _afterPluginsLoaded(
|
||||
async (resetCache: boolean = false): Promise<Certificate[]> => {
|
||||
if (!resetCache && certificatesCache) {
|
||||
return certificatesCache;
|
||||
}
|
||||
|
||||
let availableCertificates: Certificate[];
|
||||
|
||||
try {
|
||||
availableCertificates = await getAllUserCertificates(resetCache);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
availableCertificates = [];
|
||||
}
|
||||
|
||||
try {
|
||||
const containerAllCertificates: Certificate[] = await getAllContainerCertificates(resetCache);
|
||||
|
||||
if (!availableCertificates) {
|
||||
availableCertificates = containerAllCertificates;
|
||||
} else {
|
||||
let containerAllCertificatesCount = containerAllCertificates.length - 1;
|
||||
let foundAvailableCertificate;
|
||||
|
||||
while (containerAllCertificatesCount) {
|
||||
foundAvailableCertificate = availableCertificates.find(
|
||||
(cert) => cert.thumbprint === containerAllCertificates[containerAllCertificatesCount].thumbprint
|
||||
);
|
||||
|
||||
if (!foundAvailableCertificate) {
|
||||
availableCertificates.push(containerAllCertificates[containerAllCertificatesCount]);
|
||||
}
|
||||
|
||||
containerAllCertificatesCount--;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!availableCertificates) {
|
||||
throw new Error('Нет доступных сертификатов');
|
||||
}
|
||||
|
||||
certificatesCache = availableCertificates;
|
||||
|
||||
return certificatesCache;
|
||||
},
|
||||
);
|
66
src/api/getCertificates.ts
Executable file
66
src/api/getCertificates.ts
Executable file
@ -0,0 +1,66 @@
|
||||
import {Certificate} from './certificate';
|
||||
import {_afterPluginsLoaded} from '../helpers/_afterPluginsLoaded';
|
||||
import {getUserCertificates} from './getUserCertificates';
|
||||
import {getContainerCertificates} from "./getContainerCertificates";
|
||||
import {getAllUserCertificates} from "./getAllUserCertificates";
|
||||
import {getAllContainerCertificates} from "./getAllContainerCertificates";
|
||||
|
||||
|
||||
let certificatesCache: Certificate[];
|
||||
/**
|
||||
* Возвращает список сертификатов, доступных пользователю из пользовательского хранилища и закрытых ключей, не установленных в системе
|
||||
*
|
||||
* @param resetCache = false - позволяет сбросить кэш ранее полученных сертификатов
|
||||
* @returns список сертификатов
|
||||
*/
|
||||
export const getCertificates = _afterPluginsLoaded(
|
||||
async (resetCache: boolean = false): Promise<Certificate[]> => {
|
||||
|
||||
if (!resetCache && certificatesCache) {
|
||||
return certificatesCache;
|
||||
}
|
||||
|
||||
let availableCertificates: Certificate[];
|
||||
|
||||
try {
|
||||
availableCertificates = await getUserCertificates(resetCache);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
|
||||
availableCertificates = [];
|
||||
}
|
||||
|
||||
try {
|
||||
const containerCertificates: Certificate[] = await getContainerCertificates(resetCache);
|
||||
|
||||
if (!availableCertificates) {
|
||||
availableCertificates = containerCertificates;
|
||||
} else {
|
||||
let containerCertificatesCount = containerCertificates.length - 1;
|
||||
let foundAvailableCertificate;
|
||||
|
||||
while (containerCertificatesCount) {
|
||||
foundAvailableCertificate = availableCertificates.find(
|
||||
(cert) => cert.thumbprint === containerCertificates[containerCertificatesCount].thumbprint
|
||||
);
|
||||
|
||||
if (!foundAvailableCertificate) {
|
||||
availableCertificates.push(containerCertificates[containerCertificatesCount]);
|
||||
}
|
||||
|
||||
containerCertificatesCount--;
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
|
||||
if (!availableCertificates) {
|
||||
throw new Error('Нет доступных сертификатов');
|
||||
}
|
||||
|
||||
certificatesCache = availableCertificates;
|
||||
|
||||
return certificatesCache;
|
||||
},
|
||||
);
|
@ -3,6 +3,8 @@ export * from './getUserCertificates';
|
||||
export * from './getAllUserCertificates';
|
||||
export * from './getContainerCertificates';
|
||||
export * from './getAllContainerCertificates';
|
||||
export * from './getCertificates';
|
||||
export * from './getAllCertificates';
|
||||
export * from './getSystemInfo';
|
||||
export * from './isValidSystemSetup';
|
||||
export * from './createXMLSignature';
|
||||
|
Loading…
Reference in New Issue
Block a user