def test_content_block2(self): cb2 = tm10.ContentBlock( content_binding=CB_STIX_XML_10, content=six.StringIO( '<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>' )) round_trip_content_block(cb2)
def make_content(version, content_binding=CUSTOM_CONTENT_BINDING, content=CONTENT, subtype=None): if version == 10: return tm10.ContentBlock(content_binding, content) elif version == 11: content_block = tm11.ContentBlock(tm11.ContentBinding(content_binding), content) if subtype: content_block.content_binding.subtype_ids.append(subtype) return content_block else: raise ValueError('Unknown TAXII message version: %s' % version)
def create_request_message(self, args): if args.content_file is self.stix_watchlist: data = self.stix_watchlist else: with open(args.content_file, 'r') as f: data = f.read() cb = tm10.ContentBlock(args.content_binding, data) if args.subtype is not None: cb.content_binding.subtype_ids.append(args.subtype) inbox_message = tm10.InboxMessage(message_id=generate_message_id(), content_blocks=[cb]) return inbox_message
def content_block_entity_to_content_block(entity, version): content_bindings = content_binding_entity_to_content_binding( entity.content_binding, version=version) # Libtaxii requires content to be unicode content = (entity.content if isinstance(entity.content, six.string_types) else entity.content.decode('utf-8')) if version == 10: return tm10.ContentBlock(content_binding=content_bindings, content=content, timestamp_label=entity.timestamp_label) elif version == 11: return tm11.ContentBlock(content_binding=content_bindings, content=content, timestamp_label=entity.timestamp_label, message=entity.message)
def push(self, content, content_binding, uri=None, timestamp=None): """Push content into Inbox Service. if ``uri`` is not provided, client will try to discover services and find Inbox Service among them. Content Binding subtypes and Destionation collections are not supported in TAXII Specification v1.0. :param str content: content to push :param content_binding: content binding for a content :type content_binding: string or :py:class:`cabby.entities.ContentBinding` :param datetime timestamp: timestamp label of the content block (current UTC time by default) :param str uri: URI path to a specific Inbox Service :raises ValueError: if URI provided is invalid or schema is not supported :raises `cabby.exceptions.HTTPError`: if HTTP error happened :raises `cabby.exceptions.UnsuccessfulStatusError`: if Status Message received and status_type is not `SUCCESS` :raises `cabby.exceptions.ServiceNotFoundError`: if no service found :raises `cabby.exceptions.AmbiguousServicesError`: more than one service with type specified :raises `cabby.exceptions.NoURIProvidedError`: no URI provided and client can't discover services """ content_block = tm10.ContentBlock( content=content, content_binding=pack_content_binding(content_binding, version=10), timestamp_label=timestamp or get_utc_now(), ) inbox_message = tm10.InboxMessage(message_id=self._generate_id(), content_blocks=[content_block]) self._execute_request(inbox_message, uri=uri, service_type=const.SVC_INBOX) self.log.debug("Content block successfully pushed")
def content_block_entity_to_content_block(entity, version): content_bindings = content_binding_entity_to_content_binding( entity.content_binding, version=version) if version == 10: return tm10.ContentBlock( content_binding=content_bindings, content=entity.content, timestamp_label=entity.timestamp_label, ) elif version == 11: return tm11.ContentBlock( content_binding=content_bindings, content=entity.content, timestamp_label=entity.timestamp_label, message=entity.message, )
def test_content_block6(self): cb6 = tm10.ContentBlock(content_binding='RandomUnicodeString', content=unicode('abcdef')) round_trip_content_block(cb6)
def test_content_block5(self): cb5 = tm10.ContentBlock(content_binding=t.CB_STIX_XML_10, content='Something thats not XML <xml/>') round_trip_content_block(cb5)
def test_content_block4(self): cb4 = tm10.ContentBlock(content_binding=t.CB_STIX_XML_10, content='<Something thats not XML') round_trip_content_block(cb4)
def test_content_block3(self): cb3 = tm10.ContentBlock(content_binding=t.CB_STIX_XML_10, content=etree.parse(StringIO.StringIO('<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>'))) round_trip_content_block(cb3)
def test_content_block1(self): cb1 = tm10.ContentBlock(content_binding=t.CB_STIX_XML_10, content='<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>') round_trip_content_block(cb1)
</cybox:Properties> </cybox:Object> </indicator:Observable> </stix:Indicator> </stix:Indicators> </stix:STIX_Package>""" full_stix_etree = etree.parse(StringIO.StringIO(full_stix_doc)).getroot() # TODO: This is bad practice. Refactor this. # Set up some things used across multiple tests. stix_etree = etree.parse(StringIO.StringIO('<stix:STIX_Package xmlns:stix="http://stix.mitre.org/stix-1"/>')).getroot() xml_content_block1 = tm10.ContentBlock( content_binding=t.CB_STIX_XML_10, # Required content=full_stix_etree, # Required. Can be etree or string padding='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', # Optional timestamp_label=datetime.datetime.now(tzutc())) # Optional string_content_block1 = tm10.ContentBlock( content_binding='string', # Required content='Sample content', # Required padding='ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', # Optional timestamp_label=datetime.datetime.now(tzutc())) # Optional delivery_parameters1 = tm10.DeliveryParameters( inbox_protocol=t.VID_TAXII_HTTP_10, # Required if requesting push messaging inbox_address='http://example.com/inbox', # Yes, if requesting push messaging delivery_message_binding=t.VID_TAXII_XML_10, # Required if requesting push messaging content_bindings=[t.CB_STIX_XML_10]) # Optional - absence means accept all content bindings