Skip to content
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

Revert "fix(comid): bring ValueTriple into alignment with rev05" #129

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions cocli/cmd/testcases/src/test-comid.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
0: en-GB
1:
0: !!binary |-
Q7vjfy5hSzOu01PP8UKLFg==
2:
- 0: ACME Ltd.
1:
tag: 32
value: https://acme.example
2:
- 0
- 1
- 2
4:
0:
- - 0:
0:
tag: 600
value: !!binary |-
YWNtZS1pbXBsZW1lbnRhdGlvbi1pZC0wMDAwMDAwMDEK
# acme-implementation-id-000000001
1: ACME
2: RoadRunner
- - 0:
tag: 601
value:
1: BL
4: 2.1.0
5: !!binary |-
rLsRx+TaIXIFUjzkzhokWuGiOa48a/2eeHH35di66Gs=
1:
2:
- - 1
- !!binary |-
h0KPxSKAPTEGXnvOPPA/5HUJZjHl4Hu9eg/eYMTPJcc=
- 0:
tag: 601
value:
1: PRoT
4: 1.3.5
5: !!binary |-
rLsRx+TaIXIFUjzkzhokWuGiOa48a/2eeHH35di66Gs=
1:
2:
- - 1
- !!binary |-
AmOCmYm2/ZVPcrqvL8ZLwuLwHWktTecphuqAj26ZgT8=
- 0:
tag: 601
value:
1: ARoT
4: 0.1.4
5: !!binary |-
rLsRx+TaIXIFUjzkzhokWuGiOa48a/2eeHH35di66Gs=
1:
2:
- - 1
- !!binary |-
o6XnFfDMV0pzw/m+u2vCTzL/1bZ7OHJEwskJ2neaFHg=
Binary file added cocli/cmd/testcases/test-coswid.cbor
Binary file not shown.
18 changes: 10 additions & 8 deletions comid/comid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ func Test_Comid_ToJSONPretty(t *testing.T) {
Environment: Environment{
Instance: MustNewUUIDInstance(TestUUID),
},
Measurement: Measurement{
Measurements: *NewMeasurements().Add(&Measurement{
Val: Mval{
RawValue: NewRawValue().SetBytes(MustHexDecode(t, "deadbeef")),
},
},
}),
}),
}

Expand All @@ -70,14 +70,16 @@ func Test_Comid_ToJSONPretty(t *testing.T) {
"value": "31fb5abf-023e-4992-aa4e-95f9c1503bfa"
}
},
"measurement": {
"value": {
"raw-value": {
"type": "bytes",
"value": "3q2+7w=="
"measurements": [
{
"value": {
"raw-value": {
"type": "bytes",
"value": "3q2+7w=="
}
}
}
}
]
}
]
}
Expand Down
20 changes: 18 additions & 2 deletions comid/example_cca_realm_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,24 @@ func extractRealmRefVal(rv ValueTriple) error {
return fmt.Errorf("extracting realm instanceID: %w", err)
}

if err := extractMeasurement(rv.Measurement); err != nil {
return fmt.Errorf("extracting measurement: %w", err)
measurements := rv.Measurements

if err := extractMeasurements(measurements); err != nil {
return fmt.Errorf("extracting measurements: %w", err)
}

return nil
}

func extractMeasurements(m Measurements) error {
if len(m.Values) == 0 {
return fmt.Errorf("no measurements")
}

for i, meas := range m.Values {
if err := extractMeasurement(meas); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
}

return nil
Expand Down
73 changes: 36 additions & 37 deletions comid/example_cca_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,21 @@ func Example_cca_refval() {
}

// output:
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: BL
//Version: 2.1.0
//Digest: 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: PRoT
//Version: 1.3.5
//Digest: 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: ARoT
//Version: 0.1.4
//Digest: a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//Label: a non-empty (unique) label
//Raw value: 72617776616c75650a72617776616c75650a
// ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: BL
// Version: 2.1.0
// Digest: 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: PRoT
// Version: 1.3.5
// Digest: 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: ARoT
// Version: 0.1.4
// Digest: a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478
// Label: a non-empty (unique) label
// Raw value: 72617776616c75650a72617776616c75650a
}

