expose the "extensions" property on all object types

remove restriction on MarkingDefinition Object
pull/1/head
Emmanuelle Vargas-Gonzalez 2020-10-19 22:18:45 -04:00
parent 1bc11ce442
commit b17f502e8f
5 changed files with 39 additions and 10 deletions

View File

@ -21,7 +21,7 @@ from .bundle import Bundle
from .common import ( from .common import (
TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking, ExternalReference, TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking, ExternalReference,
GranularMarking, KillChainPhase, LanguageContent, MarkingDefinition, GranularMarking, KillChainPhase, LanguageContent, MarkingDefinition,
StatementMarking, TLPMarking, StatementMarking, STIXExtension, TLPMarking,
) )
from .observables import ( from .observables import (
URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem, URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem,
@ -65,6 +65,7 @@ OBJ_MAP = {
'threat-actor': ThreatActor, 'threat-actor': ThreatActor,
'tool': Tool, 'tool': Tool,
'sighting': Sighting, 'sighting': Sighting,
'stix-extension': STIXExtension,
'vulnerability': Vulnerability, 'vulnerability': Vulnerability,
} }
@ -121,7 +122,7 @@ __all__ = """
TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking, ExternalReference, TLP_AMBER, TLP_GREEN, TLP_RED, TLP_WHITE, CustomMarking, ExternalReference,
GranularMarking, KillChainPhase, LanguageContent, MarkingDefinition, GranularMarking, KillChainPhase, LanguageContent, MarkingDefinition,
StatementMarking, TLPMarking, StatementMarking, STIXExtension, TLPMarking,
URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem, URL, AlternateDataStream, ArchiveExt, Artifact, AutonomousSystem,
CustomExtension, CustomObservable, Directory, DomainName, EmailAddress, CustomExtension, CustomObservable, Directory, DomainName, EmailAddress,

View File

@ -6,7 +6,11 @@ from ..base import (
class _STIXBase21(_STIXBase): class _STIXBase21(_STIXBase):
pass
def __init__(self, **kwargs):
if 'extensions' in self._properties:
self._properties['extensions'].allow_custom = kwargs.get('allow_custom', False)
super(_STIXBase21, self).__init__(**kwargs)
class _Observable(_Observable, _STIXBase21): class _Observable(_Observable, _STIXBase21):

View File

@ -197,12 +197,13 @@ class MarkingDefinition(_STIXBase21, _MarkingsMixin):
('id', IDProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')),
('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')),
('created', TimestampProperty(default=lambda: NOW, precision='millisecond', precision_constraint='min')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond', precision_constraint='min')),
('definition_type', StringProperty(required=True)), ('definition_type', StringProperty()),
('name', StringProperty()), ('name', StringProperty()),
('definition', MarkingProperty(required=True)), ('definition', MarkingProperty()),
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def __init__(self, **kwargs): def __init__(self, **kwargs):

View File

@ -12,9 +12,10 @@ from ..exceptions import (
InvalidValueError, PropertyPresenceError, STIXDeprecationWarning, InvalidValueError, PropertyPresenceError, STIXDeprecationWarning,
) )
from ..properties import ( from ..properties import (
BooleanProperty, EnumProperty, FloatProperty, IDProperty, IntegerProperty, BooleanProperty, EnumProperty, ExtensionsProperty, FloatProperty,
ListProperty, ObservableProperty, PatternProperty, ReferenceProperty, IDProperty, IntegerProperty, ListProperty, ObservableProperty,
StringProperty, TimestampProperty, TypeProperty, PatternProperty, ReferenceProperty, StringProperty, TimestampProperty,
TypeProperty,
) )
from ..utils import NOW from ..utils import NOW
from .base import _DomainObject from .base import _DomainObject
@ -45,6 +46,7 @@ class AttackPattern(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -74,6 +76,7 @@ class Campaign(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -109,6 +112,7 @@ class CourseOfAction(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -136,6 +140,7 @@ class Grouping(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -165,6 +170,7 @@ class Identity(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -197,6 +203,7 @@ class Indicator(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -254,6 +261,7 @@ class Infrastructure(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -296,6 +304,7 @@ class IntrusionSet(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -340,6 +349,7 @@ class Location(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -449,6 +459,7 @@ class Malware(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -504,6 +515,7 @@ class MalwareAnalysis(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -536,6 +548,7 @@ class Note(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -564,6 +577,7 @@ class ObservedData(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -628,6 +642,7 @@ class Opinion(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -656,6 +671,7 @@ class Report(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -692,6 +708,7 @@ class ThreatActor(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
def _check_object_constraints(self): def _check_object_constraints(self):
@ -731,6 +748,7 @@ class Tool(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -756,6 +774,7 @@ class Vulnerability(_DomainObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
@ -807,6 +826,7 @@ def CustomObject(type='x-custom-type', properties=None):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=type)),
], ],
sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0]), sorted([x for x in properties if x[0].startswith('x_')], key=lambda x: x[0]),
])) ]))

View File

@ -3,8 +3,9 @@
from collections import OrderedDict from collections import OrderedDict
from ..properties import ( from ..properties import (
BooleanProperty, IDProperty, IntegerProperty, ListProperty, BooleanProperty, ExtensionsProperty, IDProperty, IntegerProperty,
ReferenceProperty, StringProperty, TimestampProperty, TypeProperty, ListProperty, ReferenceProperty, StringProperty, TimestampProperty,
TypeProperty,
) )
from ..utils import NOW from ..utils import NOW
from .base import _RelationshipObject from .base import _RelationshipObject
@ -39,6 +40,7 @@ class Relationship(_RelationshipObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
# Explicitly define the first three kwargs to make readable Relationship declarations. # Explicitly define the first three kwargs to make readable Relationship declarations.
@ -95,6 +97,7 @@ class Sighting(_RelationshipObject):
('external_references', ListProperty(ExternalReference)), ('external_references', ListProperty(ExternalReference)),
('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))), ('object_marking_refs', ListProperty(ReferenceProperty(valid_types='marking-definition', spec_version='2.1'))),
('granular_markings', ListProperty(GranularMarking)), ('granular_markings', ListProperty(GranularMarking)),
('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)),
]) ])
# Explicitly define the first kwargs to make readable Sighting declarations. # Explicitly define the first kwargs to make readable Sighting declarations.