def _WriteTestBinaryAndGetBlobIterator(self, binary_data, chunk_size): binary_urn = rdfvalue.RDFURN("aff4:/config/executables/foo") signed_binary_utils.WriteSignedBinary(binary_urn, binary_data, private_key=self._private_key, public_key=self._public_key, chunk_size=chunk_size) blob_iterator, _ = signed_binary_utils.FetchBlobsForSignedBinaryByURN( binary_urn) return blob_iterator
def testFetchSizeOfSignedBinary(self): binary1_urn = rdfvalue.RDFURN("aff4:/config/executables/foo1") binary2_urn = rdfvalue.RDFURN("aff4:/config/executables/foo2") binary1_data = b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99" binary2_blobs = [ rdf_crypto.SignedBlob().Sign(b"\x00\x11\x22", self._private_key), rdf_crypto.SignedBlob().Sign(b"\x33\x44", self._private_key) ] signed_binary_utils.WriteSignedBinary(binary1_urn, binary1_data, private_key=self._private_key, public_key=self._public_key, chunk_size=3) signed_binary_utils.WriteSignedBinaryBlobs(binary2_urn, binary2_blobs) binary1_size = signed_binary_utils.FetchSizeOfSignedBinary(binary1_urn) binary2_size = signed_binary_utils.FetchSizeOfSignedBinary(binary2_urn) self.assertEqual(binary1_size, 10) self.assertEqual(binary2_size, 5)
def UploadSignedConfigBlob(content, aff4_path, client_context=None, limit=None, token=None): """Upload a signed blob into the datastore. Args: content: File content to upload. aff4_path: aff4 path to upload to. client_context: The configuration contexts to use. limit: The maximum size of the chunk to use. token: A security token. Raises: IOError: On failure to write. """ if limit is None: limit = config.CONFIG["Datastore.maximum_blob_size"] # Get the values of these parameters which apply to the client running on the # target platform. if client_context is None: # Default to the windows client. client_context = ["Platform:Windows", "Client Context"] config.CONFIG.Validate( parameters="PrivateKeys.executable_signing_private_key") signing_key = config.CONFIG.Get( "PrivateKeys.executable_signing_private_key", context=client_context) verification_key = config.CONFIG.Get( "Client.executable_signing_public_key", context=client_context) signed_binary_utils.WriteSignedBinary( rdfvalue.RDFURN(aff4_path), content, signing_key, public_key=verification_key, chunk_size=limit, token=token) logging.info("Uploaded to %s", aff4_path)
def testWriteSignedBinary(self): binary_data = b"\x00\x11\x22\x33\x44\x55\x66\x77\x88\x99" # 10 bytes. test_urn = rdfvalue.RDFURN("aff4:/config/executables/foo") signed_binary_utils.WriteSignedBinary(test_urn, binary_data, private_key=self._private_key, public_key=self._public_key, chunk_size=3) blobs_iter, timestamp = signed_binary_utils.FetchBlobsForSignedBinaryByURN( test_urn) self.assertGreater(timestamp.AsMicrosecondsSinceEpoch(), 0) self.assertIsInstance(blobs_iter, collections.Iterator) # We expect blobs to have at most 3 contiguous bytes of data. expected_blobs = [ rdf_crypto.SignedBlob().Sign(b"\x00\x11\x22", self._private_key), rdf_crypto.SignedBlob().Sign(b"\x33\x44\x55", self._private_key), rdf_crypto.SignedBlob().Sign(b"\x66\x77\x88", self._private_key), rdf_crypto.SignedBlob().Sign(b"\x99", self._private_key) ] self.assertCountEqual(list(blobs_iter), expected_blobs)