Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const httpsServer = https.createServer({ key, cert }, this.router);
this.httpsInfos = { key, cert };
resolve(httpsServer);
// generate certificate on the fly (for development purposes)
} else {
// if some cert already in cache
this.httpsInfos = cache.read('server', 'httpsInfos');
if (this.httpsInfos) {
const httpsServer = https.createServer(this.httpsInfos, this.router);
resolve(httpsServer);
} else {
pem.createCertificate({ days: 1, selfSigned: true }, (err, keys) => {
this.httpsInfos = {
key: keys.serviceKey,
cert: keys.certificate,
};
const httpsServer = https.createServer(this.httpsInfos, this.router);
cache.write('server', 'httpsInfos', this.httpsInfos);
resolve(httpsServer);
});
}
}
}
}).then((httpServer) => {
this._initSockets(httpServer);
it('should allow adding a certificate to a tenant', async () => {
const certLists = await splunkCloud.forwarders.listCertificates();
const certOptions = {
country: 'US',
state: 'California',
locality: 'San Francisco',
organization: 'Splunk',
commonName: 'forwarder_01',
selfSigned: true
};
return createCertificate(certOptions, async (err, keys) => {
assert.notOk(err, err ? err.message : 'known error');
const pem = keys.certificate;
const certInfo = await splunkCloud.forwarders.addCertificate({ pem });
assert.equal(certInfo.issuer, 'CN=forwarder_01,O=Splunk,L=San Francisco,ST=California,C=US');
assert.equal(certInfo.subject, 'CN=forwarder_01,O=Splunk,L=San Francisco,ST=California,C=US');
const aftCertList = await splunkCloud.forwarders.listCertificates();
assert.equal(aftCertList.length, certLists.length + 1);
return splunkCloud.forwarders.deleteCertificate(`${certInfo.slot}`);
});
});
});
before(function generateCertificate (done) {
pem.createCertificate({days: 1, selfSigned: true}, function saveCertificate (err, keys) {
this.certificate = keys;
done(err);
});
});
after(function cleanupCertificate () {
function createCertificateOptions(app, certFile, keyFile, cb) {
const location = app.config.configPath ? app.config.configPath : './settings'
debug(`Creating certificate files in ${location}`)
pem.createCertificate(
{
days: 360,
selfSigned: true
},
function(err, keys) {
if (err) {
console.error('Could not create SSL certificate:' + err.message)
throw err
} else {
fs.writeFileSync(keyFile, keys.serviceKey)
fs.chmodSync(keyFile, '600')
fs.writeFileSync(certFile, keys.certificate)
fs.chmodSync(certFile, '600')
cb(null, {
key: keys.serviceKey,
cert: keys.certificate
this._server = require("https").createServer({
key: keys.key,
cert: keys.certificate,
ca: keys.ca
}, this.app).listen(this.globalData.config.serverPort);
this.server = new Server({
server: this._server
});
this._start();
} catch (e) {
console.log("gre{[OpenAgar]} Creating RSA Certificate:".styleMe())
pem.createCertificate({
days: 100,
selfSigned: true
}, function (err, keys) {
fs.writeFileSync("rsa.json", JSON.stringify({
key: keys.serviceKey,
certificate: keys.certificate,
expire: Date.now() + 8553600000
}));
console.log("gre{[OpenAgar]} Generated self-signed certificate".styleMe())
this.app = express();
this._server = require("https").createServer({
key: keys.serviceKey,
cert: keys.certificate
}, this.app).listen(this.globalData.config.serverPort);
start(cb) {
if (typeof cb !== 'function') {
throw new TypeError('Expect a callback function as second parameter');
} else if (this.server) {
throw new Error('Callback handler is already running');
}
pem.createCertificate({
day: 1,
selfSigned: true
}, (err, keys) => {
if (err) {
return cb(err);
}
var app = createExpressServer(cb);
var server = https.createServer({
key: keys.serviceKey,
cert: keys.certificate
}, app);
server.listen(DEFAULT_PORT, () => (
console.log(`callback handler running at ${this.hostname}`)
));
} else {
const time = new Date()
console.log(
chalk.green('Server restarted at ' + time.toTimeString().slice(0, 8))
)
}
}
if (config.ssl) {
const pem = require('pem')
const baseNames = [ 'localhost', '127.0.0.1' ]
const altNames = (ip && baseNames.indexOf(ip) === -1)
? [ip, ...baseNames]
: baseNames
pem.createCertificate({
days: 1,
selfSigned: true,
commonName: ip,
altNames
}, function (err, { serviceKey, certificate }) {
if (err) throw new Error(err)
const server = https.createServer({ key: serviceKey, cert: certificate }, handler(config, reloadReturned))
reloadReturned = elmReload(reloadOpts, server)
server.listen(config.port, listener)
})
} else {
const server = http.createServer(handler(config, reloadReturned))
reloadReturned = elmReload(reloadOpts, server)
server.listen(config.port, listener)
}
config.output.write(serverStarted)
try {
certificate = fs.readFileSync('./config/ssl/cert.pem');
} catch (e) {
console.warn('Certificate not found at ./config/ssl/key.pem');
}
if (serviceKey && certificate) {
createHttpsServer({
serviceKey: serviceKey,
certificate: certificate
});
} else {
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0';
pem.createCertificate({
days: 1,
selfSigned: true
}, (error, keys) => {
createHttpsServer(keys);
});
}
} else {
app.listen(ENV_CONFIG.ui.port, ENV_CONFIG.ui.host, () => {
serverStarted();
});
}}
const keys = yield (cb) => pem.createCertificate({
days: 1,
selfSigned: true
}, cb);
const httpsServer = https.createServer({
argv.httpsOptions = await new Promise((resolve, reject) => {
pem.createCertificate({ days: 1, selfSigned: true }, (err, keys) => {
if (err) {
reject(err);
}
resolve({ key: keys.serviceKey, cert: keys.certificate });
});
});
}