-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding Realm Endorsement Decoder Plugin
Signed-off-by: Yogesh Deshpande <[email protected]>
- Loading branch information
1 parent
ee62874
commit 74b8a5e
Showing
5 changed files
with
138 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2022-2023 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package cca_realm | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/veraison/corim/comid" | ||
) | ||
|
||
type ClassAttributes struct { | ||
UUID string | ||
Vendor string | ||
Model string | ||
} | ||
|
||
// extract mandatory ImplID and optional vendor & model | ||
func (o *ClassAttributes) FromEnvironment(e comid.Environment) error { | ||
class := e.Class | ||
|
||
if class == nil { | ||
return fmt.Errorf("expecting class in environment") | ||
} | ||
|
||
classID := class.ClassID | ||
|
||
if classID == nil { | ||
return fmt.Errorf("expecting class-id in class") | ||
} | ||
|
||
uuID, err := classID.GetUUID() | ||
if err != nil { | ||
return fmt.Errorf("could not extract uu-id from class-id: %w", err) | ||
} | ||
|
||
if err := uuID.Valid(); err != nil { | ||
return fmt.Errorf("no valid uu-id: %w", err) | ||
} | ||
|
||
o.UUID = uuID.String() | ||
|
||
if class.Vendor != nil { | ||
o.Vendor = *class.Vendor | ||
} | ||
|
||
if class.Model != nil { | ||
o.Model = *class.Model | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright 2023 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package cca_realm | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/veraison/corim/comid" | ||
"github.com/veraison/services/handler" | ||
) | ||
|
||
type CorimExtractor struct{} | ||
|
||
func (o CorimExtractor) RefValExtractor( | ||
rv comid.ReferenceValue, | ||
) ([]*handler.Endorsement, error) { | ||
var classAttrs ClassAttributes | ||
|
||
if err := classAttrs.FromEnvironment(rv.Environment); err != nil { | ||
return nil, fmt.Errorf("could not extract Realm class attributes: %w", err) | ||
} | ||
|
||
rvs := make([]*handler.Endorsement, 0, len(rv.Measurements)) | ||
|
||
for i, m := range rv.Measurements { | ||
|
||
d := m.Val.Digests | ||
|
||
if d == nil { | ||
return nil, fmt.Errorf("measurement value has no digests") | ||
} | ||
if len(*d) != 1 { | ||
return nil, fmt.Errorf("expecting exactly one digest") | ||
} | ||
algID := (*d)[0].AlgIDToString() | ||
measurementValue := (*d)[0].HashValue | ||
|
||
attrs, err := makeRefValAttrs(&classAttrs, algID, measurementValue) | ||
if err != nil { | ||
return nil, fmt.Errorf("measurement[%d].digest[%d]: %w", i, j, err) | ||
} | ||
|
||
rv := &handler.Endorsement{ | ||
Scheme: SchemeName, | ||
Type: handler.EndorsementType_REFERENCE_VALUE, | ||
Attributes: attrs, | ||
} | ||
|
||
rvs = append(rvs, rv) | ||
|
||
} | ||
|
||
if len(rvs) == 0 { | ||
return nil, fmt.Errorf("no measurements found") | ||
} | ||
|
||
return rvs, nil | ||
} | ||
|
||
func makeRefValAttrs(cAttr *ClassAttributes, algID string, digest []byte) (json.RawMessage, error) { | ||
|
||
var attrs = map[string]interface{}{ | ||
"cca-realm.vendor": cAttr.Vendor, | ||
"cca-realm.model": cAttr.Model, | ||
"cca-realm-id": cAttr.UUID, | ||
"cca-realm.alg-id": algID, | ||
"cca-realm.measurement": digest, | ||
} | ||
data, err := json.Marshal(attrs) | ||
if err != nil { | ||
return nil, fmt.Errorf("unable to marshal reference value attributes: %w", err) | ||
} | ||
return data, nil | ||
} | ||
|
||
func (o CorimExtractor) TaExtractor( | ||
avk comid.AttestVerifKey, | ||
) (*handler.Endorsement, error) { | ||
|
||
return nil, fmt.Errorf("cca realm endorsements does not have a Trust Anchor") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters