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) => {
var certificate = (data && data.certificate || '').toString();
test.ifError(error);
test.ok(certificate);
// test.ok(fs.readdirSync('./tmp').length === 0);
pem.getFingerprint(certificate, (error: any, data: any) => {
var fingerprint = (data && data.fingerprint || '').toString();
test.ifError(error);
test.ok(fingerprint);
test.ok(fingerprint.match(/^[0-9A-F]{2}(:[0-9A-F]{2}){19}$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
},
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.getFingerprint(certificate, (error: any, data: any) => {
const fingerprint = (data && data.fingerprint || '').toString();
test.ifError(error);
test.ok(fingerprint);
test.ok(fingerprint.match(/^[0-9A-F]{2}(:[0-9A-F]{2}){19}$/));
// test.ok(fs.readdirSync('./tmp').length === 0);
test.done();
});
});
},
KeystoreModel.findOne((err, keystore) => {
if (err) { return reject(err) }
if (!keystore) { return resolve() }
// convert server cert
pem.getFingerprint(keystore.cert.data, (err, obj) => {
if (err) { return reject(err) }
keystore.cert.fingerprint = obj.fingerprint
const promises = keystore.ca.map((cert) => {
return new Promise((resolve, reject) => {
pem.getFingerprint(cert.data, (err, obj) => {
if (err) { return reject(err) }
cert.fingerprint = obj.fingerprint
return resolve()
})
})
})
Promise.all(promises).then(() =>
keystore.save((err) => {
if (err != null) { logger.error(`Failed to save keystore: ${err}`) }
pem.createCertificate(certOptions, function (err, result) {
if (err) {
done(err);
} else {
fs.writeFileSync(certFile, result.certificate);
fs.writeFileSync(keyFile, result.clientKey);
pem.getFingerprint(result.certificate, function (err, result) {
thumbprint = result.fingerprint.replace(/:/g, '');
var deviceDescription = {
deviceId: argv.deviceId,
status: 'enabled',
authentication: {
x509Thumbprint: {
primaryThumbprint: thumbprint
}
}
};
registry.create(deviceDescription, function (err, deviceInfo) {
if(!!err) {
console.log(chalk.red('Could not create device: ' + err.message + '\n' + err.responseBody));
process.exit(1);
function getFingerprint (keys, next) {
pem.getFingerprint(keys.cert, next)
},
function gotFingerprint (result, next) {
pem.createCertificate(certOptions, function (err, result) {
if (err) {
inputError('You must have OpenSSL installed in your path for iothub-explorer to be able to generate x509 certificates');
} else {
fs.writeFileSync(certFile, result.certificate);
fs.writeFileSync(keyFile, result.clientKey);
printSuccess('Certificate File: ' + certFile);
printSuccess('Key File: ' + keyFile);
pem.getFingerprint(result.certificate, function (err, result) {
thumbprint = result.fingerprint.replace(/:/g, '');
deviceInfo.authentication = {
x509Thumbprint: {
primaryThumbprint: thumbprint
}
};
createDevice(deviceInfo);
});
}
});
}
async.map(services, function getFingerprint (service, done) {
pem.getFingerprint(service.env.GUVNOR_CERT, function gotFingerprint (error, fingerprint) {
if (!error) {
output[fingerprint.fingerprint] = {
name: service.Unit.Description,
script: service.env.GUVNOR_SCRIPT,
status: 'unknown',
user: service.Service.User,
group: service.Service.Group
}
} else {
logger.warn(service.Unit.Description, 'had an invalid certificate')
}
done()
})
}, function foundCertificateFingerprints (error) {
next(error, output)
pem.readCertificateInfo(cert, (err, certInfo) => {
if (err) {
logger.error(err.stack)
return callback(err)
}
return pem.getFingerprint(cert, (err, fingerprint) => {
if (err) {
logger.error(err.stack)
return callback(err)
}
certInfo.data = cert
certInfo.fingerprint = fingerprint.fingerprint
return callback(certInfo)
})
})