-
Notifications
You must be signed in to change notification settings - Fork 12
created TLP classes as defined in spec #97
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
Open
anlklsim
wants to merge
9
commits into
StephenOTT:master
Choose a base branch
from
anl-cyberscience:tlp-markings
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
35620c4
created TLP classes as defined in spec
anlklsim f0fb03b
Cleanup to adjust the usage
StephenOTT fa2d4c7
Add static vars for common props
StephenOTT 3962a7b
Add logic to ensure TLP does not have custom props
StephenOTT 7377b11
cleanup spec
StephenOTT 38874d4
Update fake data generator to generate TLPs that match the spec
StephenOTT c53472d
added example bundle with statement and tlp markings and test spec
anlklsim c6da5d5
fixed NPE while testing the TLP bundle spec
anlklsim 99529b4
Merge remote-tracking branch 'origin/tlp-markings' into tlp-markings
anlklsim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
src/main/java/io/digitalstate/stix/datamarkings/objects/Tlps.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| package io.digitalstate.stix.datamarkings.objects; | ||
|
|
||
| import io.digitalstate.stix.common.StixInstant; | ||
| import io.digitalstate.stix.datamarkings.MarkingDefinition; | ||
|
|
||
| public class Tlps { | ||
|
|
||
| public static final MarkingDefinition TLP_WHITE = Tlps.getTlpWhiteMD(); | ||
| public static final MarkingDefinition TLP_GREEN = Tlps.getTlpGreenMD(); | ||
| public static final MarkingDefinition TLP_AMBER = Tlps.getTlpAmberMD(); | ||
| public static final MarkingDefinition TLP_RED = Tlps.getTlpRedMD(); | ||
|
|
||
| public static final String TLP_WHITE_VALUE = "white"; | ||
| public static final String TLP_GREEN_VALUE = "green"; | ||
| public static final String TLP_AMBER_VALUE = "amber"; | ||
| public static final String TLP_RED_VALUE = "red"; | ||
|
|
||
| public static final String TLP_TYPE_VALUE = "tlp"; | ||
|
|
||
|
|
||
| /** | ||
| * Factory methods to create the known types | ||
| */ | ||
| private static MarkingDefinition getTlpWhiteMD() { | ||
| MarkingDefinition.Builder builder = MarkingDefinition.builder() | ||
| .id("marking-definition--613f2e26-407d-48c7-9eca-b8e91df99dc9") | ||
| .definitionType(TLP_TYPE_VALUE) | ||
| .created(StixInstant.parse("2017-01-20T00:00:00.000Z")) | ||
| .definition(Tlp.builder() | ||
| .tlp(TLP_WHITE_VALUE) | ||
| .build()); | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| private static MarkingDefinition getTlpGreenMD() { | ||
| MarkingDefinition.Builder builder = MarkingDefinition.builder() | ||
| .id("marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da") | ||
| .definitionType(TLP_TYPE_VALUE) | ||
| .created(StixInstant.parse("2017-01-20T00:00:00.000Z")) | ||
| .definition(Tlp.builder() | ||
| .tlp(TLP_GREEN_VALUE) | ||
| .build()); | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| private static MarkingDefinition getTlpAmberMD() { | ||
| MarkingDefinition.Builder builder = MarkingDefinition.builder() | ||
| .id("marking-definition--f88d31f6-486f-44da-b317-01333bde0b82") | ||
| .definitionType(TLP_TYPE_VALUE) | ||
| .created(StixInstant.parse("2017-01-20T00:00:00.000Z")) | ||
| .definition(Tlp.builder() | ||
| .tlp(TLP_AMBER_VALUE) | ||
| .build()); | ||
|
|
||
| return builder.build(); | ||
| } | ||
|
|
||
| private static MarkingDefinition getTlpRedMD() { | ||
| MarkingDefinition.Builder builder = MarkingDefinition.builder() | ||
| .id("marking-definition--5e57c739-391a-4eb3-b6be-7d15ca92d5ed") | ||
| .definitionType(TLP_TYPE_VALUE) | ||
| .created(StixInstant.parse("2017-01-20T00:00:00.000Z")) | ||
| .definition(Tlp.builder() | ||
| .tlp(TLP_RED_VALUE) | ||
| .build()); | ||
|
|
||
| return builder.build(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
src/test/groovy/stix/datamarkings/TLPmarkingsSpec.groovy
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,122 @@ | ||
| package stix.datamarkings | ||
|
|
||
| import org.skyscreamer.jsonassert.JSONAssert | ||
| import org.skyscreamer.jsonassert.JSONCompareMode | ||
|
|
||
| import com.fasterxml.jackson.databind.JsonNode | ||
| import com.fasterxml.jackson.databind.ObjectMapper | ||
|
|
||
| import io.digitalstate.stix.bundle.Bundle | ||
| import io.digitalstate.stix.common.StixInstant | ||
| import io.digitalstate.stix.datamarkings.MarkingDefinition | ||
| import io.digitalstate.stix.datamarkings.objects.Tlps | ||
| import io.digitalstate.stix.json.StixParsers | ||
| import io.digitalstate.stix.sdo.objects.Indicator | ||
| import spock.lang.Shared | ||
| import spock.lang.Specification | ||
|
|
||
| class TlpMarkingsSpec extends Specification { | ||
|
|
||
| @Shared | ||
| ObjectMapper mapper = new ObjectMapper() | ||
|
|
||
| def "TLP Defaults Creation Test: WHITE"() { | ||
| when: "Create TLP:white from pre-built TLPs" | ||
|
|
||
| MarkingDefinition originalMarkingDefinition = Tlps.TLP_WHITE | ||
|
|
||
| then: "Convert Marking Definition to Json" | ||
| JsonNode originalJson = mapper.readTree(originalMarkingDefinition.toJsonString()) | ||
| String originalJsonString = mapper.writeValueAsString(originalJson) | ||
| // println "Original Json: ${originalJsonString}" | ||
|
|
||
| then: "Parse Json back into Marking Definition Object" | ||
| MarkingDefinition parsedMarkingDefinition = (MarkingDefinition)StixParsers.parseObject(originalJsonString) | ||
| MarkingDefinition parsedMarkingDefinitionGeneric = StixParsers.parse(originalJsonString, MarkingDefinition.class) | ||
| // println "Parsed Object: ${parsedMarkingDefinition}" | ||
|
|
||
| //@TODO needs to be setup to handle dehydrated object comparison | ||
| // then: "Parsed object should match Original object" | ||
| // assert originalMarkingDefinition == parsedMarkingDefinition | ||
|
|
||
| then: "Convert Parsed Marking Definition Object back to into Json" | ||
| JsonNode newJson = mapper.readTree(parsedMarkingDefinition.toJsonString()) | ||
| String newJsonString = mapper.writeValueAsString(newJson) | ||
| // println "New Json: ${newJsonString}" | ||
|
|
||
| then: "New Json should match Original Json" | ||
| JSONAssert.assertEquals(originalJsonString, newJsonString, JSONCompareMode.NON_EXTENSIBLE) | ||
|
|
||
| } | ||
|
|
||
| def "Test indicator with Default TLP markings"() { | ||
| when: "Create TLP:green" | ||
|
|
||
| MarkingDefinition TlpGreen = Tlps.TLP_GREEN | ||
| StixInstant now = new StixInstant() | ||
|
|
||
| Indicator ind = Indicator.builder() | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Lets move this into a json file similar to the Bundle tests. The current test is basically a duplicate of the mock generation test. The json file tests is a "hardened" data example where the json file represents the "pure" unchanging json to test against |
||
| .id("indicator--59ccb738-921a-4941-8ab2-33da522bd4e1") | ||
| .created(now) | ||
| .modified(now) | ||
| .addLabel("malicious-activity") | ||
| .name("128.0.0.1") | ||
| .pattern("[ipv4-addr:value = '128.0.0.1']") | ||
| .validFrom(now) | ||
| .addObjectMarkingRef(TlpGreen) | ||
| .build() | ||
|
|
||
| then: "Convert Marking Definition to Json" | ||
| JsonNode originalJson = mapper.readTree(ind.toJsonString()) | ||
| String originalJsonString = mapper.writeValueAsString(originalJson) | ||
| // println "Original Json: ${originalJsonString}" | ||
|
|
||
| then: "Parse Json back into Marking Definition Object" | ||
| Indicator parsed = (Indicator)StixParsers.parseObject(originalJsonString) | ||
| Indicator parsedGeneric = StixParsers.parse(originalJsonString, Indicator.class) | ||
| // println "Parsed Object: ${parsed}" | ||
|
|
||
| //@TODO needs to be setup to handle dehydrated object comparison | ||
| // then: "Parsed object should match Original object" | ||
| // assert originalMarkingDefinition == parsedMarkingDefinition | ||
|
|
||
| then: "Convert Parsed Marking Definition Object back to into Json" | ||
| JsonNode newJson = mapper.readTree(parsed.toJsonString()) | ||
| String newJsonString = mapper.writeValueAsString(newJson) | ||
| // println "New Json: ${newJsonString}" | ||
|
|
||
| then: "New Json should match Original Json" | ||
| JSONAssert.assertEquals(originalJsonString, newJsonString, JSONCompareMode.NON_EXTENSIBLE) | ||
|
|
||
| } | ||
|
|
||
| def "bundle with statement and tlp"() { | ||
| when:"setup file access to bundle" | ||
|
|
||
| String bundleJson = getClass() | ||
| .getResource("/stix/baseline/json/sdo/markings/datamarkings.json").getText("UTF-8") | ||
|
|
||
| then: "Parse json into bundle" | ||
| Bundle bundle = (Bundle)StixParsers.parseBundle(bundleJson) | ||
| println bundle.inspect() | ||
| println bundle.toJsonString() | ||
|
|
||
| then: "Convert Bundle to Json" | ||
| JsonNode originalJson = mapper.readTree(bundle.toJsonString()) | ||
| String originalJsonString = mapper.writeValueAsString(originalJson) | ||
| println "Original Json: ${originalJsonString}" | ||
|
|
||
| then: "Parse Json back into Bundle Object" | ||
| Bundle parsed = StixParsers.parseBundle(originalJsonString) | ||
| println "Parsed Object: ${parsed}" | ||
|
|
||
| then: "Convert Parsed Bundlen Object back to into Json" | ||
| JsonNode newJson = mapper.readTree(parsed.toJsonString()) | ||
| String newJsonString = mapper.writeValueAsString(newJson) | ||
| println "New Json: ${newJsonString}" | ||
|
|
||
| then: "New Json should match Original Json" | ||
| JSONAssert.assertEquals(originalJsonString, newJsonString, JSONCompareMode.NON_EXTENSIBLE) | ||
|
|
||
| } | ||
| } | ||
42 changes: 42 additions & 0 deletions
42
src/test/resources/stix/baseline/json/sdo/markings/datamarkings.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| { | ||
| "type": "bundle", | ||
| "id": "bundle--6fab341c-36c5-4a7f-be29-0a6e3b85e7b0", | ||
| "spec_version": "2.0", | ||
| "objects": [ | ||
| { | ||
| "type": "marking-definition", | ||
| "id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", | ||
| "created": "2016-08-01T00:00:00.000Z", | ||
| "definition_type": "statement", | ||
| "definition": { | ||
| "statement": "Copyright 2016, Example Corp" | ||
| } | ||
| }, | ||
| { | ||
| "type": "marking-definition", | ||
| "id": "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", | ||
| "created": "2017-01-20T00:00:00.000Z", | ||
| "definition_type": "tlp", | ||
| "definition": { | ||
| "tlp": "green" | ||
| } | ||
| }, | ||
| { | ||
| "type": "indicator", | ||
| "id": "indicator--59ccb738-921a-4941-8ab2-33da522bd4e1", | ||
| "valid_from": "2019-05-16T14:41:39.655Z", | ||
| "name": "128.0.0.1", | ||
| "created": "2019-05-16T14:41:39.655Z", | ||
| "modified": "2019-05-16T14:41:39.655Z", | ||
| "revoked": false, | ||
| "labels": [ | ||
| "malicious-activity" | ||
| ], | ||
| "pattern": "[ipv4-addr:value = '128.0.0.1']", | ||
| "object_marking_refs": [ | ||
| "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da", | ||
| "marking-definition--34098fce-860f-48ae-8e50-ebd3cc5e41da" | ||
| ] | ||
| } | ||
| ] | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.