Configuration for a HTTPS server
@param options
@constructor
548310
function HttpsConfig(options) {
    var httpsOptions = options && options.httpsOptions

    underscore.extend(this, HttpsConfig._DEFAULT)
    CommonConfig.call(this, options)
    this.httpsOptions = applyHttpsOptions.call(this, httpsOptions)
    this.type = serverTypes.HTTPS
}
409443
function () {
    // Determine https vs. http
    this.server = this.ssl ?
        https.createServer(this.ssl) :
        http.createServer();

    // Bind to the request
    this.server.on('request', this.handle.bind(this));
  }
688091
function (options, callback) {
    let me = this
    let tunnel
    let sshcfg = {
      host: this.host + ':' + (options.sshport || 22),
      user: options.username,
      remoteport: this.port
    }

    if (options.password) {
      sshcfg.password = options.password
    }

    if (options.key) {
      sshcfg.key = options.key
    }

    // Dynamically determine port by availability or via option.
    // Then open the tunnel.
    if (options.port) {
      sshcfg.port = options.port
      tunnel = new NGN.Tunnel(sshcfg)
      tunnel.on('ready', function () {
        NGN.BUS.emit('sshtunnel.create', tunnel)
        callback && callback(me.host, options.port)
      })
      tunnel.connect()
    } else {
      // Create a quick TCP server on random port to secure the port,
      // then shut it down and use the newly freed port.
      let tmp = net.createServer().listen(0, '127.0.0.1', function () {
        sshcfg.port = this.address().port
        tmp.close()
      })

      tmp.on('close', function () {
        // Launch the tunnel
        tunnel = new NGN.Tunnel(sshcfg)
        tunnel.on('ready', function () {
          callback && callback('127.0.0.1', sshcfg.port)
        })
        tunnel.connect()
      })
    }
  }
1308911
function(httpServer) {
      this.stop();

      var port = isNaN(options.port) ? 3000 : +options.port;
      _httpServer = httpServer || http.createServer(function(req, res) {
        res.setHeader('Access-Control-Allow-Origin', '*');
        res.setHeader('Access-Control-Request-Method', '*');
        res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
        res.setHeader('Access-Control-Allow-Headers', '*');
        if ( req.method === 'OPTIONS' ) {
          res.writeHead(200);
          res.end();
          return;
        }
      });
      _httpServer.on('request', _handle);
      _httpServer.listen(port, function() {
        debug.log('Listening on '+port);
      });

      return _server;
    }
