Esempio n. 1
0
 class SchemaCls(GRRSignedBlob.SchemaCls):
     INSTALLATION = aff4.Attribute(
         "aff4:driver/installation",
         rdfvalue.DriverInstallTemplate,
         "The driver installation control protobuf.",
         "installation",
         default=rdfvalue.DriverInstallTemplate(driver_name="pmem",
                                                device_path=r"\\.\pmem"))
Esempio n. 2
0
    def testInstallDriver(self):
        for driver_path in self.drivers:
            print "Attempting to load %s" % driver_path
            client_context = ["Platform:Darwin"]
            # Make sure there is a signed driver for our client.
            vfs_path = maintenance_utils.UploadSignedDriverBlob(
                open(driver_path).read(),
                client_context=client_context,
                token=self.token)

            fd = aff4.FACTORY.Create(vfs_path,
                                     "GRRMemoryDriver",
                                     mode="r",
                                     token=self.token)
            self.blob = fd.Get(fd.Schema.BINARY)

            request = rdfvalue.DriverInstallTemplate(driver=self.blob,
                                                     write_path=None,
                                                     force_reload=0)
            osx.client_utils_osx.InstallDriver(
                mox.Func(lambda x: x.endswith(".kext")))
            self.mox.ReplayAll()
            self.RunAction("InstallDriver", request)
            self.mox.VerifyAll()
def UploadSignedDriverBlob(content, aff4_path=None, client_context=None,
                           install_request=None, token=None):
  """Upload a signed blob into the datastore.

  Args:
    content: Content of the driver file to upload.

    aff4_path: aff4 path to upload to. If not specified, we use the config to
      figure out where it goes.

    client_context: The configuration contexts to use.

    install_request: A DriverInstallRequest rdfvalue describing the installation
      parameters for this driver. If None these are read from the config.

    token: A security token.

  Returns:
    String containing path the file was written to.

  Raises:
    IOError: On failure to write.
  """
  sig_key = config_lib.CONFIG.Get("PrivateKeys.driver_signing_private_key",
                                  context=client_context)

  ver_key = config_lib.CONFIG.Get("Client.driver_signing_public_key",
                                  context=client_context)

  if aff4_path is None:
    aff4_paths = config_lib.CONFIG.Get("MemoryDriver.aff4_paths",
                                       context=client_context)
    if not aff4_paths:
      raise IOError("Could not determine driver location.")
    if len(aff4_paths) > 1:
      logging.info("Possible driver locations: %s", aff4_paths)
      raise IOError("Ambiguous driver location, please specify.")
    aff4_path = aff4_paths[0]

  blob_rdf = rdfvalue.SignedBlob()
  blob_rdf.Sign(content, sig_key, ver_key, prompt=True)

  with aff4.FACTORY.Create(
      aff4_path, "GRRMemoryDriver", mode="w", token=token) as fd:
    fd.Add(blob_rdf)

    if install_request is None:
      # Create install_request from the configuration.
      install_request = rdfvalue.DriverInstallTemplate(
          device_path=config_lib.CONFIG.Get(
              "MemoryDriver.device_path", context=client_context),
          driver_display_name=config_lib.CONFIG.Get(
              "MemoryDriver.driver_display_name", context=client_context),
          driver_name=config_lib.CONFIG.Get(
              "MemoryDriver.driver_service_name", context=client_context))

    fd.Set(fd.Schema.INSTALLATION(install_request))

  logging.info("Uploaded to %s", fd.urn)

  return fd.urn