diff --git a/stix2/custom.py b/stix2/custom.py index 6d1abc5..387906b 100644 --- a/stix2/custom.py +++ b/stix2/custom.py @@ -8,34 +8,12 @@ from .parsing import ( _register_marking, _register_object, _register_observable, _register_observable_extension, ) -from .utils import ( - PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, get_class_hierarchy_names, -) +from .utils import PREFIX_21_REGEX, get_class_hierarchy_names def _custom_object_builder(cls, type, properties, version, base_class): class _CustomObject(cls, base_class): - if version == "2.0": - if not re.match(TYPE_REGEX, type): - raise ValueError( - "Invalid type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-)." % - type, - ) - else: # 2.1+ - if not re.match(TYPE_21_REGEX, type): - raise ValueError( - "Invalid type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-) " - "and must begin with an a-z character" % type, - ) - - if len(type) < 3 or len(type) > 250: - raise ValueError( - "Invalid type name '%s': must be between 3 and 250 characters." % type, - ) - if not properties or not isinstance(properties, list): raise ValueError("Must supply a list, containing tuples. For example, [('property1', IntegerProperty())]") @@ -79,24 +57,6 @@ def _custom_observable_builder(cls, type, properties, version, base_class, id_co class _CustomObservable(cls, base_class): - if version == "2.0": - if not re.match(TYPE_REGEX, type): - raise ValueError( - "Invalid observable type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-)." % - type, - ) - else: # 2.1+ - if not re.match(TYPE_21_REGEX, type): - raise ValueError( - "Invalid observable type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-) " - "and must begin with an a-z character" % type, - ) - - if len(type) < 3 or len(type) > 250: - raise ValueError("Invalid observable type name '%s': must be between 3 and 250 characters." % type) - if not properties or not isinstance(properties, list): raise ValueError("Must supply a list, containing tuples. For example, [('property1', IntegerProperty())]") diff --git a/stix2/parsing.py b/stix2/parsing.py index 7dedc15..f355f41 100644 --- a/stix2/parsing.py +++ b/stix2/parsing.py @@ -7,11 +7,9 @@ import re import stix2 -from .base import _Observable +from .base import _DomainObject, _Observable from .exceptions import ParseError -from .utils import ( - EXT_21_REGEX, PREFIX_21_REGEX, TYPE_21_REGEX, TYPE_REGEX, _get_dict, -) +from .utils import PREFIX_21_REGEX, _get_dict STIX2_OBJ_MAPS = {} @@ -204,6 +202,14 @@ def _register_object(new_type, version=None): """ + if not issubclass(new_type, _DomainObject): + raise ValueError( + "'%s' must be created with the @CustomObject decorator." % + new_type.__name__, + ) + + new_type._properties['type'].clean(new_type._type) + if version: v = 'v' + version.replace('.', '') else: @@ -224,28 +230,6 @@ def _register_marking(new_marking, version=None): """ - type = new_marking._type - - if version == "2.0": - if not re.match(TYPE_REGEX, type): - raise ValueError( - "Invalid marking type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-)." % - type, - ) - else: # 2.1+ - if not re.match(TYPE_21_REGEX, type): - raise ValueError( - "Invalid marking type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-) " - "and must begin with an a-z character" % type, - ) - - if len(type) < 3 or len(type) > 250: - raise ValueError( - "Invalid marking type name '%s': must be between 3 and 250 characters." % type, - ) - properties = new_marking._properties if version == "2.1": @@ -273,6 +257,8 @@ def _register_observable(new_observable, version=None): """ + new_observable._properties['type'].clean(new_observable._type) + if version: v = 'v' + version.replace('.', '') else: @@ -304,26 +290,12 @@ def _register_observable_extension( if not issubclass(obs_class, _Observable): raise ValueError("'observable' must be a valid Observable class!") - if version == "2.0": - if not re.match(TYPE_REGEX, ext_type): - raise ValueError( - "Invalid extension type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, and hyphen (-)." % - ext_type, - ) - else: # 2.1+ - if not re.match(EXT_21_REGEX, ext_type): - raise ValueError( - "Invalid extension type name '%s': must only contain the " - "characters a-z (lowercase ASCII), 0-9, hyphen (-), " - "must begin with an a-z character" - "and end with '-ext'." % ext_type, - ) - - if len(ext_type) < 3 or len(ext_type) > 250: + temp_prop = stix2.properties.TypeProperty(ext_type, spec_version=version) + temp_prop.clean(ext_type) + if not ext_type.endswith('-ext'): raise ValueError( - "Invalid extension type name '%s': must be between 3 and 250" - " characters." % ext_type, + "Invalid extension type name '%s': must end with '-ext'." % + ext_type, ) if not new_extension._properties: diff --git a/stix2/properties.py b/stix2/properties.py index be66533..4ccfa89 100644 --- a/stix2/properties.py +++ b/stix2/properties.py @@ -17,7 +17,10 @@ from .exceptions import ( MutuallyExclusivePropertiesError, ) from .parsing import STIX2_OBJ_MAPS, parse, parse_observable -from .utils import _get_dict, get_class_hierarchy_names, parse_into_datetime +from .utils import ( + TYPE_21_REGEX, TYPE_REGEX, _get_dict, get_class_hierarchy_names, + parse_into_datetime, +) try: from collections.abc import Mapping @@ -232,9 +235,33 @@ class StringProperty(Property): class TypeProperty(Property): - def __init__(self, type): + def __init__(self, type, spec_version=stix2.DEFAULT_VERSION): + self.spec_version = spec_version super(TypeProperty, self).__init__(fixed=type) + def clean(self, value): + if self.spec_version == "2.0": + if not re.match(TYPE_REGEX, type): + raise ValueError( + "Invalid type name '%s': must only contain the " + "characters a-z (lowercase ASCII), 0-9, and hyphen (-)." % + type, + ) + else: # 2.1+ + if not re.match(TYPE_21_REGEX, type): + raise ValueError( + "Invalid type name '%s': must only contain the " + "characters a-z (lowercase ASCII), 0-9, and hyphen (-) " + "and must begin with an a-z character" % type, + ) + + if len(type) < 3 or len(type) > 250: + raise ValueError( + "Invalid type name '%s': must be between 3 and 250 characters." % type, + ) + + return value + class IDProperty(Property): diff --git a/stix2/test/v21/test_custom.py b/stix2/test/v21/test_custom.py index a9969b8..2183d4f 100644 --- a/stix2/test/v21/test_custom.py +++ b/stix2/test/v21/test_custom.py @@ -1186,9 +1186,9 @@ def test_register_custom_object(): class CustomObject2(object): _type = 'awesome-object' - stix2.parsing._register_object(CustomObject2, version="2.1") - # Note that we will always check against newest OBJ_MAP. - assert (CustomObject2._type, CustomObject2) in stix2.v21.OBJ_MAP.items() + with pytest.raises(ValueError) as excinfo: + stix2.parsing._register_object(CustomObject2, version="2.1") + assert '@CustomObject decorator' in str(excinfo) def test_extension_property_location(): diff --git a/stix2/utils.py b/stix2/utils.py index 69489d9..7acf523 100644 --- a/stix2/utils.py +++ b/stix2/utils.py @@ -28,7 +28,6 @@ STIX_UNMOD_PROPERTIES = ['created', 'created_by_ref', 'id', 'type'] TYPE_REGEX = re.compile(r'^\-?[a-z0-9]+(-[a-z0-9]+)*\-?$') TYPE_21_REGEX = re.compile(r'^([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-?$') -EXT_21_REGEX = re.compile(r'^([a-z][a-z0-9]*)+(-[a-z0-9]+)*\-ext$') PREFIX_21_REGEX = re.compile(r'^[a-z].*') diff --git a/stix2/v20/bundle.py b/stix2/v20/bundle.py index b811a79..25b948d 100644 --- a/stix2/v20/bundle.py +++ b/stix2/v20/bundle.py @@ -15,7 +15,7 @@ class Bundle(_STIXBase20): _type = 'bundle' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), # Not technically correct: STIX 2.0 spec doesn't say spec_version must # have this value, but it's all we support for now. diff --git a/stix2/v20/common.py b/stix2/v20/common.py index 55f2c3e..a92f81d 100644 --- a/stix2/v20/common.py +++ b/stix2/v20/common.py @@ -120,7 +120,7 @@ class MarkingDefinition(_STIXBase20, _MarkingsMixin): _type = 'marking-definition' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW)), diff --git a/stix2/v20/observables.py b/stix2/v20/observables.py index eb9bfde..3491c47 100644 --- a/stix2/v20/observables.py +++ b/stix2/v20/observables.py @@ -26,7 +26,7 @@ class Artifact(_Observable): _type = 'artifact' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('mime_type', StringProperty()), ('payload_bin', BinaryProperty()), ('url', StringProperty()), @@ -47,7 +47,7 @@ class AutonomousSystem(_Observable): _type = 'autonomous-system' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('number', IntegerProperty(required=True)), ('name', StringProperty()), ('rir', StringProperty()), @@ -62,7 +62,7 @@ class Directory(_Observable): _type = 'directory' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('path', StringProperty(required=True)), ('path_enc', StringProperty()), # these are not the created/modified timestamps of the object itself @@ -81,7 +81,7 @@ class DomainName(_Observable): _type = 'domain-name' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types=['ipv4-addr', 'ipv6-addr', 'domain-name']))), ('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=_type)), @@ -95,7 +95,7 @@ class EmailAddress(_Observable): _type = 'email-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('display_name', StringProperty()), ('belongs_to_ref', ObjectReferenceProperty(valid_types='user-account')), @@ -127,7 +127,7 @@ class EmailMessage(_Observable): _type = 'email-message' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('is_multipart', BooleanProperty(required=True)), ('date', TimestampProperty()), ('content_type', StringProperty()), @@ -306,7 +306,7 @@ class File(_Observable): _type = 'file' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('hashes', HashesProperty()), ('size', IntegerProperty()), ('name', StringProperty()), @@ -339,7 +339,7 @@ class IPv4Address(_Observable): _type = 'ipv4-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types='mac-addr'))), ('belongs_to_refs', ListProperty(ObjectReferenceProperty(valid_types='autonomous-system'))), @@ -354,7 +354,7 @@ class IPv6Address(_Observable): _type = 'ipv6-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ObjectReferenceProperty(valid_types='mac-addr'))), ('belongs_to_refs', ListProperty(ObjectReferenceProperty(valid_types='autonomous-system'))), @@ -369,7 +369,7 @@ class MACAddress(_Observable): _type = 'mac-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=_type)), ]) @@ -382,7 +382,7 @@ class Mutex(_Observable): _type = 'mutex' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('name', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=_type)), ]) @@ -483,7 +483,7 @@ class NetworkTraffic(_Observable): _type = 'network-traffic' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('start', TimestampProperty()), ('end', TimestampProperty()), ('is_active', BooleanProperty()), @@ -575,7 +575,7 @@ class Process(_Observable): _type = 'process' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('is_hidden', BooleanProperty()), ('pid', IntegerProperty()), ('name', StringProperty()), @@ -615,7 +615,7 @@ class Software(_Observable): _type = 'software' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('name', StringProperty(required=True)), ('cpe', StringProperty()), ('languages', ListProperty(StringProperty)), @@ -632,7 +632,7 @@ class URL(_Observable): _type = 'url' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('value', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=_type)), ]) @@ -659,7 +659,7 @@ class UserAccount(_Observable): _type = 'user-account' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('user_id', StringProperty(required=True)), ('account_login', StringProperty()), ('account_type', StringProperty()), # open vocab @@ -713,7 +713,7 @@ class WindowsRegistryKey(_Observable): _type = 'windows-registry-key' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('key', StringProperty(required=True)), ('values', ListProperty(EmbeddedObjectProperty(type=WindowsRegistryValueType))), # this is not the modified timestamps of the object itself @@ -757,7 +757,7 @@ class X509Certificate(_Observable): _type = 'x509-certificate' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('is_self_signed', BooleanProperty()), ('hashes', HashesProperty()), ('version', StringProperty()), @@ -791,7 +791,7 @@ def CustomObservable(type='x-custom-observable', properties=None): """ def wrapper(cls): _properties = list(itertools.chain.from_iterable([ - [('type', TypeProperty(type))], + [('type', TypeProperty(type, spec_version='2.0'))], properties, [('extensions', ExtensionsProperty(spec_version="2.0", enclosing_type=type))], ])) diff --git a/stix2/v20/sdo.py b/stix2/v20/sdo.py index cb5ba04..8cbd94b 100644 --- a/stix2/v20/sdo.py +++ b/stix2/v20/sdo.py @@ -24,7 +24,7 @@ class AttackPattern(_DomainObject): _type = 'attack-pattern' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -47,7 +47,7 @@ class Campaign(_DomainObject): _type = 'campaign' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -73,7 +73,7 @@ class CourseOfAction(_DomainObject): _type = 'course-of-action' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -95,7 +95,7 @@ class Identity(_DomainObject): _type = 'identity' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -120,7 +120,7 @@ class Indicator(_DomainObject): _type = 'indicator' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -151,7 +151,7 @@ class IntrusionSet(_DomainObject): _type = 'intrusion-set' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -180,7 +180,7 @@ class Malware(_DomainObject): _type = 'malware' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -203,7 +203,7 @@ class ObservedData(_DomainObject): _type = 'observed-data' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -233,7 +233,7 @@ class Report(_DomainObject): _type = 'report' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -257,7 +257,7 @@ class ThreatActor(_DomainObject): _type = 'threat-actor' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -287,7 +287,7 @@ class Tool(_DomainObject): _type = 'tool' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -311,7 +311,7 @@ class Vulnerability(_DomainObject): _type = 'vulnerability' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -358,7 +358,7 @@ def CustomObject(type='x-custom-type', properties=None): def wrapper(cls): _properties = list(itertools.chain.from_iterable([ [ - ('type', TypeProperty(type)), + ('type', TypeProperty(type, spec_version='2.0')), ('id', IDProperty(type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), diff --git a/stix2/v20/sro.py b/stix2/v20/sro.py index b7d1ad3..1372a5e 100644 --- a/stix2/v20/sro.py +++ b/stix2/v20/sro.py @@ -20,7 +20,7 @@ class Relationship(_RelationshipObject): _type = 'relationship' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -59,7 +59,7 @@ class Sighting(_RelationshipObject): _type = 'sighting' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.0')), ('id', IDProperty(_type, spec_version='2.0')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.0')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), diff --git a/stix2/v21/bundle.py b/stix2/v21/bundle.py index ca60fe0..1b8c652 100644 --- a/stix2/v21/bundle.py +++ b/stix2/v21/bundle.py @@ -16,7 +16,7 @@ class Bundle(_STIXBase21): _type = 'bundle' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('objects', ListProperty(STIXObjectProperty(spec_version='2.1'))), ]) diff --git a/stix2/v21/common.py b/stix2/v21/common.py index 4254767..115bdb5 100644 --- a/stix2/v21/common.py +++ b/stix2/v21/common.py @@ -87,7 +87,7 @@ class LanguageContent(_STIXBase21): _type = 'language-content' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -158,7 +158,7 @@ class MarkingDefinition(_STIXBase21, _MarkingsMixin): _type = 'marking-definition' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type)), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), diff --git a/stix2/v21/observables.py b/stix2/v21/observables.py index e71e445..275bbbe 100644 --- a/stix2/v21/observables.py +++ b/stix2/v21/observables.py @@ -29,7 +29,7 @@ class Artifact(_Observable): _type = 'artifact' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('mime_type', StringProperty()), ('payload_bin', BinaryProperty()), @@ -59,7 +59,7 @@ class AutonomousSystem(_Observable): _type = 'autonomous-system' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('number', IntegerProperty(required=True)), ('name', StringProperty()), @@ -81,7 +81,7 @@ class Directory(_Observable): _type = 'directory' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('path', StringProperty(required=True)), ('path_enc', StringProperty()), @@ -107,7 +107,7 @@ class DomainName(_Observable): _type = 'domain-name' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ReferenceProperty(valid_types=['ipv4-addr', 'ipv6-addr', 'domain-name'], spec_version='2.1'))), @@ -128,7 +128,7 @@ class EmailAddress(_Observable): _type = 'email-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('display_name', StringProperty()), @@ -168,7 +168,7 @@ class EmailMessage(_Observable): _type = 'email-message' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('is_multipart', BooleanProperty(required=True)), ('date', TimestampProperty()), @@ -361,7 +361,7 @@ class File(_Observable): _type = 'file' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('hashes', HashesProperty(spec_version='2.1')), ('size', IntegerProperty(min=0)), @@ -397,7 +397,7 @@ class IPv4Address(_Observable): _type = 'ipv4-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ReferenceProperty(valid_types='mac-addr', spec_version='2.1'))), @@ -419,7 +419,7 @@ class IPv6Address(_Observable): _type = 'ipv6-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('resolves_to_refs', ListProperty(ReferenceProperty(valid_types='mac-addr', spec_version='2.1'))), @@ -441,7 +441,7 @@ class MACAddress(_Observable): _type = 'mac-addr' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)), @@ -461,7 +461,7 @@ class Mutex(_Observable): _type = 'mutex' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('name', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)), @@ -586,7 +586,7 @@ class NetworkTraffic(_Observable): _type = 'network-traffic' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('start', TimestampProperty()), ('end', TimestampProperty()), @@ -711,7 +711,7 @@ class Process(_Observable): _type = 'process' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('is_hidden', BooleanProperty()), ('pid', IntegerProperty()), @@ -756,7 +756,7 @@ class Software(_Observable): _type = 'software' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('name', StringProperty(required=True)), ('cpe', StringProperty()), @@ -781,7 +781,7 @@ class URL(_Observable): _type = 'url' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('value', StringProperty(required=True)), ('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=_type)), @@ -816,7 +816,7 @@ class UserAccount(_Observable): _type = 'user-account' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('user_id', StringProperty()), ('credential', StringProperty()), @@ -879,7 +879,7 @@ class WindowsRegistryKey(_Observable): _type = 'windows-registry-key' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('key', StringProperty()), ('values', ListProperty(EmbeddedObjectProperty(type=WindowsRegistryValueType))), @@ -931,7 +931,7 @@ class X509Certificate(_Observable): _type = 'x509-certificate' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('is_self_signed', BooleanProperty()), ('hashes', HashesProperty(spec_version='2.1')), @@ -983,7 +983,7 @@ def CustomObservable(type='x-custom-observable', properties=None, id_contrib_pro """ def wrapper(cls): _properties = list(itertools.chain.from_iterable([ - [('type', TypeProperty(type))], + [('type', TypeProperty(type, spec_version='2.1'))], [('id', IDProperty(type, spec_version='2.1'))], properties, [('extensions', ExtensionsProperty(spec_version='2.1', enclosing_type=type))], diff --git a/stix2/v21/sdo.py b/stix2/v21/sdo.py index 1e9633e..396b030 100644 --- a/stix2/v21/sdo.py +++ b/stix2/v21/sdo.py @@ -29,7 +29,7 @@ class AttackPattern(_DomainObject): _type = 'attack-pattern' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -57,7 +57,7 @@ class Campaign(_DomainObject): _type = 'campaign' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -97,7 +97,7 @@ class CourseOfAction(_DomainObject): _type = 'course-of-action' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -123,7 +123,7 @@ class Grouping(_DomainObject): _type = 'grouping' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -151,7 +151,7 @@ class Identity(_DomainObject): _type = 'identity' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -181,7 +181,7 @@ class Indicator(_DomainObject): _type = 'indicator' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -241,7 +241,7 @@ class Infrastructure(_DomainObject): _type = 'infrastructure' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -282,7 +282,7 @@ class IntrusionSet(_DomainObject): _type = 'intrusion-set' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -325,7 +325,7 @@ class Location(_DomainObject): _type = 'location' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -433,7 +433,7 @@ class Malware(_DomainObject): _type = 'malware' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -486,7 +486,7 @@ class MalwareAnalysis(_DomainObject): _type = 'malware-analysis' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created', TimestampProperty(default=lambda: NOW, precision='millisecond')), @@ -531,7 +531,7 @@ class Note(_DomainObject): _type = 'note' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -559,7 +559,7 @@ class ObservedData(_DomainObject): _type = 'observed-data' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -615,7 +615,7 @@ class Opinion(_DomainObject): _type = 'opinion' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -653,7 +653,7 @@ class Report(_DomainObject): _type = 'report' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -682,7 +682,7 @@ class ThreatActor(_DomainObject): _type = 'threat-actor' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -729,7 +729,7 @@ class Tool(_DomainObject): _type = 'tool' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -759,7 +759,7 @@ class Vulnerability(_DomainObject): _type = 'vulnerability' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -809,7 +809,7 @@ def CustomObject(type='x-custom-type', properties=None): def wrapper(cls): _properties = list(itertools.chain.from_iterable([ [ - ('type', TypeProperty(type)), + ('type', TypeProperty(type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), diff --git a/stix2/v21/sro.py b/stix2/v21/sro.py index 3ffdd77..9f85004 100644 --- a/stix2/v21/sro.py +++ b/stix2/v21/sro.py @@ -21,7 +21,7 @@ class Relationship(_RelationshipObject): _type = 'relationship' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')), @@ -76,7 +76,7 @@ class Sighting(_RelationshipObject): _type = 'sighting' _properties = OrderedDict([ - ('type', TypeProperty(_type)), + ('type', TypeProperty(_type, spec_version='2.1')), ('spec_version', StringProperty(fixed='2.1')), ('id', IDProperty(_type, spec_version='2.1')), ('created_by_ref', ReferenceProperty(valid_types='identity', spec_version='2.1')),