From 2bfb83175aa0eb13a4f4a8b87abbc9722ed44e7b Mon Sep 17 00:00:00 2001 From: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Date: Thu, 17 Mar 2022 17:43:01 +0100 Subject: [PATCH 1/5] JSON schema for ROLIE feed - addresses parts of oasis-tcs/csaf#480 - draft first JSON schema for ROLIE feeds --- .../json_schema/ROLIE_feed_json_schema.json | 292 ++++++++++++++++++ 1 file changed, 292 insertions(+) create mode 100644 csaf_2.0/json_schema/ROLIE_feed_json_schema.json diff --git a/csaf_2.0/json_schema/ROLIE_feed_json_schema.json b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json new file mode 100644 index 000000000..c9438396a --- /dev/null +++ b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json @@ -0,0 +1,292 @@ +{ + "$schema": "https://json-schema.org/draft/2020-12/schema", + "$id": "https://raw.githubusercontent.com/oasis-tcs/csaf/master/csaf_2.0/json_schema/ROLIE_feed_json_schema.json", + "title": "ROLIE Feed auxiliary Schema", + "description": "Representation of CSAF ROLIE feed as a JSON document.", + "$defs": { + "json_link_t": { + "title": "JSON Link", + "description": "Contains the URL of the JSON file.", + "type": "string", + "format": "uri", + "pattern": "^https://.+\\.json$" + }, + "link_t": { + "title": "List of Links", + "description": "Contains a list of links related to the current context.", + "type": "array", + "prefixItems": [ + { + "title": "Link", + "description": "Specifies the JSON link.", + "type": "object", + "required": [ + "rel", + "href" + ], + "properties": { + "href": { + "title": "Hyper reference", + "description": "Contains the URL of the JSON file.", + "$ref": "#/$defs/json_link_t" + }, + "rel": { + "title": "Relationship", + "description": "Contains the relationship value of the link.", + "type": "string", + "enum": [ + "self" + ] + } + } + } + ], + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Link", + "description": "Specifies a single link.", + "type": "object", + "required": [ + "rel", + "href" + ], + "properties": { + "href": { + "title": "Hyper reference", + "description": "Contains the URL of the link.", + "type": "string", + "format": "uri" + }, + "rel": { + "title": "Relationship", + "description": "Contains the relationship value of the link.", + "type": "string", + "minLength": 1 + } + } + } + } + }, + "type": "object", + "required": [ + "feed" + ], + "properties": { + "feed": { + "title": "CSAF ROLIE feed", + "description": "Contains all information of the feed.", + "type": "object", + "required": [ + "id", + "title", + "link", + "category", + "updated", + "entry" + ], + "properties": { + "id": { + "title": "ID", + "description": "Contains a unique identifier for this ROLIE feed.", + "type": "string", + "pattern": "^[a-zA-Z0-9+\\-_\\.]+$", + "minLength": 1 + }, + "title": { + "title": "Feed title", + "description": "Contains the title for this ROLIE feed.", + "type": "string", + "minLength": 1 + }, + "link": { + "title": "List of Links", + "description": "Contains a list of links related to this feed.", + "$ref": "#/$defs/link_t" + }, + "category": { + "title": "List of Categories", + "description": "Contains a list of categories related to this feed.", + "type": "array", + "prefixItems": [ + { + "title": "CSAF ROLIE category", + "description": "Contains the required ROLIE category value.", + "type": "object", + "required": [ + "scheme", + "term" + ], + "properties": { + "scheme": { + "title": "Scheme", + "description": "Contains the URI of the scheme to use.", + "type": "string", + "enum": [ + "urn:ietf:params:rolie:category:information-type" + ] + }, + "term": { + "title": "Term", + "description": "Contains the term that is valid in the context of the scheme.", + "type": "string", + "enum": [ + "csaf" + ] + } + } + } + ], + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Category", + "description": "Specifies a single category.", + "type": "object", + "required": [ + "scheme", + "term" + ], + "properties": { + "scheme": { + "title": "Scheme", + "description": "Contains the URI of the scheme to use.", + "type": "string", + "format": "uri" + }, + "term": { + "title": "Term", + "description": "Contains the term that is valid in the context of the scheme.", + "type": "string", + "minLength": 1 + } + } + } + }, + "updated": { + "title": "Updated", + "description": "Contains the date and time this feed was updated the last time.", + "type": "string", + "format": "date-time" + }, + "entry": { + "title": "List of Entries", + "description": "Contains a list of feed entries.", + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "title": "Entry", + "description": "Contains all information for a single feed entry.", + "type": "object", + "required": [ + "id", + "title", + "link", + "published", + "updated", + "content", + "format" + ], + "properties": { + "id": { + "title": "ID", + "description": "Contains the document tracking ID of the CSAF document.", + "type": "string", + "pattern": "^[\\S](.*[\\S])?$", + "minLength": 1 + }, + "title": { + "title": "Title", + "description": "Contains the document title of the CSAF document.", + "type": "string", + "minLength": 1 + }, + "link": { + "title": "List of Links", + "description": "Contains a list of links related to this entry.", + "$ref": "#/$defs/link_t" + }, + "published": { + "title": "Published", + "description": "Contains the date and time this entry was initially added to the feed.", + "type": "string", + "format": "date-time" + }, + "updated": { + "title": "Updated", + "description": "Contains the date and time this entry was the last time updated in the feed.", + "type": "string", + "format": "date-time" + }, + "summary": { + "title": "", + "description": "", + "type": "object", + "properties": { + "content": { + "title": "", + "description": "", + "type": "string", + "minLength": 1 + } + } + }, + "content": { + "title": "Content of the entry", + "description": "Contains information about the content.", + "type": "object", + "required": [ + "type", + "src" + ], + "properties": { + "src": { + "title": "Source Code", + "description": "Contains a link to the source code of the file", + "$ref": "#/$defs/json_link_t" + }, + "type": { + "title": "MIME type", + "description": "Contains the MIME type of the content.", + "type": "string", + "enum": [ + "application/json" + ] + } + } + }, + "format": { + "title": "", + "description": "", + "type": "object", + "required": [ + "schema", + "version" + ], + "properties": { + "schema": { + "title": "Schema of the entry", + "description": "Contains the schema the CSAF document is valid against.", + "type": "string", + "enum": [ + "https://docs.oasis-open.org/csaf/csaf/v2.0/csaf_json_schema.json" + ] + }, + "version": { + "title": "CSAF Version", + "description": "Contains the CSAF version the document was written in.", + "type": "string", + "enum": [ + "2.0" + ] + } + } + } + } + } + } + } + } + } +} \ No newline at end of file From 33d612e2636b3611b2db84d83d6eaa1c2ee7bf41 Mon Sep 17 00:00:00 2001 From: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Date: Thu, 17 Mar 2022 18:14:46 +0100 Subject: [PATCH 2/5] JSON schema for ROLIE feed - addresses parts of oasis-tcs/csaf#480 - update timestamps to conform format "date-time" --- csaf_2.0/examples/ROLIE/example-01-feed-tlp-white.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csaf_2.0/examples/ROLIE/example-01-feed-tlp-white.json b/csaf_2.0/examples/ROLIE/example-01-feed-tlp-white.json index 2467208aa..83b8b156f 100644 --- a/csaf_2.0/examples/ROLIE/example-01-feed-tlp-white.json +++ b/csaf_2.0/examples/ROLIE/example-01-feed-tlp-white.json @@ -14,7 +14,7 @@ "term": "csaf" } ], - "updated": "2021-01-01T12:00Z", + "updated": "2021-01-01T12:00:00Z", "entry": [ { "id": "2020-ESA-001", @@ -33,8 +33,8 @@ "href": "https://psirt.domain.tld/advisories/csaf/2020/2020-ESA-001.json.asc" } ], - "published": "2021-01-01T11:00Z", - "updated": "2021-01-01T12:00Z", + "published": "2021-01-01T11:00:00Z", + "updated": "2021-01-01T12:00:00Z", "summary": { "content": "Vulnerabilities fixed in ABC 0.0.1" }, From 2df1632672001b388925aea606608ec173845a60 Mon Sep 17 00:00:00 2001 From: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Date: Thu, 17 Mar 2022 18:25:20 +0100 Subject: [PATCH 3/5] JSON schema for ROLIE feed - addresses parts of oasis-tcs/csaf#480 - add test for ROLIE feed schema - integrate into GitHub actions --- .github/workflows/main.yml | 3 ++ csaf_2.0/test/ROLIE/feed_schema/run_tests.sh | 43 ++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100755 csaf_2.0/test/ROLIE/feed_schema/run_tests.sh diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 9ea12913b..52caa9e24 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -28,6 +28,8 @@ jobs: run: ./csaf_2.0/test/provider_schema/run_tests.sh - name: Test examples against Aggregator schema run: ./csaf_2.0/test/aggregator_schema/run_tests.sh + - name: Test examples against ROLIE feed schema + run: ./csaf_2.0/test/ROLIE/feed_schema/run_tests.sh - name: Upload strict JSON schema artifact uses: actions/upload-artifact@v2 with: @@ -36,3 +38,4 @@ jobs: csaf_strict_schema.json provider_strict_schema.json aggregator_strict_schema.json + ROLIE_feed_strict_schema.json diff --git a/csaf_2.0/test/ROLIE/feed_schema/run_tests.sh b/csaf_2.0/test/ROLIE/feed_schema/run_tests.sh new file mode 100755 index 000000000..72e916bbe --- /dev/null +++ b/csaf_2.0/test/ROLIE/feed_schema/run_tests.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +ORIG_SCHEMA=csaf_2.0/json_schema/ROLIE_feed_json_schema.json +STRICT_SCHEMA=ROLIE_feed_strict_schema.json +VALIDATOR=csaf_2.0/test/validator.py +STRICT_GENERATOR=csaf_2.0/test/generate_strict_schema.py +TESTPATH=csaf_2.0/examples/ROLIE/*feed*.json + +FAIL=0 + +# go to root of git repository +cd `dirname $0`/../../../.. + +validate() { + printf "%s" "Testing file $1 against schema ${SCHEMA} ... " + if python3 ${VALIDATOR} ${SCHEMA} $1; then + printf "%s\n" SUCCESS + else + printf "%s\n" FAILED + FAIL=1 + fi + +} + +test_all() { + for i in ${TESTPATH} + do + validate $i + done +} + +SCHEMA=${ORIG_SCHEMA} +test_all + + +printf "%s" "Generating strict schema ... " +python3 "${STRICT_GENERATOR}" "${ORIG_SCHEMA}" > "${STRICT_SCHEMA}" +printf "%s\n" "done" + +SCHEMA=${STRICT_SCHEMA} +test_all + +exit ${FAIL} From 91a20ab84a1f2cc6a1b1569dd5fe3d8fd202b73e Mon Sep 17 00:00:00 2001 From: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Date: Wed, 8 Feb 2023 01:05:00 +0100 Subject: [PATCH 4/5] JSON schema for ROLIE feed - addresses parts of oasis-tcs/csaf#480 - entry in ROLIE feeds can be empty (e.g. if it just was created) --- csaf_2.0/json_schema/ROLIE_feed_json_schema.json | 1 - 1 file changed, 1 deletion(-) diff --git a/csaf_2.0/json_schema/ROLIE_feed_json_schema.json b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json index c9438396a..da3a12f41 100644 --- a/csaf_2.0/json_schema/ROLIE_feed_json_schema.json +++ b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json @@ -173,7 +173,6 @@ "title": "List of Entries", "description": "Contains a list of feed entries.", "type": "array", - "minItems": 1, "uniqueItems": true, "items": { "title": "Entry", From 09964cc31d9cc17ddfaf6daa5e819573a2edd748 Mon Sep 17 00:00:00 2001 From: tschmidtb51 <65305130+tschmidtb51@users.noreply.github.com> Date: Wed, 8 Feb 2023 01:07:21 +0100 Subject: [PATCH 5/5] JSON schema for ROLIE feed - addresses parts of oasis-tcs/csaf#480 - add missing titles and descriptions --- csaf_2.0/json_schema/ROLIE_feed_json_schema.json | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/csaf_2.0/json_schema/ROLIE_feed_json_schema.json b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json index da3a12f41..8afe6460e 100644 --- a/csaf_2.0/json_schema/ROLIE_feed_json_schema.json +++ b/csaf_2.0/json_schema/ROLIE_feed_json_schema.json @@ -219,13 +219,13 @@ "format": "date-time" }, "summary": { - "title": "", - "description": "", + "title": "Summary", + "description": "Contains the summary of the CSAF document.", "type": "object", "properties": { "content": { - "title": "", - "description": "", + "title": "Content", + "description": "Contains the actual text of the summary.", "type": "string", "minLength": 1 } @@ -256,8 +256,8 @@ } }, "format": { - "title": "", - "description": "", + "title": "Format", + "description": "Contains information about the format of the entry.", "type": "object", "required": [ "schema", @@ -274,7 +274,7 @@ }, "version": { "title": "CSAF Version", - "description": "Contains the CSAF version the document was written in.", + "description": "Contains the CSAF version the document was written in.", "type": "string", "enum": [ "2.0"