Skip to content

Commit

Permalink
chg: my AWS free trial ended. Add try run.
Browse files Browse the repository at this point in the history
  • Loading branch information
FloatingGhost committed Oct 20, 2017
1 parent 5428231 commit c0d3c0b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
18 changes: 11 additions & 7 deletions misp_stix_converter/converters/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,20 @@ def STIXtoMISP(stix, mispAPI, **kwargs):
log.debug("Encoding to b64...")
b64Pkg = base64.b64encode(stixPackage.to_xml()).decode("utf-8")
log.debug("Attaching original document...")

misp_event.add_attribute(type="attachment", value=filename, data=b64Pkg)

if misp_event.attributes:
log.debug("Attributes exist. Pushing...")
response = mispAPI.add_event(json.dumps(misp_event, cls=MISPEncode))
if response.get('errors'):
raise Exception("PACKAGE: {}\nERROR: {}".format(
json.dumps(misp_event, cls=MISPEncode),
response.get('errors')))

return response
if mispAPI:
response = mispAPI.add_event(json.dumps(misp_event, cls=MISPEncode))
if response.get('errors'):
raise Exception("PACKAGE: {}\nERROR: {}".format(
json.dumps(misp_event, cls=MISPEncode),
response.get('errors')))

return response
else:
return True # Dry run
else:
log.warning("No attributes found, ignoring.")
3 changes: 1 addition & 2 deletions tests/test_stix-to-misp.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
def test_convert():
# This is a public MISP instance.
# Just running on AWS, nothing particularly interesting.
mispAPI = misp.MISP("http://35.163.95.230", "pF4Rq3JOHbYAJLMiFDqRPpLxAh3s0PakiSPKWSN5")
test_files = glob.glob("test_files/*.xml")
for test_file in test_files:
with open(test_file, "r") as f:
convert.STIXtoMISP(f.read(), mispAPI.mispAPI)
convert.STIXtoMISP(f.read(), None)

0 comments on commit c0d3c0b

Please sign in to comment.