Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var ret = common.parseStringParam(migrationResp.authToken, 0);
var authCert = ret.str;
var cert = x509.parseCert(authCert);
console.log(util.inspect(cert));
//console.log(options.currentAuthPublicKey.toString());
//console.log(x509.parseCert(options.currentAuthPublicKey.toString()));
// verify certificate
var caCert = fs.readFileSync('../../../auth/credentials/ca/CACert.pem');
var trustedCertificateList = [];
for (var i = 0; i < options.trustedAuthPublicKeyList.length; i++) {
trustedCertificateList.push(options.trustedAuthPublicKeyList.toString());
}
trustedCertificateList.push(caCert.toString());
pem.verifySigningChain(authCert.toString(),
trustedCertificateList,
// this callback brings about the verification result
function(err, result) {
console.log(err);
console.log(result);
if (result != true) {
helperEventHandlers.onError('Certificate of new Auth is NOT verified!');
return;
}
console.log('Certificate of new Auth is verified!');
var authCertSubject = x509.getSubject(authCert);
if (authCertSubject.organizationalUnitName != 'Auth' + migrationResp.authId) {
helperEventHandlers.onError('Subject information does NOT match Auth ID!');
return;
}
console.log('Subject information matches Auth ID!');
}, (error: any, cert: any) => {
test.ifError(error);
pem.verifySigningChain(cert.certificate, [intermediate.certificate], (error: any, valid: any) => {
test.ifError(error);
test.ok(valid === false);
test.done();
});
});
});
}, (error: any, cert: any) => {
test.ifError(error);
pem.verifySigningChain(cert.certificate, ca.certificate, (error: any, valid: any) => {
test.ifError(error);
test.ok(valid === true);
test.done();
});
});
});
}, (error: any, cert: any) => {
test.ifError(error);
pem.verifySigningChain(cert.certificate, [ca.certificate, intermediate.certificate], (error: any, valid: any) => {
test.ifError(error);
test.ok(valid === true);
test.done();
});
});
});
}, (error: any, cert: any) => {
test.ifError(error);
pem.verifySigningChain(cert.certificate, ca.certificate, (error: any, valid: any) => {
test.ifError(error);
test.ok(valid === true);
test.done();
});
});
});