Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions cybox/bindings/cybox_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ def exportChildren(self, lwrite, level, namespace_='cyboxCommon:', name_='Locati
else:
eol_ = ''
if self.Name is not None:
showIndent(lwrite, level, pretty_print)
lwrite('<%sName>%s</%sName>%s' % ('cyboxCommon:', self.gds_format_string(quote_xml(self.Name), input_name='Name'), 'cyboxCommon:', eol_))
def build(self, node):
self.__sourcenode__ = node
Expand Down
10 changes: 5 additions & 5 deletions cybox/bindings/cybox_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -3193,7 +3193,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'Event':
obj_ = EventType.factory()
obj_.build(child_)
self.Event.append(obj_)
self.add_Event(obj_)
# end class EventPoolType

class ActionPoolType(GeneratedsSuper):
Expand Down Expand Up @@ -3266,7 +3266,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'Action':
obj_ = ActionType.factory()
obj_.build(child_)
self.Action.append(obj_)
self.add_Action(obj_)
# end class ActionPoolType

class ObjectPoolType(GeneratedsSuper):
Expand Down Expand Up @@ -3339,7 +3339,7 @@ def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'Object':
obj_ = ObjectType.factory()
obj_.build(child_)
self.set_Object(obj_)
self.add_Object(obj_)
# end class ObjectPoolType

class PropertyPoolType(GeneratedsSuper):
Expand Down Expand Up @@ -3410,9 +3410,9 @@ def buildAttributes(self, node, attrs, already_processed):
pass
def buildChildren(self, child_, node, nodeName_, fromsubclass_=False):
if nodeName_ == 'Property':
obj_ = ActionPertinentObjectPropertyType.factory()
obj_ = cybox_common.PropertyType.factory()
obj_.build(child_)
self.Property.append(obj_)
self.add_Property(obj_)
# end class PropertyPoolType

class ObfuscationTechniquesType(GeneratedsSuper):
Expand Down
1 change: 1 addition & 0 deletions cybox/common/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from .digitalsignature import DigitalSignature, DigitalSignatureList
from .environment_variable import EnvironmentVariable, EnvironmentVariableList
from .hashes import Hash, HashList, HashName
from .location import Location
from .object_properties import ObjectProperties, Property
from .structured_text import StructuredText
from .time import Time
Expand Down
25 changes: 25 additions & 0 deletions cybox/common/location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

from mixbox import entities, fields

import cybox.bindings.cybox_common as common_binding


class Location(entities.Entity):
_binding = common_binding
_binding_class = common_binding.LocationType
_namespace = 'http://cybox.mitre.org/common-2'
_XSI_TYPE = None # overridden by subclasses

id_ = fields.IdrefField("id")
idref = fields.IdrefField("idref")
name = fields.TypedField("Name")

def to_dict(self):
d = super(Location, self).to_dict()

if self._XSI_TYPE:
d["xsi:type"] = self._XSI_TYPE

return d
3 changes: 2 additions & 1 deletion cybox/common/vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def is_plain(self):

"""
return (
(self.xsi_type is None or type(self)._XSI_TYPE == self.xsi_type) and
self.xsi_type is None and
self.vocab_name is None and
self.vocab_reference is None and
super(VocabString, self).is_plain()
Expand Down Expand Up @@ -149,6 +149,7 @@ def from_obj(cls, cls_obj):
#: Mapping of Controlled Vocabulary xsi:type's to their class implementations.
_VOCAB_MAP = {}


def _get_terms(vocab_class):
"""Helper function used by register_vocab."""
for k, v in vocab_class.__dict__.items():
Expand Down
1 change: 1 addition & 0 deletions cybox/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
from .event import Event, EventType
from .pattern_fidelity import (PatternFidelity, ObfuscationTechniques,
ObfuscationTechnique)
from .pool import ActionPool, EventPool, PropertyPool, ObjectPool, Pools
from .observable import Observable, Observables, ObservableComposition
4 changes: 3 additions & 1 deletion cybox/core/action.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AssociatedObjects(entities.EntityList):
_namespace = 'http://cybox.mitre.org/cybox-2'
associated_object = fields.TypedField("Associated_Object", AssociatedObject, multiple=True)


class ActionRelationship(entities.Entity):
_binding = core_binding
_binding_class = _binding.ActionRelationshipType
Expand All @@ -59,6 +60,7 @@ class ActionRelationships(entities.EntityList):
_namespace = 'http://cybox.mitre.org/cybox-2'
relationship = fields.TypedField("Relationship", ActionRelationship, multiple=True)


class Action(entities.Entity):
_binding = core_binding
_binding_class = core_binding.ActionType
Expand All @@ -84,4 +86,4 @@ class Action(entities.Entity):
class Actions(entities.EntityList):
_binding_class = core_binding.ActionsType
_namespace = 'http://cybox.mitre.org/cybox-2'
action = fields.TypedField("Action", Action, multiple=True)
action = fields.TypedField("Action", Action, multiple=True)
4 changes: 2 additions & 2 deletions cybox/core/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mixbox import fields

import cybox.bindings.cybox_core as core_binding
from cybox.common import StructuredText, MeasureSource
from cybox.common import StructuredText, MeasureSource, Location
from cybox.common.vocabs import EventType, VocabField
from cybox.core import Actions, Frequency

Expand All @@ -23,7 +23,7 @@ class Event(entities.Entity):
observation_method = fields.TypedField("Observation_Method", MeasureSource)
actions = fields.TypedField("Actions", Actions)
frequency = fields.TypedField("Frequency", Frequency)

location = fields.TypedField("Location", Location)
event = fields.TypedField("Event", multiple=True)

# Allow recursive definition of events
Expand Down
5 changes: 4 additions & 1 deletion cybox/core/object.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,5 +210,8 @@ def to_obj(self, ns_info=None):

def to_dict(self):
d = super(DomainSpecificObjectProperties, self).to_dict()
d['xsi:type'] = self._XSI_TYPE

if self._XSI_TYPE:
d['xsi:type'] = self._XSI_TYPE

return d
26 changes: 14 additions & 12 deletions cybox/core/observable.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
import collections

from mixbox import entities
from mixbox import fields
from mixbox import idgen
from mixbox import entities, fields, idgen

from cybox import Unicode
import cybox.bindings.cybox_core as core_binding
Expand Down Expand Up @@ -127,15 +124,14 @@ def add_keyword(self, value):

class Observables(entities.EntityList):
"""The root CybOX Observables object.

Pools are not currently supported.
"""
_binding = core_binding
_binding_class = _binding.ObservablesType
_namespace = 'http://cybox.mitre.org/cybox-2'

observable_package_source = fields.TypedField("Observable_Package_Source", MeasureSource)
observables = fields.TypedField("Observable", Observable, multiple=True, key_name="observables")
pools = fields.TypedField("Pools", type_="cybox.core.pool.Pools")

def __init__(self, observables=None):
super(Observables, self).__init__(observables)
Expand All @@ -144,12 +140,19 @@ def __init__(self, observables=None):
self._minor_version = 1
self._update_version = 0

def add(self, observable):
if not observable:
def add(self, object_):
from cybox.core.pool import Pools
if not object_:
return
if not isinstance(observable, Observable):
observable = Observable(observable)
self.observables.append(observable)
elif isinstance(object_, MeasureSource):
self.observable_package_source = object_
return
elif isinstance(object_, Pools):
self.pools = object_
return
elif not isinstance(object_, Observable):
object_ = Observable(object_)
self.observables.append(object_)

def to_obj(self, ns_info=None):
observables_obj = super(Observables, self).to_obj(ns_info=ns_info)
Expand Down Expand Up @@ -190,4 +193,3 @@ def add(self, observable):
if not observable:
raise ValueError("'observable' must not be None")
self.append(observable)

51 changes: 51 additions & 0 deletions cybox/core/pool.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

from mixbox import entities, fields

import cybox.bindings.cybox_core as core_binding
from cybox.common import Property
from cybox.core import Action, Event, Object


class EventPool(entities.Entity):
_binding = core_binding
_binding_class = _binding.EventPoolType
_namespace = 'http://cybox.mitre.org/cybox-2'

events = fields.TypedField("Event", Event, multiple=True, key_name="events")


class ActionPool(entities.Entity):
_binding = core_binding
_binding_class = _binding.ActionPoolType
_namespace = 'http://cybox.mitre.org/cybox-2'

actions = fields.TypedField("Action", Action, multiple=True, key_name="actions")


class ObjectPool(entities.Entity):
_binding = core_binding
_binding_class = _binding.ObjectPoolType
_namespace = 'http://cybox.mitre.org/cybox-2'

objects = fields.TypedField("Object", Object, multiple=True, key_name="objects")


class PropertyPool(entities.Entity):
_binding = core_binding
_binding_class = _binding.PropertyPoolType
_namespace = 'http://cybox.mitre.org/cybox-2'

properties = fields.TypedField("Property", Property, multiple=True, key_name="properties")


class Pools(entities.Entity):
_binding = core_binding
_binding_class = _binding.PoolsType
_namespace = 'http://cybox.mitre.org/cybox-2'

event_pool = fields.TypedField("Event_Pool", EventPool)
action_pool = fields.TypedField("Action_Pool", ActionPool)
object_pool = fields.TypedField("Object_Pool", ObjectPool)
property_pool = fields.TypedField("Property_Pool", PropertyPool)
15 changes: 15 additions & 0 deletions cybox/test/common/location_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

import unittest

from cybox.common import Location
import cybox.test


class TestLocation(cybox.test.EntityTestCase, unittest.TestCase):
klass = Location
_full_dict = {
'name': "Bedford, MA",
'id': "example:12345",
}
11 changes: 10 additions & 1 deletion cybox/test/common/tools_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,16 @@ class TestToolInformation(EntityTestCase, unittest.TestCase):
'id': "example:Tool-A1",
# 'idref': "example:Tool-A1-ref", # CAnnot set both an id and idref
'name': "AwesomeTool(tm)",
'type': [u('NIDS'), u('HIPS')],
'type': [
{
'value': u('NIDS'),
'xsi:type': 'cyboxVocabs:ToolTypeVocab-1.1'
},
{
'value': u('HIPS'),
'xsi:type': 'cyboxVocabs:ToolTypeVocab-1.1'
}
],
'description': {'structuring_format': 'HTML',
'value': '<p>An awesome tool!</p>'},

Expand Down
18 changes: 12 additions & 6 deletions cybox/test/common/vocab_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,18 @@ def test_add_vocabstring(self):
def test_to_dict(self):
from cybox.common.vocabs import ActionName
d = ActionName(ActionName.TERM_ADD_USER).to_dict()
if 'xsi:type' in d:
self.assertEqual(d['xsi:type'], ActionName._XSI_TYPE)
if 'value' in d:
self.assertEqual(d['value'], ActionName.TERM_ADD_USER)
else:
self.assertEqual(d, ActionName.TERM_ADD_USER)
self.assertEqual(d['xsi:type'], ActionName._XSI_TYPE)
self.assertEqual(d['value'], ActionName.TERM_ADD_USER)

def test_vocab_is_plain_false(self):
from cybox.common.vocabs import ActionName
action = ActionName(ActionName.TERM_ADD_USER)
self.assertFalse(action.is_plain())

def test_vocab_is_plain_true(self):
from cybox.common.vocabs import VocabString
vocab = VocabString(value="foo")
self.assertTrue(vocab.is_plain())


class HashNameTests(unittest.TestCase):
Expand Down
4 changes: 4 additions & 0 deletions cybox/test/core/event_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ class TestEvent(EntityTestCase, unittest.TestCase):
{'idref': "example:Action-5"},
{'idref': "example:Action-6"},
],
'location': {
'name': "Some location",
'id': "example:Location-A"
},
# Once the choice is implemented, this won't work
'event': [
{'idref': "example:Event-A"},
Expand Down
Loading