Added exception guard in authenticode.js
Ylian Saint-Hilaire committed
Jun 1, 2022 at 14:36 UTC
2758af8c1169acf6306b6659987a619320ae9401
1 file changed
+23
-22
authenticode.js
+23
-22
@@ -216,32 +216,33 @@ function createAuthenticodeHandler(path) {
216
217
// Get the signing attributes
218
obj.signingAttribs = [];
219
- for (var i in pkcs7.rawCapture.authenticatedAttributes) {
220
- if (
221
- (pkcs7.rawCapture.authenticatedAttributes[i].value != null) &&
222
- (pkcs7.rawCapture.authenticatedAttributes[i].value[0] != null) &&
223
- (pkcs7.rawCapture.authenticatedAttributes[i].value[0].value != null) &&
224
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1] != null) &&
225
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value != null) &&
226
- (forge.asn1.derToOid(pkcs7.rawCapture.authenticatedAttributes[i].value[0].value) == obj.Oids.SPC_SP_OPUS_INFO_OBJID))
227
- {
228
- for (var j in pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value) {
229
- if (
230
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j] != null) &&
231
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value != null) &&
232
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0] != null) &&
233
- (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0].value != null)
234
- ) {
235
- var v = pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0].value;
236
- if (v.startsWith('http://') || v.startsWith('https://') || ((v.length % 2) == 1)) { obj.signingAttribs.push(v); } else {
237
- var r = ""; // This string value is in UCS2 format, convert it to a normal string.
238
- for (var k = 0; k < v.length; k += 2) { r += String.fromCharCode((v.charCodeAt(k + 8) << 8) + v.charCodeAt(k + 1)); }
239
- obj.signingAttribs.push(r);
219
+ try {
220
+ for (var i in pkcs7.rawCapture.authenticatedAttributes) {
221
+ if (
222
+ (pkcs7.rawCapture.authenticatedAttributes[i].value != null) &&
223
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[0] != null) &&
224
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[0].value != null) &&
225
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1] != null) &&
226
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value != null) &&
227
+ (forge.asn1.derToOid(pkcs7.rawCapture.authenticatedAttributes[i].value[0].value) == obj.Oids.SPC_SP_OPUS_INFO_OBJID)) {
228
+ for (var j in pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value) {
229
+ if (
230
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j] != null) &&
231
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value != null) &&
232
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0] != null) &&
233
+ (pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0].value != null)
234
+ ) {
235
+ var v = pkcs7.rawCapture.authenticatedAttributes[i].value[1].value[0].value[j].value[0].value;
236
+ if (v.startsWith('http://') || v.startsWith('https://') || ((v.length % 2) == 1)) { obj.signingAttribs.push(v); } else {
237
+ var r = ""; // This string value is in UCS2 format, convert it to a normal string.
238
+ for (var k = 0; k < v.length; k += 2) { r += String.fromCharCode((v.charCodeAt(k + 8) << 8) + v.charCodeAt(k + 1)); }
239
+ obj.signingAttribs.push(r);
240
+ }
241
}
242
}
243
}
244
}
244
- }
245
+ } catch (ex) { }
246
247
// Set the certificate chain
248
obj.certificates = pkcs7.certificates;