Beispiel #1
0
 class SchemaCls(GRRSignedBlob.SchemaCls):
     INSTALLATION = aff4.Attribute(
         "aff4:driver/installation",
         rdf_client.DriverInstallTemplate,
         "The driver installation control protobuf.",
         "installation",
         default=rdf_client.DriverInstallTemplate(driver_name="pmem",
                                                  device_path=r"\\.\pmem"))
Beispiel #2
0
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 = rdf_crypto.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 = rdf_client.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