Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then((enrollment) => {
let cert;
try {
cert = X509.parseCert(FabricCAServices.normalizeX509(enrollment.certificate));
} catch (err) {
t.fail(util.format('Failed to parse enrollment cert\n%s\n. Error: %s', enrollment.certificate, err));
}
if (!cert.extensions || !cert.extensions.authorityKeyIdentifier) {
t.fail(util.format('Parsed certificate does not contain Authority Key Identifier needed for revoke(): %j', cert));
}
// convert the raw AKI string in the form of 'keyid:HX:HX....' (HX represents a hex-encoded byte) to a hex string
const akiString = cert.extensions.authorityKeyIdentifier;
const arr = akiString.split(':');
if (arr[0] !== 'keyid') {
t.fail(util.format('Found an Autheority Key Identifier we do not understand: first segment is not "keyid": %s', akiString));
}
arr.shift(); // remove the 'keyid'
.then((enrollResponse) => {
t.pass('Successfully invoked enroll API with enrollmentID \'' + enrollmentID + '\'');
// check that we got back the expected certificate
let subject;
try {
subject = X509.getSubject(FabricCAServices.normalizeX509(enrollResponse.enrollmentCert));
} catch (err) {
t.fail(util.format('Failed to parse enrollment cert\n%s\n. Error: %s', enrollResponse.enrollmentCert, err));
}
t.equal(subject.commonName, enrollmentID, 'Subject should be /CN=' + enrollmentID);
t.end();
})
.catch((err) => {
.then((enrollment) => {
t.pass('Successfully enrolled \'' + req.enrollmentID + '\'.');
eResult = enrollment;
// check that we got back the expected certificate
let subject;
try {
subject = X509.getSubject(FabricCAServices.normalizeX509(enrollment.certificate));
} catch (err) {
t.fail(util.format('Failed to parse enrollment cert\n%s\n. Error: %s', enrollment.certificate, err));
}
t.equal(subject.commonName, req.enrollmentID, 'Subject should be /CN=' + req.enrollmentID);
return caService.getCryptoSuite().importKey(enrollment.certificate);
}, (err) => {
t.fail('Failed to enroll the admin. Can not progress any further. Exiting. ' + err.stack ? err.stack : err);