2017-09-25 22:39:58 +02:00
|
|
|
"""STIX 2 error classes.
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
2017-04-18 21:19:16 +02:00
|
|
|
class STIXError(Exception):
|
|
|
|
"""Base class for errors generated in the stix2 library."""
|
|
|
|
|
|
|
|
|
2017-04-18 21:42:59 +02:00
|
|
|
class InvalidValueError(STIXError, ValueError):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""An invalid value was provided to a STIX object's ``__init__``."""
|
2017-04-18 21:19:16 +02:00
|
|
|
|
|
|
|
def __init__(self, cls, prop_name, reason):
|
2017-04-18 21:42:59 +02:00
|
|
|
super(InvalidValueError, self).__init__()
|
2017-04-18 21:19:16 +02:00
|
|
|
self.cls = cls
|
|
|
|
self.prop_name = prop_name
|
|
|
|
self.reason = reason
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
msg = "Invalid value for {0.cls.__name__} '{0.prop_name}': {0.reason}"
|
|
|
|
return msg.format(self)
|
2017-04-18 21:41:18 +02:00
|
|
|
|
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
class MissingPropertiesError(STIXError, ValueError):
|
2017-05-16 18:27:30 +02:00
|
|
|
"""Missing one or more required properties when constructing STIX object."""
|
2017-04-18 21:41:18 +02:00
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def __init__(self, cls, properties):
|
2017-05-19 19:51:59 +02:00
|
|
|
super(MissingPropertiesError, self).__init__()
|
2017-04-18 21:41:18 +02:00
|
|
|
self.cls = cls
|
2017-05-16 18:27:30 +02:00
|
|
|
self.properties = sorted(list(properties))
|
2017-04-18 21:41:18 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-16 18:27:30 +02:00
|
|
|
msg = "No values for required properties for {0}: ({1})."
|
2018-07-13 17:10:05 +02:00
|
|
|
return msg.format(
|
|
|
|
self.cls.__name__,
|
|
|
|
", ".join(x for x in self.properties),
|
|
|
|
)
|
2017-04-18 21:56:16 +02:00
|
|
|
|
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
class ExtraPropertiesError(STIXError, TypeError):
|
2017-05-16 18:27:30 +02:00
|
|
|
"""One or more extra properties were provided when constructing STIX object."""
|
2017-04-18 21:56:16 +02:00
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def __init__(self, cls, properties):
|
2017-05-19 19:51:59 +02:00
|
|
|
super(ExtraPropertiesError, self).__init__()
|
2017-04-18 21:56:16 +02:00
|
|
|
self.cls = cls
|
2017-05-16 18:27:30 +02:00
|
|
|
self.properties = sorted(list(properties))
|
2017-04-18 21:56:16 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-16 18:27:30 +02:00
|
|
|
msg = "Unexpected properties for {0}: ({1})."
|
2018-07-13 17:10:05 +02:00
|
|
|
return msg.format(
|
|
|
|
self.cls.__name__,
|
|
|
|
", ".join(x for x in self.properties),
|
|
|
|
)
|
2017-04-18 22:05:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ImmutableError(STIXError, ValueError):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Attempted to modify an object after creation."""
|
2017-04-18 22:05:20 +02:00
|
|
|
|
2017-06-01 18:43:06 +02:00
|
|
|
def __init__(self, cls, key):
|
|
|
|
super(ImmutableError, self).__init__()
|
|
|
|
self.cls = cls
|
|
|
|
self.key = key
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-06-02 13:33:31 +02:00
|
|
|
msg = "Cannot modify '{0.key}' property in '{0.cls.__name__}' after creation."
|
2017-06-01 18:43:06 +02:00
|
|
|
return msg.format(self)
|
2017-05-03 20:10:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
class DictionaryKeyError(STIXError, ValueError):
|
|
|
|
"""Dictionary key does not conform to the correct format."""
|
|
|
|
|
|
|
|
def __init__(self, key, reason):
|
|
|
|
super(DictionaryKeyError, self).__init__()
|
|
|
|
self.key = key
|
|
|
|
self.reason = reason
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-09 21:28:32 +02:00
|
|
|
msg = "Invalid dictionary key {0.key}: ({0.reason})."
|
2017-05-03 20:10:10 +02:00
|
|
|
return msg.format(self)
|
2017-05-05 18:32:02 +02:00
|
|
|
|
|
|
|
|
|
|
|
class InvalidObjRefError(STIXError, ValueError):
|
|
|
|
"""A STIX Cyber Observable Object contains an invalid object reference."""
|
|
|
|
|
|
|
|
def __init__(self, cls, prop_name, reason):
|
|
|
|
super(InvalidObjRefError, self).__init__()
|
|
|
|
self.cls = cls
|
|
|
|
self.prop_name = prop_name
|
|
|
|
self.reason = reason
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
msg = "Invalid object reference for '{0.cls.__name__}:{0.prop_name}': {0.reason}"
|
|
|
|
return msg.format(self)
|
2017-05-08 17:11:56 +02:00
|
|
|
|
|
|
|
|
2017-05-03 18:14:09 +02:00
|
|
|
class UnmodifiablePropertyError(STIXError, ValueError):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Attempted to modify an unmodifiable property of object when creating a new version."""
|
2017-05-02 20:06:42 +02:00
|
|
|
|
2017-05-03 18:14:09 +02:00
|
|
|
def __init__(self, unchangable_properties):
|
|
|
|
super(UnmodifiablePropertyError, self).__init__()
|
|
|
|
self.unchangable_properties = unchangable_properties
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
msg = "These properties cannot be changed when making a new version: {0}."
|
|
|
|
return msg.format(", ".join(self.unchangable_properties))
|
|
|
|
|
|
|
|
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
class MutuallyExclusivePropertiesError(STIXError, TypeError):
|
|
|
|
"""Violating interproperty mutually exclusive constraint of a STIX object type."""
|
2017-05-09 21:28:32 +02:00
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def __init__(self, cls, properties):
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
super(MutuallyExclusivePropertiesError, self).__init__()
|
2017-05-09 21:28:32 +02:00
|
|
|
self.cls = cls
|
2017-05-16 18:27:30 +02:00
|
|
|
self.properties = sorted(list(properties))
|
2017-05-09 21:28:32 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-19 19:51:59 +02:00
|
|
|
msg = "The ({1}) properties for {0} are mutually exclusive."
|
2018-07-13 17:10:05 +02:00
|
|
|
return msg.format(
|
|
|
|
self.cls.__name__,
|
|
|
|
", ".join(x for x in self.properties),
|
|
|
|
)
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
|
|
|
|
|
2017-05-19 19:51:59 +02:00
|
|
|
class DependentPropertiesError(STIXError, TypeError):
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
"""Violating interproperty dependency constraint of a STIX object type."""
|
|
|
|
|
|
|
|
def __init__(self, cls, dependencies):
|
2017-05-19 19:51:59 +02:00
|
|
|
super(DependentPropertiesError, self).__init__()
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
self.cls = cls
|
|
|
|
self.dependencies = dependencies
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
msg = "The property dependencies for {0}: ({1}) are not met."
|
2018-07-13 17:10:05 +02:00
|
|
|
return msg.format(
|
|
|
|
self.cls.__name__,
|
|
|
|
", ".join(name for x in self.dependencies for name in x),
|
|
|
|
)
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
class AtLeastOnePropertyError(STIXError, TypeError):
|
|
|
|
"""Violating a constraint of a STIX object type that at least one of the given properties must be populated."""
|
|
|
|
|
2017-05-16 18:27:30 +02:00
|
|
|
def __init__(self, cls, properties):
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
super(AtLeastOnePropertyError, self).__init__()
|
|
|
|
self.cls = cls
|
2017-05-16 18:27:30 +02:00
|
|
|
self.properties = sorted(list(properties))
|
Changes so File object creation doesn't violate on of the MUSTs
Added three new exceptions: DependentPropertiestError, AtLeastOnePropertyError, MutuallyExclusivePropertiesError
Added tests for NetworkTraffic, Process, URL, WindowsRegistryKey and X509Certificate
Added error tests for EmailMessage, NetworkTraffic, Artifact,
Added interproperty checker methods to the base class: _check_mutually_exclusive_properties, _check_at_least_one_property and _check_properties_dependency
Added interproperty checkers to Artifact, EmailMIMEComponent, EmailMessage, NetworkTraffic
Made NetworkTraffic.protocols required
Added X509V3ExtenstionsType class
Use EmbeddedObjectProperty for X509Certificate.x509_v3_extensions
2017-05-11 21:22:46 +02:00
|
|
|
|
|
|
|
def __str__(self):
|
2017-05-19 19:51:59 +02:00
|
|
|
msg = "At least one of the ({1}) properties for {0} must be populated."
|
2018-07-13 17:10:05 +02:00
|
|
|
return msg.format(
|
|
|
|
self.cls.__name__,
|
|
|
|
", ".join(x for x in self.properties),
|
|
|
|
)
|
2017-05-09 21:28:32 +02:00
|
|
|
|
|
|
|
|
2017-05-03 18:14:09 +02:00
|
|
|
class RevokeError(STIXError, ValueError):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Attempted to an operation on a revoked object."""
|
2017-05-03 18:14:09 +02:00
|
|
|
|
|
|
|
def __init__(self, called_by):
|
|
|
|
super(RevokeError, self).__init__()
|
|
|
|
self.called_by = called_by
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
if self.called_by == "revoke":
|
|
|
|
return "Cannot revoke an already revoked object."
|
|
|
|
else:
|
|
|
|
return "Cannot create a new version of a revoked object."
|
2017-06-12 18:54:05 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ParseError(STIXError, ValueError):
|
2017-09-22 17:03:25 +02:00
|
|
|
"""Could not parse object."""
|
2017-06-12 18:54:05 +02:00
|
|
|
|
|
|
|
def __init__(self, msg):
|
|
|
|
super(ParseError, self).__init__(msg)
|
2017-08-17 18:26:46 +02:00
|
|
|
|
|
|
|
|
2018-04-13 17:18:56 +02:00
|
|
|
class CustomContentError(STIXError, ValueError):
|
|
|
|
"""Custom STIX Content (SDO, Observable, Extension, etc.) detected."""
|
|
|
|
|
|
|
|
def __init__(self, msg):
|
|
|
|
super(CustomContentError, self).__init__(msg)
|
|
|
|
|
|
|
|
|
2017-08-24 18:47:14 +02:00
|
|
|
class InvalidSelectorError(STIXError, AssertionError):
|
2017-06-12 14:06:13 +02:00
|
|
|
"""Granular Marking selector violation. The selector must resolve into an existing STIX object property."""
|
|
|
|
|
|
|
|
def __init__(self, cls, key):
|
|
|
|
super(InvalidSelectorError, self).__init__()
|
|
|
|
self.cls = cls
|
|
|
|
self.key = key
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-24 18:47:14 +02:00
|
|
|
msg = "Selector {0} in {1} is not valid!"
|
|
|
|
return msg.format(self.key, self.cls.__class__.__name__)
|
2017-06-12 14:06:13 +02:00
|
|
|
|
|
|
|
|
2017-08-24 18:47:14 +02:00
|
|
|
class MarkingNotFoundError(STIXError, AssertionError):
|
|
|
|
"""Marking violation. The marking reference must be present in SDO or SRO."""
|
2017-06-12 14:06:13 +02:00
|
|
|
|
|
|
|
def __init__(self, cls, key):
|
2017-08-24 18:47:14 +02:00
|
|
|
super(MarkingNotFoundError, self).__init__()
|
2017-06-12 14:06:13 +02:00
|
|
|
self.cls = cls
|
|
|
|
self.key = key
|
|
|
|
|
|
|
|
def __str__(self):
|
2017-08-24 18:47:14 +02:00
|
|
|
msg = "Marking {0} was not found in {1}!"
|
|
|
|
return msg.format(self.key, self.cls.__class__.__name__)
|