@it-enterprise/digital-signature 1.4.4 → 1.4.6
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/dist/it-digital-signature.mjs +210 -195
- package/dist/it-digital-signature.mjs.map +1 -1
- package/dist/it-digital-signature.umd.js +1 -1
- package/dist/it-digital-signature.umd.js.map +1 -1
- package/package.json +2 -2
- package/src/DigitalSignature.js +98 -64
- package/src/Models.js +2 -2
- package/src/Utils.js +10 -1
package/package.json
CHANGED
package/src/DigitalSignature.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { EndUser, EndUserConstants, EndUserProxySettings, EndUserError, KSPSettings, EndUserCertificate, EndUserKeyMedia, EndUserSignContainerInfo, EndUserCertificateInfoEx, EndUserTaxReport } from "../euscp/euscp";
|
|
2
2
|
import { DigitalSignatureKeyType, PrivateKeyInfo, FilePrivateKeyInfo, HardwarePrivateKeyInfo, KspPrivateKeyInfo, EndUserKSP, KSPKeyMediasResponse, KSPUserAuthData, KSPPrivateKeyAuthData, DigitalSignatureKeyTypeWindowsCertStore, ProtectTaxReportParams } from "./Models";
|
|
3
|
-
import { arrayToBase64, base64ToArray, convertToBase64, downloadAndSignFiles, downloadData, format, isDefaultValue, readFile } from "./Utils";
|
|
3
|
+
import { arrayToBase64, base64ToArray, convertToBase64, dateWithoutTimezone, downloadAndSignFiles, downloadData, format, isDefaultValue, readFile } from "./Utils";
|
|
4
4
|
import UmCAService from "./umcaservice";
|
|
5
5
|
import Resourses from "./Resourses.json";
|
|
6
6
|
import GlSign from "./GlSign";
|
|
@@ -322,6 +322,10 @@ export default class DigitalSignature {
|
|
|
322
322
|
return await this.readHardwareKey(keyInfo.keyMedia, keyInfo.certificates);
|
|
323
323
|
case DigitalSignatureKeyType.KSP:
|
|
324
324
|
return await this.readPrivateKeyKSP(keyInfo.ksp, keyInfo.kspUserId, false);
|
|
325
|
+
case DigitalSignatureKeyType.UmCAService:
|
|
326
|
+
return await this.readPrivateKeyUmCAService(keyInfo.keyMedia);
|
|
327
|
+
case DigitalSignatureKeyType.WindowsCertStore:
|
|
328
|
+
return await this.readWindowsCertStorePrivateKey();
|
|
325
329
|
default:
|
|
326
330
|
return null;
|
|
327
331
|
}
|
|
@@ -579,7 +583,7 @@ export default class DigitalSignature {
|
|
|
579
583
|
/**
|
|
580
584
|
* Считать ключ с помощью UmCAService
|
|
581
585
|
* @param {EndUserKeyMedia} keyMedia - Параметры ключа
|
|
582
|
-
* @returns {PrivateKeyInfo}
|
|
586
|
+
* @returns {Promise<PrivateKeyInfo>}
|
|
583
587
|
*/
|
|
584
588
|
async readPrivateKeyUmCAService(keyMedia) {
|
|
585
589
|
await this.setLibraryType(DigitalSignatureKeyType.UmCAService);
|
|
@@ -669,7 +673,7 @@ export default class DigitalSignature {
|
|
|
669
673
|
}
|
|
670
674
|
try {
|
|
671
675
|
return await this._euSign.IsPrivateKeyReaded();
|
|
672
|
-
} catch
|
|
676
|
+
} catch {
|
|
673
677
|
return false;
|
|
674
678
|
}
|
|
675
679
|
}
|
|
@@ -893,26 +897,23 @@ export default class DigitalSignature {
|
|
|
893
897
|
const signContainerInfo = await this._euSign.GetSignContainerInfo(sign.val || sign);
|
|
894
898
|
|
|
895
899
|
if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.ASiC) {
|
|
896
|
-
return await this._euSign.ASiCVerifyData(sign, signIndex);
|
|
900
|
+
return await this._euSign.ASiCVerifyData(sign.val || sign, signIndex);
|
|
897
901
|
} else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.PAdES) {
|
|
898
|
-
return await this._euSign.PDFVerifyData(sign, signIndex);
|
|
902
|
+
return await this._euSign.PDFVerifyData(sign.val || sign, signIndex);
|
|
899
903
|
} else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.XAdES) {
|
|
900
904
|
return await this._euSign.XAdESVerifyData(data, sign.val || sign, signIndex);
|
|
901
905
|
} else if (signContainerInfo.type === EndUserConstants.EndUserSignContainerType.CAdES) {
|
|
902
|
-
if (
|
|
903
|
-
if (
|
|
906
|
+
if (!data) {
|
|
907
|
+
if (signContainerInfo.subType === EndUserConstants.EndUserCAdESType.Detached) {
|
|
904
908
|
throw {
|
|
905
909
|
code: EndUserError.EU_ERROR_BAD_PARAMETER,
|
|
906
910
|
message: this._resourses.BadParameter + " data"
|
|
907
911
|
};
|
|
908
912
|
}
|
|
909
|
-
return await this._euSign.VerifyData(data.val || data, sign.val || sign, signIndex);
|
|
910
|
-
} else {
|
|
911
913
|
return await this._euSign.VerifyDataInternal(sign.val || sign, signIndex);
|
|
912
914
|
}
|
|
913
915
|
}
|
|
914
|
-
|
|
915
|
-
return await this._euSign.VerifyData(data, sign, signIndex);
|
|
916
|
+
return await this._euSign.VerifyData(data.val || data, sign.val || sign, signIndex);
|
|
916
917
|
}
|
|
917
918
|
|
|
918
919
|
/**
|
|
@@ -986,43 +987,11 @@ export default class DigitalSignature {
|
|
|
986
987
|
if (Array.isArray(data)) {
|
|
987
988
|
const result = [];
|
|
988
989
|
for (let i = 0; i < signs.length; i++) {
|
|
989
|
-
|
|
990
|
-
let signInfo = await this.verifyData(data[i].val || data[i], sign.val || sign);
|
|
991
|
-
if (Array.isArray(signInfo)) {
|
|
992
|
-
signInfo = signInfo[signInfo.length - 1];
|
|
993
|
-
}
|
|
994
|
-
const cert = this._readedKey.certificates[0];
|
|
995
|
-
if (cert) {
|
|
996
|
-
signInfo.ownerInfo.certBeginTime = cert.infoEx.certBeginTime;
|
|
997
|
-
signInfo.ownerInfo.certEndTime = cert.infoEx.certEndTime;
|
|
998
|
-
}
|
|
999
|
-
result[i] = {
|
|
1000
|
-
Success: true,
|
|
1001
|
-
Sign: sign.val || sign,
|
|
1002
|
-
SignatureInfo: {
|
|
1003
|
-
Success: true,
|
|
1004
|
-
DateTimeStr: signInfo.timeInfo.time,
|
|
1005
|
-
Signer: signInfo.ownerInfo.subjCN,
|
|
1006
|
-
OwnerInfo: signInfo.ownerInfo
|
|
1007
|
-
}
|
|
1008
|
-
};
|
|
990
|
+
result[i] = await this._formatSignInfo(data[i], signs[i], false);
|
|
1009
991
|
}
|
|
1010
992
|
return result;
|
|
1011
993
|
} else {
|
|
1012
|
-
|
|
1013
|
-
if (Array.isArray(signInfo)) {
|
|
1014
|
-
signInfo = signInfo[signInfo.length - 1];
|
|
1015
|
-
}
|
|
1016
|
-
return {
|
|
1017
|
-
Success: true,
|
|
1018
|
-
Sign: signs.val || signs,
|
|
1019
|
-
SignatureInfo: {
|
|
1020
|
-
Success: true,
|
|
1021
|
-
DateTimeStr: signInfo.timeInfo.time,
|
|
1022
|
-
Signer: signInfo.ownerInfo.subjCN,
|
|
1023
|
-
OwnerInfo: signInfo.ownerInfo
|
|
1024
|
-
}
|
|
1025
|
-
};
|
|
994
|
+
return await this._formatSignInfo(data, signs);
|
|
1026
995
|
}
|
|
1027
996
|
}
|
|
1028
997
|
|
|
@@ -1045,39 +1014,95 @@ export default class DigitalSignature {
|
|
|
1045
1014
|
if (Array.isArray(hash)) {
|
|
1046
1015
|
const result = [];
|
|
1047
1016
|
for (let i = 0; i < signs.length; i++) {
|
|
1048
|
-
|
|
1049
|
-
let signInfo = await this.verifyHash(hash[i].val || hash[i], sign.val || sign);
|
|
1050
|
-
if (Array.isArray(signInfo)) {
|
|
1051
|
-
signInfo = signInfo[signInfo.length - 1];
|
|
1052
|
-
}
|
|
1053
|
-
result[i] = {
|
|
1054
|
-
Success: true,
|
|
1055
|
-
Sign: sign.val || sign,
|
|
1056
|
-
SignatureInfo: {
|
|
1057
|
-
Success: true,
|
|
1058
|
-
DateTimeStr: signInfo.timeInfo.time,
|
|
1059
|
-
Signer: signInfo.ownerInfo.subjCN,
|
|
1060
|
-
OwnerInfo: signInfo.ownerInfo
|
|
1061
|
-
}
|
|
1062
|
-
};
|
|
1017
|
+
result[i] = await this._formatSignInfo(hash[i], signs[i], true);
|
|
1063
1018
|
}
|
|
1064
1019
|
return result;
|
|
1065
1020
|
} else {
|
|
1066
|
-
|
|
1021
|
+
return await this._formatSignInfo(hash, signs, true);
|
|
1022
|
+
}
|
|
1023
|
+
}
|
|
1024
|
+
|
|
1025
|
+
async _formatSignInfo(data, sign, isHash) {
|
|
1026
|
+
const that = this;
|
|
1027
|
+
return await getSignInfo(data.val || data, sign.val || sign);
|
|
1028
|
+
|
|
1029
|
+
async function getSignInfo(data, sign) {
|
|
1030
|
+
let signInfo;
|
|
1031
|
+
if (isHash) {
|
|
1032
|
+
signInfo = await that.verifyHash(data, sign);
|
|
1033
|
+
} else {
|
|
1034
|
+
signInfo = await that.verifyData(data, sign);
|
|
1035
|
+
}
|
|
1067
1036
|
if (Array.isArray(signInfo)) {
|
|
1068
|
-
signInfo = signInfo
|
|
1037
|
+
signInfo = signInfo.pop();
|
|
1069
1038
|
}
|
|
1039
|
+
|
|
1040
|
+
const signer = await getSigner(sign);
|
|
1041
|
+
signInfo.ownerInfo.certBeginTime = dateWithoutTimezone(signer.certBeginTime);
|
|
1042
|
+
signInfo.ownerInfo.certEndTime = dateWithoutTimezone(signer.certEndTime);
|
|
1043
|
+
signInfo.ownerInfo.publicKeyType = signer.publicKeyType;
|
|
1044
|
+
signInfo.ownerInfo.keyUsageType = signer.keyUsageType;
|
|
1045
|
+
signInfo.ownerInfo.certHashType = that._readedKey.getHashAlgo();
|
|
1046
|
+
|
|
1047
|
+
const timeInfo = signInfo.timeInfo
|
|
1048
|
+
const time = dateWithoutTimezone(timeInfo.isSignTimeStampAvail ? timeInfo.signTimeStamp : timeInfo.time);
|
|
1049
|
+
if (timeInfo.isSignTimeStampAvail || timeInfo.isTimeStamp) {
|
|
1050
|
+
signInfo.ownerInfo.timestamp = dateWithoutTimezone(timeInfo.isSignTimeStampAvail ? timeInfo.signTimeStamp : timeInfo.time);
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
switch (that._readedKey.keyType) {
|
|
1054
|
+
case DigitalSignatureKeyType.File:
|
|
1055
|
+
signInfo.ownerInfo.privateKeyType = "FileKey";
|
|
1056
|
+
break;
|
|
1057
|
+
case DigitalSignatureKeyType.Token:
|
|
1058
|
+
signInfo.ownerInfo.privateKeyType = "HardwareKey";
|
|
1059
|
+
break;
|
|
1060
|
+
case DigitalSignatureKeyType.UmCAService:
|
|
1061
|
+
signInfo.ownerInfo.privateKeyType = "UmCAService";
|
|
1062
|
+
break;
|
|
1063
|
+
case DigitalSignatureKeyType.WindowsCertStore:
|
|
1064
|
+
signInfo.ownerInfo.privateKeyType = "WindowsCertStore";
|
|
1065
|
+
break;
|
|
1066
|
+
case DigitalSignatureKeyType.KSP:
|
|
1067
|
+
signInfo.ownerInfo.privateKeyType = that._readedKey.ksp.ksp != EndUserKSP.GRYADA
|
|
1068
|
+
? that._readedKey.ksp.id:
|
|
1069
|
+
"GRYADA";
|
|
1070
|
+
break;
|
|
1071
|
+
}
|
|
1072
|
+
|
|
1070
1073
|
return {
|
|
1071
1074
|
Success: true,
|
|
1072
|
-
Sign:
|
|
1075
|
+
Sign: sign,
|
|
1073
1076
|
SignatureInfo: {
|
|
1074
1077
|
Success: true,
|
|
1075
|
-
DateTimeStr:
|
|
1078
|
+
DateTimeStr: time,
|
|
1076
1079
|
Signer: signInfo.ownerInfo.subjCN,
|
|
1077
1080
|
OwnerInfo: signInfo.ownerInfo
|
|
1078
1081
|
}
|
|
1079
1082
|
};
|
|
1080
1083
|
}
|
|
1084
|
+
async function getSigner(sign) {
|
|
1085
|
+
const containerInfo = await that._euSign.GetSignContainerInfo(sign);
|
|
1086
|
+
let signerInfo;
|
|
1087
|
+
switch (containerInfo.type) {
|
|
1088
|
+
case EndUserConstants.EU_SIGN_CONTAINER_TYPE_CADES:
|
|
1089
|
+
signerInfo = await that._euSign.GetSigner(sign);
|
|
1090
|
+
break;
|
|
1091
|
+
case EndUserConstants.EU_SIGN_CONTAINER_TYPE_XADES:
|
|
1092
|
+
signerInfo = await that._euSign.XAdESGetSigner(sign);
|
|
1093
|
+
break;
|
|
1094
|
+
case EndUserConstants.EU_SIGN_CONTAINER_TYPE_PADES:
|
|
1095
|
+
signerInfo = await that._euSign.PDFGetSigner(sign);
|
|
1096
|
+
break;
|
|
1097
|
+
case EndUserConstants.EU_SIGN_CONTAINER_TYPE_ASIC:
|
|
1098
|
+
signerInfo = await that._euSign.ASiCGetSigner(sign);
|
|
1099
|
+
break;
|
|
1100
|
+
}
|
|
1101
|
+
if (Array.isArray(signerInfo)) {
|
|
1102
|
+
signerInfo = signerInfo.pop();
|
|
1103
|
+
}
|
|
1104
|
+
return signerInfo.infoEx;
|
|
1105
|
+
}
|
|
1081
1106
|
}
|
|
1082
1107
|
|
|
1083
1108
|
/**
|
|
@@ -1426,6 +1451,14 @@ export default class DigitalSignature {
|
|
|
1426
1451
|
else if (key.keyType == DigitalSignatureKeyType.KSP) {
|
|
1427
1452
|
key = new KspPrivateKeyInfo(key.keyType, key.ownerInfo, key.certificates, key.userId, key.ksp, key.keyId);
|
|
1428
1453
|
}
|
|
1454
|
+
else if (key.keyType == DigitalSignatureKeyType.UmCAService) {
|
|
1455
|
+
const keyMedia = key.keyMedia;
|
|
1456
|
+
key = new PrivateKeyInfo(key.keyType, key.ownerInfo, key.certificates, key.visibleName, key.id);
|
|
1457
|
+
key.keyMedia = keyMedia;
|
|
1458
|
+
}
|
|
1459
|
+
else if (key.keyType == DigitalSignatureKeyType.WindowsCertStore) {
|
|
1460
|
+
key = new PrivateKeyInfo(key.keyType, key.ownerInfo, key.certificates, key.visibleName, key.id);
|
|
1461
|
+
}
|
|
1429
1462
|
const certs = [];
|
|
1430
1463
|
key.certificates.forEach(cert => {
|
|
1431
1464
|
const certObj = Object.assign(new EndUserCertificate(), cert);
|
|
@@ -1434,6 +1467,7 @@ export default class DigitalSignature {
|
|
|
1434
1467
|
});
|
|
1435
1468
|
key.certificates = certs;
|
|
1436
1469
|
key.password = password;
|
|
1470
|
+
key._glSign = this._glSign;
|
|
1437
1471
|
result.push(key);
|
|
1438
1472
|
});
|
|
1439
1473
|
return result;
|
package/src/Models.js
CHANGED
|
@@ -147,8 +147,8 @@ export class LegacySettingsProvider {
|
|
|
147
147
|
new LegacyCertificatesProvider(
|
|
148
148
|
testMode,
|
|
149
149
|
this.basePath + "/Data/version.txt",
|
|
150
|
-
this.basePath + (testMode ? "/Data/CAs.
|
|
151
|
-
this.basePath + (testMode ? "/Data/CACertificates.
|
|
150
|
+
this.basePath + (testMode ? "/Data/CAs.Test.json" : "/Data/CAs.json"),
|
|
151
|
+
this.basePath + (testMode ? "/Data/CACertificates.Test.p7b" : "/Data/CACertificates.p7b")
|
|
152
152
|
),
|
|
153
153
|
this.workerPath || "/euscp.worker.js"
|
|
154
154
|
);
|
package/src/Utils.js
CHANGED
|
@@ -249,7 +249,8 @@ export function isUrlValid(url) {
|
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
export function getFileNameFromUrl(url) {
|
|
252
|
-
|
|
252
|
+
url = new URL(url);
|
|
253
|
+
return url.searchParams.get("file") || url.searchParams.get("name") || url.pathname.split("/").pop();
|
|
253
254
|
}
|
|
254
255
|
|
|
255
256
|
export async function downloadAndSignFiles(fileUrl, signFunc) {
|
|
@@ -297,3 +298,11 @@ export function isDefaultValue(value) {
|
|
|
297
298
|
// реальная дата - 01.07.2026
|
|
298
299
|
/* eslint-disable no-magic-numbers */
|
|
299
300
|
export const IS_DSTU_7564_DAY = () => Date.now() >= new Date(2026, 6, 1);
|
|
301
|
+
|
|
302
|
+
export function dateWithoutTimezone(date) {
|
|
303
|
+
const tzoffset = date.getTimezoneOffset() * 60000; //offset in milliseconds
|
|
304
|
+
const withoutTimezone = new Date(date.valueOf() - tzoffset)
|
|
305
|
+
.toISOString()
|
|
306
|
+
.slice(0, -1);
|
|
307
|
+
return withoutTimezone;
|
|
308
|
+
};
|