Exemple #1
0
        def TestAnd(val1, val2, expected):
            self.assertEqual(rdfvalue.RDFBool(val1) & val2, expected)
            self.assertEqual(val1 & rdfvalue.RDFBool(val2), expected)

            value = rdfvalue.RDFBool(val1)
            value &= val2
            self.assertEqual(value, expected)

            value = val1
            value &= rdfvalue.RDFBool(val2)
            self.assertEqual(value, expected)
Exemple #2
0
        def TestOr(val1, val2, expected):
            self.assertEqual(rdfvalue.RDFBool(val1) | val2, expected)
            self.assertEqual(val1 | rdfvalue.RDFBool(val2), expected)

            value = rdfvalue.RDFBool(val1)
            value |= val2
            self.assertEqual(value, expected)

            value = val1
            value |= rdfvalue.RDFBool(val2)
            self.assertEqual(value, expected)
Exemple #3
0
 def testRepr(self):
     """Test RDFValue.__repr__."""
     self.assertEqual(repr(rdfvalue.RDFBool(True)), "<RDFBool('1')>")
     self.assertEqual(
         repr(rdfvalue.RDFString(long_string)),
         "<RDFString('\\xe8\\xbf\\x8e\\xe6\\xac\\xa2\\xe8\\xbf\\x8e\\nLorem "
         "ipsum dolor sit amet, consectetur adipiscing elit. Morbi luctus ex "
         "sed dictum volutp...')>")
Exemple #4
0
    def EnrolFleetspeakClient(self, client_id):
        """Enrols a Fleetspeak-enabled client for use with GRR."""
        client_urn = rdf_client.ClientURN(client_id)

        # If already enrolled, return.
        if data_store.RelationalDBReadEnabled():
            if data_store.REL_DB.ReadClientMetadata(client_id):
                return
        else:
            if aff4.FACTORY.ExistsWithType(client_urn,
                                           aff4_type=aff4_grr.VFSGRRClient,
                                           token=self.token):
                return

        logging.info("Enrolling a new Fleetspeak client: %r", client_id)

        if data_store.RelationalDBWriteEnabled():
            data_store.REL_DB.WriteClientMetadata(client_id,
                                                  fleetspeak_enabled=True)

        # TODO(fleetspeak-team,grr-team): If aff4 isn't reliable enough, we can
        # catch exceptions from it and forward them to Fleetspeak by failing its
        # gRPC call. Fleetspeak will then retry with a random, perhaps healthier,
        # instance of the GRR frontend.
        with aff4.FACTORY.Create(client_urn,
                                 aff4_type=aff4_grr.VFSGRRClient,
                                 mode="rw",
                                 token=self.token) as client:

            client.Set(client.Schema.FLEETSPEAK_ENABLED,
                       rdfvalue.RDFBool(True))

            index = client_index.CreateClientIndex(token=self.token)
            index.AddClient(client)
            if data_store.RelationalDBWriteEnabled():
                index = client_index.ClientIndex()
                index.AddClient(data_migration.ConvertVFSGRRClient(client))

        enrollment_session_id = rdfvalue.SessionID(queue=queues.ENROLLMENT,
                                                   flow_name="Enrol")

        publish_msg = rdf_flows.GrrMessage(
            payload=client_urn,
            session_id=enrollment_session_id,
            # Fleetspeak ensures authentication.
            auth_state=rdf_flows.GrrMessage.AuthorizationState.AUTHENTICATED,
            source=enrollment_session_id,
            priority=rdf_flows.GrrMessage.Priority.MEDIUM_PRIORITY)

        # Publish the client enrollment message.
        events.Events.PublishEvent("ClientEnrollment",
                                   publish_msg,
                                   token=self.token)
Exemple #5
0
    def EnrolFleetspeakClient(self, client_id):
        """Enrols a Fleetspeak-enabled client for use with GRR."""
        client_urn = rdf_client.ClientURN(client_id)

        # If already enrolled, return.
        if data_store.RelationalDBReadEnabled():
            if data_store.REL_DB.ReadClientMetadata(client_id):
                return
        else:
            if aff4.FACTORY.ExistsWithType(client_urn,
                                           aff4_type=aff4_grr.VFSGRRClient,
                                           token=self.token):
                return

        logging.info("Enrolling a new Fleetspeak client: %r", client_id)

        if data_store.RelationalDBWriteEnabled():
            data_store.REL_DB.WriteClientMetadata(client_id,
                                                  fleetspeak_enabled=True)

        # TODO(fleetspeak-team,grr-team): If aff4 isn't reliable enough, we can
        # catch exceptions from it and forward them to Fleetspeak by failing its
        # gRPC call. Fleetspeak will then retry with a random, perhaps healthier,
        # instance of the GRR frontend.
        with aff4.FACTORY.Create(client_urn,
                                 aff4_type=aff4_grr.VFSGRRClient,
                                 mode="rw",
                                 token=self.token) as client:

            client.Set(client.Schema.FLEETSPEAK_ENABLED,
                       rdfvalue.RDFBool(True))

            index = client_index.CreateClientIndex(token=self.token)
            index.AddClient(client)
            if data_store.RelationalDBWriteEnabled():
                index = client_index.ClientIndex()
                index.AddClient(data_migration.ConvertVFSGRRClient(client))

        # Publish the client enrollment message.
        events.Events.PublishEvent("ClientEnrollment",
                                   client_urn,
                                   token=self.token)
    def InitFromKeyValue(self, key, value):
        self.key = key

        # Convert primitive types to rdf values so they can be serialized.
        if isinstance(value, float) and not value.is_integer():
            # TODO(user): Do not convert float values here and mark them invalid
            # later. ATM, we do not have means to properly represent floats. Change
            # this part once we have a RDFFloat implementation.
            pass
        elif rdfvalue.RDFInteger.IsNumeric(value):
            value = rdfvalue.RDFInteger(value)
        elif isinstance(value, basestring):
            value = rdfvalue.RDFString(value)
        elif isinstance(value, bool):
            value = rdfvalue.RDFBool(value)

        if isinstance(value, rdfvalue.RDFValue):
            self.type = value.__class__.__name__
            self.value = value
        else:
            self.invalid = True

        return self
Exemple #7
0
 def testComparableToPrimitiveBooleans(self):
     self.assertEqual(rdfvalue.RDFBool(True), True)
     self.assertNotEqual(rdfvalue.RDFBool(True), False)
     self.assertEqual(rdfvalue.RDFBool(False), False)
     self.assertNotEqual(rdfvalue.RDFBool(False), True)
Exemple #8
0
 def GenerateSample(self, number=0):
     return rdfvalue.RDFBool(number % 2)
def SetAFF4FSEnabledFlag(grr_id, token):
    with aff4.FACTORY.Create(grr_id,
                             aff4.AFF4Object.classes["VFSGRRClient"],
                             mode="w",
                             token=token) as client:
        client.Set(client.Schema.FLEETSPEAK_ENABLED, rdfvalue.RDFBool(True))
Exemple #10
0
 def testStr(self):
     """Test RDFValue.__str__."""
     self.assertEqual(str(rdfvalue.RDFBool(True)), "1")
     self.assertEqual(str(rdfvalue.RDFString(long_string)), long_string)