Skip to content

Commit

Permalink
Merge pull request #64 from casework/use_urirefs_for_facets
Browse files Browse the repository at this point in the history
Use URIRefs for Facets
  • Loading branch information
kchason authored Sep 1, 2022
2 parents faeafe2 + 33ebd89 commit d78453d
Show file tree
Hide file tree
Showing 7 changed files with 304 additions and 288 deletions.
12 changes: 8 additions & 4 deletions case_utils/case_file/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,19 @@ def create_file_node(
:returns: The File Observable Object's node.
:rtype: rdflib.URIRef
"""
node_namespace = rdflib.Namespace(node_prefix)

if node_iri is None:
node_slug = "file-" + case_utils.local_uuid.local_uuid()
node_iri = rdflib.Namespace(node_prefix)[node_slug]
node_iri = node_namespace[node_slug]
n_file = rdflib.URIRef(node_iri)
graph.add((n_file, NS_RDF.type, NS_UCO_OBSERVABLE.File))

basename = os.path.basename(filepath)
literal_basename = rdflib.Literal(basename)

file_stat = os.stat(filepath)
n_file_facet = rdflib.BNode()
n_file_facet = node_namespace["file-facet-" + case_utils.local_uuid.local_uuid()]
graph.add(
(
n_file_facet,
Expand All @@ -119,7 +121,9 @@ def create_file_node(
graph.add((n_file_facet, NS_UCO_OBSERVABLE.modifiedTime, literal_mtime))

if not disable_hashes:
n_contentdata_facet = rdflib.BNode()
n_contentdata_facet = node_namespace[
"content-data-facet-" + case_utils.local_uuid.local_uuid()
]
graph.add((n_file, NS_UCO_CORE.hasFacet, n_contentdata_facet))
graph.add(
(n_contentdata_facet, NS_RDF.type, NS_UCO_OBSERVABLE.ContentDataFacet)
Expand Down Expand Up @@ -191,7 +195,7 @@ def create_file_node(
for key in successful_hashdict._fields:
if key not in ("md5", "sha1", "sha256", "sha512"):
continue
n_hash = rdflib.BNode()
n_hash = node_namespace["hash-" + case_utils.local_uuid.local_uuid()]
graph.add((n_contentdata_facet, NS_UCO_OBSERVABLE.hash, n_hash))
graph.add((n_hash, NS_RDF.type, NS_UCO_TYPES.Hash))
graph.add(
Expand Down
170 changes: 99 additions & 71 deletions tests/case_utils/case_file/kb.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,92 +8,120 @@
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@graph": [
{
"@id": "kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169",
"@type": "uco-observable:ContentDataFacet",
"uco-observable:hash": [
{
"@id": "kb:hash-24644904-83ea-5911-aea8-be687a9f3caf"
},
{
"@id": "kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21"
},
{
"@id": "kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f"
},
{
"@id": "kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932"
}
],
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
},
{
"@id": "kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9",
"@type": "uco-observable:File",
"uco-core:hasFacet": {
"@type": "uco-observable:FileFacet",
"uco-observable:fileName": "sample.txt",
"uco-observable:modifiedTime": {
"@type": "xsd:dateTime",
"@value": "2010-01-02T03:04:56+00:00"
},
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
"@id": "kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d"
}
},
{
"@id": "kb:file-ace6460a-92a9-58b9-83ea-a18ae87f6e04",
"@type": "uco-observable:File",
"uco-core:hasFacet": [
{
"@type": "uco-observable:ContentDataFacet",
"uco-observable:hash": [
{
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "MD5"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "098f6bcd4621d373cade4e832627b4f6"
}
},
{
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA1"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
}
},
{
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA256"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
}
},
{
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA512"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
}
}
],
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
"@id": "kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169"
},
{
"@type": "uco-observable:FileFacet",
"uco-observable:fileName": "sample.txt",
"uco-observable:modifiedTime": {
"@type": "xsd:dateTime",
"@value": "2010-01-02T03:04:56+00:00"
},
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
"@id": "kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10"
}
]
},
{
"@id": "kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10",
"@type": "uco-observable:FileFacet",
"uco-observable:fileName": "sample.txt",
"uco-observable:modifiedTime": {
"@type": "xsd:dateTime",
"@value": "2010-01-02T03:04:56+00:00"
},
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
},
{
"@id": "kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d",
"@type": "uco-observable:FileFacet",
"uco-observable:fileName": "sample.txt",
"uco-observable:modifiedTime": {
"@type": "xsd:dateTime",
"@value": "2010-01-02T03:04:56+00:00"
},
"uco-observable:sizeInBytes": {
"@type": "xsd:integer",
"@value": "4"
}
},
{
"@id": "kb:hash-24644904-83ea-5911-aea8-be687a9f3caf",
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "MD5"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "098f6bcd4621d373cade4e832627b4f6"
}
},
{
"@id": "kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21",
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA1"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"
}
},
{
"@id": "kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f",
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA256"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"
}
},
{
"@id": "kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932",
"@type": "uco-types:Hash",
"uco-types:hashMethod": {
"@type": "uco-vocabulary:HashNameVocab",
"@value": "SHA512"
},
"uco-types:hashValue": {
"@type": "xsd:hexBinary",
"@value": "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"
}
}
]
}
90 changes: 52 additions & 38 deletions tests/case_utils/case_file/kb.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -8,51 +8,65 @@
@prefix uco-vocabulary: <https://ontology.unifiedcyberontology.org/uco/vocabulary/> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .

kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169
a uco-observable:ContentDataFacet ;
uco-observable:hash
kb:hash-24644904-83ea-5911-aea8-be687a9f3caf ,
kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21 ,
kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f ,
kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932
;
uco-observable:sizeInBytes "4"^^xsd:integer ;
.

kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9
a uco-observable:File ;
uco-core:hasFacet [
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
] ;
uco-core:hasFacet kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d ;
.

kb:file-ace6460a-92a9-58b9-83ea-a18ae87f6e04
a uco-observable:File ;
uco-core:hasFacet
[
a uco-observable:ContentDataFacet ;
uco-observable:hash
[
a uco-types:Hash ;
uco-types:hashMethod "MD5"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "098f6bcd4621d373cade4e832627b4f6"^^xsd:hexBinary ;
] ,
[
a uco-types:Hash ;
uco-types:hashMethod "SHA1"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"^^xsd:hexBinary ;
] ,
[
a uco-types:Hash ;
uco-types:hashMethod "SHA256"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"^^xsd:hexBinary ;
] ,
[
a uco-types:Hash ;
uco-types:hashMethod "SHA512"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"^^xsd:hexBinary ;
]
;
uco-observable:sizeInBytes "4"^^xsd:integer ;
] ,
[
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
]
kb:content-data-facet-1833f979-1f19-5543-9d82-6cefd144b169 ,
kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10
;
.

kb:file-facet-1297a4bd-563b-54c3-ad8a-f67f01ba9b10
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
.

kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
.

kb:hash-24644904-83ea-5911-aea8-be687a9f3caf
a uco-types:Hash ;
uco-types:hashMethod "MD5"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "098f6bcd4621d373cade4e832627b4f6"^^xsd:hexBinary ;
.

kb:hash-295bdeb5-7f23-5a3f-8b7f-4bb1191b7c21
a uco-types:Hash ;
uco-types:hashMethod "SHA1"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "a94a8fe5ccb19ba61c4c0873d391e987982fbbd3"^^xsd:hexBinary ;
.

kb:hash-39127f5c-598b-51d4-a720-2e949f18f85f
a uco-types:Hash ;
uco-types:hashMethod "SHA256"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08"^^xsd:hexBinary ;
.

kb:hash-49e81fee-c6b3-5f5f-af8b-0746d32e4932
a uco-types:Hash ;
uco-types:hashMethod "SHA512"^^uco-vocabulary:HashNameVocab ;
uco-types:hashValue "ee26b0dd4af7e749aa1a8ee3c10ae9923f618980772e473f8819a5d4940e0db27ac185f8a0e1d5f84f88bc887fd67b143732c304cc5fa9ad8e6f57f50028a8ff"^^xsd:hexBinary ;
.

14 changes: 8 additions & 6 deletions tests/case_utils/case_file/sample.txt-disable_hashes.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,13 @@

kb:file-800784de-5c9e-5eb2-b843-0ac51a1bd4b9
a uco-observable:File ;
uco-core:hasFacet [
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
] ;
uco-core:hasFacet kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d ;
.

kb:file-facet-ffa3e6bb-dffc-549d-a7c4-ffc5e90ac55d
a uco-observable:FileFacet ;
uco-observable:fileName "sample.txt" ;
uco-observable:modifiedTime "2010-01-02T03:04:56+00:00"^^xsd:dateTime ;
uco-observable:sizeInBytes "4"^^xsd:integer ;
.

Loading

0 comments on commit d78453d

Please sign in to comment.