Skip to content

Commit

Permalink
Parsec-TPM and Parsec-CCA and CCA Unit tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Oct 16, 2024
1 parent 4e9bdb7 commit 433c1e3
Show file tree
Hide file tree
Showing 12 changed files with 88 additions and 85 deletions.
75 changes: 38 additions & 37 deletions scheme/common/cca/platform/cca_ssd_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,57 +20,58 @@ type CcaSsdExtractor struct {
func (o CcaSsdExtractor) RefValExtractor(rvs comid.ValueTriples) ([]*handler.Endorsement, error) {
refVals := make([]*handler.Endorsement, 0, len(rvs.Values))

for i, rv := range rvs.Values {
for _, rv := range rvs.Values {
var classAttrs platform.ClassAttributes
var refVal *handler.Endorsement
var err error

if err := classAttrs.FromEnvironment(rv.Environment); err != nil {
return nil, fmt.Errorf("could not extract PSA class attributes: %w", err)
}
for i, m := range rv.Measurements.Values {
if m.Key == nil {
return nil, fmt.Errorf("measurement key is not set at index %d ", i)
}

if rv.Measurement.Key == nil {
return nil, fmt.Errorf("measurement key is not present")
}
if !m.Key.IsSet() {
return nil, fmt.Errorf("measurement key is not set")
}

if !rv.Measurement.Key.IsSet() {
return nil, fmt.Errorf("measurement key is not set")
}
// Check which MKey is present and then decide which extractor to invoke
switch m.Key.Type() {
case comid.PSARefValIDType:
var swCompAttrs platform.SwCompAttributes

// Check which MKey is present and then decide which extractor to invoke
switch rv.Measurement.Key.Type() {
case comid.PSARefValIDType:
var swCompAttrs platform.SwCompAttributes

refVal, err = o.extractMeasurement(
&swCompAttrs,
rv.Measurement,
classAttrs,
)
if err != nil {
refVal, err = o.extractMeasurement(
&swCompAttrs,
m,
classAttrs,
)
if err != nil {
return nil, fmt.Errorf(
"unable to extract measurement at index %d, %w",
i,
err,
)
}
case comid.CCAPlatformConfigIDType:
var ccaPlatformConfigID CCAPlatformConfigID
refVal, err = o.extractMeasurement(
&ccaPlatformConfigID,
m,
classAttrs,
)
if err != nil {
return nil, fmt.Errorf("unable to extract measurement: %w", err)
}
default:
return nil, fmt.Errorf(
"unable to extract measurement at index %d, %w",
i,
err,
"unknown measurement key: %T",
reflect.TypeOf(m.Key),
)
}
case comid.CCAPlatformConfigIDType:
var ccaPlatformConfigID CCAPlatformConfigID
refVal, err = o.extractMeasurement(
&ccaPlatformConfigID,
rv.Measurement,
classAttrs,
)
if err != nil {
return nil, fmt.Errorf("unable to extract measurement: %w", err)
}
default:
return nil, fmt.Errorf(
"unknown measurement key: %T",
reflect.TypeOf(rv.Measurement.Key),
)
refVals = append(refVals, refVal)
}
refVals = append(refVals, refVal)
}

if len(refVals) == 0 {
Expand Down
35 changes: 18 additions & 17 deletions scheme/common/cca/realm/realm_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,24 +40,25 @@ func (o RealmExtractor) RefValExtractor(rvs comid.ValueTriples) ([]*handler.Endo
err,
)
}

if err := rAttr.FromMeasurement(rv.Measurement); err != nil {
return nil, fmt.Errorf(
"unable to extract realm reference attributes from measurement: %w",
err,
)
}
refAttrs, err := makeRefValAttrs(&classAttrs, &rAttr)
if err != nil {
return nil, fmt.Errorf("unable to make reference attributes: %w", err)
}
refVal = &handler.Endorsement{
Scheme: o.Scheme,
Type: handler.EndorsementType_REFERENCE_VALUE,
SubType: rAttr.GetRefValType(),
Attributes: refAttrs,
for _, m := range rv.Measurements.Values {
if err := rAttr.FromMeasurement(m); err != nil {
return nil, fmt.Errorf(
"unable to extract realm reference attributes from measurement: %w",
err,
)
}
refAttrs, err := makeRefValAttrs(&classAttrs, &rAttr)
if err != nil {
return nil, fmt.Errorf("unable to make reference attributes: %w", err)
}
refVal = &handler.Endorsement{
Scheme: o.Scheme,
Type: handler.EndorsementType_REFERENCE_VALUE,
SubType: rAttr.GetRefValType(),
Attributes: refAttrs,
}
refVals = append(refVals, refVal)
}
refVals = append(refVals, refVal)
}

if len(refVals) == 0 {
Expand Down
Binary file not shown.
Binary file not shown.
43 changes: 21 additions & 22 deletions scheme/parsec-tpm/corim_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,39 @@ func (o CorimExtractor) RefValExtractor(
rvs comid.ValueTriples,
) ([]*handler.Endorsement, error) {
refVals := make([]*handler.Endorsement, 0, len(rvs.Values))

for i, rv := range rvs.Values {
for _, rv := range rvs.Values {
var id ID

if err := id.FromEnvironment(rv.Environment); err != nil {
return nil, fmt.Errorf(
"could not extract id from ref-val environment: %w",
err,
)
}

pcr, err := extractPCR(rv.Measurement)
if err != nil {
return nil, fmt.Errorf("could not extract PCR: %w", err)
}

digests, err := extractDigests(rv.Measurement)
if err != nil {
return nil, fmt.Errorf("measurement[%d]: %w", i, err)
}

for j, digest := range digests {
attrs, err := makeRefValAttrs(id.class, pcr, digest)
for i, m := range rv.Measurements.Values {
var refval *handler.Endorsement
pcr, err := extractPCR(m)
if err != nil {
return nil, fmt.Errorf("measurement[%d].digest[%d]: %w", i, j, err)
return nil, fmt.Errorf("could not extract PCR: %w", err)
}

rv := &handler.Endorsement{
Scheme: SchemeName,
Type: handler.EndorsementType_REFERENCE_VALUE,
Attributes: attrs,
digests, err := extractDigests(m)
if err != nil {
return nil, fmt.Errorf("measurement[%d]: %w", i, err)
}

refVals = append(refVals, rv)
for j, digest := range digests {
attrs, err := makeRefValAttrs(id.class, pcr, digest)
if err != nil {
return nil, fmt.Errorf("measurement[%d].digest[%d]: %w", i, j, err)
}

refval = &handler.Endorsement{
Scheme: SchemeName,
Type: handler.EndorsementType_REFERENCE_VALUE,
Attributes: attrs,
}
}
refVals = append(refVals, refval)
}
}

Expand Down
18 changes: 10 additions & 8 deletions scheme/parsec-tpm/test/corim/src/ComidParsecTpmPcrsNoDigests.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,17 @@
}
}
},
"measurement": {
"key": {
"type": "uint",
"value": 0
},
"value": {
"serial-number": "1234"
"measurements": [
{
"key": {
"type": "uint",
"value": 0
},
"value": {
"serial-number": "1234"
}
}
}
]
}
]
}
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion scheme/psa-iot/corim_extractor.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ func (o CorimExtractor) RefValExtractor(rvs comid.ValueTriples) ([]*handler.Endo
default:
return nil, fmt.Errorf("unknown measurement key: %T", reflect.TypeOf(m.Key))
}
refVals = append(refVals, refVal)
}
refVals = append(refVals, refVal)
}

if len(refVals) == 0 {
Expand Down

0 comments on commit 433c1e3

Please sign in to comment.