Refactor extension properties
to inherit from a base class so all extension classes will include the check for at least one propertystix2.1
parent
0d736509e2
commit
9bc3242736
|
@ -222,3 +222,10 @@ class _Observable(_STIXBase):
|
||||||
elif prop_name.endswith('_refs'):
|
elif prop_name.endswith('_refs'):
|
||||||
for ref in kwargs[prop_name]:
|
for ref in kwargs[prop_name]:
|
||||||
self._check_ref(ref, prop, prop_name)
|
self._check_ref(ref, prop, prop_name)
|
||||||
|
|
||||||
|
|
||||||
|
class _Extension(_STIXBase):
|
||||||
|
|
||||||
|
def _check_object_constraints(self):
|
||||||
|
super(_Extension, self)._check_object_constraints()
|
||||||
|
self._check_at_least_one_property()
|
||||||
|
|
|
@ -5,7 +5,7 @@ embedded in Email Message objects, inherit from _STIXBase instead of Observable
|
||||||
and do not have a '_type' attribute.
|
and do not have a '_type' attribute.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from .base import _Observable, _STIXBase
|
from .base import _Extension, _Observable, _STIXBase
|
||||||
from .exceptions import AtLeastOnePropertyError
|
from .exceptions import AtLeastOnePropertyError
|
||||||
from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
|
from .properties import (BinaryProperty, BooleanProperty, DictionaryProperty,
|
||||||
EmbeddedObjectProperty, EnumProperty,
|
EmbeddedObjectProperty, EnumProperty,
|
||||||
|
@ -113,7 +113,7 @@ class EmailMessage(_Observable):
|
||||||
# self._dependency(["is_multipart"], ["body"], [False])
|
# self._dependency(["is_multipart"], ["body"], [False])
|
||||||
|
|
||||||
|
|
||||||
class ArchiveExt(_STIXBase):
|
class ArchiveExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'contains_refs': ListProperty(ObjectReferenceProperty(valid_types='file'), required=True),
|
'contains_refs': ListProperty(ObjectReferenceProperty(valid_types='file'), required=True),
|
||||||
'version': StringProperty(),
|
'version': StringProperty(),
|
||||||
|
@ -129,18 +129,14 @@ class AlternateDataStream(_STIXBase):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class NTFSExt(_STIXBase):
|
class NTFSExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'sid': StringProperty(),
|
'sid': StringProperty(),
|
||||||
'alternate_data_streams': ListProperty(EmbeddedObjectProperty(type=AlternateDataStream)),
|
'alternate_data_streams': ListProperty(EmbeddedObjectProperty(type=AlternateDataStream)),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _check_object_constraints(self):
|
|
||||||
super(NTFSExt, self)._check_object_constraints()
|
|
||||||
self._check_at_least_one_property()
|
|
||||||
|
|
||||||
|
class PDFExt(_Extension):
|
||||||
class PDFExt(_STIXBase):
|
|
||||||
_properties = {
|
_properties = {
|
||||||
'version': StringProperty(),
|
'version': StringProperty(),
|
||||||
'is_optimized': BooleanProperty(),
|
'is_optimized': BooleanProperty(),
|
||||||
|
@ -149,12 +145,8 @@ class PDFExt(_STIXBase):
|
||||||
'pdfid1': StringProperty(),
|
'pdfid1': StringProperty(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _check_object_constraints(self):
|
|
||||||
super(PDFExt, self)._check_object_constraints()
|
|
||||||
self._check_at_least_one_property()
|
|
||||||
|
|
||||||
|
class RasterImageExt(_Extension):
|
||||||
class RasterImageExt(_STIXBase):
|
|
||||||
_properties = {
|
_properties = {
|
||||||
'image_height': IntegerProperty(),
|
'image_height': IntegerProperty(),
|
||||||
'image_weight': IntegerProperty(),
|
'image_weight': IntegerProperty(),
|
||||||
|
@ -163,10 +155,6 @@ class RasterImageExt(_STIXBase):
|
||||||
'exif_tags': DictionaryProperty(),
|
'exif_tags': DictionaryProperty(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _check_object_constraints(self):
|
|
||||||
super(RasterImageExt, self)._check_object_constraints()
|
|
||||||
self._check_at_least_one_property()
|
|
||||||
|
|
||||||
|
|
||||||
class WindowsPEOptionalHeaderType(_STIXBase):
|
class WindowsPEOptionalHeaderType(_STIXBase):
|
||||||
_properties = {
|
_properties = {
|
||||||
|
@ -217,7 +205,7 @@ class WindowsPESection(_STIXBase):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class WindowsPEBinaryExt(_STIXBase):
|
class WindowsPEBinaryExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'pe_type': StringProperty(required=True), # open_vocab
|
'pe_type': StringProperty(required=True), # open_vocab
|
||||||
'imphash': StringProperty(),
|
'imphash': StringProperty(),
|
||||||
|
@ -299,7 +287,7 @@ class Mutex(_Observable):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class HTTPRequestExt(_STIXBase):
|
class HTTPRequestExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'request_method': StringProperty(required=True),
|
'request_method': StringProperty(required=True),
|
||||||
'request_value': StringProperty(required=True),
|
'request_value': StringProperty(required=True),
|
||||||
|
@ -310,14 +298,14 @@ class HTTPRequestExt(_STIXBase):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class ICMPExt(_STIXBase):
|
class ICMPExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'icmp_type_hex': HexProperty(required=True),
|
'icmp_type_hex': HexProperty(required=True),
|
||||||
'icmp_code_hex': HexProperty(required=True),
|
'icmp_code_hex': HexProperty(required=True),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class SocketExt(_STIXBase):
|
class SocketExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'address_family': EnumProperty([
|
'address_family': EnumProperty([
|
||||||
"AF_UNSPEC",
|
"AF_UNSPEC",
|
||||||
|
@ -350,16 +338,12 @@ class SocketExt(_STIXBase):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class TCPExt(_STIXBase):
|
class TCPExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'src_flags_hex': HexProperty(),
|
'src_flags_hex': HexProperty(),
|
||||||
'dst_flags_hex': HexProperty(),
|
'dst_flags_hex': HexProperty(),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _check_object_constraints(self):
|
|
||||||
super(TCPExt, self)._check_object_constraints()
|
|
||||||
self._check_at_least_one_property()
|
|
||||||
|
|
||||||
|
|
||||||
class NetworkTraffic(_Observable):
|
class NetworkTraffic(_Observable):
|
||||||
_type = 'network-traffic'
|
_type = 'network-traffic'
|
||||||
|
@ -390,7 +374,7 @@ class NetworkTraffic(_Observable):
|
||||||
self._check_at_least_one_property(["src_ref", "dst_ref"])
|
self._check_at_least_one_property(["src_ref", "dst_ref"])
|
||||||
|
|
||||||
|
|
||||||
class WindowsProcessExt(_STIXBase):
|
class WindowsProcessExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'aslr_enabled': BooleanProperty(),
|
'aslr_enabled': BooleanProperty(),
|
||||||
'dep_enabled': BooleanProperty(),
|
'dep_enabled': BooleanProperty(),
|
||||||
|
@ -401,7 +385,7 @@ class WindowsProcessExt(_STIXBase):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class WindowsServiceExt(_STIXBase):
|
class WindowsServiceExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'service_name': StringProperty(required=True),
|
'service_name': StringProperty(required=True),
|
||||||
'descriptions': ListProperty(StringProperty),
|
'descriptions': ListProperty(StringProperty),
|
||||||
|
@ -489,7 +473,7 @@ class URL(_Observable):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class UNIXAccountExt(_STIXBase):
|
class UNIXAccountExt(_Extension):
|
||||||
_properties = {
|
_properties = {
|
||||||
'gid': IntegerProperty(),
|
'gid': IntegerProperty(),
|
||||||
'groups': ListProperty(StringProperty),
|
'groups': ListProperty(StringProperty),
|
||||||
|
|
Loading…
Reference in New Issue