1# Copyright (c) 2017, The MITRE Corporation. All rights reserved. 2# See LICENSE.txt for complete terms. 3 4from mixbox import fields 5from mixbox.vendor import six 6 7import cybox.bindings.address_object as address_binding 8from cybox.common import ObjectProperties, String, Integer 9 10 11@six.python_2_unicode_compatible 12class Address(ObjectProperties): 13 _binding = address_binding 14 _binding_class = _binding.AddressObjectType 15 _namespace = 'http://cybox.mitre.org/objects#AddressObject-2' 16 _value_field = 'address_value' 17 _XSI_NS = 'AddressObj' 18 _XSI_TYPE = 'AddressObjectType' 19 20 CAT_ASN = "asn" 21 CAT_ATM = "atm" 22 CAT_CIDR = "cidr" 23 CAT_EMAIL = "e-mail" 24 CAT_MAC = "mac" 25 CAT_IPV4 = "ipv4-addr" 26 CAT_IPV4_NET = "ipv4-net" 27 CAT_IPV4_NETMASK = "ipv4-netmask" 28 CAT_IPV6 = "ipv6-addr" 29 CAT_IPV6_NET = "ipv6-net" 30 CAT_IPV6_NETMASK = "ipv6-netmask" 31 32 address_value = fields.TypedField("Address_Value", String) 33 category = fields.TypedField("category") 34 is_destination = fields.TypedField("is_destination") 35 is_source = fields.TypedField("is_source") 36 is_spoofed = fields.TypedField("is_spoofed") 37 vlan_name = fields.TypedField("VLAN_Name", String) 38 vlan_num = fields.TypedField("VLAN_Num", Integer) 39 40 def __init__(self, address_value=None, category=None): 41 super(Address, self).__init__() 42 self.address_value = address_value 43 self.category = category 44 45 def __str__(self): 46 return six.text_type(self.address_value) 47 48 # Shortcuts 49 @property 50 def condition(self): 51 return self.address_value.condition 52 53 @condition.setter 54 def condition(self, value): 55 self.address_value.condition = value 56 57 58class EmailAddress(Address): 59 """Convenience class for creating email addresses. 60 61 Note that this is not an actual CybOX type.""" 62 63 def __init__(self, addr_string=None): 64 super(EmailAddress, self).__init__(addr_string, Address.CAT_EMAIL) 65 66 @classmethod 67 def istypeof(cls, obj): 68 return isinstance(obj, Address) and obj.category == Address.CAT_EMAIL 69