Fixed authenticode.js timestamp if executable already has a time stamp.
Ylian Saint-Hilaire committed
Jun 17, 2022 at 21:40 UTC
4887b7612b01bb7e18ce6097fea271b857dc6446
1 file changed
+9
authenticode.js
+9
@@ -413,6 +413,14 @@ function createAuthenticodeHandler(path) {
413
const timeasn1Certs = timepkcs7der.value[1].value[0].value[3].value;
414
for (var i in timeasn1Certs) { pkcs7der.value[1].value[0].value[3].value.push(timeasn1Certs[i]); }
415
416
+ // Remove any existing time stamp signatures
417
+ var newValues = [];
418
+ for (var i in pkcs7der.value[1].value[0].value[4].value[0].value) {
419
+ const j = pkcs7der.value[1].value[0].value[4].value[0].value[i];
420
+ if ((j.tagClass != 128) || (j.type != 1)) { newValues.push(j); } // If this is not a time stamp, add it to out new list.
421
+ }
422
+ pkcs7der.value[1].value[0].value[4].value[0].value = newValues; // Set the new list
423
+
424
// Get the time signature and add it to the executables PKCS7
425
const timeasn1Signature = timepkcs7der.value[1].value[0].value[4];
426
const countersignatureOid = asn1.oidToDer('1.2.840.113549.1.9.6').data;
@@ -1606,6 +1614,7 @@ function createAuthenticodeHandler(path) {
1614
1615
// Re-encode the executable signature block
1616
const p7signature = Buffer.from(forge.asn1.toDer(pkcs7der).data, 'binary');
1617
+ console.log('r3');
1618
1619
// Write the file with the signature block
1620
writeExecutableEx(output, p7signature, written, func);