Skip to content

Commit 646c6fb

Browse files
Add comprehensive CMW example files for issue #24
- Created 6 example CMW files covering different scenarios - Added documentation (README.md) explaining structure and usage - Included validation script (test-examples.sh) for quality assurance - All examples use proper base64 encoding and CMW structure - Supports mock-tsm and tsm-report attesters with JSON/CBOR formats Resolves: #24 Signed-off-by: Sukuna0007Abhi <[email protected]>
1 parent deca591 commit 646c6fb

File tree

8 files changed

+230
-0
lines changed

8 files changed

+230
-0
lines changed

examples/cmw/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# CMW Example Files
2+
3+
This directory contains example Conceptual Message Wrapper (CMW) files for testing and development purposes with RATSD.
4+
5+
## File Overview
6+
7+
- **`basic-mock-tsm.json`** - Simple mock TSM attester example with minimal required fields
8+
- **`mock-tsm-with-privilege.json`** - Mock TSM attester with privilege level specified
9+
- **`tsm-report-basic.json`** - Basic TSM report attester example
10+
- **`multi-attester.json`** - Example showing both mock-tsm and tsm-report attesters in one CMW
11+
- **`tsm-cbor-format.json`** - TSM report using CBOR content type instead of JSON
12+
13+
## CMW Structure
14+
15+
All CMW files follow this basic structure:
16+
17+
```json
18+
{
19+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
20+
"<attester-name>": [
21+
"<content-type>",
22+
<evidence-data>
23+
]
24+
}
25+
```
26+
27+
## Available Attesters
28+
29+
### mock-tsm
30+
- **Content Type**: `application/vnd.veraison.configfs-tsm+json`
31+
- **Required Fields**: `auxblob`, `outblob`
32+
- **Optional Fields**: `provider`, `privilege_level` (0-3)
33+
34+
### tsm-report
35+
- **Content Types**:
36+
- `application/vnd.veraison.configfs-tsm+json` (JSON format)
37+
- `application/vnd.veraison.configfs-tsm+cbor` (CBOR format)
38+
- **Required Fields**: `auxblob`, `outblob`
39+
- **Optional Fields**: `provider`, `privilege_level` (0-3)
40+
41+
## Usage with RATSD
42+
43+
These files can be used for testing RATSD in mock mode or as reference for understanding the expected CMW format.
44+
45+
### Testing with curl
46+
47+
```bash
48+
# Basic query (returns all available attesters)
49+
curl -X POST http://localhost:8895/ratsd/chares \
50+
-H "Content-type: application/vnd.veraison.chares+json" \
51+
-d '{"nonce": "TUlEQk5IMjhpaW9pc2pQeXh4eHh4eHh4eHh4eHh4eHhNSURCTkgyOGlpb2lzalB5eHh4eHh4eHh4eHh4eHh4eA"}'
52+
53+
# Query with specific attester selection
54+
curl -X POST http://localhost:8895/ratsd/chares \
55+
-H "Content-type: application/vnd.veraison.chares+json" \
56+
-d '{
57+
"nonce": "TUlEQk5IMjhpaW9pc2pQeXh4eHh4eHh4eHh4eHh4eHhNSURCTkgyOGlpb2lzalB5eHh4eHh4eHh4eHh4eHh4eA",
58+
"attester-selection": {
59+
"mock-tsm": {
60+
"privilege_level": "3"
61+
}
62+
}
63+
}'
64+
```
65+
66+
## Notes
67+
68+
- All `auxblob` and `outblob` values are base64-encoded
69+
- The examples use fake/placeholder data for demonstration purposes
70+
- For CBOR format, the evidence data itself is base64-encoded CBOR
71+
- Privilege levels range from 0 (lowest) to 3 (highest)

examples/cmw/basic-mock-tsm.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"mock-tsm": [
4+
"application/vnd.veraison.configfs-tsm+json",
5+
{
6+
"auxblob": "YVhWNFlteHZZZw==",
7+
"outblob": "cHJpdmlsZWdlLWxldmVsLWJhc2ljLW1vY2stdHNtLWV4YW1wbGUtZGF0YQ==",
8+
"provider": "mock-hardware"
9+
}
10+
]
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"mock-tsm": [
4+
"application/vnd.veraison.configfs-tsm+json",
5+
{
6+
"auxblob": "bW9jay10c20tYXV4LWRhdGE=",
7+
"outblob": "cHJpdmlsZWdlLWxldmVsLXRocmVlLW1vY2stdHNtLWV4YW1wbGUtZGF0YQ==",
8+
"provider": "secure-enclave",
9+
"privilege_level": "3"
10+
}
11+
]
12+
}