func extractCcaRefVals(c *Comid) error {
Expand All @@ -57,33 +54,35 @@ func extractCcaRefVals(c *Comid) error {

func extractCCARefVal(rv ValueTriple) error {
class := rv.Environment.Class
m := rv.Measurement

if err := extractImplementationID(class); err != nil {
return fmt.Errorf("extracting impl-id: %w", err)
}

if m.Key == nil {
return fmt.Errorf("missing mKey")
}
if !m.Key.IsSet() {
return fmt.Errorf("mKey not set")
}

switch t := m.Key.Value.(type) {
case *TaggedPSARefValID:
if err := extractSwMeasurement(m); err != nil {
return fmt.Errorf("extracting measurement: %w", err)
for i, m := range rv.Measurements.Values {
if m.Key == nil {
return fmt.Errorf("missing mKey at index %d", i)
}
case *TaggedCCAPlatformConfigID:
if err := extractCCARefValID(m.Key); err != nil {
return fmt.Errorf("extracting cca-refval-id: %w", err)
if !m.Key.IsSet() {
return fmt.Errorf("mKey not set at index %d", i)
}
if err := extractRawValue(m.Val.RawValue); err != nil {
return fmt.Errorf("extracting raw vlue: %w", err)

switch t := m.Key.Value.(type) {
case *TaggedPSARefValID:
if err := extractSwMeasurement(m); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
case *TaggedCCAPlatformConfigID:
if err := extractCCARefValID(m.Key); err != nil {
return fmt.Errorf("extracting cca-refval-id: %w", err)
}
if err := extractRawValue(m.Val.RawValue); err != nil {
return fmt.Errorf("extracting raw vlue: %w", err)
}
default:
return fmt.Errorf("unexpected Mkey type: %T", t)
}
default:
return fmt.Errorf("unexpected Mkey type: %T", t)

}

return nil
Expand Down
46 changes: 30 additions & 16 deletions comid/example_psa_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,19 @@ func Example_psa_refval() {
}

// output:
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: BL
//Version: 2.1.0
//Digest: 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: PRoT
//Version: 1.3.5
//Digest: 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f
//ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
//SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
//Label: ARoT
//Version: 0.1.4
//Digest: a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478
// ImplementationID: 61636d652d696d706c656d656e746174696f6e2d69642d303030303030303031
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: BL
// Version: 2.1.0
// Digest: 87428fc522803d31065e7bce3cf03fe475096631e5e07bbd7a0fde60c4cf25c7
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: PRoT
// Version: 1.3.5
// Digest: 0263829989b6fd954f72baaf2fc64bc2e2f01d692d4de72986ea808f6e99813f
// SignerID: acbb11c7e4da217205523ce4ce1a245ae1a239ae3c6bfd9e7871f7e5d8bae86b
// Label: ARoT
// Version: 0.1.4
// Digest: a3a5e715f0cc574a73c3f9bebb6bc24f32ffd5b67b387244c2c909da779a1478
}

func extractRefVals(c *Comid) error {
Expand All @@ -59,13 +57,29 @@ func extractPSARefVal(rv ValueTriple) error {
return fmt.Errorf("extracting impl-id: %w", err)
}

if err := extractSwMeasurement(rv.Measurement); err != nil {
measurements := rv.Measurements

if err := extractSwMeasurements(measurements); err != nil {
return fmt.Errorf("extracting measurements: %w", err)
}

return nil
}

func extractSwMeasurements(m Measurements) error {
if len(m.Values) == 0 {
return fmt.Errorf("no measurements")
}

for i, m := range m.Values {
if err := extractSwMeasurement(m); err != nil {
return fmt.Errorf("extracting measurement at index %d: %w", i, err)
}
}

return nil
}

func extractSwMeasurement(m Measurement) error {
if err := extractPSARefValID(m.Key); err != nil {
return fmt.Errorf("extracting PSA refval id: %w", err)
Expand Down
Loading
Loading