示例#1
0
        server: (function () {
            if (options.get('scheme') === 'https') {
                const pfxPath = options.getIn(['https', 'pfx']);

                if (pfxPath) {
                    return https.createServer(getPFX(pfxPath), app);
                }

                return https.createServer(getKeyAndCert(options), app);
            }
            return http.createServer(app);
        })(),
示例#2
0
 _startAuthenticationServer():Promise {
   var result = deferred();
   
   var port = config.controlChannelPort + 1;
   var serverOptions = {
     key: keys.privateKey,
     cert: keys.certificate
   };
   https.createServer(serverOptions, (req, res) => {
     var path = this._pathForRequest(req);
     console.log("Path:", path);
     if (path.indexOf('authenticate') === 0) {
       return this._authenticate(req, res);
     }
   }).listen(port, function(err) {
     if (err) {
       result.reject('Unable to start control channel server: ' +  err);
     } else {
       console.log('Listening for authentication requests on port', port);
       result.resolve();
     }
   });
   
   return result.promise;
 }
示例#3
0
文件: server.ts 项目: zaidka/genieacs
export function start(
  port,
  networkInterface,
  ssl,
  _listener,
  onConnection?
): void {
  listener = _listener;

  if (ssl) {
    const options = {
      key: fs.readFileSync(ssl.key),
      cert: fs.readFileSync(ssl.cert),
      ca: null
    };

    try {
      // Use intermediate certificates if available
      options.ca = fs
        .readFileSync(ssl.ca)
        .toString()
        .match(/-+BEGIN CERTIFICATE-+[0-9a-zA-Z+\-/=\s]+?-+END CERTIFICATE-+/g);
    } catch (error) {
      // No intermediate certificate
    }
    server = https.createServer(options, listener);
    if (onConnection != null) server.on("secureConnection", onConnection);
  } else {
    server = http.createServer(listener);
    if (onConnection != null) server.on("connection", onConnection);
  }

  server.listen(port, networkInterface);
}
示例#4
0
function startServer(webServerConfig: IWebServerConfig, app: core.Express, done:(secure: boolean, host:string, port:number) => void, errorCallback?:(err:any) => void ) : void {
	let server: net.Server = null;
	let wsConfig: IHTTPServerConfig = null;
	if (webServerConfig.https) {
		wsConfig = webServerConfig.https;
		let httpsConfig = webServerConfig.https;
		let sslConfig = httpsConfig.ssl;
		let private_key_file = sslConfig.private_key_file;
		let certificate_file = sslConfig.certificate_file;
		let ca_files = sslConfig.ca_files;
		let privateKey  = fs.readFileSync(private_key_file, 'utf8');
		let certificate = fs.readFileSync(certificate_file, 'utf8');
		let credentials:https.ServerOptions = {key: privateKey, cert: certificate};
		if (ca_files && ca_files.length > 0) {
			let ca:string[] = [];
			for (let i in ca_files)
				ca.push(fs.readFileSync(ca_files[i], 'utf8'));
			credentials.ca = ca;
		}
		server = https.createServer(credentials, app);
	} else {
		wsConfig = webServerConfig.http;
		server = http.createServer(app);
	}
	let port = (wsConfig.port ? wsConfig.port : (webServerConfig.https ? 443 : 80));
	let host = (wsConfig.host ? wsConfig.host : "0.0.0.0");	
	server.on('error', (err:any) => {
		if (typeof errorCallback === 'function') errorCallback(err);
	});
	server.listen(port, host, () => {
		let host = server.address().address;
		let port = server.address().port;
		if (typeof done === 'function') done((webServerConfig.https ? true : false), host, port);
	});
}
示例#5
0
export async function createHttpServer(devServerConfig: d.DevServerConfig, fs: d.FileSystem, destroys: d.DevServerDestroy[]) {
  // figure out the port to be listening on
  // by figuring out the first one available
  devServerConfig.port = await findClosestOpenPort(devServerConfig.address, devServerConfig.port);

  // create our request handler
  const reqHandler = createRequestHandler(devServerConfig, fs);

  let server: http.Server;

  if (devServerConfig.protocol === 'https') {
    // https server
    server = https.createServer(await getSSL(), reqHandler) as any;

  } else {
    // http server
    server = http.createServer(reqHandler);
  }

  destroys.push(() => {
    // close down the serve on destroy
    server.close();
    server = null;
  });

  return server;
}
示例#6
0
 _startControlChannelServer():Promise {
   var result = deferred();
   
   var port = config.controlChannelPort;
   var serverOptions = {
     key: keys.privateKey,
     cert: keys.certificate,
     ca: [keys.certificate],
     requestCert: true,
     rejectUnauthorized: true
   };
   https.createServer(serverOptions, (req, res) => {
     var path = this._pathForRequest(req);
     console.log(req.connection.getPeerCertificate());
     console.log(req.secure);
     console.log(req.client.authorized);
   }).listen(port, function(err) {
     if (err) {
       result.reject('Unable to start control channel server: ' +  err);
     } else {
       console.log('Listening for control channel traffic on port', port);
       result.resolve();
     }
   });
   
   return result.promise;
 }
示例#7
0
function createSimpleServer({ port = 8000 }) {
    const server = createServer({ key: privateKey, cert: certificate });
    server.addListener('request', request);
    server.listen(port);
    console.log(`Listen port ${port}, for simple server`);
    console.log(`https://${ip}:${port}`);
}
示例#8
0
  async run(inputs: CommandLineInputs, options: CommandLineOptions) {
    const [ url ] = inputs;
    const { host, port, ssl } = options;

    const protocol = ssl ? 'https' : 'http';
    const projectType = options['project-type'];
    const name = options['app-name'];
    const version = options['app-version'];

    const app = express();

    app.use('/', express.static(WWW_DIRECTORY));

    app.get('/api/app', (req, res) => {
      res.json({ url, name, version, projectType });
    });

    const server = ssl ? https.createServer(await this.collectSecureContextOptions(options), app) : http.createServer(app);
    server.listen({ port, host });

    const labUrl = `${protocol}://${host}:${port}`;

    server.on('listening', () => {
      process.stdout.write(
        'Ionic Lab running!\n' +
        `Lab: ${chalk.bold(labUrl)}\n` +
        `App: ${chalk.bold(url)}\n`
      );
    });
  }
示例#9
0
  before((done) => {
    const options = {
      key: fs.readFileSync(path.join(certPath, 'server.key')),
      cert: fs.readFileSync(path.join(certPath, 'server.pem')),
      ca: [
        fs.readFileSync(path.join(certPath, 'rootCA.pem')),
        fs.readFileSync(path.join(certPath, 'intermediateCA.pem'))
      ],
      requestCert: true,
      rejectUnauthorized: false
    }

    server = https.createServer(options, (req, res) => {
      if ((req as any).client.authorized) {
        res.writeHead(200)
        res.end('<title>authorized</title>')
      } else {
        res.writeHead(401)
        res.end('<title>denied</title>')
      }
    })

    server.listen(0, '127.0.0.1', () => {
      const port = (server.address() as net.AddressInfo).port
      secureUrl = `https://127.0.0.1:${port}`
      done()
    })
  })
示例#10
0
  return co(function *createHttpsServer() {
    const privateKeyPromise = fs.readFileAsync(keypath, 'utf8');
    const certificatePromise = fs.readFileAsync(crtpath, 'utf8');

    const [key, cert] = yield Promise.all([privateKeyPromise, certificatePromise]);

    return https.createServer({ secureOptions: SSL_OP_NO_TLSv1, key, cert }, app);
  }).call(this);