def Run(self, args): file_fd = vfs.VFSOpen(args.pathspec, progress_callback=self.Progress) # Gzip the original file. gzip_fd = uploads.GzipWrapper(file_fd) # And then encrypt it. server_certificate = rdf_crypto.RDFX509Cert( self.grr_worker.client.server_certificate) fd = uploads.EncryptStream(server_certificate.GetPublicKey(), config_lib.CONFIG["Client.private_key"], gzip_fd) response = self.grr_worker.http_manager.OpenServerEndpoint( u"/upload/", data=self.FileGenerator(fd), headers={ "x-grr-hmac": base64.b64encode(args.hmac), "x-grr-policy": base64.b64encode(args.policy), }, method="POST") if response.code != 200: raise IOError("Unable to upload %s" % args.pathspec.CollapsePath()) logging.debug("Uploaded %s (%s bytes)", args.pathspec, self.sent_data) stat_entry = file_fd.Stat() # Sometimes the file we upload does not report its correct size in the # st_size attribute (e.g. /proc files). We modify the st_size to force it to # report the actual amount of data uploaded. stat_entry.st_size = self.sent_data self.SendReply(stat_entry)
def Run(self, args): file_fd = vfs.VFSOpen(args.pathspec, progress_callback=self.Progress) # Gzip the original file. gzip_fd = uploads.GzipWrapper(file_fd) # And then encrypt it. server_certificate = rdf_crypto.RDFX509Cert( self.grr_worker.client.server_certificate) fd = uploads.EncryptStream(server_certificate.GetPublicKey(), config_lib.CONFIG["Client.private_key"], gzip_fd) response = self.grr_worker.http_manager.OpenServerEndpoint( u"/upload/", data=self.FileGenerator(fd), headers={ "x-grr-hmac": base64.b64encode(args.hmac), "x-grr-policy": base64.b64encode(args.policy), }, method="POST") if response.code != 200: raise IOError("Unable to upload %s" % args.pathspec.CollapsePath()) self.SendReply(file_fd.Stat())
def testGUnzipWrapper(self): gzip_data = uploads.GzipWrapper(self.infd).read(10000) outfd = StringIO.StringIO() uploads.GunzipWrapper(outfd).write(gzip_data) self.assertEqual(outfd.getvalue(), self.test_string) outfd = StringIO.StringIO() wrapped = uploads.GunzipWrapper(outfd) for c in gzip_data: wrapped.write(c) self.assertEqual(outfd.getvalue(), self.test_string)
def testGzipWrapperSmallReads(self): gzip_fd = uploads.GzipWrapper(self.infd) gzip_data = "" while True: chunk = gzip_fd.read(5) if not chunk: break gzip_data += chunk fd = gzip.GzipFile(mode="r", fileobj=StringIO.StringIO(gzip_data)) self.assertEqual(fd.read(), self.test_string)
def testGzipWrapperLimit(self): gzip_data = uploads.GzipWrapper(self.infd, byte_limit=100).read(10000) fd = gzip.GzipFile(mode="r", fileobj=StringIO.StringIO(gzip_data)) self.assertEqual(fd.read(), self.test_string[:100])