Skip to content

Commit

Permalink
Restore expressing multiplicity of measurements in Value Triples
Browse files Browse the repository at this point in the history
Fixes #128

Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Oct 1, 2024
1 parent 4830705 commit b39b35d
Show file tree
Hide file tree
Showing 36 changed files with 743 additions and 648 deletions.
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
17 changes: 15 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,21 @@ 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
72 changes: 34 additions & 38 deletions comid/example_cca_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,21 @@ func Example_cca_refval() {
panic(err)
}

// 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 +53,33 @@ 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
45 changes: 28 additions & 17 deletions comid/example_psa_refval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ func Example_psa_refval() {
panic(err)
}

// 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,26 @@ 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

0 comments on commit b39b35d

Please sign in to comment.