def LoadServerCertificate(self, server_certificate=None,
                            ca_certificate=None):
    """Loads and verifies the server certificate."""
    try:
      server_cert = X509.load_cert_string(str(server_certificate))
      ca_cert = X509.load_cert_string(str(ca_certificate))

      # Check that the server certificate verifies
      if server_cert.verify(ca_cert.get_pubkey()) != 1:
        self.server_name = None
        raise IOError("Server cert is invalid.")

      # Make sure that the serial number is higher.
      server_cert_serial = server_cert.get_serial_number()

      if server_cert_serial < config_lib.CONFIG["Client.server_serial_number"]:
        # We can not accept this serial number...
        raise IOError("Server cert is too old.")
      elif server_cert_serial > config_lib.CONFIG[
          "Client.server_serial_number"]:
        logging.info("Server serial number updated to %s", server_cert_serial)
        config_lib.CONFIG.Set("Client.server_serial_number", server_cert_serial)

        # Save the new data to the config file.
        config_lib.CONFIG.Write()

    except X509.X509Error:
      raise IOError("Server cert is invalid.")

    self.server_name = self.pub_key_cache.GetCNFromCert(server_cert)
    self.server_certificate = server_certificate
    self.ca_certificate = ca_certificate

    # We need to store the serialised version of the public key due
    # to M2Crypto memory referencing bugs
    self.pub_key_cache.Put(
        self.server_name, self.pub_key_cache.PubKeyFromCert(server_cert))
dataset/ETHPy150Open google/grr/grr/client/comms.py/ClientCommunicator.LoadServerCertificate/original