Skip to content

Commit

Permalink
Added tools member to stix.common.information_source. Closes #18
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Worrell committed Jun 5, 2013
1 parent 5b10e15 commit 207b68a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 15 deletions.
29 changes: 29 additions & 0 deletions examples/ex_04.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) 2013, The MITRE Corporation. All rights reserved.
# See LICENSE.txt for complete terms.
'''
File: ex_04.py
Description: Build a STIX Document with Tool Information
'''

from stix.core import STIXPackage, STIXHeader
from stix.common import InformationSource
from cybox.common import ToolInformationList, ToolInformation

def main():
stix_package = STIXPackage()
stix_header = STIXHeader()

# Add tool information
stix_header.information_source = InformationSource()
stix_header.information_source.tools = ToolInformationList()
stix_header.information_source.tools.append(ToolInformation("python-stix ex_04.py", "The MITRE Corporation"))

stix_header.description = "Example 04"
stix_package.stix_header = stix_header

print(stix_package.to_xml())
print(stix_package.to_dict())

if __name__ == '__main__':
main()
2 changes: 1 addition & 1 deletion stix/bindings/stix_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ def exportChildren(self, outfile, level, nsmap, namespace_=XML_NS, name_='Inform
if self.Time is not None:
self.Time.export(outfile, level, "%s:" % (nsmap[namespace_]), name_='Time', pretty_print=pretty_print)
if self.Tools is not None:
self.Tools.export(outfile, level, nsmap, namespace_, name_='Tools', pretty_print=pretty_print)
self.Tools.export(outfile, level, "%s:" % (nsmap[namespace_]), name_='Tools', pretty_print=pretty_print)
if self.References is not None:
self.References.export(outfile, level, nsmap, namespace_, name_='References', pretty_print=pretty_print)
def exportLiteral(self, outfile, level, name_='InformationSourceType'):
Expand Down
45 changes: 31 additions & 14 deletions stix/common/information_source.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,19 @@

from stix.extensions.identity import CIQIdentity3_0Instance
from stix.common.identity import Identity
from cybox.common import Time
from cybox.common import Time, ToolInformationList

import cybox.bindings.cybox_common as cybox_common_binding
import stix.bindings.indicator as stix_indicator_binding
import stix.bindings.stix_common as stix_common_binding
import stix.bindings.extensions.identity.ciq_identity_3_0 as ciq_identity_binding



class InformationSource(stix.Entity):
def __init__(self, identity=None, time=None):
def __init__(self, identity=None, time=None, tools=None):
self.identity = identity
#self.contributors = []
self.time = time
#self.tools = []
self.tools = tools
#self.references = []

@property
Expand All @@ -44,13 +42,25 @@ def time(self, value):

self._time = value

@property
def tools(self):
return self._tools

@tools.setter
def tools(self, value):
if value and not isinstance(value, ToolInformationList):
raise ValueError('value must be instance of cybox.common.ToolInformationList')

self._tools = value


def to_obj(self, return_obj=None):
if return_obj == None:
return_obj = stix_common_binding.InformationSourceType()

identity_obj = self.identity.to_obj() if self.identity else None
time_obj = self.time.to_obj() if self.time else None
identity_obj = self.identity.to_obj() if self.identity else None
time_obj = self.time.to_obj() if self.time else None
tools_obj = self.tools.to_obj() if self.tools else None

#=======================================================================
# contributors_obj = stix_common_binding.ContributorsType() if self.contributors else None
Expand All @@ -59,10 +69,6 @@ def to_obj(self, return_obj=None):
# contributors_obj.add_Contributor(contributor_obj)
#
#
# tools_obj = cybox_common_binding.ToolsInformationType() if self.tools else None
# for tool in self.tools:
# tool_obj = tool.to_obj()
# tools_obj.add_Tool(tool_obj)
#
# references_obj = stix_common_binding.ReferencesType() if self.references else None
# for reference in self.references:
Expand All @@ -73,6 +79,7 @@ def to_obj(self, return_obj=None):

return_obj.set_Identity(identity_obj)
return_obj.set_Time(time_obj)
return_obj.set_Tools(tools_obj)
#return_obj.set_Contributors(contributors_obj)
#return_obj.set_Tools(tools_obj)
#return_obj.set_References(references_obj)
Expand All @@ -96,7 +103,10 @@ def from_obj(cls, obj, return_obj=None):

if obj.get_Time():
return_obj.time = Time.from_obj(obj.get_Time())


if obj.get_Tools():
return_obj.tools = ToolInformationList.from_obj(obj.get_Tools())

return return_obj


Expand All @@ -108,8 +118,9 @@ def from_dict(cls, dict_repr, return_obj=None):
if not return_obj:
return_obj = cls()

identity_dict = dict_repr.get('identity', None)
time_dict = dict_repr.get('time', None)
identity_dict = dict_repr.get('identity')
time_dict = dict_repr.get('time')
tools_list = dict_repr.get('tools')

if identity_dict:
xsi_type = identity_dict.get('xsi:type')
Expand All @@ -125,6 +136,9 @@ def from_dict(cls, dict_repr, return_obj=None):
if time_dict:
return_obj.time = Time.from_dict(time_dict)

if tools_list:
return_obj.tools = ToolInformationList.from_list(tools_list)

return return_obj


Expand All @@ -138,6 +152,9 @@ def to_dict(self, return_dict=None):
if self.time:
return_dict['time'] = self.time.to_dict()

if self.tools:
return_dict['tools'] = self.tools.to_list()

return return_dict


Expand Down

0 comments on commit 207b68a

Please sign in to comment.