Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// test.ok(fs.readdirSync('./tmp').length === 0);
const pkcs12Buffer = new Buffer(pkcs12.pkcs12);
pem.readPkcs12(pkcs12Buffer, (error: any, keystore: pem.Pkcs12ReadResult) => {
test.ifError(error);
test.ok(keystore);
test.equal(ca.certificate, keystore.ca[0]);
test.equal(cert.certificate, keystore.cert);
test.equal(cert.clientKey, keystore.key);
});
const pkcs12File: string = __dirname + '/test.pkcs12';
fs.writeFileSync(pkcs12File, pkcs12Buffer);
pem.readPkcs12(pkcs12File, (error: any, keystore: pem.Pkcs12ReadResult) => {
test.ifError(error);
test.ok(keystore);
test.equal(ca.certificate, keystore.ca[0]);
test.equal(cert.certificate, keystore.cert);
test.equal(cert.clientKey, keystore.key);
test.done();
});
});
});
pem.createPkcs12(cert.clientKey, cert.certificate, '', {certFiles: [ca.certificate]}, (error: any, pkcs12: any) => {
test.ifError(error);
test.ok(pkcs12.pkcs12);
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.readPkcs12(pkcs12.pkcs12, (error: any, keystore: any) => {
test.ifError(error);
test.ok(keystore);
test.equal(ca.certificate, keystore.ca[0]);
test.equal(cert.certificate, keystore.cert);
test.equal(cert.clientKey, keystore.key);
test.done();
});
});
});
pem.createPkcs12(cert.clientKey, cert.certificate, '', {certFiles: [ca.certificate]}, (error: any, pkcs12: any) => {
test.ifError(error);
test.ok(pkcs12.pkcs12);
// test.ok(fs.readdirSync('./tmp').length === 0);
const pkcs12Buffer = new Buffer(pkcs12.pkcs12);
pem.readPkcs12(pkcs12Buffer, (error: any, keystore: pem.Pkcs12ReadResult) => {
test.ifError(error);
test.ok(keystore);
test.equal(ca.certificate, keystore.ca[0]);
test.equal(cert.certificate, keystore.cert);
test.equal(cert.clientKey, keystore.key);
});
const pkcs12File: string = __dirname + '/test.pkcs12';
fs.writeFileSync(pkcs12File, pkcs12Buffer);
pem.readPkcs12(pkcs12File, (error: any, keystore: pem.Pkcs12ReadResult) => {
test.ifError(error);
test.ok(keystore);
test.equal(ca.certificate, keystore.ca[0]);
'Respond with ENOENT for missing PKCS12 file': (test: any) => {
pem.readPkcs12('/i/do/not/exist.p12', (error: any) => {
test.ok(error);
test.equal(error.code, 'ENOENT');
test.done();
});
},
'Verify sigining chain': (test: any) => {
'Respond with ENOENT for missing PKCS12 file': (test: any) => {
pem.readPkcs12('/i/do/not/exist.p12', (error: any) => {
test.ok(error);
test.equal(error.code, 'ENOENT');
test.done();
});
},
'Verify sigining chain': (test: any) => {
return new Promise((resolve, reject) => {
pem.readPkcs12(certBuffer, { //unlock it with the settings password
p12Password: settings.securityOptions.passphrase
}, function (err, res) {
if (err) {
return reject(err);
}
return resolve(res);
});
});
}