Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relationship target refs are causing errors on certain IDs. #114

Closed
tigerkatz opened this issue Jun 27, 2018 · 7 comments
Closed

Relationship target refs are causing errors on certain IDs. #114

tigerkatz opened this issue Jun 27, 2018 · 7 comments
Assignees
Labels
Milestone

Comments

@tigerkatz
Copy link

tigerkatz commented Jun 27, 2018

We are working to convert a repository of STIX 1 data to STIX 2 and plan to use the stix2elevator project. We have encountered an issue with some objects using ‘idref’ for objects that are outside of the package, but in the DB. It seems the stix2elevator is replacing these idrefs with a new identifier. Clearly the stix2elevator can not possibly map these IDs as it does not have access to the data outside the package. However, generating new IDs for these unresolvable refs seems like a problem.

This becomes an issue when stix2 IDs are created for relationship references like in stix_convert.py : fix_relationships on line 533:
if reference_needs_fixing(ref["target_ref"]): if not exists_id_key(ref["target_ref"]): new_id = generate_stix20_id(None, str.lower(ref["target_ref"]))
Additionally, our IDs follow the <name space>:<type>-<zero padded integer> pattern rather than the suggested practice of <name space>:<type>-<GUID>. This is causing a None Type Error when the elevator tries to create a stix2 ID for these references in ids.py : generate_stix20_id line 75:
`warn("Malformed id %s. Generated a new uuid", 605, stix12_id)

return stix20_so_name + "--" + text_type(uuid.uuid4())
ETypeError: unsupported operand type(s) for +: 'NoneType' and 'str'`
Thank you.

@rpiazza
Copy link
Contributor

rpiazza commented Jun 28, 2018

You state:

Additionally, our IDs follow the :- pattern rather than the suggested practice of :-

I'm not sure what you are trying to say. Maybe include an example id??

This function assumes ids with a certain pattern. Perhaps you need to special case your code to handle the pattern you use.

@tigerkatz
Copy link
Author

My apologies.

Our IDs follow the ctap:TTP-00000000######## pattern rather than the suggested ctap:TTP-uuid4 pattern.

@rpiazza
Copy link
Contributor

rpiazza commented Jun 28, 2018

@tigerkatz, the STIX 2.0 spec says that an ID must use a uuid:

Identifiers MUST follow the form object-type--UUIDv4, where object-type is the exact value (all type names are lowercase strings, by definition) from the type property of the object being identified or referenced and where the UUIDv4 is an RFC 4122-compliant Version 4 UUID.

Perhaps there is some pre or post processing you can do to associate your STIX 1.x ids with the new valid STIX 2.0 ones?

@gtback
Copy link
Contributor

gtback commented Jun 28, 2018

You state:

Additionally, our IDs follow the :- pattern rather than the suggested practice of :-

I updated the original comment to put backticks (``) around what this was supposed to say:

Additionally, our IDs follow the <name space>:<type>-<zero padded integer> pattern rather than the suggested practice of <name space>:<type>-<GUID>

GitHub's Markdown renderer treats everything between angle brackets (<>) as an "HTML" tag and doesn't show it by default.

@gtback
Copy link
Contributor

gtback commented Jun 28, 2018

We should fix the TypeError caused by the NoneType. More broadly, I can see us doing one or more of the following:

  • Providing a hook/configuration option for you to set a function that gets called to transform a STIX 1.x ID into a 2.x one. We can continue to use the current behavior as a default.
  • Provide an option to write a "ID map" file which maps old IDs to the new generated ones (rather than needing to parse the elevator's entire log file.

@tigerkatz
Copy link
Author

Thank you very much.

Yes, we are working on the pre-processing to re-map the IDs now. As it relates to the generation of new IDs in generate_stix20_id, to pass in a None value assumes that the existing ID follows a suggested practice in Stix1. It would be helpful if there was a way to handle this so that if the regex search in the method fails to extract a value for stix20_so_name from the ID, it would put some string value for stix20_so_name instead of trying to create a string to return with a None value (which causes a Type Error exception). Sorry for the mixup with my previous note here.

@gtback gtback added this to the Version 1.2.0 milestone Jun 28, 2018
@gtback gtback added the bug label Jun 28, 2018
@gtback
Copy link
Contributor

gtback commented Jun 28, 2018

We should definitely fix the bug when you pass in None.

I'm tempted to hold off on the other things for now, since it sounds like you are working on your own methods of addressing that.

Thanks so much for reporting this, @tigerkatz !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants