-
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.
Signed-off-by: Yogesh Deshpande <[email protected]>
- Loading branch information
1 parent
86c4206
commit b7e1e5b
Showing
7 changed files
with
140 additions
and
36 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
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
28 changes: 28 additions & 0 deletions
28
scheme/cca-realm-provisioning/test/store/refvalEndorsementsNoRpv.json
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,28 @@ | ||
{ | ||
"scheme": "CCA_REALM", | ||
"type": "REFERENCE_VALUE", | ||
"attributes": { | ||
"CCA_REALM.vendor": "Worload Client Ltd", | ||
"CCA_REALM.class-id": "CD1F0E55-26F9-460D-B9D8-F7FDE171787C", | ||
"CCA_REALM.realm-initial-measurement": "QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1", | ||
"CCA_REALM.hash-alg-id": "sha-384", | ||
"CCA_REALM.realm-personalization-value": "", | ||
"CCA_REALM.measurements": [ | ||
{ | ||
"rim": "QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1" | ||
}, | ||
{ | ||
"rem0": "IQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4" | ||
}, | ||
{ | ||
"rem1": "JQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4" | ||
}, | ||
{ | ||
"rem2": "MQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4" | ||
}, | ||
{ | ||
"rem3": "NQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4" | ||
} | ||
] | ||
} | ||
} |
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,75 @@ | ||
// Copyright 2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package arm | ||
|
||
import ( | ||
"encoding/json" | ||
"errors" | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
"github.com/veraison/services/handler" | ||
"github.com/veraison/services/log" | ||
) | ||
|
||
func GetRim(scheme string, attr json.RawMessage) (string, error) { | ||
var at map[string]interface{} | ||
err := json.Unmarshal(attr, &at) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to get Instance ID: %w", err) | ||
} | ||
key := scheme + ".realm-initial-measurement" | ||
rim, ok := at[key].(string) | ||
if !ok { | ||
return "", errors.New("unable to get realm initial measurements") | ||
} | ||
return rim, nil | ||
} | ||
|
||
func GetRpv(scheme string, attr json.RawMessage) (string, error) { | ||
var at map[string]interface{} | ||
err := json.Unmarshal(attr, &at) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to get Instance ID: %w", err) | ||
} | ||
key := scheme + ".realm-personalization-value" | ||
rpv, ok := at[key].(string) | ||
if !ok { | ||
return "", errors.New("unable to get realm personalization value") | ||
} | ||
return rpv, nil | ||
} | ||
|
||
func SynthKeyFromRefVal(scheme string, tenantID string, refVal *handler.Endorsement) (string, error) { | ||
if refVal == nil { | ||
return "", errors.New("no reference value in SynthKeyFromRefVal") | ||
} | ||
rim, err := GetRim(scheme, refVal.Attributes) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to get rim: %w", err) | ||
} | ||
rpv, err := GetRpv(scheme, refVal.Attributes) | ||
if err != nil { | ||
return "", fmt.Errorf("unable to get rpv: %w", err) | ||
} | ||
lookupKey := refValLookupKey(scheme, tenantID, rim, rpv) | ||
log.Debugf("Scheme %s realm RefVal Look Up Key= %s\n", scheme, lookupKey) | ||
return lookupKey, nil | ||
} | ||
|
||
func refValLookupKey(schemeName, tenantID, rim string, rpv string) string { | ||
var absPath []string | ||
if rpv != "" { | ||
absPath = []string{rim, rpv} | ||
} else { | ||
absPath = []string{rim} | ||
} | ||
|
||
u := url.URL{ | ||
Scheme: schemeName, | ||
Host: tenantID, | ||
Path: strings.Join(absPath, "/"), | ||
} | ||
return u.String() | ||
} |