Skip to content

Commit 1f9167b

Browse files
committed
Fix style.
- Use same ancient ES5 style as the rest of the codebase for consistency. - Minor formatting.
1 parent faa1308 commit 1f9167b

File tree

1 file changed

+24
-26
lines changed

1 file changed

+24
-26
lines changed

tests/security/cve-2025-12816.js

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,39 @@
11
'use strict';
22

3-
const assert = require('assert');
4-
const forge = require('../../lib/forge');
5-
const md = require('../../lib/md');
6-
const pkcs12 = require('../../lib/pkcs12');
7-
const asn1 = require('../../lib/asn1');
8-
const pki = require('../../lib/pki');
3+
var assert = require('assert');
4+
var md = require('../../lib/md');
5+
var pkcs12 = require('../../lib/pkcs12');
6+
var asn1 = require('../../lib/asn1');
7+
var pki = require('../../lib/pki');
98

109
/**
1110
* Build a minimal certificate-only PKCS#12 (PFX) with a MAC.
1211
*/
1312
function buildCertOnlyPfxWithMac(password) {
14-
const keys = pki.rsa.generateKeyPair({ bits: 1024, e: 0x10001 });
15-
const cert = pki.createCertificate();
13+
var keys = pki.rsa.generateKeyPair({bits: 1024, e: 0x10001});
14+
var cert = pki.createCertificate();
1615
cert.publicKey = keys.publicKey;
1716
cert.serialNumber = '01';
1817
cert.validity.notBefore = new Date();
1918
cert.validity.notAfter = new Date();
2019
cert.validity.notAfter.setFullYear(cert.validity.notBefore.getFullYear() + 1);
21-
cert.setSubject([{ name: 'commonName', value: 'p12-demo' }]);
22-
cert.setIssuer([{ name: 'commonName', value: 'p12-demo' }]);
20+
cert.setSubject([{name: 'commonName', value: 'p12-demo'}]);
21+
cert.setIssuer([{name: 'commonName', value: 'p12-demo'}]);
2322
cert.sign(keys.privateKey, md.sha256.create());
2423

2524
return pkcs12.toPkcs12Asn1(
2625
null,
2726
cert,
2827
password,
29-
{ useMac: true, count: 2048, saltSize: 8 }
28+
{useMac: true, count: 2048, saltSize: 8}
3029
);
3130
}
3231

3332
/**
3433
* Replace macData node with arbitrary junk.
3534
*/
3635
function corruptMacData(pfxAsn1) {
37-
const clone = asn1.fromDer(asn1.toDer(pfxAsn1).getBytes());
36+
var clone = asn1.fromDer(asn1.toDer(pfxAsn1).getBytes());
3837
// Replace 3rd element (macData) with garbage node
3938
clone.value[2] = asn1.create(
4039
asn1.Class.UNIVERSAL,
@@ -45,33 +44,32 @@ function corruptMacData(pfxAsn1) {
4544
return clone;
4645
}
4746

48-
describe('PKCS#12 MAC corruption security test', function () {
49-
const correctPw = 'correct-horse-battery-staple';
50-
const wrongPw = 'wrong-password';
51-
let legit;
47+
describe('PKCS#12 MAC corruption', function() {
48+
var correctPw = 'correct-horse-battery-staple';
49+
var wrongPw = 'wrong-password';
50+
var legit;
5251

53-
before(function () {
52+
before(function() {
5453
legit = buildCertOnlyPfxWithMac(correctPw);
5554
});
5655

57-
it('accepts valid PFX with correct password', function () {
58-
assert.doesNotThrow(() => {
59-
const obj = pkcs12.pkcs12FromAsn1(legit, true, correctPw);
56+
it('should accept valid PFX with correct password', function() {
57+
assert.doesNotThrow(function() {
58+
var obj = pkcs12.pkcs12FromAsn1(legit, true, correctPw);
6059
assert(obj, 'pkcs12FromAsn1 should return an object');
6160
});
6261
});
6362

64-
it('rejects valid PFX with wrong password (MAC mismatch)', function () {
65-
assert.throws(() => {
63+
it('should reject valid PFX with wrong password (MAC mismatch)', function() {
64+
assert.throws(function() {
6665
pkcs12.pkcs12FromAsn1(legit, true, wrongPw);
6766
}, /MAC|password|verify/i);
6867
});
6968

70-
it('rejects tampered PFX with corrupted macData', function () {
71-
const tampered = corruptMacData(legit);
72-
assert.throws(() => {
69+
it('should reject tampered PFX with corrupted macData', function() {
70+
var tampered = corruptMacData(legit);
71+
assert.throws(function() {
7372
pkcs12.pkcs12FromAsn1(tampered, true, wrongPw);
7473
}, /mac|digest|invalid|malformed/i);
7574
});
7675
});
77-

0 commit comments

Comments
 (0)