Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
pem.createCertificate((error: any, data: any) => {
const certificate = (data && data.certificate || '').toString();
test.ifError(error);
test.ok(certificate);
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(certificate, (error: any, data: any) => {
const certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(certificate, (error: any, data: any) => {
const keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
});
pem.getModulus(certificate, (error: any, data: any) => {
var certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(key, 'password', (error: any, data: any) => {
var keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
pem.getModulus(certificate, (error: any, data: any) => {
var certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(certificate, (error: any, data: any) => {
var keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
});
'Get modulus from a protected key': (test: any) => {
var certificate = ''; // fs.readFileSync('./test/fixtures/test.crt').toString();
var key = ''; // fs.readFileSync('./test/fixtures/test.key').toString();
pem.getModulus(certificate, (error: any, data: any) => {
var certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(key, 'password', (error: any, data: any) => {
var keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
'Get modulus from a protected key': (test: any) => {
const certificate = ''; // fs.readFileSync('./test/fixtures/test.crt').toString();
const key = ''; // fs.readFileSync('./test/fixtures/test.key').toString();
pem.getModulus(certificate, (error: any, data: any) => {
const certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(key, 'password', (error: any, data: any) => {
const keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
},
pem.getModulus(certificate, (error: any, data: any) => {
const certmodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(certmodulus);
test.ok(certmodulus.match(/^[0-9A-F]*$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getModulus(key, 'password', (error: any, data: any) => {
const keymodulus = (data && data.modulus || '').toString();
test.ifError(error);
test.ok(keymodulus);
test.ok(keymodulus.match(/^[0-9A-F]*$/));
test.ok(keymodulus === certmodulus);
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
},
return KeystoreModelAPI.findOne((err, keystoreDoc) => {
if (err) { return callback(err, null) }
// if the key is encrypted but no passphrase is supplied, return false instantly
if (/Proc-Type:.*ENCRYPTED/.test(keystoreDoc.key) && ((keystoreDoc.passphrase == null) || (keystoreDoc.passphrase.length === 0))) {
return callback(null, false)
}
return pem.getModulus(keystoreDoc.key, keystoreDoc.passphrase, (err, keyModulus) => {
if (err) { return callback(err, null) }
return pem.getModulus(keystoreDoc.cert.data, (err, certModulus) => {
if (err) { return callback(err, null) }
// if cert/key match and are valid
if (keyModulus.modulus === certModulus.modulus) {
return callback(null, true)
} else {
return callback(null, false)
}
})
})
})
}
return pem.getModulus(keystoreDoc.key, keystoreDoc.passphrase, (err, keyModulus) => {
if (err) { return callback(err, null) }
return pem.getModulus(keystoreDoc.cert.data, (err, certModulus) => {
if (err) { return callback(err, null) }
// if cert/key match and are valid
if (keyModulus.modulus === certModulus.modulus) {
return callback(null, true)
} else {
return callback(null, false)
}
})
})
})