Skip to content

Commit

Permalink
More cleanup. Fixed some a few VocabString instantiation issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Worrell committed Mar 1, 2015
1 parent 0e7c66d commit 89da4c0
Show file tree
Hide file tree
Showing 40 changed files with 173 additions and 85 deletions.
4 changes: 2 additions & 2 deletions stix/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# See LICENSE.txt for complete terms.

# builtin
import itertools
import json
import collections
import itertools
import StringIO
import json

# external
import lxml.etree
Expand Down
2 changes: 1 addition & 1 deletion stix/common/confidence.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

from __future__ import absolute_import


import stix
import stix.utils as utils
import stix.bindings.stix_common as common_binding

from .structured_text import StructuredText
from .vocabs import VocabString, HighMediumLow


class Confidence(stix.Entity):
_namespace = 'http://stix.mitre.org/common-1'
_binding = common_binding
Expand Down
2 changes: 2 additions & 0 deletions stix/common/datetimewithprecision.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
import stix.utils as utils
import stix.bindings.stix_common as common_binding


DATE_PRECISION_VALUES = ("year", "month", "day")
TIME_PRECISION_VALUES = ("hour", "minute", "second")
DATETIME_PRECISION_VALUES = DATE_PRECISION_VALUES + TIME_PRECISION_VALUES


class DateTimeWithPrecision(stix.Entity):
_binding = common_binding
_binding_class = _binding.DateTimeWithPrecisionType
Expand Down
2 changes: 0 additions & 2 deletions stix/common/identity.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import stix.utils
import stix.bindings.stix_common as common_binding

# import of RelatedIdentity is below


class Identity(stix.Entity):
_binding = common_binding
Expand Down
7 changes: 3 additions & 4 deletions stix/common/information_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
import stix
import stix.utils as utils
import stix.bindings.stix_common as stix_common_binding
from stix.common import VocabString
from stix.common.vocabs import InformationSourceRole
from stix.common import vocabs, VocabString

from .identity import Identity
from .structured_text import StructuredText
Expand Down Expand Up @@ -152,7 +151,7 @@ def add_role(self, value):
elif isinstance(value, VocabString):
self.roles.append(value)
else:
role = InformationSourceRole(value)
role = vocabs.InformationSourceRole(value)
self.roles.append(value=role)

def to_obj(self, return_obj=None, ns_info=None):
Expand Down Expand Up @@ -252,4 +251,4 @@ class Roles(stix.EntityList):
_contained_type = VocabString

def _fix_value(self, value):
return InformationSourceRole(value)
return vocabs.InformationSourceRole(value)
9 changes: 8 additions & 1 deletion stix/common/related.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@

from __future__ import absolute_import

# internal
import stix
import stix.bindings.stix_common as common_binding
import stix.bindings.stix_core as core_binding

# relative
from .vocabs import VocabString
from .information_source import InformationSource
from .confidence import Confidence


class GenericRelationship(stix.Entity):
_namespace = "http://stix.mitre.org/common-1"
_binding = common_binding
Expand Down Expand Up @@ -252,6 +256,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class RelatedPackages(GenericRelationshipList):
_namespace = 'http://stix.mitre.org/stix-1'
_binding = core_binding
Expand All @@ -270,7 +275,6 @@ class RelatedPackageRefs(stix.EntityList):
_inner_name = "packages"



