@it-enterprise/digital-signature 1.3.12 → 1.3.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +3 -0
- package/package.json +1 -1
- package/src/DigitalSignature.js +20 -18
- package/src/Models.js +21 -13
- package/src/Utils.js +2 -2
package/.eslintrc.js
CHANGED
package/package.json
CHANGED
package/src/DigitalSignature.js
CHANGED
|
@@ -259,13 +259,13 @@ export default class DigitalSignature {
|
|
|
259
259
|
|
|
260
260
|
/**
|
|
261
261
|
* Распарсить сертификат
|
|
262
|
-
* @param {Uint8Array|string} cert
|
|
262
|
+
* @param {Uint8Array|string} cert
|
|
263
263
|
* @returns {Promise<EndUserCertificate>}
|
|
264
264
|
*/
|
|
265
265
|
async parseCertificate(cert) {
|
|
266
266
|
await this.setLibraryType(DigitalSignatureKeyType.File);
|
|
267
267
|
|
|
268
|
-
if (typeof cert ==
|
|
268
|
+
if (typeof cert == "string") {
|
|
269
269
|
cert = base64ToArray(cert);
|
|
270
270
|
}
|
|
271
271
|
|
|
@@ -465,7 +465,7 @@ export default class DigitalSignature {
|
|
|
465
465
|
* @param {boolean?} getCerts - Получать информацию о ключе пользователя. Это приведёт к дополнительному запросу на подписание
|
|
466
466
|
*/
|
|
467
467
|
async readPrivateKeyDepositsign(userId, getCerts = false) {
|
|
468
|
-
|
|
468
|
+
const deposit = this.KSPs.find(ksp => ksp.id === "depositsign");
|
|
469
469
|
return await this.readPrivateKeyKSP(deposit, userId, getCerts);
|
|
470
470
|
}
|
|
471
471
|
|
|
@@ -474,7 +474,7 @@ export default class DigitalSignature {
|
|
|
474
474
|
* @param {boolean?} getCerts - Получать информацию о ключе пользователя. Это приведёт к дополнительному запросу на подписание
|
|
475
475
|
*/
|
|
476
476
|
async readPrivateKeyDiia(getCerts = false) {
|
|
477
|
-
|
|
477
|
+
const diia = this.KSPs.find(ksp => ksp.id === "diia-sign");
|
|
478
478
|
return await this.readPrivateKeyKSP(diia, null, getCerts);
|
|
479
479
|
}
|
|
480
480
|
|
|
@@ -513,8 +513,8 @@ export default class DigitalSignature {
|
|
|
513
513
|
|
|
514
514
|
/**
|
|
515
515
|
* Получить список ключей у пользователя облачного провайдера
|
|
516
|
-
* @param {KSPSettings} kspSettings
|
|
517
|
-
* @param {KSPUserAuthData} authData
|
|
516
|
+
* @param {KSPSettings} kspSettings Облачный провайдер
|
|
517
|
+
* @param {KSPUserAuthData} authData
|
|
518
518
|
* @returns {KSPKeyMediasResponse}
|
|
519
519
|
*/
|
|
520
520
|
async getKeyMediasKSP(kspSettings, authData) {
|
|
@@ -560,6 +560,7 @@ export default class DigitalSignature {
|
|
|
560
560
|
let keyInfo;
|
|
561
561
|
|
|
562
562
|
try {
|
|
563
|
+
// eslint-disable-next-line no-undef
|
|
563
564
|
keyInfo = await SignerDigital.getSelectedCertificate();
|
|
564
565
|
} catch (error) {
|
|
565
566
|
throw {
|
|
@@ -570,7 +571,7 @@ export default class DigitalSignature {
|
|
|
570
571
|
|
|
571
572
|
keyInfo = JSON.parse(keyInfo);
|
|
572
573
|
const certInfo = await this.parseCertificate(keyInfo.Cert);
|
|
573
|
-
|
|
574
|
+
|
|
574
575
|
this._readedKey = new PrivateKeyInfo(DigitalSignatureKeyType.WindowsCertStore, certInfo.infoEx, [certInfo], certInfo.infoEx.subjCN, keyInfo.CertThumbPrint);
|
|
575
576
|
|
|
576
577
|
return this._readedKey;
|
|
@@ -681,7 +682,7 @@ export default class DigitalSignature {
|
|
|
681
682
|
}
|
|
682
683
|
}
|
|
683
684
|
}
|
|
684
|
-
|
|
685
|
+
|
|
685
686
|
if (this.readedKey.keyType === DigitalSignatureKeyType.WindowsCertStore) {
|
|
686
687
|
if (signType.type !== EndUserConstants.EU_SIGN_CONTAINER_TYPE_CADES) {
|
|
687
688
|
throw {
|
|
@@ -718,7 +719,7 @@ export default class DigitalSignature {
|
|
|
718
719
|
|
|
719
720
|
if (signType.subType === EndUserConstants.EndUserCAdESType.Detached) {
|
|
720
721
|
const hash = await this._euSign.HashData(this._readedKey.getHashAlgo(), data, !asByteArray);
|
|
721
|
-
|
|
722
|
+
|
|
722
723
|
if (this._readedKey.keyType == DigitalSignatureKeyTypeWindowsCertStore) {
|
|
723
724
|
return this._signHashWindowsCertificateStore(hash, signType, asByteArray);
|
|
724
725
|
}
|
|
@@ -727,10 +728,10 @@ export default class DigitalSignature {
|
|
|
727
728
|
} else {
|
|
728
729
|
|
|
729
730
|
if (this._readedKey.keyType == DigitalSignatureKeyTypeWindowsCertStore) {
|
|
730
|
-
|
|
731
|
+
const hash = await this._euSign.HashData(this._readedKey.getHashAlgo(), data, !asByteArray);
|
|
731
732
|
const signedData = await this._signHashWindowsCertificateStore(hash, signType, asByteArray);
|
|
732
733
|
|
|
733
|
-
return this._euSign.m_library.m_worker.postMessage("AppendDataToSignedData", [signedData, data,
|
|
734
|
+
return this._euSign.m_library.m_worker.postMessage("AppendDataToSignedData", [signedData, data, !asByteArray]);
|
|
734
735
|
}
|
|
735
736
|
|
|
736
737
|
return await this._euSign.SignDataEx(this._readedKey.getSignAlgo(), data, false, true, !asByteArray);
|
|
@@ -901,7 +902,7 @@ export default class DigitalSignature {
|
|
|
901
902
|
if (Array.isArray(signInfo)) {
|
|
902
903
|
signInfo = signInfo[signInfo.length - 1];
|
|
903
904
|
}
|
|
904
|
-
|
|
905
|
+
const cert = this._readedKey.certificates[0];
|
|
905
906
|
if (cert) {
|
|
906
907
|
signInfo.ownerInfo.certBeginTime = cert.infoEx.certBeginTime;
|
|
907
908
|
signInfo.ownerInfo.certEndTime = cert.infoEx.certEndTime;
|
|
@@ -1044,23 +1045,24 @@ export default class DigitalSignature {
|
|
|
1044
1045
|
|
|
1045
1046
|
const that = this;
|
|
1046
1047
|
async function signFunc(signValue) {
|
|
1047
|
-
if (typeof signValue !=
|
|
1048
|
+
if (typeof signValue != "string") {
|
|
1048
1049
|
signValue = convertToBase64(signValue);
|
|
1049
1050
|
}
|
|
1050
1051
|
|
|
1051
1052
|
let signedData;
|
|
1052
1053
|
|
|
1053
1054
|
try {
|
|
1054
|
-
|
|
1055
|
-
|
|
1055
|
+
const signAlgo = 2;
|
|
1056
|
+
// eslint-disable-next-line no-undef
|
|
1057
|
+
signedData = await SignerDigital.signHashCms(signValue, hashType, signAlgo, that._readedKey.id);
|
|
1056
1058
|
} catch (error) {
|
|
1057
1059
|
throw {
|
|
1058
1060
|
code: EndUserError.EU_ERROR_BAD_CERT,
|
|
1059
1061
|
message: String(error)
|
|
1060
|
-
}
|
|
1062
|
+
};
|
|
1061
1063
|
}
|
|
1062
|
-
|
|
1063
|
-
return await that._euSign.m_library.m_worker.postMessage("AppendValidationData",
|
|
1064
|
+
|
|
1065
|
+
return await that._euSign.m_library.m_worker.postMessage("AppendValidationData",
|
|
1064
1066
|
[signedData, that._readedKey.certificates[0].data, that._readedKey.getSignAlgo(), !asByteArray]);
|
|
1065
1067
|
}
|
|
1066
1068
|
|
package/src/Models.js
CHANGED
|
@@ -87,7 +87,7 @@ export class WebserviceSettingProvider {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
async getGlSign() {
|
|
90
|
-
return new GlSign(await downloadData(`${this.apiPath}/webservice.asmx/ExecuteEx?pureJSON=`, undefined, undefined, { calcId:
|
|
90
|
+
return new GlSign(await downloadData(`${this.apiPath}/webservice.asmx/ExecuteEx?pureJSON=`, undefined, undefined, { calcId: "GETGLSIGNBEFORELOGIN", args: "", ticket: "" }));
|
|
91
91
|
}
|
|
92
92
|
|
|
93
93
|
async getSettings() {
|
|
@@ -95,7 +95,7 @@ export class WebserviceSettingProvider {
|
|
|
95
95
|
return this._settings;
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
const json = await downloadData(`${this.apiPath}/webservice.asmx/ExecuteEx?pureJSON=`, "json", undefined, { calcId:
|
|
98
|
+
const json = await downloadData(`${this.apiPath}/webservice.asmx/ExecuteEx?pureJSON=`, "json", undefined, { calcId: "GETCASANDCERTIFICATEFILES", args: "", ticket: "" });
|
|
99
99
|
this._settings = new DigitalSignatureSettings(
|
|
100
100
|
this.language,
|
|
101
101
|
this.userId,
|
|
@@ -335,15 +335,17 @@ export const EndUserKSP = {
|
|
|
335
335
|
DIIA: EU_KSP_DIIA,
|
|
336
336
|
GRYADA: EU_KSP_GRYADA,
|
|
337
337
|
VTOKEN: EU_KSP_VTOKEN
|
|
338
|
-
}
|
|
338
|
+
};
|
|
339
|
+
|
|
340
|
+
export const EU_KSP_ClientIdType = -1;
|
|
339
341
|
|
|
340
342
|
export const EndUserKSPClientIdType = {
|
|
341
|
-
Default:
|
|
342
|
-
Name:
|
|
343
|
-
Phone:
|
|
344
|
-
Email:
|
|
345
|
-
NamePassword:
|
|
346
|
-
}
|
|
343
|
+
Default: EndUserConstants.EndUserKSPClientIdType.Default,
|
|
344
|
+
Name: EndUserConstants.EndUserKSPClientIdType.Name,
|
|
345
|
+
Phone: EndUserConstants.EndUserKSPClientIdType.Phone,
|
|
346
|
+
Email: EndUserConstants.EndUserKSPClientIdType.Email,
|
|
347
|
+
NamePassword: EU_KSP_ClientIdType
|
|
348
|
+
};
|
|
347
349
|
|
|
348
350
|
export class PrivateKeyInfo {
|
|
349
351
|
/**
|
|
@@ -430,7 +432,13 @@ export class PrivateKeyInfo {
|
|
|
430
432
|
getHashAlgo() {
|
|
431
433
|
const certificates = this.certificates;
|
|
432
434
|
if (certificates.length > 0 && certificates[0]?.infoEx?.certHashType) {
|
|
433
|
-
|
|
435
|
+
const hashType = certificates[0].infoEx.certHashType;
|
|
436
|
+
|
|
437
|
+
if (hashType == EndUserConstants.EndUserHashAlgo.GOST34311) {
|
|
438
|
+
return EndUserConstants.EndUserHashAlgo.DSTU7564_256;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return hashType;
|
|
434
442
|
}
|
|
435
443
|
return signAlgoToHashAlgo(this.getSignAlgo());
|
|
436
444
|
}
|
|
@@ -605,7 +613,7 @@ export function getDefaultKSPs(allowTest) {
|
|
|
605
613
|
vtoken.directAccess = true;
|
|
606
614
|
vtoken.clientIdType = EndUserKSPClientIdType.NamePassword;
|
|
607
615
|
|
|
608
|
-
|
|
616
|
+
const ksps = [
|
|
609
617
|
depositsign,
|
|
610
618
|
diia,
|
|
611
619
|
smartId,
|
|
@@ -685,7 +693,7 @@ export class KSPUserAuthData {
|
|
|
685
693
|
*/
|
|
686
694
|
export class KSPPrivateKeyAuthData {
|
|
687
695
|
/**
|
|
688
|
-
*
|
|
696
|
+
*
|
|
689
697
|
* @param {string} pin Пароль от ключа
|
|
690
698
|
* @param {string} token Токен авторизации аккаунта
|
|
691
699
|
* @param {string} twoFactorCode Код двухфакторной авторизации
|
|
@@ -695,4 +703,4 @@ export class KSPPrivateKeyAuthData {
|
|
|
695
703
|
this.token = token;
|
|
696
704
|
this.twoFactorCode = twoFactorCode;
|
|
697
705
|
}
|
|
698
|
-
}
|
|
706
|
+
}
|
package/src/Utils.js
CHANGED
|
@@ -185,7 +185,7 @@ export function convertToBase64(str) {
|
|
|
185
185
|
}
|
|
186
186
|
|
|
187
187
|
export function convertFromBase64(str) {
|
|
188
|
-
return arrayToString(base64ToArray(str))
|
|
188
|
+
return arrayToString(base64ToArray(str));
|
|
189
189
|
}
|
|
190
190
|
|
|
191
191
|
/**
|
|
@@ -220,7 +220,7 @@ export function getSupportedSignAlgos(certificates) {
|
|
|
220
220
|
}
|
|
221
221
|
switch (certificate.infoEx.publicKeyType) {
|
|
222
222
|
case EndUserConstants.EndUserCertKeyType.DSTU4145:
|
|
223
|
-
signAlgos.push(EndUserConstants.EndUserSignAlgo.
|
|
223
|
+
signAlgos.push(EndUserConstants.EndUserSignAlgo.DSTU4145WithDSTU7564);
|
|
224
224
|
break;
|
|
225
225
|
case EndUserConstants.EndUserCertKeyType.RSA:
|
|
226
226
|
signAlgos.push(EndUserConstants.EndUserSignAlgo.RSAWithSHA);
|