Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function main() {
let cmdName, subCmdName, cmd;
if (pem.version) {
pem.config({sync: true});
pem.version((err, data) => {
if (err) {
throw Error("Could not run openssl. beame-insta-ssl requires openssl. Please make sure openssl is installed and is in PATH");
}
});
pem.config({sync: false});
} else {
if (!process.env.BEAME_NO_PEM_WARNING) {
logger.info("WARNING: Using 'pem' module without 'config' function. Not checking for openssl availability.");
}
}
// getHelpMessage() is only defined in this file.
commands.creds.getCreds.toText = (metadata) => `Certificate created! Certificate FQDN is ${metadata.fqdn}\n\n` + getHelpMessage('certificate-created.txt');
// Old CLI compatibility - start
//noinspection JSUnresolvedVariable
this.fqdn = this.extractCommonName();
this.beameStoreServices = new BeameStoreDataServices(this.fqdn);
this._updateCertData();
});
pem.getPublicKey(this.getKey("X509") + "", (err, publicKey) => {
this.publicKeyStr = publicKey.publicKey;
this.publicKeyNodeRsa = new NodeRsa();
try {
this.publicKeyNodeRsa.importKey(this.publicKeyStr, "pkcs8-public-pem");
} catch (e) {
console.log(`could not import services ${this.publicKeyStr}`)
}
});
pem.config({sync: false});
}
if (this.hasPrivateKey) {
this.privateKeyNodeRsa = new NodeRsa();
this.privateKeyNodeRsa.importKey(this.PRIVATE_KEY + " ", "private");
}
}
initCryptoKeys() {
if (this.hasKey("X509")) {
pem.config({sync: true});
pem.readCertificateInfo(this.getKey("X509") + "", (err, certData) => {
if (this.fqdn && this.fqdn !== certData.commonName) {
throw new Error(`Credentialing mismatch ${this.metadata} the common name in x509 does not match the metadata`);
}
this.certData = err ? null : certData;
//noinspection JSUnresolvedVariable
this.fqdn = this.extractCommonName();
this.beameStoreServices = new BeameStoreDataServices(this.fqdn);
this._updateCertData();
});
pem.getPublicKey(this.getKey("X509") + "", (err, publicKey) => {
this.publicKeyStr = publicKey.publicKey;
this.publicKeyNodeRsa = new NodeRsa();
try {
this.publicKeyNodeRsa.importKey(this.publicKeyStr, "pkcs8-public-pem");
initFromX509(x509, metadata) {
pem.config({sync: true});
pem.readCertificateInfo(x509, (err, certData) => {
assert(!err, err);
this.certData = certData;
this.beameStoreServices = new BeameStoreDataServices(certData.commonName);
this.metadata.fqdn = certData.commonName;
this.fqdn = certData.commonName;
this.beameStoreServices.writeObject(Config.CertFileNames.X509, x509);
this._updateCertData();
});
pem.getPublicKey(x509, (err, publicKey) => {
assert(!err, err);
this.publicKeyStr = publicKey.publicKey;
this.publicKeyNodeRsa = new NodeRsa();
try {
this.publicKeyNodeRsa.importKey(this.publicKeyStr, "pkcs8-public-pem");