415757
function(options) {

    var self = this;

    console.log('options are', options);

    this.connected = false;

    this.config = this.getConfig(options);

    this.cbSocketWrapper = new CBSocketWrapper(this.config);

    this.cbSocketWrapper.on('connect', function(message) {
        self.connected = true;
        self.emit('connect');
        logger.log('debug', 'Client connect');
    });

    this.cbSocketWrapper.on('disconnect', function(message) {
        self.connected = false;
        self.emit('disconnect');
    });

    this.cbSocketWrapper.on('message', function(message) {

        self.emit('message', message);

        var source = message.get('source');
        self.emit(source, message);
        //logger.info('CB => Client: ', message)
    });

    // Restart connection process on 'giveUp'
    this.cbSocketWrapper.on('fail', function() {
        self.cbSocketWrapper.giveUp();
        self.connect();
    });

    this.faultTolerantAuth = retry.operation()

    this.connect();
}
178885
function ProxyHttp(options) {
    ProxyAbstract.call(this, options);
    this._server = options.server || 'https://api.smsapi.pl/';
    this._auth = options.auth || null;
}
929798
function createMiddleware(options) {
  const conf = (options && options.subdomainMapping) || {};
  const enabled = conf.enable && conf.baseDomains && conf.baseDomains.length;
  return (req, res, next) => {
    if (!enabled) {
      return next();
    }

    let { host } = req.headers;
    const origUrl = host + req.url;

    // trim :<port>
    [host] = host.split(':');

    // match & remove base domain
    const i = _.findIndex(conf.baseDomains, dom => _.endsWith(host, dom));
    if (i === -1) {
      return next();
    }
    host = _.trimEnd(host.slice(0, -conf.baseDomains[i].length), '.');
    if (!host.length) {
      // no subdomains
      return next();
    }

    req.url = `/${host.split('.').join('/')}${req.url}`;
    req.mappedSubDomain = true;

    logger.debug(`${origUrl} => ${req.url}`);

    // pass on to next middleware
    return next();
  };
}
363912
function(config){
  this.options = {
    hostname : config.url,
    port :      443,
    path :       '', //override
    method :     '', //override
    auth :    config.user + ':' + config.passwd,
    headers : config.headers
  };
}
708955
function(options) {
  if (typeof options !== 'object') {
    options = {};
  }
  this._options = options = _.defaults(options, {
    trustedProxies: ['127.0.0.1'],
    clickjacking: 'deny',
    noMimeSniffing: true,
    log: console.log,
    maxInputSize: 1024 * 1024
  });

  this._app = connect();

  this._app.use(function(req, res, next) {
    // Set body to stream if posting data not yet processed by the bodyparser.
    if (['GET', 'HEAD'].indexOf(req.method) < 0 && typeof req.headers['content-type'] === 'string') {
      req.body = new Readable();
      req.body.wrap(req);
      // Parse the boundary for multipart data.
      var boundary = req.headers['content-type'].match(/^multipart\/.+?(?:; boundary=(?:(?:"(.+)")|(?:([^\s]+))))$/i);
      req.multipartBoundary = boundary ? boundary[1] || boundary[2] : null;
    }
    next();
  });
  this._app.use(bodyParser.urlencoded({extended: false}));
  this._app.use(bodyParser.json({limit: options.maxInputSize}));
  this._app.use(bodyParser.text({type: 'text/*', limit: this._options.maxInputSize}));
  this._app.use(cookieParser());
  this._app.use(compression());

  this.phases = [
    {name: 'initialize', concurrent: true, error: false, errorStatus: 500},
    {name: 'authentication', concurrent: false, error: false, errorStatus: 401},
    {name: 'authorisation', concurrent: false, error: false, errorStatus: 403},
    {name: 'prevalidation', concurrent: true, error: false, errorStatus: 400},
    {name: 'preprocess', concurrent: false, error: false, errorStatus: 500},
    {name: 'postvalidation', concurrent: true, error: false, errorStatus: 400},
    {name: 'process', concurrent: false, error: false, errorStatus: 500},
    {name: 'postprocess', concurrent: false, error: false, errorStatus: 500},
    {name: '_send', concurrent: false, error: false},
    {name: 'after', concurrent: true, error: false},
    {name: 'error', concurrent: false, error: true, errorStatus: 500},
    {name: '_senderror', concurrent: false, error: true},
    {name: 'aftererror', concurrent: true, error: true}
  ];
  this.addRegisterFunctions(this);

  this._types = {
    'alpha': '[a-z]+',
    'alphanum': '[a-z0-9]+',
    'bool': '(?:1|0|true|false)',
    'float': '\\-?[0-9\\.]+',
    'int': '[1-9][0-9]*',
    'path': '.+?',
    'signed': '\\-?[0-9]+',
    'string': '[^\\/]+',
    'unsigned': '[0-9]+',
    'uuid': '[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}'
  };

  this._send(sendHandler);
  this.error(errorHandler);
  this._senderror(sendHandler);

  var log = this._options.log;
  if (typeof log === 'function') {
    this.after(function() { logHandler.apply(this, [log]); });
    this.aftererror(function() { logHandler.apply(this, [log]); });
  }
}
753298
function HttpConnection(options) {
    options = options ?
        ({
            protocol: (options.protocol || 'http:'),
            host: (options.host || 'localhost'),
            port: (options.port || '80'),
            path: httpPath,
            withCredentials: false
        }) :
        ({
            path: 'http://localhost:80' + httpPath
        });
    this.options = util._extend({
        localAddress: process.env.LOCAL_ADDRESS
    }, options);
    this._config = JSON.stringify(this.options);
    if (logger.isDebugEnabled()) {
        logger.debug('created with %s', this._config);
    }
}
1232940
function rereq(options, done) {
  let req;

  req = https.request(options, (res) => {
    let chunk = '';

    res.on('data', (data) => {
      chunk += data;
    });
    res.on('end', () => {
      done(null, chunk.toString('utf8'));
    });
  });
  req.on('error', (e) => {
    done(e);
  });
  req.end();
}
384008
function BaseCoverArt(options) {

  options = options || {};

  this.userAgent = options.userAgent || _userAgent;
  this.host = _host;
  this.basePath = _path;
  this.http = _http;
}
1114918
function JWT (options) {
  options = options || {};
  var optionDefaults = {
    crypto: {
      algorithm: 'HS256'
    },
    header: {
      typ: 'JWT'
    },
    claims: {},
    validations: {}
  };
  _.defaultsDeep(options, optionDefaults);

  // -- Private
  var isHmac = false;
  var isSign = false;
  var isUnsecured = false;
  var validations;

  var algPrefix;
  var algBitLength;
  var algorithm;
  var crypto;

  var privateKey;
  var publicKey;
  var secret;

  var jwtClaims;
  var jwtHeader;

  function processKey (key) {
    if (!_.isUndefined(key)) {
      if (Buffer.isBuffer(key)) {
        return key.toString();
      } else {
        return key;
      }
    } else {
      return key;
    }
  }

  // -- Protected
  this.isHmac = function () {
    return isHmac;
  };

  this.isSign = function () {
    return isSign;
  };

  this.isUnsecured = function () {
    return isUnsecured;
  };

  this.getAlgorithm = function () {
    return algorithm;
  };

  this.getCrypto = function () {
    return crypto;
  };

  this.getHeader = function () {
    return jwtHeader;
  };

  this.getClaims = function () {
    return jwtClaims;
  };

  this.getSecret = function () {
    return secret;
  };

  this.getPrivateKey = function () {
    return privateKey;
  };

  this.getPublicKey = function () {
    return publicKey;
  };

  this.getValidations = function () {
    return validations;
  };

  // Public
  this.setValidations = function (obj) {
    validations = obj || {};
    return this;
  };

  this.setPrivateKey = function (key) {
    privateKey = processKey.bind(this)(key) || undefined;
    return this;
  };

  this.setPublicKey = function (key) {
    publicKey = processKey.bind(this)(key) || undefined;
    return this;
  };

  this.setSecret = function (sec) {
    if (!_.isUndefined(sec)) {
      if (Buffer.isBuffer(sec)) {
        secret =  sec.toString();
      } else {
        secret = sec;
      }
    } else {
      secret = sec;
    }
    return this;
  };

  this.setAlgorithm = function (alg) {
    if (_.has(JWT.getSupportedAlgorithms(), alg)) {
      jwtHeader = _.merge(options.header, { alg: alg.toUpperCase() });
      if (alg === 'NONE') {
        isHmac = false;
        isSign = false;
        isUnsecured = true;
        crypto = '';
      } else {
        algorithm = alg.toUpperCase();
        algPrefix = alg.substring(0,2);
        algBitLength = alg.substring(2,5);

        // Set type key
        if (algPrefix === 'RS'
            || algPrefix === 'ES'
            || algPrefix === 'PS'
        ) {
          isHmac = false;
          isSign = true;
          isUnsecured = false;
          crypto = 'RSA-SHA' + algBitLength;
        } else {
          isHmac = true;
          isSign = false;
          isUnsecured = false;
          crypto = 'sha' + algBitLength;
        }
      }
    } else {
      throw new JWTError(JWT_UNKNOWN_ALGORITHM + ' ' +  alg);
    }
    return this;
  };

  this.setClaims = function(claims) {
    jwtClaims = claims;
    return this;
  };

  //-- Initialization
  // Set header / alg
  this.setAlgorithm(options.crypto.algorithm);

  // Set secret / keys
  if (!_.isUndefined(options.crypto.secret)) {
    this.setSecret(options.crypto.secret);
  }

  if (!_.isUndefined(options.crypto.privateKey)) {
    this.setPrivateKey(options.crypto.privateKey);
  }

  if (!_.isUndefined(options.crypto.publicKey)) {
    this.setPublicKey(options.crypto.publicKey);
  }

  // Set default claims
  this.setClaims(options.claims);

  // Set Validations
  this.setValidations(options.validations);

  // Return instance
  return this;
}
611034
public static ClientHttpConnector create(ClientOptions options) {
		HttpClient httpClient = HttpClient.create();

		if (usingCustomCerts(options)) {
			TrustManagerFactory trustManagerFactory =
					sslCertificateUtils.createTrustManagerFactory(options.getCaCertFiles());

			httpClient = httpClient.secure(sslContextSpec -> sslContextSpec
					.sslContext(SslContextBuilder.forClient()
							.sslProvider(SslProvider.JDK)
							.trustManager(trustManagerFactory)));
		} else {
			httpClient = httpClient.secure(sslContextSpec -> sslContextSpec
					.sslContext(SslContextBuilder.forClient()
							.sslProvider(SslProvider.JDK)));
		}

		if (options.getConnectionTimeout() != null) {
			httpClient = httpClient.tcpConfiguration(tcpClient ->
					tcpClient.option(ChannelOption.CONNECT_TIMEOUT_MILLIS,
							Math.toIntExact(options.getConnectionTimeout().toMillis())));
		}

		return new ReactorClientHttpConnector(httpClient);
	}
