How to use the pem.createCertificate function in pem

To help you get started, we’ve selected a few pem examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github collective-soundworks / soundworks / src / server / core / server.js View on Github external
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);
github splunk / splunk-cloud-sdk-js / test / integration / forwarders_proxy.ts View on Github external
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}`);
        });
    });
});
github uber / eight-track / test / utils / server.js View on Github external
before(function generateCertificate (done) {
    pem.createCertificate({days: 1, selfSigned: true}, function saveCertificate (err, keys) {
      this.certificate = keys;
      done(err);
    });
  });
  after(function cleanupCertificate () {
github SignalK / signalk-server-node / src / security.js View on Github external
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
github AJS-development / OpenAgar / source / core / socketService.js View on Github external
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);
github salesforce / lwc / packages / benchmark / runner / cli / callback-handler.js View on Github external
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}`)
            ));
github wking-io / elm-live / lib / src / server / server.js View on Github external
} 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)
github DSpace / dspace-angular / src / server.ts View on Github external
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();
    });
  }}
github chinesedfan / parrot-mocker-web / server / index.js View on Github external
    const keys = yield (cb) => pem.createCertificate({
        days: 1,
        selfSigned: true
    }, cb);
    const httpsServer = https.createServer({
github redfin / react-server / packages / react-server-cli / src / parseCliArgs.js View on Github external
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 });
				});
			});
		}