mirror of
https://github.com/crypto-pro-web/crypto-pro-js.git
synced 2024-11-27 12:56:00 +03:00
2.2.0
This commit is contained in:
parent
9958c9884a
commit
c0566b7654
@ -116,6 +116,7 @@ import { getUserCertificates, Certificate } from 'crypto-pro';
|
|||||||
- [getCertificate](src/api/getCertificate.ts) - возвращает [сертификат](#api-certificate) по отпечатку
|
- [getCertificate](src/api/getCertificate.ts) - возвращает [сертификат](#api-certificate) по отпечатку
|
||||||
- [createAttachedSignature](src/api/createAttachedSignature.ts) - создает совмещенную (присоединенную) подпись сообщения
|
- [createAttachedSignature](src/api/createAttachedSignature.ts) - создает совмещенную (присоединенную) подпись сообщения
|
||||||
- [createDetachedSignature](src/api/createDetachedSignature.ts) - создает отсоединенную (открепленную) подпись сообщения
|
- [createDetachedSignature](src/api/createDetachedSignature.ts) - создает отсоединенную (открепленную) подпись сообщения
|
||||||
|
- [createXMLSignature](src/api/createXMLSignature.ts) - создает XML подпись для документа в формате XML
|
||||||
- [createHash](src/api/createHash.ts) - создает хеш сообщения по ГОСТ Р 34.11-2012 256 бит
|
- [createHash](src/api/createHash.ts) - создает хеш сообщения по ГОСТ Р 34.11-2012 256 бит
|
||||||
- [createSignature](src/api/createSignature.ts) - создает подпись сообщения
|
- [createSignature](src/api/createSignature.ts) - создает подпись сообщения
|
||||||
> Является устаревшим и будет убран из будущих версий.
|
> Является устаревшим и будет убран из будущих версий.
|
||||||
|
8
dist/api/createXMLSignature.d.ts
vendored
Normal file
8
dist/api/createXMLSignature.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Создает XML подпись для документа в формате XML
|
||||||
|
*
|
||||||
|
* @param thumbprint - отпечаток сертификата
|
||||||
|
* @param unencryptedMessage - подписываемое сообщение в формате XML
|
||||||
|
* @returns подпись
|
||||||
|
*/
|
||||||
|
export declare const createXMLSignature: (thumbprint: string, unencryptedMessage: string) => Promise<string>;
|
1
dist/api/index.d.ts
vendored
1
dist/api/index.d.ts
vendored
@ -3,6 +3,7 @@ export * from './getUserCertificates';
|
|||||||
export * from './getSystemInfo';
|
export * from './getSystemInfo';
|
||||||
export * from './isValidSystemSetup';
|
export * from './isValidSystemSetup';
|
||||||
export * from './createSignature';
|
export * from './createSignature';
|
||||||
|
export * from './createXMLSignature';
|
||||||
export * from './createDetachedSignature';
|
export * from './createDetachedSignature';
|
||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
|
2
dist/crypto-pro.d.ts
vendored
2
dist/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// Type definitions for crypto-pro 2.1.0
|
// Type definitions for crypto-pro 2.2.0
|
||||||
// Project: crypto-pro
|
// Project: crypto-pro
|
||||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||||
|
|
||||||
|
110
dist/crypto-pro.js
vendored
110
dist/crypto-pro.js
vendored
@ -3215,6 +3215,115 @@ exports.createSignature = _afterPluginsLoaded_1._afterPluginsLoaded(function (th
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./api/createXMLSignature.ts":
|
||||||
|
/*!***********************************!*\
|
||||||
|
!*** ./api/createXMLSignature.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 _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");
|
||||||
|
/**
|
||||||
|
* Создает XML подпись для документа в формате XML
|
||||||
|
*
|
||||||
|
* @param thumbprint - отпечаток сертификата
|
||||||
|
* @param unencryptedMessage - подписываемое сообщение в формате XML
|
||||||
|
* @returns подпись
|
||||||
|
*/
|
||||||
|
exports.createXMLSignature = _afterPluginsLoaded_1._afterPluginsLoaded(function (thumbprint, unencryptedMessage) { 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 createXMLSignature() {
|
||||||
|
var cadesSigner;
|
||||||
|
var cadesSignedXML;
|
||||||
|
try {
|
||||||
|
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||||
|
cadesSignedXML = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.SignedXML');
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
var signatureMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256';
|
||||||
|
var digestMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256';
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_CheckCertificate(true));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_Content(unencryptedMessage));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||||
|
cadesSignedXML.propset_SignatureType(cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_SignatureMethod(signatureMethod));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_DigestMethod(digestMethod));
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при указании данных для подписи');
|
||||||
|
}
|
||||||
|
var signature;
|
||||||
|
try {
|
||||||
|
signature = _generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.Sign(cadesSigner);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||||
|
}
|
||||||
|
return signature;
|
||||||
|
}))];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}); });
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ "./api/getCertificate.ts":
|
/***/ "./api/getCertificate.ts":
|
||||||
@ -3449,6 +3558,7 @@ __export(__webpack_require__(/*! ./getUserCertificates */ "./api/getUserCertific
|
|||||||
__export(__webpack_require__(/*! ./getSystemInfo */ "./api/getSystemInfo.ts"));
|
__export(__webpack_require__(/*! ./getSystemInfo */ "./api/getSystemInfo.ts"));
|
||||||
__export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSetup.ts"));
|
__export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSetup.ts"));
|
||||||
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
||||||
|
__export(__webpack_require__(/*! ./createXMLSignature */ "./api/createXMLSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.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
6
examples/angular/package-lock.json
generated
6
examples/angular/package-lock.json
generated
@ -3308,9 +3308,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
||||||
"integrity": "sha512-zLPX/m51fiMS6aWXZ8e8e/Lcw/8VkeIlMo0nvsdvMik6koec+UbNP+syRp07eWJEmRDb8IZLjzLGjrb0oGT64g=="
|
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
"@angular/platform-browser": "~9.0.7",
|
"@angular/platform-browser": "~9.0.7",
|
||||||
"@angular/platform-browser-dynamic": "~9.0.7",
|
"@angular/platform-browser-dynamic": "~9.0.7",
|
||||||
"@angular/router": "~9.0.7",
|
"@angular/router": "~9.0.7",
|
||||||
"crypto-pro": "2.1.0",
|
"crypto-pro": "2.2.0",
|
||||||
"rxjs": "~6.5.4",
|
"rxjs": "~6.5.4",
|
||||||
"tslib": "^1.10.0",
|
"tslib": "^1.10.0",
|
||||||
"zone.js": "~0.10.2"
|
"zone.js": "~0.10.2"
|
||||||
|
6
examples/react/package-lock.json
generated
6
examples/react/package-lock.json
generated
@ -3712,9 +3712,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
||||||
"integrity": "sha512-zLPX/m51fiMS6aWXZ8e8e/Lcw/8VkeIlMo0nvsdvMik6koec+UbNP+syRp07eWJEmRDb8IZLjzLGjrb0oGT64g=="
|
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
||||||
},
|
},
|
||||||
"css": {
|
"css": {
|
||||||
"version": "2.2.4",
|
"version": "2.2.4",
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
"@testing-library/jest-dom": "4.2.4",
|
"@testing-library/jest-dom": "4.2.4",
|
||||||
"@testing-library/react": "9.5.0",
|
"@testing-library/react": "9.5.0",
|
||||||
"@testing-library/user-event": "7.2.1",
|
"@testing-library/user-event": "7.2.1",
|
||||||
"crypto-pro": "2.1.0",
|
"crypto-pro": "2.2.0",
|
||||||
"react": "^16.13.1",
|
"react": "^16.13.1",
|
||||||
"react-app-polyfill": "1.0.6",
|
"react-app-polyfill": "1.0.6",
|
||||||
"react-dom": "^16.13.1",
|
"react-dom": "^16.13.1",
|
||||||
|
6
examples/script-tag/package-lock.json
generated
6
examples/script-tag/package-lock.json
generated
@ -42,9 +42,9 @@
|
|||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"crypto-pro": {
|
"crypto-pro": {
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/crypto-pro/-/crypto-pro-2.2.0.tgz",
|
||||||
"integrity": "sha512-zLPX/m51fiMS6aWXZ8e8e/Lcw/8VkeIlMo0nvsdvMik6koec+UbNP+syRp07eWJEmRDb8IZLjzLGjrb0oGT64g=="
|
"integrity": "sha512-OUOmAMtzWXO3wuY6WBPv7QdkamI4WABjkRD/8OFoDyx2S9bsbZzukktFlPIgz0nvVUS7UTXACQeO0q56bh+whA=="
|
||||||
},
|
},
|
||||||
"fs.realpath": {
|
"fs.realpath": {
|
||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
|
@ -13,6 +13,6 @@
|
|||||||
"symlink-dir": "3.1.2"
|
"symlink-dir": "3.1.2"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"crypto-pro": "2.1.0"
|
"crypto-pro": "2.2.0"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,27 @@
|
|||||||
|
|
||||||
function createSignature(message, hash) {
|
function createSignature(message, hash) {
|
||||||
var thumbprint = $certificate.value,
|
var thumbprint = $certificate.value,
|
||||||
detachedSignature = document.querySelector('input[name="signatureType"]:checked').value,
|
signatureType = document.querySelector('input[name="signatureType"]:checked').value,
|
||||||
signaturePromise;
|
signaturePromise;
|
||||||
|
|
||||||
detachedSignature = Boolean(Number(detachedSignature));
|
|
||||||
|
|
||||||
$hash.value = hash;
|
$hash.value = hash;
|
||||||
|
|
||||||
$signature.placeholder = 'Создается...';
|
$signature.placeholder = 'Создается...';
|
||||||
$signature.value = '';
|
$signature.value = '';
|
||||||
|
|
||||||
if (detachedSignature) {
|
switch (signatureType) {
|
||||||
signaturePromise = window.cryptoPro.createDetachedSignature(thumbprint, hash);
|
case 'attached':
|
||||||
} else {
|
|
||||||
signaturePromise = window.cryptoPro.createAttachedSignature(thumbprint, message);
|
signaturePromise = window.cryptoPro.createAttachedSignature(thumbprint, message);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'xml':
|
||||||
|
signaturePromise = window.cryptoPro.createXMLSignature(thumbprint, message);
|
||||||
|
|
||||||
|
break;
|
||||||
|
case 'detached':
|
||||||
|
signaturePromise = window.cryptoPro.createDetachedSignature(thumbprint, hash);
|
||||||
|
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
signaturePromise.then(function (signature) {
|
signaturePromise.then(function (signature) {
|
||||||
|
@ -36,9 +36,11 @@
|
|||||||
|
|
||||||
<label>Тип подписи: *</label>
|
<label>Тип подписи: *</label>
|
||||||
<br>
|
<br>
|
||||||
<label><input type="radio" name="signatureType" value="0">Совмещенная</label>
|
<label><input type="radio" name="signatureType" value="attached">Совмещенная</label>
|
||||||
<br>
|
<br>
|
||||||
<label><input type="radio" name="signatureType" value="1" checked>Отделенная</label>
|
<label><input type="radio" name="signatureType" value="xml">XML</label>
|
||||||
|
<br>
|
||||||
|
<label><input type="radio" name="signatureType" value="detached" checked>Отделенная</label>
|
||||||
<br><br>
|
<br><br>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
8
lib/api/createXMLSignature.d.ts
vendored
Normal file
8
lib/api/createXMLSignature.d.ts
vendored
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
/**
|
||||||
|
* Создает XML подпись для документа в формате XML
|
||||||
|
*
|
||||||
|
* @param thumbprint - отпечаток сертификата
|
||||||
|
* @param unencryptedMessage - подписываемое сообщение в формате XML
|
||||||
|
* @returns подпись
|
||||||
|
*/
|
||||||
|
export declare const createXMLSignature: (thumbprint: string, unencryptedMessage: string) => Promise<string>;
|
1
lib/api/index.d.ts
vendored
1
lib/api/index.d.ts
vendored
@ -3,6 +3,7 @@ export * from './getUserCertificates';
|
|||||||
export * from './getSystemInfo';
|
export * from './getSystemInfo';
|
||||||
export * from './isValidSystemSetup';
|
export * from './isValidSystemSetup';
|
||||||
export * from './createSignature';
|
export * from './createSignature';
|
||||||
|
export * from './createXMLSignature';
|
||||||
export * from './createDetachedSignature';
|
export * from './createDetachedSignature';
|
||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
|
2
lib/crypto-pro.d.ts
vendored
2
lib/crypto-pro.d.ts
vendored
@ -1,4 +1,4 @@
|
|||||||
// Type definitions for crypto-pro 2.1.0
|
// Type definitions for crypto-pro 2.2.0
|
||||||
// Project: crypto-pro
|
// Project: crypto-pro
|
||||||
// Definitions by: Vitalii Goma https://github.com/vgoma
|
// Definitions by: Vitalii Goma https://github.com/vgoma
|
||||||
|
|
||||||
|
@ -2961,6 +2961,80 @@ exports.createSignature = _afterPluginsLoaded_1._afterPluginsLoaded((thumbprint,
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
|
/***/ }),
|
||||||
|
|
||||||
|
/***/ "./api/createXMLSignature.ts":
|
||||||
|
/*!***********************************!*\
|
||||||
|
!*** ./api/createXMLSignature.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 _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");
|
||||||
|
/**
|
||||||
|
* Создает XML подпись для документа в формате XML
|
||||||
|
*
|
||||||
|
* @param thumbprint - отпечаток сертификата
|
||||||
|
* @param unencryptedMessage - подписываемое сообщение в формате XML
|
||||||
|
* @returns подпись
|
||||||
|
*/
|
||||||
|
exports.createXMLSignature = _afterPluginsLoaded_1._afterPluginsLoaded((thumbprint, unencryptedMessage) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
const { cadesplugin } = window;
|
||||||
|
const cadesCertificate = yield _getCadesCert_1._getCadesCert(thumbprint);
|
||||||
|
return eval(_generateCadesFn_1._generateCadesFn(function createXMLSignature() {
|
||||||
|
let cadesSigner;
|
||||||
|
let cadesSignedXML;
|
||||||
|
try {
|
||||||
|
cadesSigner = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||||
|
cadesSignedXML = _generateCadesFn_1.__cadesAsyncToken__ + _generateCadesFn_1.__createCadesPluginObject__('CAdESCOM.SignedXML');
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
const signatureMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256';
|
||||||
|
const digestMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256';
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSigner.propset_CheckCertificate(true));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_Content(unencryptedMessage));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ +
|
||||||
|
cadesSignedXML.propset_SignatureType(cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_SignatureMethod(signatureMethod));
|
||||||
|
void (_generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.propset_DigestMethod(digestMethod));
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при указании данных для подписи');
|
||||||
|
}
|
||||||
|
let signature;
|
||||||
|
try {
|
||||||
|
signature = _generateCadesFn_1.__cadesAsyncToken__ + cadesSignedXML.Sign(cadesSigner);
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage_1._extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||||
|
}
|
||||||
|
return signature;
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ "./api/getCertificate.ts":
|
/***/ "./api/getCertificate.ts":
|
||||||
@ -3159,6 +3233,7 @@ __export(__webpack_require__(/*! ./getUserCertificates */ "./api/getUserCertific
|
|||||||
__export(__webpack_require__(/*! ./getSystemInfo */ "./api/getSystemInfo.ts"));
|
__export(__webpack_require__(/*! ./getSystemInfo */ "./api/getSystemInfo.ts"));
|
||||||
__export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSetup.ts"));
|
__export(__webpack_require__(/*! ./isValidSystemSetup */ "./api/isValidSystemSetup.ts"));
|
||||||
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
__export(__webpack_require__(/*! ./createSignature */ "./api/createSignature.ts"));
|
||||||
|
__export(__webpack_require__(/*! ./createXMLSignature */ "./api/createXMLSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createDetachedSignature */ "./api/createDetachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
__export(__webpack_require__(/*! ./createAttachedSignature */ "./api/createAttachedSignature.ts"));
|
||||||
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
__export(__webpack_require__(/*! ./createHash */ "./api/createHash.ts"));
|
||||||
|
File diff suppressed because one or more lines are too long
2
package-lock.json
generated
2
package-lock.json
generated
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "crypto-pro",
|
"name": "crypto-pro",
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "crypto-pro",
|
"name": "crypto-pro",
|
||||||
"version": "2.1.0",
|
"version": "2.2.0",
|
||||||
"description": "API для взаимодействия с КриптоПро",
|
"description": "API для взаимодействия с КриптоПро",
|
||||||
"main": "./lib/crypto-pro.js",
|
"main": "./lib/crypto-pro.js",
|
||||||
"types": "./lib/crypto-pro.d.ts",
|
"types": "./lib/crypto-pro.d.ts",
|
||||||
|
71
src/api/createXMLSignature.test.ts
Normal file
71
src/api/createXMLSignature.test.ts
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
import 'cadesplugin';
|
||||||
|
import { rawCertificates, parsedCertificates } from '../__mocks__/certificates';
|
||||||
|
import { createXMLSignature } from './createXMLSignature';
|
||||||
|
import { _getCadesCert } from '../helpers/_getCadesCert';
|
||||||
|
|
||||||
|
const [rawCertificateMock] = rawCertificates;
|
||||||
|
const [parsedCertificateMock] = parsedCertificates;
|
||||||
|
|
||||||
|
jest.mock('../helpers/_getCadesCert', () => ({ _getCadesCert: jest.fn(() => rawCertificateMock) }));
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
(_getCadesCert as jest.Mock).mockClear();
|
||||||
|
});
|
||||||
|
|
||||||
|
const executionSteps = [Symbol('step 0'), Symbol('step 1'), Symbol('step 2')];
|
||||||
|
|
||||||
|
const executionFlow = {
|
||||||
|
[executionSteps[0]]: {
|
||||||
|
propset_Certificate: jest.fn(),
|
||||||
|
propset_CheckCertificate: jest.fn(),
|
||||||
|
},
|
||||||
|
[executionSteps[1]]: {
|
||||||
|
propset_Content: jest.fn(),
|
||||||
|
propset_SignatureType: jest.fn(),
|
||||||
|
propset_SignatureMethod: jest.fn(),
|
||||||
|
propset_DigestMethod: jest.fn(),
|
||||||
|
Sign: jest.fn(() => executionSteps[2]),
|
||||||
|
},
|
||||||
|
[executionSteps[2]]: 'signature',
|
||||||
|
};
|
||||||
|
|
||||||
|
window.cadesplugin.__defineExecutionFlow(executionFlow);
|
||||||
|
window.cadesplugin.CreateObjectAsync.mockImplementation((object) => {
|
||||||
|
switch (object) {
|
||||||
|
case 'CAdESCOM.CPSigner':
|
||||||
|
return executionSteps[0];
|
||||||
|
case 'CAdESCOM.SignedXML':
|
||||||
|
return executionSteps[1];
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('createXMLSignature', () => {
|
||||||
|
test('uses specified certificate', async () => {
|
||||||
|
await createXMLSignature(parsedCertificateMock.thumbprint, 'message');
|
||||||
|
|
||||||
|
expect(_getCadesCert).toHaveBeenCalledWith(parsedCertificateMock.thumbprint);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('returns signature', async () => {
|
||||||
|
const signature = await createXMLSignature(
|
||||||
|
parsedCertificateMock.thumbprint,
|
||||||
|
`
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
Original XML doc file for sign example.
|
||||||
|
-->
|
||||||
|
<Envelope xmlns="urn:envelope">
|
||||||
|
<Data>
|
||||||
|
Hello, World!
|
||||||
|
</Data>
|
||||||
|
<Node xml:id="nodeID">
|
||||||
|
Hello, Node!
|
||||||
|
</Node>
|
||||||
|
|
||||||
|
</Envelope>
|
||||||
|
`,
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(signature).toEqual('signature');
|
||||||
|
});
|
||||||
|
});
|
65
src/api/createXMLSignature.ts
Normal file
65
src/api/createXMLSignature.ts
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
import { _afterPluginsLoaded } from '../helpers/_afterPluginsLoaded';
|
||||||
|
import { _extractMeaningfulErrorMessage } from '../helpers/_extractMeaningfulErrorMessage';
|
||||||
|
import { __cadesAsyncToken__, __createCadesPluginObject__, _generateCadesFn } from '../helpers/_generateCadesFn';
|
||||||
|
import { _getCadesCert } from '../helpers/_getCadesCert';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Создает XML подпись для документа в формате XML
|
||||||
|
*
|
||||||
|
* @param thumbprint - отпечаток сертификата
|
||||||
|
* @param unencryptedMessage - подписываемое сообщение в формате XML
|
||||||
|
* @returns подпись
|
||||||
|
*/
|
||||||
|
export const createXMLSignature = _afterPluginsLoaded(
|
||||||
|
async (thumbprint: string, unencryptedMessage: string): Promise<string> => {
|
||||||
|
const { cadesplugin } = window;
|
||||||
|
const cadesCertificate = await _getCadesCert(thumbprint);
|
||||||
|
|
||||||
|
return eval(
|
||||||
|
_generateCadesFn(function createXMLSignature(): string {
|
||||||
|
let cadesSigner;
|
||||||
|
let cadesSignedXML;
|
||||||
|
|
||||||
|
try {
|
||||||
|
cadesSigner = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.CPSigner');
|
||||||
|
cadesSignedXML = __cadesAsyncToken__ + __createCadesPluginObject__('CAdESCOM.SignedXML');
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при инициализации подписи');
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const signatureMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34102012-gostr34112012-256';
|
||||||
|
const digestMethod = 'urn:ietf:params:xml:ns:cpxmlsec:algorithms:gostr34112012-256';
|
||||||
|
|
||||||
|
void (__cadesAsyncToken__ + cadesSigner.propset_Certificate(cadesCertificate));
|
||||||
|
void (__cadesAsyncToken__ + cadesSigner.propset_CheckCertificate(true));
|
||||||
|
void (__cadesAsyncToken__ + cadesSignedXML.propset_Content(unencryptedMessage));
|
||||||
|
void (
|
||||||
|
__cadesAsyncToken__ +
|
||||||
|
cadesSignedXML.propset_SignatureType(cadesplugin.CADESCOM_XML_SIGNATURE_TYPE_ENVELOPED)
|
||||||
|
);
|
||||||
|
void (__cadesAsyncToken__ + cadesSignedXML.propset_SignatureMethod(signatureMethod));
|
||||||
|
void (__cadesAsyncToken__ + cadesSignedXML.propset_DigestMethod(digestMethod));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при указании данных для подписи');
|
||||||
|
}
|
||||||
|
|
||||||
|
let signature: string;
|
||||||
|
|
||||||
|
try {
|
||||||
|
signature = __cadesAsyncToken__ + cadesSignedXML.Sign(cadesSigner);
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
|
||||||
|
throw new Error(_extractMeaningfulErrorMessage(error) || 'Ошибка при подписании данных');
|
||||||
|
}
|
||||||
|
|
||||||
|
return signature;
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
@ -3,6 +3,7 @@ export * from './getUserCertificates';
|
|||||||
export * from './getSystemInfo';
|
export * from './getSystemInfo';
|
||||||
export * from './isValidSystemSetup';
|
export * from './isValidSystemSetup';
|
||||||
export * from './createSignature';
|
export * from './createSignature';
|
||||||
|
export * from './createXMLSignature';
|
||||||
export * from './createDetachedSignature';
|
export * from './createDetachedSignature';
|
||||||
export * from './createAttachedSignature';
|
export * from './createAttachedSignature';
|
||||||
export * from './createHash';
|
export * from './createHash';
|
||||||
|
Loading…
Reference in New Issue
Block a user