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-04-18 21:19:16 +02:00
|
|
|
"""An invalid value was provided to a STIX object's __init__."""
|
|
|
|
|
|
|
|
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})."
|
2017-04-18 21:41:18 +02:00
|
|
|
return msg.format(self.cls.__name__,
|
2017-05-16 18:27:30 +02:00
|
|
|
", ".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})."
|
2017-04-18 21:56:16 +02:00
|
|
|
return msg.format(self.cls.__name__,
|
2017-05-16 18:27:30 +02:00
|
|
|
", ".join(x for x in self.properties))
|
2017-04-18 22:05:20 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ImmutableError(STIXError, ValueError):
|
|
|
|
"""Attempted to modify an object after creation"""
|
|
|
|
|
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):
|
|
|
|
"""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."
|
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
|
|
|
return msg.format(self.cls.__name__,
|
2017-05-16 18:27:30 +02:00
|
|
|
", ".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."
|
|
|
|
return msg.format(self.cls.__name__,
|
|
|
|
", ".join(x for x in self.dependencies))
|
|
|
|
|
|
|
|
|
|
|
|
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."
|
2017-05-09 21:28:32 +02:00
|
|
|
return msg.format(self.cls.__name__,
|
2017-05-16 18:27:30 +02:00
|
|
|
", ".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):
|
|
|
|
"""Attempted to an operation on a revoked object"""
|
|
|
|
|
|
|
|
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."
|