mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2024-11-24 00:55:00 +03:00
added all user certificates
This commit is contained in:
parent
bf3be501a1
commit
4f29faf3c3
8
dist/api/addAttachedSignature.d.ts
vendored
Normal file
8
dist/api/addAttachedSignature.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Добавляет присоединенную подпись к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
export declare const addAttachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer) => Promise<string>;
|
9
dist/api/addDetachedSignature.d.ts
vendored
Normal file
9
dist/api/addDetachedSignature.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Добавляет отсоединенную подпись хеша к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
export declare const addDetachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer, messageHash: string) => Promise<string>;
|
2
dist/api/index.d.ts
vendored
2
dist/api/index.d.ts
vendored
@ -5,6 +5,8 @@ export * from './isValidSystemSetup';
|
||||
export * from './createSignature';
|
||||
export * from './createXMLSignature';
|
||||
export * from './createDetachedSignature';
|
||||
export * from './addDetachedSignature';
|
||||
export * from './createAttachedSignature';
|
||||
export * from './addAttachedSignature';
|
||||
export * from './createHash';
|
||||
export * from './certificate';
|
||||
|
2
dist/crypto-pro.d.ts
vendored
2
dist/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for crypto-pro 2.2.0
|
||||
// Type definitions for crypto-pro 2.2.2
|
||||
// Project: crypto-pro
|
||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||
|
||||
|
266
dist/crypto-pro.js
vendored
266
dist/crypto-pro.js
vendored
@ -2202,6 +2202,270 @@ try {
|
||||
module.exports = g;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/addAttachedSignature.ts":
|
||||
/*!*************************************!*\
|
||||
!*** ./api/addAttachedSignature.ts ***!
|
||||
\*************************************/
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* WEBPACK VAR INJECTION */(function(Buffer) {
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var constants_1 = __webpack_require__(/*! ../constants */ "./constants/index.ts");
|
||||
var _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||
var _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||
var _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||
var _getCadesCert_1 = __webpack_require__(/*! ../helpers/_getCadesCert */ "./helpers/_getCadesCert.ts");
|
||||
var _getDateObj_1 = __webpack_require__(/*! ../helpers/_getDateObj */ "./helpers/_getDateObj.ts");
|
||||
/**
|
||||
* Добавляет присоединенную подпись к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
exports.addAttachedSignature = _afterPluginsLoaded_1._afterPluginsLoaded(function (thumbprint, signedMessage) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var cadesplugin, cadesCertificate;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cadesplugin = window.cadesplugin;
|
||||
return [4 /*yield*/, _getCadesCert_1._getCadesCert(thumbprint)];
|
||||
case 1:
|
||||
cadesCertificate = _a.sent();
|
||||
return [2 /*return*/, eval(_generateCadesFn_1._generateCadesFn(function addAttachedSignature() {
|
||||
var cadesAttrs;
|
||||
var cadesSignedData;
|
||||
var cadesSigner;
|
||||
try {
|
||||
cadesAttrs = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CADESCOM.CPAttribute');
|
||||
cadesSignedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CadesSignedData');
|
||||
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||
}
|
||||
var currentTime = _getDateObj_1._getDateObj(new Date());
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Name(constants_1.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Value(currentTime));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке времени подписи');
|
||||
}
|
||||
var messageBase64;
|
||||
try {
|
||||
messageBase64 = Buffer.from(signedMessage).toString('base64');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error('Ошибка при преобразовании сообщения в Base64');
|
||||
}
|
||||
var cadesAuthAttrs;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||
cadesAuthAttrs = _generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.AuthenticatedAttributes2;
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAuthAttrs.Add(cadesAttrs));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.propset_ContentEncoding(cadesplugin.CADESCOM_BASE64_TO_BINARY));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.propset_Content(messageBase64));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Options(cadesplugin.CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при указании данных для подписи');
|
||||
}
|
||||
var signature;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.VerifyCades(signedMessage, cadesplugin.CADESCOM_PKCS7_TYPE));
|
||||
signature = _generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.CoSignCades(cadesSigner, cadesplugin.CADESCOM_PKCS7_TYPE);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||
}
|
||||
return signature;
|
||||
}))];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
|
||||
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/buffer/index.js */ "../node_modules/buffer/index.js").Buffer))
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/addDetachedSignature.ts":
|
||||
/*!*************************************!*\
|
||||
!*** ./api/addDetachedSignature.ts ***!
|
||||
\*************************************/
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
var __generator = (this && this.__generator) || function (thisArg, body) {
|
||||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
||||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
||||
function verb(n) { return function (v) { return step([n, v]); }; }
|
||||
function step(op) {
|
||||
if (f) throw new TypeError("Generator is already executing.");
|
||||
while (_) try {
|
||||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
||||
if (y = 0, t) op = [op[0] & 2, t.value];
|
||||
switch (op[0]) {
|
||||
case 0: case 1: t = op; break;
|
||||
case 4: _.label++; return { value: op[1], done: false };
|
||||
case 5: _.label++; y = op[1]; op = [0]; continue;
|
||||
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
||||
default:
|
||||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
||||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
||||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
||||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
||||
if (t[2]) _.ops.pop();
|
||||
_.trys.pop(); continue;
|
||||
}
|
||||
op = body.call(thisArg, _);
|
||||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
||||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
||||
}
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
var constants_1 = __webpack_require__(/*! ../constants */ "./constants/index.ts");
|
||||
var _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||
var _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||
var _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||
var _getCadesCert_1 = __webpack_require__(/*! ../helpers/_getCadesCert */ "./helpers/_getCadesCert.ts");
|
||||
var _getDateObj_1 = __webpack_require__(/*! ../helpers/_getDateObj */ "./helpers/_getDateObj.ts");
|
||||
/**
|
||||
* Добавляет отсоединенную подпись хеша к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
exports.addDetachedSignature = _afterPluginsLoaded_1._afterPluginsLoaded(function (thumbprint, signedMessage, messageHash) { return __awaiter(void 0, void 0, void 0, function () {
|
||||
var cadesplugin, cadesCertificate;
|
||||
return __generator(this, function (_a) {
|
||||
switch (_a.label) {
|
||||
case 0:
|
||||
cadesplugin = window.cadesplugin;
|
||||
return [4 /*yield*/, _getCadesCert_1._getCadesCert(thumbprint)];
|
||||
case 1:
|
||||
cadesCertificate = _a.sent();
|
||||
return [2 /*return*/, eval(_generateCadesFn_1._generateCadesFn(function addDetachedSignature() {
|
||||
var cadesAttrs;
|
||||
var cadesHashedData;
|
||||
var cadesSignedData;
|
||||
var cadesSigner;
|
||||
try {
|
||||
cadesAttrs = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CADESCOM.CPAttribute');
|
||||
cadesHashedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.HashedData');
|
||||
cadesSignedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CadesSignedData');
|
||||
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||
}
|
||||
var currentTime = _getDateObj_1._getDateObj(new Date());
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Name(constants_1.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Value(currentTime));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке времени подписи');
|
||||
}
|
||||
var cadesAuthAttrs;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||
cadesAuthAttrs = _generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.AuthenticatedAttributes2;
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAuthAttrs.Add(cadesAttrs));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Options(cadesplugin.CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке сертификата');
|
||||
}
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesHashedData.propset_Algorithm(cadesplugin.CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesHashedData.SetHashValue(messageHash));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке хеша');
|
||||
}
|
||||
var signature;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesSignedData.VerifyHash(cadesHashedData, signedMessage, cadesplugin.CADESCOM_PKCS7_TYPE));
|
||||
signature =
|
||||
_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesSignedData.CoSignHash(cadesHashedData, cadesSigner, cadesplugin.CADESCOM_PKCS7_TYPE);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||
}
|
||||
return signature;
|
||||
}))];
|
||||
}
|
||||
});
|
||||
}); });
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/certificate/certificate.ts":
|
||||
@ -3560,7 +3824,9 @@ __export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSet
|
||||
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createXMLSignature */ "./api/createXMLSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./addDetachedSignature */ "./api/addDetachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./addAttachedSignature */ "./api/addAttachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
||||
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
||||
|
||||
|
2
dist/crypto-pro.js.map
vendored
2
dist/crypto-pro.js.map
vendored
File diff suppressed because one or more lines are too long
4
dist/crypto-pro.min.js
vendored
4
dist/crypto-pro.min.js
vendored
File diff suppressed because one or more lines are too long
2
dist/crypto-pro.min.js.map
vendored
2
dist/crypto-pro.min.js.map
vendored
File diff suppressed because one or more lines are too long
8
lib/api/addAttachedSignature.d.ts
vendored
Normal file
8
lib/api/addAttachedSignature.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* Добавляет присоединенную подпись к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
export declare const addAttachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer) => Promise<string>;
|
9
lib/api/addDetachedSignature.d.ts
vendored
Normal file
9
lib/api/addDetachedSignature.d.ts
vendored
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Добавляет отсоединенную подпись хеша к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
export declare const addDetachedSignature: (thumbprint: string, signedMessage: string | ArrayBuffer, messageHash: string) => Promise<string>;
|
2
lib/api/index.d.ts
vendored
2
lib/api/index.d.ts
vendored
@ -5,6 +5,8 @@ export * from './isValidSystemSetup';
|
||||
export * from './createSignature';
|
||||
export * from './createXMLSignature';
|
||||
export * from './createDetachedSignature';
|
||||
export * from './addDetachedSignature';
|
||||
export * from './createAttachedSignature';
|
||||
export * from './addAttachedSignature';
|
||||
export * from './createHash';
|
||||
export * from './certificate';
|
||||
|
2
lib/crypto-pro.d.ts
vendored
2
lib/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
||||
// Type definitions for crypto-pro 2.2.0
|
||||
// Type definitions for crypto-pro 2.2.2
|
||||
// Project: crypto-pro
|
||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||
|
||||
|
@ -2202,6 +2202,200 @@ try {
|
||||
module.exports = g;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/addAttachedSignature.ts":
|
||||
/*!*************************************!*\
|
||||
!*** ./api/addAttachedSignature.ts ***!
|
||||
\*************************************/
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
/* WEBPACK VAR INJECTION */(function(Buffer) {
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = __webpack_require__(/*! ../constants */ "./constants/index.ts");
|
||||
const _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||
const _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||
const _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||
const _getCadesCert_1 = __webpack_require__(/*! ../helpers/_getCadesCert */ "./helpers/_getCadesCert.ts");
|
||||
const _getDateObj_1 = __webpack_require__(/*! ../helpers/_getDateObj */ "./helpers/_getDateObj.ts");
|
||||
/**
|
||||
* Добавляет присоединенную подпись к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
exports.addAttachedSignature = _afterPluginsLoaded_1._afterPluginsLoaded((thumbprint, signedMessage) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { cadesplugin } = window;
|
||||
const cadesCertificate = yield _getCadesCert_1._getCadesCert(thumbprint);
|
||||
return eval(_generateCadesFn_1._generateCadesFn(function addAttachedSignature() {
|
||||
let cadesAttrs;
|
||||
let cadesSignedData;
|
||||
let cadesSigner;
|
||||
try {
|
||||
cadesAttrs = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CADESCOM.CPAttribute');
|
||||
cadesSignedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CadesSignedData');
|
||||
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||
}
|
||||
const currentTime = _getDateObj_1._getDateObj(new Date());
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Name(constants_1.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Value(currentTime));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке времени подписи');
|
||||
}
|
||||
let messageBase64;
|
||||
try {
|
||||
messageBase64 = Buffer.from(signedMessage).toString('base64');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error('Ошибка при преобразовании сообщения в Base64');
|
||||
}
|
||||
let cadesAuthAttrs;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||
cadesAuthAttrs = _generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.AuthenticatedAttributes2;
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAuthAttrs.Add(cadesAttrs));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.propset_ContentEncoding(cadesplugin.CADESCOM_BASE64_TO_BINARY));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.propset_Content(messageBase64));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Options(cadesplugin.CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при указании данных для подписи');
|
||||
}
|
||||
let signature;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.VerifyCades(signedMessage, cadesplugin.CADESCOM_PKCS7_TYPE));
|
||||
signature = _generateCadesFn_1.__cadesAsyncToken__ + cadesSignedData.CoSignCades(cadesSigner, cadesplugin.CADESCOM_PKCS7_TYPE);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||
}
|
||||
return signature;
|
||||
}));
|
||||
}));
|
||||
|
||||
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../node_modules/buffer/index.js */ "../node_modules/buffer/index.js").Buffer))
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/addDetachedSignature.ts":
|
||||
/*!*************************************!*\
|
||||
!*** ./api/addDetachedSignature.ts ***!
|
||||
\*************************************/
|
||||
/*! no static exports found */
|
||||
/***/ (function(module, exports, __webpack_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const constants_1 = __webpack_require__(/*! ../constants */ "./constants/index.ts");
|
||||
const _afterPluginsLoaded_1 = __webpack_require__(/*! ../helpers/_afterPluginsLoaded */ "./helpers/_afterPluginsLoaded.ts");
|
||||
const _extractMeaningfulErrorMessage_1 = __webpack_require__(/*! ../helpers/_extractMeaningfulErrorMessage */ "./helpers/_extractMeaningfulErrorMessage.ts");
|
||||
const _generateCadesFn_1 = __webpack_require__(/*! ../helpers/_generateCadesFn */ "./helpers/_generateCadesFn.ts");
|
||||
const _getCadesCert_1 = __webpack_require__(/*! ../helpers/_getCadesCert */ "./helpers/_getCadesCert.ts");
|
||||
const _getDateObj_1 = __webpack_require__(/*! ../helpers/_getDateObj */ "./helpers/_getDateObj.ts");
|
||||
/**
|
||||
* Добавляет отсоединенную подпись хеша к подписанному сообщению по отпечатку сертификата
|
||||
*
|
||||
* @param thumbprint - отпечаток сертификата
|
||||
* @param signedMessage - подписанное сообщение
|
||||
* @param messageHash - хеш подписываемого сообщения, сгенерированный по ГОСТ Р 34.11-2012 256 бит
|
||||
* @returns подпись в формате PKCS#7
|
||||
*/
|
||||
exports.addDetachedSignature = _afterPluginsLoaded_1._afterPluginsLoaded((thumbprint, signedMessage, messageHash) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { cadesplugin } = window;
|
||||
const cadesCertificate = yield _getCadesCert_1._getCadesCert(thumbprint);
|
||||
return eval(_generateCadesFn_1._generateCadesFn(function addDetachedSignature() {
|
||||
let cadesAttrs;
|
||||
let cadesHashedData;
|
||||
let cadesSignedData;
|
||||
let cadesSigner;
|
||||
try {
|
||||
cadesAttrs = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CADESCOM.CPAttribute');
|
||||
cadesHashedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.HashedData');
|
||||
cadesSignedData = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CadesSignedData');
|
||||
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||
}
|
||||
const currentTime = _getDateObj_1._getDateObj(new Date());
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Name(constants_1.CADESCOM_AUTHENTICATED_ATTRIBUTE_SIGNING_TIME));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAttrs.propset_Value(currentTime));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке времени подписи');
|
||||
}
|
||||
let cadesAuthAttrs;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||
cadesAuthAttrs = _generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.AuthenticatedAttributes2;
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesAuthAttrs.Add(cadesAttrs));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Options(cadesplugin.CAPICOM_CERTIFICATE_INCLUDE_WHOLE_CHAIN));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке сертификата');
|
||||
}
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesHashedData.propset_Algorithm(cadesplugin.CADESCOM_HASH_ALGORITHM_CP_GOST_3411_2012_256));
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesHashedData.SetHashValue(messageHash));
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при установке хеша');
|
||||
}
|
||||
let signature;
|
||||
try {
|
||||
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesSignedData.VerifyHash(cadesHashedData, signedMessage, cadesplugin.CADESCOM_PKCS7_TYPE));
|
||||
signature =
|
||||
_generateCadesFn_1.__cadesAsyncToken__ +
|
||||
cadesSignedData.CoSignHash(cadesHashedData, cadesSigner, cadesplugin.CADESCOM_PKCS7_TYPE);
|
||||
}
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||
}
|
||||
return signature;
|
||||
}));
|
||||
}));
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ "./api/certificate/certificate.ts":
|
||||
@ -3235,7 +3429,9 @@ __export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSet
|
||||
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createXMLSignature */ "./api/createXMLSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./addDetachedSignature */ "./api/addDetachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./addAttachedSignature */ "./api/addAttachedSignature.ts"));
|
||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
||||
__export(__webpack_require__(/*! ./certificate */ "./api/certificate/index.ts"));
|
||||
|
||||
|
File diff suppressed because one or more lines are too long
@ -1,5 +1,5 @@
|
||||
{
|
||||
"name": "crypto-pro",
|
||||
"name": "@gaarutyunov/crypto-pro-fork",
|
||||
"version": "2.2.2",
|
||||
"description": "API для взаимодействия с КриптоПро",
|
||||
"main": "./lib/crypto-pro.js",
|
||||
|
@ -15,8 +15,6 @@ const executionSteps = [
|
||||
Symbol('step 6'),
|
||||
Symbol('step 7'),
|
||||
Symbol('step 8'),
|
||||
Symbol('step 9'),
|
||||
Symbol('step 10'),
|
||||
];
|
||||
|
||||
const executionFlow = {
|
||||
@ -26,34 +24,28 @@ const executionFlow = {
|
||||
Open: jest.fn(),
|
||||
},
|
||||
[executionSteps[1]]: {
|
||||
Find: jest.fn(() => executionSteps[2]),
|
||||
},
|
||||
[executionSteps[2]]: {
|
||||
Find: jest.fn(() => executionSteps[3]),
|
||||
Count: executionSteps[2],
|
||||
Item: jest.fn(() => executionSteps[3]),
|
||||
},
|
||||
[executionSteps[2]]: 1,
|
||||
[executionSteps[3]]: {
|
||||
Count: executionSteps[4],
|
||||
Item: jest.fn(() => executionSteps[5]),
|
||||
IssuerName: executionSteps[6],
|
||||
SubjectName: executionSteps[5],
|
||||
Thumbprint: executionSteps[4],
|
||||
ValidFromDate: executionSteps[7],
|
||||
ValidToDate: executionSteps[8],
|
||||
},
|
||||
[executionSteps[4]]: 1,
|
||||
[executionSteps[5]]: {
|
||||
IssuerName: executionSteps[8],
|
||||
SubjectName: executionSteps[7],
|
||||
Thumbprint: executionSteps[6],
|
||||
ValidFromDate: executionSteps[9],
|
||||
ValidToDate: executionSteps[10],
|
||||
},
|
||||
[executionSteps[8]]: rawCertificateMock.IssuerName,
|
||||
[executionSteps[7]]: rawCertificateMock.SubjectName,
|
||||
[executionSteps[6]]: rawCertificateMock.Thumbprint,
|
||||
[executionSteps[9]]: rawCertificateMock.ValidFromDate,
|
||||
[executionSteps[10]]: rawCertificateMock.ValidToDate,
|
||||
[executionSteps[6]]: rawCertificateMock.IssuerName,
|
||||
[executionSteps[5]]: rawCertificateMock.SubjectName,
|
||||
[executionSteps[4]]: rawCertificateMock.Thumbprint,
|
||||
[executionSteps[7]]: rawCertificateMock.ValidFromDate,
|
||||
[executionSteps[8]]: rawCertificateMock.ValidToDate,
|
||||
};
|
||||
|
||||
window.cadesplugin.__defineExecutionFlow(executionFlow);
|
||||
window.cadesplugin.CreateObjectAsync.mockImplementation(() => executionSteps[0]);
|
||||
|
||||
describe('getAllUserCertificates', () => {
|
||||
describe('getUserCertificates', () => {
|
||||
test('returns certificates list', async () => {
|
||||
const certificates = await getAllUserCertificates();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user