From b090fa4e6c3f812db739988eadf120dae6cd29f6 Mon Sep 17 00:00:00 2001 From: vgoma Date: Sat, 17 Oct 2020 10:46:07 +0300 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B0=D1=82=D1=80=D0=B8=D0=B1=D1=83=D1=82=20=D0=B2=D1=80=D0=B5?= =?UTF-8?q?=D0=BC=D0=B5=D0=BD=D0=B8=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81?= =?UTF-8?q?=D0=B0=D0=BD=D0=B8=D1=8F=20=D0=B4=D0=BB=D1=8F=20=D0=BE=D1=82?= =?UTF-8?q?=D1=81=D0=BE=D0=B5=D0=B4=D0=B8=D0=BD=D0=B5=D0=BD=D0=BD=D0=BE?= =?UTF-8?q?=D0=B9=20=D0=BF=D0=BE=D0=B4=D0=BF=D0=B8=D1=81=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/createDetachedSignature.ts | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/api/createDetachedSignature.ts b/src/api/createDetachedSignature.ts index 0c3b37b..8358829 100644 --- a/src/api/createDetachedSignature.ts +++ b/src/api/createDetachedSignature.ts @@ -1,7 +1,9 @@ +import { CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME } from '../constants'; import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded'; import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage'; import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn'; import { _getCadesCert } from '../helpers/_getCadesCert'; +import { _getDateObj } from '../helpers/_getDateObj'; /** * Создает отсоединенную подпись хеша по отпечатку сертификата @@ -17,11 +19,13 @@ export const createDetachedSignature = _afterPluginsLoaded( return eval( _generateCadesFn(function createDetachedSignature(): string { + let cadesAttrs; let cadesHashedData; let cadesSignedData; let cadesSigner; try { + cadesAttrs = __cadesAsyncToken__ + __createCadesPluginObject__('CADESCOM.CPAttribute'); cadesHashedData = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.HashedData'); cadesSignedData = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.CadesSignedData'); cadesSigner = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.CPSigner'); @@ -31,8 +35,23 @@ export const createDetachedSignature = _afterPluginsLoaded( throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи'); } + const currentTime = _getDateObj(new Date()); + + try { + void (__cadesAsyncToken__ + cadesAttrs.propset_Name(CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME)); + void (__cadesAsyncToken__ + cadesAttrs.propset_Value(currentTime)); + } catch (error) { + console.error(error); + + throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при установке времени подписи'); + } + + let cadesAuthAttrs; + try { void (__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate)); + cadesAuthAttrs = __cadesAsyncToken__ + cadesSigner.AuthenticatedAttributes2; + void (__cadesAsyncToken__ + cadesAuthAttrs.Add(cadesAttrs)); void (__cadesAsyncToken__ + cadesSigner.propset_Options(cadesplugin.CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN)); } catch (error) { console.error(error);