examples/cmw/multi-attester.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"mock-tsm": [
4+
"application/vnd.veraison.configfs-tsm+json",
5+
{
6+
"auxblob": "bW9jay10c20tYXV4",
7+
"outblob": "bW9jay10c20tb3V0YmxvYi1kYXRhLWZvci1tdWx0aS1hdHRlc3Rlci1leGFtcGxl",
8+
"provider": "mock-hardware",
9+
"privilege_level": "1"
10+
}
11+
],
12+
"tsm-report": [
13+
"application/vnd.veraison.configfs-tsm+json",
14+
{
15+
"auxblob": "dHNtLXJlcG9ydC1hdXgtbXVsdGk=",
16+
"outblob": "dHNtLXJlcG9ydC1vdXRibG9iLWRhdGEtZm9yLW11bHRpLWF0dGVzdGVyLWV4YW1wbGUtd2l0aC1ib3RoLWF0dGVzdGVycy1wcmVzZW50",
17+
"provider": "real-tsm",
18+
"privilege_level": "2"
19+
}
20+
]
21+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"mock-tsm": [
4+
"application/vnd.veraison.configfs-tsm+json",
5+
{
6+
"auxblob": "cHJpdmlsZWdlLWxldmVsLXRlc3QtYXV4",
7+
"outblob": "cHJpdmlsZWdlLWxldmVsLXRlc3Qtb3V0YmxvYi13aXRoLW1heGltdW0tc2VjdXJpdHktcHJpdmlsZWdlLWxldmVsLTM=",
8+
"provider": "secure-enclave",
9+
"privilege_level": "3",
10+
"description": "Maximum privilege level for secure operations"
11+
}
12+
]
13+
}

examples/cmw/test-examples.sh

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
#!/bin/bash
2+
3+
# Test script for CMW examples
4+
# This script validates that the example CMW files are properly formatted
5+
6+
echo "Testing CMW Example Files..."
7+
echo "================================"
8+
9+
EXAMPLES_DIR="$(dirname "$0")"
10+
FAILED_TESTS=0
11+
12+
# Function to test JSON validity
13+
test_json_validity() {
14+
local file="$1"
15+
echo -n "Testing $file... "
16+
17+
if jq empty "$file" 2>/dev/null; then
18+
echo "✓ Valid JSON"
19+
else
20+
echo "✗ Invalid JSON"
21+
((FAILED_TESTS++))
22+
fi
23+
}
24+
25+
# Function to test CMW structure
26+
test_cmw_structure() {
27+
local file="$1"
28+
echo -n "Testing CMW structure in $file... "
29+
30+
# Check for required __cmwc_t field
31+
if jq -e '.__cmwc_t == "tag:github.com,2025:veraison/ratsd/cmw"' "$file" >/dev/null 2>&1; then
32+
echo "✓ Valid CMW structure"
33+
else
34+
echo "✗ Invalid CMW structure"
35+
((FAILED_TESTS++))
36+
fi
37+
}
38+
39+
# Function to test base64 fields
40+
test_base64_fields() {
41+
local file="$1"
42+
echo -n "Testing base64 fields in $file... "
43+
44+
# Extract all auxblob and outblob values and test if they're valid base64
45+
local base64_valid=true
46+
47+
while IFS= read -r blob; do
48+
if [[ -n "$blob" ]]; then
49+
if ! echo "$blob" | base64 -d >/dev/null 2>&1; then
50+
base64_valid=false
51+
break
52+
fi
53+
fi
54+
done < <(jq -r '.. | select(type == "object") | select(has("auxblob")) | .auxblob, .outblob' "$file" 2>/dev/null)
55+
56+
if $base64_valid; then
57+
echo "✓ Valid base64 encoding"
58+
else
59+
echo "✗ Invalid base64 encoding"
60+
((FAILED_TESTS++))
61+
fi
62+
}
63+
64+
# Test all JSON files in the directory
65+
for file in "$EXAMPLES_DIR"/*.json; do
66+
if [[ -f "$file" ]]; then
67+
echo
68+
echo "Testing $(basename "$file"):"
69+
test_json_validity "$file"
70+
test_cmw_structure "$file"
71+
test_base64_fields "$file"
72+
fi
73+
done
74+
75+
echo
76+
echo "================================"
77+
if [[ $FAILED_TESTS -eq 0 ]]; then
78+
echo "All tests passed! ✓"
79+
exit 0
80+
else
81+
echo "$FAILED_TESTS test(s) failed! ✗"
82+
exit 1
83+
fi

examples/cmw/tsm-cbor-format.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"tsm-report": [
4+
"application/vnd.veraison.configfs-tsm+cbor",
5+
"pGNhdXhqQ0JPUi1hdXgtZGF0YWZvdXRibG9ieFpDQk9SLWVuY29kZWQtdHNtLXJlcG9ydC1kYXRhLWZvci1yYXRzZC1leGFtcGxlLXB1cnBvc2VzLW9ubHktbm90LXJlYWwtZGF0YWhwcm92aWRlcmx0c20tY2Jvci1oYXJkd2FyZW9wcml2aWxlZ2VfbGV2ZWxhMw=="
6+
]
7+
}

examples/cmw/tsm-report-basic.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"__cmwc_t": "tag:github.com,2025:veraison/ratsd/cmw",
3+
"tsm-report": [
4+
"application/vnd.veraison.configfs-tsm+json",
5+
{
6+
"auxblob": "dHNtLXJlcG9ydC1hdXg=",
7+
"outblob": "dHNtLXJlcG9ydC1vdXRibG9iLWRhdGEtZXhhbXBsZS1mb3ItcmF0c2QtZGVtb25zdHJhdGlvbi1wdXJwb3Nlcy1vbmx5LXRoaXMtaXMtbm90LWEtcmVhbC10c20tcmVwb3J0LWJ1dC1hLXNhbXBsZS1mb3ItdGVzdGluZw==",
8+
"provider": "tsm-hardware",
9+
"privilege_level": "0"
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)