Skip to content

Commit

Permalink
Add optional elements to CCA Realm
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed May 28, 2024
1 parent 5a009f3 commit 477e3c9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 25 deletions.
1 change: 1 addition & 0 deletions scheme/cca/test/refval-endorsements.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"scheme": "CCA_SSD",
"subscheme": "CCA_SSD_PLATFORM",
"type":"REFERENCE_VALUE",
"subType": "CCA_SSD.platform-config",
"attributes":{
Expand Down
37 changes: 26 additions & 11 deletions scheme/common/arm/cca/cca_realm_attributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package cca

import (
"errors"
"fmt"
"strings"

Expand All @@ -11,10 +12,10 @@ import (
)

type RealmAttributes struct {
Rim []byte
Rem [4][]byte
Rim *[]byte
Rem [4]*[]byte
HashAlgID string
Rpv []byte
Rpv *[]byte
}

func (o *RealmAttributes) FromMeasurement(m comid.Measurement) error {
Expand All @@ -25,6 +26,9 @@ func (o *RealmAttributes) FromMeasurement(m comid.Measurement) error {
return fmt.Errorf("extracting measurement: %w", err)
}

if err := o.Valid(); err != nil {
return fmt.Errorf("extracting realm attributes: %w", err)
}
return nil
}

Expand Down Expand Up @@ -54,15 +58,15 @@ func (o *RealmAttributes) extractRegisterIndexes(r *comid.IntegrityRegisters) er
switch key {
case "rim":
o.HashAlgID = a
o.Rim = d
*o.Rim = d
case "rem0":
o.Rem[0] = d
*o.Rem[0] = d
case "rem1":
o.Rem[1] = d
*o.Rem[1] = d
case "rem2":
o.Rem[2] = d
*o.Rem[2] = d
case "rem3":
o.Rem[3] = d
*o.Rem[3] = d
default:
return fmt.Errorf("unexpected register index: %s", key)
}
Expand All @@ -83,13 +87,24 @@ func (o *RealmAttributes) extractRealmPersonalizationValue(r *comid.RawValue) er
log.Debug("realm personalization value not present")
return nil
}
o.Rpv, err = r.GetBytes()
*o.Rpv, err = r.GetBytes()
if err != nil {
return err
} else if len(o.Rpv) != 64 {
} else if len(*o.Rpv) != 64 {
{
return fmt.Errorf("invalid length %d, for realm personalization value", len(o.Rpv))
return fmt.Errorf("invalid length %d, for realm personalization value", len(*o.Rpv))
}
}
return nil
}

func (o *RealmAttributes) Valid() error {
if o == nil {
return errors.New("no realm attributes object")
}

if o.Rim == nil {
return errors.New("no realm initial measurements")
}
return nil
}
34 changes: 24 additions & 10 deletions scheme/common/arm/cca/cca_realm_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,30 @@ func makeRefValAttrs(cAttr *ClassAttributes,
rAttr *RealmAttributes) (json.RawMessage, error) {

var attrs = map[string]interface{}{
"CCA_REALM.vendor": cAttr.Vendor,
"CCA_REALM.class-id": cAttr.UUID,
"CCA_REALM.realm-initial-measurement": rAttr.Rim,
"CCA_REALM.hash-alg-id": rAttr.HashAlgID,
"CCA_REALM.realm-personalization-value": rAttr.Rpv,
"CCA_REALM.rim": rAttr.Rim,
"CCA_REALM.rem0": rAttr.Rem[0],
"CCA_REALM.rem1": rAttr.Rem[1],
"CCA_REALM.rem2": rAttr.Rem[2],
"CCA_REALM.rem3": rAttr.Rem[3],
"CCA_REALM.realm-initial-measurement": *rAttr.Rim,
"CCA_REALM.hash-alg-id": rAttr.HashAlgID,
"CCA_REALM.rim": *rAttr.Rim,
}
if rAttr.Rpv != nil {
attrs["CCA_REALM.realm-personalization-value"] = *rAttr.Rpv
}
if cAttr.Vendor != nil {
attrs["CCA_REALM.vendor"] = *cAttr.Vendor
}
if cAttr.UUID != nil {
attrs["CCA_REALM.class-id"] = *cAttr.UUID
}
if rAttr.Rem[0] != nil {
attrs["CCA_REALM.rem0"] = *rAttr.Rem[0]
}
if rAttr.Rem[1] != nil {
attrs["CCA_REALM.rem1"] = *rAttr.Rem[1]
}
if rAttr.Rem[2] != nil {
attrs["CCA_REALM.rem2"] = *rAttr.Rem[2]
}
if rAttr.Rem[3] != nil {
attrs["CCA_REALM.rem3"] = *rAttr.Rem[3]
}

data, err := json.Marshal(attrs)
Expand Down
8 changes: 4 additions & 4 deletions scheme/common/arm/cca/realm_classattributes.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import (
)

type ClassAttributes struct {
UUID string
Vendor string
UUID *string
Vendor *string
}

// extract class variables from environment
Expand All @@ -38,11 +38,11 @@ func (o *ClassAttributes) FromEnvironment(e comid.Environment) error {
return fmt.Errorf("no valid uu-id: %w", err)
}

o.UUID = UUID.String()
*o.UUID = UUID.String()
}

if class.Vendor != nil {
o.Vendor = *class.Vendor
*o.Vendor = *class.Vendor
} else {
return errors.New("class is neither UUID or Vendor Name")
}
Expand Down

0 comments on commit 477e3c9

Please sign in to comment.