xades-bes-signer 1.0.2 → 1.0.4
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.
|
@@ -25,7 +25,7 @@ export declare function getPCK12CertInfo(certificate: Uint8Array<ArrayBufferLike
|
|
|
25
25
|
issuerSerialNumber: number;
|
|
26
26
|
signingTime: string;
|
|
27
27
|
certificateX509: string;
|
|
28
|
-
modulus: string
|
|
28
|
+
modulus: string;
|
|
29
29
|
exponent: string;
|
|
30
30
|
key: forge.pki.rsa.PrivateKey;
|
|
31
31
|
};
|
|
@@ -133,22 +133,23 @@ function getPCK12CertInfo(certificate, certKey) {
|
|
|
133
133
|
let key = getKey(pckcs8);
|
|
134
134
|
const pem = certX509ToPem(cert);
|
|
135
135
|
let certificateX509 = pem.substring(pem.indexOf("\n") + 1, pem.indexOf("-----END CERTIFICATE-----"));
|
|
136
|
-
certificateX509.replace(/\r?\n|\r/g, "").replace(/([^\0]{76})/g, "$1\n");
|
|
136
|
+
certificateX509 = certificateX509.replace(/\r?\n|\r/g, "").replace(/([^\0]{76})/g, "$1\n");
|
|
137
137
|
const ISODateTime = new Date().toISOString().slice(0, 19);
|
|
138
138
|
const certificateANS1 = certX509ToASN1(cert);
|
|
139
139
|
const certificateDER = forge.asn1.toDer(certificateANS1).getBytes();
|
|
140
140
|
const hashCErtificateX509DER = (0, security_1.sha1ToBase64)(certificateDER, "utf-8");
|
|
141
141
|
const certificateX509SN = parseInt(cert === null || cert === void 0 ? void 0 : cert.serialNumber, 16);
|
|
142
142
|
const exponent = (0, security_1.hexToBase64)(key.e.data[0].toString(16));
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
const
|
|
147
|
-
const
|
|
148
|
-
const
|
|
149
|
-
const
|
|
150
|
-
const
|
|
151
|
-
const
|
|
143
|
+
let modulus = (0, security_1.bigintToBase64)(BigInt(key.n.toString()));
|
|
144
|
+
modulus = modulus.replace(/\r?\n|\r/g, '').replace(/([^\0]{76})/g, '$1\n');
|
|
145
|
+
const certificateNumber = (0, security_1.getRandomValues)(999990, 9999999);
|
|
146
|
+
const signatureNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
147
|
+
const signedPropertiesNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
148
|
+
const signedInfoNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
149
|
+
const signedPropertiesIdNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
150
|
+
const referenceIdNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
151
|
+
const signatureValueNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
152
|
+
const objectNumber = (0, security_1.getRandomValues)(99990, 999999);
|
|
152
153
|
return {
|
|
153
154
|
radomValues: {
|
|
154
155
|
certificateNumber,
|
package/dist/src/libs/signer.js
CHANGED
|
@@ -54,7 +54,7 @@ function getSignedPropertiesNode(params) {
|
|
|
54
54
|
`</etsi:Cert>` +
|
|
55
55
|
`</etsi:SigningCertificate>` +
|
|
56
56
|
`<etsi:SignedDataObjectProperties>` +
|
|
57
|
-
`<etsi:DataObjectFormat ObjectReference="#Reference-ID
|
|
57
|
+
`<etsi:DataObjectFormat ObjectReference="#Reference-ID-${params.referenceIdNumber}">` +
|
|
58
58
|
`<etsi:Description>contenido comprobante</etsi:Description>` +
|
|
59
59
|
`<etsi:MimeType>text/xml</etsi:MimeType>` +
|
|
60
60
|
`</etsi:DataObjectFormat>` +
|
|
@@ -67,7 +67,7 @@ function getKeyInfoNode(params) {
|
|
|
67
67
|
`\n<ds:X509Certificate>\n${params.certificateX509}\n</ds:X509Certificate>` +
|
|
68
68
|
`\n</ds:X509Data>` +
|
|
69
69
|
`\n</ds:KeyValue>\n<ds:RSAKeyValue>\n<ds:Modulus>\n${params.modulus}\n</ds:Modulus>` +
|
|
70
|
-
`\n<ds:Exponent
|
|
70
|
+
`\n<ds:Exponent>${params.exponent}</ds:Exponent>` +
|
|
71
71
|
`\n</ds:RSAKeyValue>` +
|
|
72
72
|
`\n</ds:KeyInfo>`);
|
|
73
73
|
}
|
|
@@ -91,7 +91,7 @@ function getSignedInfoNode(params) {
|
|
|
91
91
|
`\n<ds:DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></ds:DigestMethod>` +
|
|
92
92
|
`\n<ds:DigestValue>${params.sha1Xml}</ds:DigestValue>` +
|
|
93
93
|
`\n</ds:Reference>` +
|
|
94
|
-
|
|
94
|
+
`\n</ds:SignedInfo>`);
|
|
95
95
|
}
|
|
96
96
|
function getSignatureObject(params) {
|
|
97
97
|
const objectSignature = `<ds:Object Id="Signature${params.signatureNumber}-Object${params.objectNumber}">` +
|
|
@@ -183,8 +183,8 @@ function sign(params) {
|
|
|
183
183
|
const md = (0, security_1.toSha1)(signedInfoCanonicalized, "utf8");
|
|
184
184
|
const signatureValue = (_b = (_a = (0, security_1.toBase64String)(certInfo.certInfo.key.sign(md))
|
|
185
185
|
.match(/.{1,76}/g)) === null || _a === void 0 ? void 0 : _a.join("\n")) !== null && _b !== void 0 ? _b : "";
|
|
186
|
-
const signatureValueNode =
|
|
187
|
-
|
|
186
|
+
const signatureValueNode = `<ds:SignatureValue Id="SignatureValue${certInfo.radomValues.signatureValueNumber}">` +
|
|
187
|
+
`\n${signatureValue}\n</ds:SignatureValue>`;
|
|
188
188
|
const objectSignature = getSignatureObject({
|
|
189
189
|
signatureNumber: certInfo.radomValues.signatureNumber,
|
|
190
190
|
objectNumber: certInfo.radomValues.objectNumber,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xades-bes-signer",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "XAdES-BES signer utilities for Node.js (TypeScript) — certificate handling and XAdES-BES signature helpers.",
|
|
5
5
|
"main": "/dist/src/main.js",
|
|
6
6
|
"types": "/dist/src/main.d.ts",
|