cti-python-stix2/stix2/common.py

54 lines
1.3 KiB
Python
Raw Normal View History

2017-02-10 22:35:02 +01:00
"""STIX 2 Common Data Types and Properties"""
2017-02-15 23:10:30 +01:00
import re
2017-02-10 22:35:02 +01:00
from .base import _STIXBase
from .properties import Property
2017-02-10 22:35:02 +01:00
from .utils import NOW
2017-02-15 23:10:30 +01:00
ref_regex = ("^[a-z][a-z-]+[a-z]--[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}"
"-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}$")
REF_PROPERTY = {
'validate': (lambda x, val: re.match(ref_regex, val)),
'error_msg': "{type} {field} values must consist of a valid STIX type name and a valid UUID, separated by '--'."
}
2017-02-20 22:19:07 +01:00
BOOL_PROPERTY = {
'validate': (lambda x, val: isinstance(val, bool)),
'error_msg': "{type} {field} value must be a boolean."
}
2017-02-10 22:35:02 +01:00
COMMON_PROPERTIES = {
# 'type' and 'id' should be defined on each individual type
2017-02-10 22:35:02 +01:00
'created': {
'default': NOW,
},
'modified': {
'default': NOW,
},
2017-02-24 18:56:55 +01:00
'external_references': {},
2017-02-20 22:19:07 +01:00
'revoked': BOOL_PROPERTY,
2017-02-15 23:10:30 +01:00
'created_by_ref': REF_PROPERTY
2017-02-10 22:35:02 +01:00
}
class ExternalReference(_STIXBase):
_properties = {
'source_name': Property(required=True),
'description': Property(),
'url': Property(),
'external_id': Property(),
2017-02-10 22:35:02 +01:00
}
class KillChainPhase(_STIXBase):
_properties = {
'kill_chain_name': {
'required': True,
},
'phase_name': {
'required': True,
},
}