Skip to content

Commit

Permalink
Add Realm Endorsement Tests
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed May 29, 2024
1 parent f404bcb commit 37b1882
Show file tree
Hide file tree
Showing 11 changed files with 622 additions and 12 deletions.
50 changes: 48 additions & 2 deletions scheme/cca/endorsement_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func TestDecoder_Decode_invalid_data(t *testing.T) {
assert.EqualError(t, err, expectedErr)
}

func TestDecoder_Decode_CcaRefVal_OK(t *testing.T) {
func TestDecoder_Decode_CcaSsdRefVal_OK(t *testing.T) {
tvs := []string{
unsignedCorimComidCcaRefValOne,
unsignedCorimComidCcaRefValFour,
Expand All @@ -80,7 +80,7 @@ func TestDecoder_Decode_CcaRefVal_OK(t *testing.T) {
}
}

func TestDecoder_Decode_CCaRefVal_NOK(t *testing.T) {
func TestDecoder_Decode_CCaSsdRefVal_NOK(t *testing.T) {
tvs := []struct {
desc string
input string
Expand All @@ -105,3 +105,49 @@ func TestDecoder_Decode_CCaRefVal_NOK(t *testing.T) {
assert.EqualError(t, err, tv.expectedErr)
}
}

func TestDecoder_DecodeCcaRealm_OK(t *testing.T) {
tvs := []string{
unsignedCorimcomidCcaRealm,
unsignedCorimcomidCcaRealmNoClass,
}

d := &EndorsementHandler{}

for _, tv := range tvs {
data := comid.MustHexDecode(t, tv)
_, err := d.Decode(data)
assert.NoError(t, err)
}
}

func TestDecoder_DecodeCcaRealm_negative_tests(t *testing.T) {
tvs := []struct {
desc string
input string
expectedErr string
}{
{
desc: "no realm instance identity in corim",
input: unsignedCorimcomidCcaRealmNoInstance,
expectedErr: "bad software component in CoMID at index 0: could not extract Realm instance attributes: expecting instance in environment",
},
{
desc: "invalid instance identity in corim",
input: unsignedCorimcomidCcaRealmInvalidInstance,
expectedErr: "bad software component in CoMID at index 0: could not extract Realm instance attributes: expecting instance as bytes for CCA Realm",
},
{
desc: "invalid class identity in corim",
input: unsignedCorimcomidCcaRealmInvalidClass,
expectedErr: "bad software component in CoMID at index 0: could not extract Realm class attributes: could not extract uu-id from class-id: class-id type is: *comid.TaggedImplID",
},
}

for _, tv := range tvs {
data := comid.MustHexDecode(t, tv.input)
d := &EndorsementHandler{}
_, err := d.Decode(data)
assert.EqualError(t, err, tv.expectedErr)
}
}
43 changes: 43 additions & 0 deletions scheme/cca/test/corim/build-test-vectors.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/bin/bash
# Copyright 2022-2024 Contributors to the Veraison project.
# SPDX-License-Identifier: Apache-2.0

set -eu
set -o pipefail

# function generate_go_test_vector constructs CBOR test vector using
# supplied comid and corim json template and saves them in a file
# $1 file name for comid json template, example one of COMID_TEMPLATES
# $2 file name for corim json template, example CORIM_TEMPLATE
# $3 a qualifier for each cbor test vector name
# $4 name of the file where the generated CBOR test vectors are aggregated
generate_go_test_vector () {
echo "generating test vector using $1 $2"
cocli comid create -t $1.json
cocli corim create -m $1.cbor -t $2 -o corim$1.cbor
echo "// automatically generated from:" >> $4
echo "// $1.json and $2" >> $4
echo "var $3$1 = "'`' >> $4
cat corim$1.cbor | xxd -p >> $4
echo '`' >> $4
}

CORIM_TEMPLATE="corimCcaRealm.json"

COMID_TEMPLATES=
COMID_TEMPLATES="${COMID_TEMPLATES} comidCcaRealm"
COMID_TEMPLATES="${COMID_TEMPLATES} comidCcaRealmNoClass"
COMID_TEMPLATES="${COMID_TEMPLATES} comidCcaRealmNoInstance"
COMID_TEMPLATES="${COMID_TEMPLATES} comidCcaRealmInvalidInstance"
COMID_TEMPLATES="${COMID_TEMPLATES} comidCcaRealmInvalidClass"

TV_DOT_GO=${TV_DOT_GO?must be set in the environment.}

printf "package cca\n\n" > ${TV_DOT_GO}

for t in ${COMID_TEMPLATES}
do
generate_go_test_vector $t $CORIM_TEMPLATE "unsignedCorim" $TV_DOT_GO
done

gofmt -w $TV_DOT_GO
79 changes: 79 additions & 0 deletions scheme/cca/test/corim/comidCcaRealm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"lang": "en-GB",
"tag-identity": {
"id": "43BBE37F-2E61-4B33-AED3-53CFF1428B16",
"version": 0
},
"entities": [
{
"name": "Workload Client Ltd.",
"regid": "https://workloadclient.example",
"roles": [
"tagCreator",
"creator",
"maintainer"
]
}
],
"triples": {
"reference-values": [
{
"environment": {
"class": {
"id": {
"type": "uuid",
"value": "CD1F0E55-26F9-460D-B9D8-F7FDE171787C"
},
"vendor": "Workload Client Ltd"
},
"instance": {
"type": "bytes",
"value": "QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1"
}
},
"measurements": [
{
"value": {
"raw-value": {
"type": "bytes",
"value": "5Fty9cDAtXLbTY06t+l/No/3TmI0eoJN7LZ6hOUiTXXkW3L1wMC1cttNjTq36X82j/dOYjR6gk3stnqE5SJNdQ=="
},
"integrity-registers": {
"rim": {
"key-type": "text",
"value": [
"sha-384;QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1"
]
},
"rem0": {
"key-type": "text",
"value": [
"sha-384;IQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem1": {
"key-type": "text",
"value": [
"sha-384;JQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem2": {
"key-type": "text",
"value": [
"sha-384;MQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem3": {
"key-type": "text",
"value": [
"sha-384;NQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
}
}
}
}
]
}
]
}
}
79 changes: 79 additions & 0 deletions scheme/cca/test/corim/comidCcaRealmInvalidClass.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
{
"lang": "en-GB",
"tag-identity": {
"id": "43BBE37F-2E61-4B33-AED3-53CFF1428B16",
"version": 0
},
"entities": [
{
"name": "Workload Client Ltd.",
"regid": "https://workloadclient.example",
"roles": [
"tagCreator",
"creator",
"maintainer"
]
}
],
"triples": {
"reference-values": [
{
"environment": {
"class": {
"id": {
"type": "psa.impl-id",
"value": "YWNtZS1pbXBsZW1lbnRhdGlvbi1pZC0wMDAwMDAwMDE="
},
"vendor": "ACME"
},
"instance": {
"type": "bytes",
"value": "QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1"
}
},
"measurements": [
{
"value": {
"raw-value": {
"type": "bytes",
"value": "5Fty9cDAtXLbTY06t+l/No/3TmI0eoJN7LZ6hOUiTXXkW3L1wMC1cttNjTq36X82j/dOYjR6gk3stnqE5SJNdQ=="
},
"integrity-registers": {
"rim": {
"key-type": "text",
"value": [
"sha-384;QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1"
]
},
"rem0": {
"key-type": "text",
"value": [
"sha-384;IQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem1": {
"key-type": "text",
"value": [
"sha-384;JQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem2": {
"key-type": "text",
"value": [
"sha-384;MQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem3": {
"key-type": "text",
"value": [
"sha-384;NQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
}
}
}
}
]
}
]
}
}
75 changes: 75 additions & 0 deletions scheme/cca/test/corim/comidCcaRealmInvalidInstance.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"lang": "en-GB",
"tag-identity": {
"id": "43BBE37F-2E61-4B33-AED3-53CFF1428B16",
"version": 0
},
"entities": [
{
"name": "Workload Client Ltd.",
"regid": "https://workloadclient.example",
"roles": [
"tagCreator",
"creator",
"maintainer"
]
}
],
"triples": {
"reference-values": [
{
"environment": {
"class": {
"id": {
"type": "uuid",
"value": "CD1F0E55-26F9-460D-B9D8-F7FDE171787C"
},
"vendor": "Workload Client Ltd"
},
"instance": {
"type": "ueid",
"value": "Ac7rrnuJJ6MiflMDz14PH3s0u1Qq1yUKwD+83jbsLxUI"
}
},
"measurements": [
{
"value": {
"integrity-registers": {
"rim": {
"key-type": "text",
"value": [
"sha-384;QoS1aUymwNLPR4mguVrIAlyBjeUjBDZL580pgbLS7caFsyInfsJYGZYkE9jJssH1"
]
},
"rem0": {
"key-type": "text",
"value": [
"sha-384;IQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem1": {
"key-type": "text",
"value": [
"sha-384;JQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem2": {
"key-type": "text",
"value": [
"sha-384;MQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
},
"rem3": {
"key-type": "text",
"value": [
"sha-384;NQe752H8pS2VE2oTVNt6TdV7Gya+DT2nHZ6yOYazS6YVq/ZRTPNeWp6lWgMtBop4"
]
}
}
}
}
]
}
]
}
}
Loading

0 comments on commit 37b1882

Please sign in to comment.