Esempio n. 1
0
  def _start(self):
    """Starts this ForeLink.

    This method must be called before attempting to exchange tickets with this
    object.
    """
    with self._condition:
      address = '[::]:%d' % (
          0 if self._requested_port is None else self._requested_port)
      self._completion_queue = _low.CompletionQueue()
      if self._root_certificates is None and not self._key_chain_pairs:
        self._server = _low.Server(self._completion_queue)
        self._port = self._server.add_http2_addr(address)
      else:
        server_credentials = _low.ServerCredentials(
          self._root_certificates, self._key_chain_pairs, False)
        self._server = _low.Server(self._completion_queue)
        self._port = self._server.add_secure_http2_addr(
            address, server_credentials)
      self._server.start()

      self._server.service(None)

      self._pool.submit(self._spin, self._completion_queue, self._server)
      self._spinning = True

      return self
Esempio n. 2
0
def ssl_server_credentials(
    private_key_certificate_chain_pairs, root_certificates=None,
    require_client_auth=False):
  """Creates a ServerCredentials for use with an SSL-enabled Server.

  Args:
    private_key_certificate_chain_pairs: A nonempty sequence each element of
      which is a pair the first element of which is a PEM-encoded private key
      and the second element of which is the corresponding PEM-encoded
      certificate chain.
    root_certificates: PEM-encoded client root certificates to be used for
      verifying authenticated clients. If omitted, require_client_auth must also
      be omitted or be False.
    require_client_auth: A boolean indicating whether or not to require clients
      to be authenticated. May only be True if root_certificates is not None.

  Returns:
    A ServerCredentials for use with an SSL-enabled Server.
  """
  if len(private_key_certificate_chain_pairs) == 0:
    raise ValueError(
        'At least one private key-certificate chain pairis required!')
  elif require_client_auth and root_certificates is None:
    raise ValueError(
        'Illegal to require client auth without providing root certificates!')
  else:
    intermediary_low_credentials = _intermediary_low.ServerCredentials(
        root_certificates, private_key_certificate_chain_pairs,
        require_client_auth)
    return ServerCredentials(
        intermediary_low_credentials._internal, intermediary_low_credentials)  # pylint: disable=protected-access