Skip to content

Commit b11e2b4

Browse files
Add comprehensive CMW example files for issue #24
- Created 6 example CMW files covering different scenarios: * basic-mock-tsm.json - Simple mock TSM example * mock-tsm-with-privilege.json - Mock TSM with privilege level * tsm-report-basic.json - Basic TSM report example * multi-attester.json - Multiple attesters in one CMW * tsm-cbor-format.json - CBOR format example * privilege-level-3.json - Maximum privilege level example - Added comprehensive documentation (README.md) - Included validation script (test-examples.sh) for quality assurance - All examples use proper base64 encoding and CMW structure - Covers both JSON and CBOR content types - Supports mock-tsm and tsm-report attesters Resolves: #24 Signed-off-by: Sukuna0007Abhi <[email protected]>
1 parent deca591 commit b11e2b4

File tree

9 files changed

+319
-0
lines changed

9 files changed

+319
-0
lines changed

examples/IMPLEMENTATION_SUMMARY.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# CMW Examples Implementation Summary
2+
3+
## Overview
4+
This implementation addresses issue #24 "Example CMW Files" by providing comprehensive example files for testing and development with RATSD.
5+
6+
## Files Created
7+
8+
### Example CMW Files
9+
1. **`basic-mock-tsm.json`** - Minimal mock TSM attester example
10+
2. **`mock-tsm-with-privilege.json`** - Mock TSM with privilege level configuration
11+
3. **`tsm-report-basic.json`** - Basic TSM report attester example
12+
4. **`multi-attester.json`** - Multi-attester example with both mock-tsm and tsm-report
13+
5. **`tsm-cbor-format.json`** - TSM report using CBOR content type
14+
6. **`privilege-level-3.json`** - Example showing maximum privilege level
15+
16+
### Documentation and Testing
17+
7. **`README.md`** - Comprehensive documentation explaining CMW structure, usage, and examples
18+
8. **`test-examples.sh`** - Validation script to test JSON validity, CMW structure, and base64 encoding
19+
20+
## Technical Implementation Details
21+
22+
### CMW Structure Compliance
23+
- All examples follow the standard CMW collection format with `__cmwc_t` tag
24+
- Proper content type specifications for each attester type
25+
- Valid base64 encoding for `auxblob` and `outblob` fields
26+
27+
### Attester Coverage
28+
- **Mock TSM**: JSON format with configurable privilege levels
29+
- **TSM Report**: Both JSON and CBOR content types supported
30+
- **Multi-attester**: Demonstrates multiple attesters in single CMW
31+
32+
### Validation Features
33+
- JSON syntax validation
34+
- CMW structure verification
35+
- Base64 encoding validation
36+
- Automated testing script for continuous validation
37+
38+
## Usage Scenarios
39+
40+
### Development Testing
41+
- Mock mode testing without real hardware
42+
- API endpoint validation
43+
- Integration testing scenarios
44+
45+
### Documentation Reference
46+
- Clear examples for developers
47+
- Format specification demonstrations
48+
- Best practices illustration
49+
50+
## Integration with RATSD
51+
52+
### API Compatibility
53+
- Compatible with `/ratsd/chares` endpoint
54+
- Supports attester selection mechanisms
55+
- Works with both `list-options: all` and `list-options: selected` configurations
56+
57+
### Content Type Support
58+
- `application/vnd.veraison.configfs-tsm+json`
59+
- `application/vnd.veraison.configfs-tsm+cbor`
60+
61+
## Quality Assurance
62+
63+
### Testing
64+
- Automated validation script included
65+
- JSON syntax verification
66+
- CMW structure compliance checking
67+
- Base64 encoding validation
68+
69+
### Documentation
70+
- Comprehensive README with usage examples
71+
- Clear structure explanations
72+
- API integration examples
73+
74+
## Benefits for Project
75+
76+
1. **Developer Experience**: Easy to understand examples for new contributors
77+
2. **Testing Infrastructure**: Ready-to-use test data for development
78+
3. **Documentation**: Clear reference for CMW format implementation
79+
4. **Quality**: Automated validation ensures examples remain valid
80+
81+
## Future Enhancements
82+
83+
The examples are designed to be extensible for:
84+
- Additional attester types as they're implemented
85+
- More complex privilege level scenarios
86+
- Extended evidence format variations
87+
- Performance testing scenarios
88+
89+
This implementation provides a solid foundation for issue #24 and supports the broader mock mode functionality being developed in the project.

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)