401084
function configure(options) {
    if (options && isArray(options.globalMessages)) {
        globalMessages = options.globalMessages;
    }
    if (options && isObject(options.errorTypes)) {
        errorTypes = options.errorTypes;
    }
}
605804
function getRequestOptions(conf) {
  const strictSSL = conf.get('strict-ssl');

  let options = {
    uri: downloadUrl,
    encoding: null, // Get response as a buffer
    followRedirect: true, // The default download path redirects to a CDN URL.
    headers: {},
    strictSSL: strictSSL
  };

  let proxyUrl = conf.get('https-proxy') || conf.get('http-proxy') || conf.get('proxy');
  if (proxyUrl) {

    // Print using proxy
    let proxy = url.parse(proxyUrl);
    if (proxy.auth) {
      // Mask password
      proxy.auth = proxy.auth.replace(/:.*$/, ':******');
    }
    log.info('Using proxy ' + url.format(proxy));

    // Enable proxy
    options.proxy = proxyUrl;

    // If going through proxy, use the user-agent string from the npm config
    options.headers['User-Agent'] = conf.get('user-agent');
  }

  // Use certificate authority settings from npm
  const ca = conf.get('ca');
  if (ca) {
    log.info('Using npmconf ca');
    options.ca = ca;
  }

  return options;
}
696362
private void configureSsl(SocketChannel ch) {
        ch.pipeline().addLast(sslCtx.newHandler(ch.alloc()), new Http2OrHttpHandler());
    }