oasis-open / cti-stix-slider

OASIS TC Open Repository: The repository cti-stix-slider supports development of a Python application to convert STIX 2.0 content to STIX 1.x content
https://cti-stix-slider.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
21 stars 15 forks source link

STIX 1.1.1 support #41

Closed yuriyvolkov closed 4 years ago

yuriyvolkov commented 4 years ago

Fix for the following problem: python-stix<1.2 doesn't contain a report module (https://github.com/STIXProject/python-stix/tree/v1.1.1.13/stix) so import fails at https://github.com/oasis-open/cti-stix-slider/blob/v2.0.0/stix2slider/convert_stix.py#L45

rpiazza commented 4 years ago

Hi @yuriyvolkov. This is an excellent addition to the slider. I have a few additional changes in mind - do you want to work on those? If not, I will put them in myself.

For us to include these changes, we need you to sign a CLA with OASIS - the standards organization which has IP rights. Here is the link: https://www.oasis-open.org/resources/open-repositories/cla/individual-cla.

Thanks for your contribution - and ping me when you have signed the CLA.

yuriyvolkov commented 4 years ago

@rpiazza I've signed a CLA with OASIS. Feel free to request additional changes in a PR review as I'm sure my implementation is not really an idiomatic Python :)

yuriyvolkov commented 4 years ago

@rpiazza I've encountered it during test runs on stix2 content, trying to narrow it down to some indicator/whatever right now.

yuriyvolkov commented 4 years ago

@rpiazza here's an exact traceback

[stixmarx.utils] [WARNING] [2019-11-15 14:45:16,290] No module named 'stix.report'
Traceback (most recent call last):
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/bin/stix2_slider", line 11, in <module>
    load_entry_point('stix2-slider==2.0.0', 'console_scripts', 'stix2_slider')()
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2_slider-2.0.0-py3.6.egg/stix2slider/cli.py", line 132, in main
    result = slide_file(slider_args.file_)
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2_slider-2.0.0-py3.6.egg/stix2slider/__init__.py", line 29, in slide_file
    stix_package = convert_bundle(obj)
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2_slider-2.0.0-py3.6.egg/stix2slider/convert_stix.py", line 1209, in convert_bundle
    pkg.add_indicator(convert_indicator(o))
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2_slider-2.0.0-py3.6.egg/stix2slider/convert_stix.py", line 615, in convert_indicator
    add_missing_list_property_to_description(indicator2x, "labels", indicator2x["labels"])
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2_slider-2.0.0-py3.6.egg/stix2slider/convert_stix.py", line 399, in add_missing_list_property_to_description
    obj1x.description = property_name + ": " + ", ".join(property_values)            
  File "/home/dev/projects/src/cti-stix-slider/python/stix-slider-synsec/lib/python3.6/site-packages/stix2-1.2.1-py3.6.egg/stix2/base.py", line 218, in __setattr__
    raise ImmutableError(self.__class__, name)
stix2.exceptions.ImmutableError: Cannot modify 'description' property in 'Indicator' after creation.

and the root cause for this (and possible other errors) is below

            if "labels" in ident2x:
                add_missing_list_property_to_description(ident2x, "labels", ident2x["labels"])
        if "labels" in indicator2x:
            add_missing_list_property_to_description(indicator2x, "labels", indicator2x["labels"])
        if "labels" in indicator2x:
            add_missing_list_property_to_description(indicator2x, "labels", indicator2x["labels"])
        if "labels" in malware2x:
            add_missing_list_property_to_description(malware2x, "labels", malware2x["labels"])
        if "labels" in ta2x:
            add_missing_list_property_to_description(ta2x, "labels", ta2x["labels"])

is that intentional/as designed (i.e. modifying properties of ident2x, indicator2x, malware2x, ta2x) ?

rpiazza commented 4 years ago

Good catch @yuriyvolkov !!!

Yes, if we look at formal parameters of add_missing_list_property_to_description, we see it expects a 1x object in the first argument. Can you make those changes as a part of your PR?

yuriyvolkov commented 4 years ago

@rpiazza done

clenk commented 4 years ago

Thank you for your contribution, @yuriyvolkov!