class _BaseRelated(GenericRelationship):
"""A base class for related types.
Expand Down Expand Up @@ -358,20 +362,23 @@ class RelatedCampaign(_BaseRelated):
# _base_type is set in common/__init__.py
_inner_var = "Campaign"


class RelatedCOA(_BaseRelated):
_namespace = "http://stix.mitre.org/common-1"
_binding = common_binding
_binding_class = common_binding.RelatedCourseOfActionType
# _base_type is set in common/__init__.py
_inner_var = "Course_Of_Action"


class RelatedExploitTarget(_BaseRelated):
_namespace = "http://stix.mitre.org/common-1"
_binding = common_binding
_binding_class = common_binding.RelatedExploitTargetType
# _base_type is set in common/__init__.py
_inner_var = "Exploit_Target"


class RelatedIdentity(_BaseRelated):
_namespace = 'http://stix.mitre.org/common-1'
_binding = common_binding
Expand Down
6 changes: 5 additions & 1 deletion stix/common/tools.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

from stix.common import StructuredText
# external
import cybox.common

# internal
from stix.common import StructuredText
import stix.bindings.stix_common as common_binding


class ToolInformation(cybox.common.ToolInformation):
_namespace = 'http://stix.mitre.org/common-1'
_binding = common_binding
Expand Down
2 changes: 2 additions & 0 deletions stix/common/vocabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

import stix
import stix.bindings.stix_common as stix_common_binding


#TODO: handle normalization
#from cybox.utils import normalize_to_xml, denormalize_from_xml

Expand Down
8 changes: 3 additions & 5 deletions stix/core/stix_header.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@
import stix.utils as utils
import stix.bindings.stix_common as stix_common_binding
import stix.bindings.stix_core as stix_core_binding
from stix.common import InformationSource, StructuredText, VocabString
from stix.common import vocabs, InformationSource, StructuredText, VocabString
from stix.data_marking import Marking

from stix.common.vocabs import PackageIntent

class STIXHeader(stix.Entity):
_binding = stix_core_binding
_namespace = 'http://stix.mitre.org/stix-1'
Expand Down Expand Up @@ -111,7 +109,7 @@ def add_package_intent(self, package_intent):
elif isinstance(package_intent, VocabString):
self.package_intents.append(package_intent)
else:
tmp_package_intent = PackageIntent(value=package_intent)
tmp_package_intent = vocabs.PackageIntent(value=package_intent)
self.package_intents.append(tmp_package_intent)

@property
Expand Down Expand Up @@ -217,4 +215,4 @@ class PackageIntents(stix.EntityList):
_contained_type = VocabString

def _fix_value(self, value):
return PackageIntent(value)
return vocabs.PackageIntent(value)
4 changes: 2 additions & 2 deletions stix/core/ttps.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import stix
import stix.utils as utils
from stix.ttp import TTP

import stix.bindings.stix_core as core_binding
from stix.bindings import stix_core as core_binding
from stix.common.kill_chains import KillChains


class TTPs(stix.EntityList):
_binding = core_binding
_binding_class = _binding.TTPsType
Expand Down
1 change: 1 addition & 0 deletions stix/data_marking.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import stix.utils as utils
import stix.bindings.data_marking as stix_data_marking_binding


class Marking(stix.Entity):
_binding = stix_data_marking_binding
_binding_class = stix_data_marking_binding.MarkingType
Expand Down
10 changes: 7 additions & 3 deletions stix/exploit_target/__init__.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# Copyright (c) 2015, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.

# internal
import stix
import stix.utils as utils

import stix.bindings.exploit_target as exploit_target_binding
from stix.common.related import (GenericRelationshipList, RelatedCOA,
RelatedExploitTarget, RelatedPackageRefs)
from stix.common.related import (
GenericRelationshipList, RelatedCOA, RelatedExploitTarget,
RelatedPackageRefs
)
from stix.common import StructuredText, InformationSource
from stix.data_marking import Marking

# relative
from .vulnerability import Vulnerability
from .weakness import Weakness
from .configuration import Configuration
Expand Down
24 changes: 22 additions & 2 deletions stix/extensions/identity/ciq_identity_3_0.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import stix.common as common
import stix.bindings.extensions.identity.ciq_identity_3_0 as ciq_identity_binding


XML_NS_XPIL = "urn:oasis:names:tc:ciq:xpil:3"
XML_NS_XNL = "urn:oasis:names:tc:ciq:xnl:3"
XML_NS_XAL = "urn:oasis:names:tc:ciq:xal:3"
Expand All @@ -18,6 +19,7 @@
et.register_namespace('xal', XML_NS_XAL)
et.register_namespace('ExtSch', XML_NS_STIX_EXT)


class CIQIdentity3_0Instance(common.Identity):
_binding = ciq_identity_binding
_namespace = "http://stix.mitre.org/extensions/Identity#CIQIdentity3.0-1"
Expand Down Expand Up @@ -132,6 +134,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class STIXCIQIdentity3_0(stix.Entity):
_namespace = "http://stix.mitre.org/extensions/Identity#CIQIdentity3.0-1"
XML_TAG = "{%s}Specification" % _namespace
Expand Down Expand Up @@ -391,6 +394,7 @@ def to_dict(self):
d['contact_numbers'] = [x.to_dict() for x in self.contact_numbers]
return d


class Address(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}Address" % _namespace
Expand Down Expand Up @@ -457,6 +461,7 @@ def from_dict(cls, d, return_obj=None):
return_obj.country = Country.from_dict(d.get('country'))
return_obj.administrative_area = AdministrativeArea.from_dict(d.get('administrative_area'))
return return_obj


class AdministrativeArea(stix.Entity):
_namespace = XML_NS_XAL
Expand Down Expand Up @@ -528,6 +533,7 @@ def from_dict(cls, d, return_obj=None):

return_obj.name_elements = [NameElement.from_dict(x) for x in d.get('name_elements', [])]
return return_obj


class Country(stix.Entity):
_namespace = XML_NS_XAL
Expand Down Expand Up @@ -600,6 +606,7 @@ def from_dict(cls, d, return_obj=None):
return_obj.name_elements = [NameElement.from_dict(x) for x in d.get('name_elements', [])]
return return_obj


class NameElement(stix.Entity):
_namespace = XML_NS_XAL
XML_TAG = "{%s}NameElement" % XML_NS_XAL
Expand Down Expand Up @@ -638,6 +645,7 @@ def from_dict(cls, d):
return_obj.value = d.get('value')
return return_obj


class FreeTextAddress(stix.Entity):
_namespace = XML_NS_XAL
XML_TAG = "{%s}FreeTextAddress" % XML_NS_XAL
Expand Down Expand Up @@ -702,7 +710,8 @@ def to_dict(self):
if self.address_lines:
d['address_lines'] = self.address_lines
return d



class PartyName(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}PartyName" % _namespace
Expand Down Expand Up @@ -837,6 +846,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class NameLine(stix.Entity):
_namespace = XML_NS_XNL
XML_TAG = "{%s}NameLine" % _namespace
Expand Down Expand Up @@ -907,6 +917,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class PersonName(stix.Entity):
_namespace = XML_NS_XNL
XML_TAG = "{%s}PersonName" % _namespace
Expand Down Expand Up @@ -979,6 +990,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class OrganisationName(stix.Entity):
_namespace = XML_NS_XNL
XML_TAG = "{%s}OrganisationName" % _namespace
Expand Down Expand Up @@ -1142,6 +1154,7 @@ def to_dict(self, d):
d['value'] = self.value
return d


class PersonNameElement(_BaseNameElement):
_namespace = XML_NS_XNL
XML_TAG = "{%s}NameElement" % _namespace
Expand Down Expand Up @@ -1225,6 +1238,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class OrganisationNameElement(_BaseNameElement):
_namespace = XML_NS_XNL
XML_TAG = "{%s}NameElement" % _namespace
Expand Down Expand Up @@ -1299,6 +1313,7 @@ def from_dict(cls, dict_repr, return_obj=None):

return return_obj


class SubDivisionName(stix.Entity):
_namespace = XML_NS_XNL
XML_TAG = "{%s}SubDivisionName" % _namespace
Expand Down Expand Up @@ -1374,6 +1389,7 @@ def from_dict(cls, dict_repr, return_obj=None):
return_obj.type = dict_repr.get('type')
return return_obj


class Language(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}Language" % _namespace
Expand Down Expand Up @@ -1411,6 +1427,7 @@ def from_dict(cls, d):
return_obj = cls()
return_obj.value = d.get('value')
return return_obj


class ElectronicAddressIdentifier(stix.Entity):
_namespace = XML_NS_XPIL
Expand Down Expand Up @@ -1459,6 +1476,7 @@ def from_dict(cls, d):
return_obj.type_ = d.get('type')
return return_obj


class OrganisationInfo(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}OrganisationInfo" % _namespace
Expand Down Expand Up @@ -1547,6 +1565,7 @@ def from_dict(cls, d):
return_obj.value = d.get('value')
return return_obj


class ContactNumber(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}ContactNumber" % _namespace
Expand Down Expand Up @@ -1643,7 +1662,8 @@ def from_dict(cls, d):
return_obj.contact_number_elements = [ContactNumberElement.from_dict(x) for x in d.get('contact_number_elements', [])]

return return_obj



class ContactNumberElement(stix.Entity):
_namespace = XML_NS_XPIL
XML_TAG = "{%s}ContactNumberElement" % _namespace
Expand Down

0 comments on commit 89da4c0

Please sign in to comment.