From c4c2fb950ec4b58a1d2ace21893c02a1e408bd9b Mon Sep 17 00:00:00 2001 From: Emmanuelle Vargas-Gonzalez Date: Wed, 11 Oct 2017 13:30:26 -0400 Subject: [PATCH] Implement LanguageContent object. Update GranularMarking and other missing properties --- stix2/common.py | 36 ++++++++++++++++++++++++++++++++---- stix2/observables.py | 4 +++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/stix2/common.py b/stix2/common.py index 2946fdc..0d624ff 100644 --- a/stix2/common.py +++ b/stix2/common.py @@ -4,9 +4,10 @@ from collections import OrderedDict from .base import _STIXBase from .markings import _MarkingsMixin -from .properties import (HashesProperty, IDProperty, ListProperty, Property, - ReferenceProperty, SelectorProperty, StringProperty, - TimestampProperty, TypeProperty) +from .properties import (BooleanProperty, DictionaryProperty, HashesProperty, + IDProperty, ListProperty, Property, ReferenceProperty, + SelectorProperty, StringProperty, TimestampProperty, + TypeProperty) from .utils import NOW, get_dict @@ -39,10 +40,37 @@ class GranularMarking(_STIXBase): _properties = OrderedDict() _properties.update([ - ('marking_ref', ReferenceProperty(required=True, type="marking-definition")), + ('lang', StringProperty()), + ('marking_ref', ReferenceProperty(type="marking-definition")), # TODO: In 2.0 is required, not in 2.1 ('selectors', ListProperty(SelectorProperty, required=True)), ]) + def _check_object_constraints(self): + super(GranularMarking, self)._check_object_constraints() + self._check_at_least_one_property(["lang", "marking_ref"]) + + +class LanguageContent(_STIXBase): + _type = 'language-content' + _properties = OrderedDict() + _properties.update([ + ('type', TypeProperty(_type)), + ('id', IDProperty(_type)), + ('created_by_ref', ReferenceProperty(type="identity")), + ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), + ('modified', TimestampProperty(default=lambda: NOW, precision='millisecond')), + ('object_ref', ReferenceProperty(required=True)), + # TODO: 'object_modified' it MUST be an exact match for the modified time of the STIX Object (SRO or SDO) being referenced. + ('object_modified', TimestampProperty(required=True)), + # TODO: 'contents' https://docs.google.com/document/d/1ShNq4c3e1CkfANmD9O--mdZ5H0O_GLnjN28a_yrEaco/edit#heading=h.cfz5hcantmvx + ('contents', DictionaryProperty(required=True)), + ('revoked', BooleanProperty()), + ('labels', ListProperty(StringProperty)), + ('external_references', ListProperty(ExternalReference)), + ('object_marking_refs', ListProperty(ReferenceProperty(type="marking-definition"))), + ('granular_markings', ListProperty(GranularMarking)), + ]) + class TLPMarking(_STIXBase): diff --git a/stix2/observables.py b/stix2/observables.py index 57add29..45c3066 100644 --- a/stix2/observables.py +++ b/stix2/observables.py @@ -98,7 +98,7 @@ class AutonomousSystem(_Observable): _properties = OrderedDict() _properties.update([ ('type', TypeProperty(_type)), - ('number', IntegerProperty()), + ('number', IntegerProperty(required=True)), ('name', StringProperty()), ('rir', StringProperty()), ('extensions', ExtensionsProperty(enclosing_type=_type)), @@ -459,6 +459,8 @@ class SocketExt(_Extension): "SOCK_RDM", "SOCK_SEQPACKET", ])), + ('socket_descriptor', IntegerProperty()), + ('socket_handle', IntegerProperty()) ])