diff --git a/platform/claims_test.go b/platform/claims_test.go index 015f9ee..7ad33e0 100644 --- a/platform/claims_test.go +++ b/platform/claims_test.go @@ -293,6 +293,7 @@ func Test_CCAPlatform_UnmarshalJSON_negatives(t *testing.T) { /* 12 */ "testvectors/json/test-instance-id-invalid.json", /* 13 */ "testvectors/json/test-config-missing.json", /* 14 */ "testvectors/json/test-hash-algid-missing.json", + /* 15 */ "testvectors/json/test-invalid-psa-claims.json", } for i, fn := range tvs { @@ -385,7 +386,6 @@ func Test_DecodeUnvalidatedJSONCCAClaims(t *testing.T) { // invalid {"testvectors/json/test-no-sw-components.json", &Claims{}}, - {"testvectors/json/test-invalid-profile.json", &Claims{}}, {"testvectors/json/test-invalid-psa-claims.json", &Claims{}}, } @@ -395,7 +395,7 @@ func Test_DecodeUnvalidatedJSONCCAClaims(t *testing.T) { v, err := DecodeClaimsFromJSON(buf) - assert.NoError(t, err) + require.NoError(t, err) assert.IsType(t, tv.Expected, v) } } diff --git a/platform/iclaims.go b/platform/iclaims.go index 8f5225e..1d1d76f 100644 --- a/platform/iclaims.go +++ b/platform/iclaims.go @@ -5,6 +5,7 @@ package platform import ( "encoding/json" + "errors" "fmt" "github.com/veraison/psatoken" @@ -61,7 +62,12 @@ func DecodeClaimsFromCBOR(buf []byte) (IClaims, error) { return nil, err } - return i.(IClaims), nil + ic, ok := i.(IClaims) + if !ok { + return nil, errors.New("not a CCA platform token") + } + + return ic, nil } // DecodeAndValidateClaimsFromJSON unmarshals and validates CCA platform claims @@ -81,13 +87,17 @@ func DecodeAndValidateClaimsFromJSON(buf []byte) (IClaims, error) { // DecodeClaimsFromJSON unmarshals CCA platform claims from provided JSON buf. func DecodeClaimsFromJSON(buf []byte) (IClaims, error) { - cl := NewClaims() - - if err := json.Unmarshal(buf, cl); err != nil { + i, err := psatoken.DecodeClaimsFromJSON(buf) + if err != nil { return nil, err } - return cl, nil + ic, ok := i.(IClaims) + if !ok { + return nil, errors.New("not a (JSON-encoded) CCA platform token") + } + + return ic, nil } // ValidateAndEncodeClaimsToCBOR validates and then marshals CCA platform claims diff --git a/platform/testvectors/json/test-invalid-psa-claims.json b/platform/testvectors/json/test-invalid-psa-claims.json index 100d96d..4f04b5c 100644 --- a/platform/testvectors/json/test-invalid-psa-claims.json +++ b/platform/testvectors/json/test-invalid-psa-claims.json @@ -1,5 +1,5 @@ { - "cca-platform-profile": "http://arm.com/PSA-SSD/1.0.0", + "cca-platform-profile": "http://arm.com/CCA-SSD/1.0.0", "cca-platform-challenge": "AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=", "cca-platform-instance-id": "AQICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC", "psa-implementation-id": "AQIDBAUGBwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyA=",