diff --git a/comid/tdx-profile/example_qe_refval_test.go b/comid/tdx-profile/example_qe_refval_test.go index e91ccf7..7f8119b 100644 --- a/comid/tdx-profile/example_qe_refval_test.go +++ b/comid/tdx-profile/example_qe_refval_test.go @@ -58,56 +58,3 @@ func Example_tdx_qe_refval() { //a301a1005043bbe37f2e614b33aed353cff1428b200281a30065494e54454c01d8207168747470733a2f2f696e74656c2e636f6d028301000204a1008182a100a300d86f4c6086480186f84d01020304050171496e74656c20436f72706f726174696f6e02675444585345414d81a101a100a20065312e322e330101 } - -func Example_tdx_qe_refval1() { - profID, err := eat.NewProfile("http://intel.com/test-profile") - if err != nil { - fmt.Printf("Unable to get new Profile") - } - - extMap := extensions.NewMap(). - Add(comid.ExtReferenceValue, &MvalExtensions{}) - err = corim.RegisterProfile(profID, extMap) - myprofile, found := corim.GetProfile(profID) - if !found { - fmt.Printf("Profile NOT Found") - return - } - coMID := myprofile.GetComid() - if coMID == nil { - fmt.Printf("\n CoMID is NIL\n") - } - if err := coMID.FromJSON([]byte(TDXQERefValTemplate)); err != nil { - fmt.Printf("From JSON Failed %s", err.Error()) - } else { - fmt.Printf("From JSON Passed \n") - } - if coMID.Triples.ReferenceValues == nil { - fmt.Printf("\n CoMID REFERENCE VALUES ARE NIL\n") - } - if len(coMID.Triples.ReferenceValues.Values) == 0 { - fmt.Printf("\n CoMID REFERENCE VALUES NO VALUE TRIPLES\n") - return - } - - for _, m := range coMID.Triples.ReferenceValues.Values[0].Measurements.Values { - val, err := m.Val.Extensions.Get("tcbevalnum") - f, ok := val.(*teeTcbEvalNum) - if !ok { - fmt.Printf("val was not pointer to teeTcbEvalNum") - } - tcbValNum := *f - if err != nil { - fmt.Printf(" \n tcbEvalNum NOT Set: %s \n", err.Error()) - } else { - fmt.Printf(" \n tcbEvalNum is Set %d", tcbValNum) - } - } - - if err := coMID.Valid(); err != nil { - panic(err) - } - // Output: - //a301a1005043bbe37f2e614b33aed353cff1428b200281a30065494e54454c01d8207168747470733a2f2f696e74656c2e636f6d028301000204a1008182a100a300d86f4c6086480186f84d01020304050171496e74656c20436f72706f726174696f6e02675444585345414d81a101a100a20065312e322e330101 - -} diff --git a/comid/tdx-profile/example_seam_refval_test.go b/comid/tdx-profile/example_seam_refval_test.go index 0d1a794..d4ba68d 100644 --- a/comid/tdx-profile/example_seam_refval_test.go +++ b/comid/tdx-profile/example_seam_refval_test.go @@ -33,7 +33,7 @@ func Example_decode_JSON() { } if err := coMID.Valid(); err != nil { - fmt.Errorf("CoMID is invalid %s", err.Error()) + panic(err) } if err := extractRefVals(coMID); err != nil { @@ -72,31 +72,29 @@ func Example_encode_tdx_seam_refval_without_profile() { refVal.Measurements.Add(measurement) coMID.Triples.AddReferenceValue(*refVal) - err := coMID.RegisterExtensions(extMap) - if err != nil { + if err := coMID.RegisterExtensions(extMap); err != nil { panic(err) } - // fmt.Printf("len of Measurements = %d ", len(coMID.Triples.ReferenceValues.Values[0].Measurements.Values)) - // Set the Extensions now - // setMValExtensions(&measurement.Val) ==> this does not work, though - setMValExtensions(&coMID.Triples.ReferenceValues.Values[0].Measurements.Values[0].Val) - err = coMID.Valid() - if err != nil { - fmt.Printf("coMID is not Valid :%s", err.Error()) + + if err := setMValExtensions(&coMID.Triples.ReferenceValues.Values[0].Measurements.Values[0].Val); err != nil { + panic(err) + } + if err := coMID.Valid(); err != nil { + panic(err) } cbor, err := coMID.ToCBOR() if err == nil { fmt.Printf("%x\n", cbor) } else { - fmt.Printf("\n To CBOR Failed: %s \n", err.Error()) + fmt.Printf("To CBOR failed \n") } json, err := coMID.ToJSON() if err == nil { fmt.Printf("%s\n", string(json)) } else { - fmt.Printf("\n To JSON Failed \n") + fmt.Printf("To JSON failed \n") } // Output: @@ -117,7 +115,7 @@ func Example_encode_tdx_seam_refval_with_profile() { coMID := profile.GetComid() if coMID == nil { - fmt.Printf("\n CoMID is NIL\n") + panic(err) } coMID.SetTagIdentity("43BBE37F-2E61-4B33-AED3-53CFF1428B20", 0). AddEntity("INTEL", &TestRegID, comid.RoleCreator, comid.RoleTagCreator, comid.RoleMaintainer) @@ -133,7 +131,11 @@ func Example_encode_tdx_seam_refval_with_profile() { refVal.Measurements.Add(measurement) coMID.Triples.AddReferenceValue(*refVal) - setMValExtensions(&coMID.Triples.ReferenceValues.Values[0].Measurements.Values[0].Val) + err = setMValExtensions(&coMID.Triples.ReferenceValues.Values[0].Measurements.Values[0].Val) + if err != nil { + fmt.Printf("unable to set extensions :%s", err.Error()) + } + err = coMID.Valid() if err != nil { fmt.Printf("coMID is not Valid :%s", err.Error()) @@ -211,7 +213,7 @@ func setMValExtensions(val *comid.Mval) error { tcbDate := tdate("123") isvProdID := teeIsvProdID([]byte{0x01, 0x01}) svn := teeSVN(10) - teeTcbEvalNum := teeTcbEvalNum(11) + teeTcbEvNum := teeTcbEvalNum(11) teeAttr := teeAttributes([]byte{0x01, 0x01}) err := val.Extensions.Set("tcbdate", &tcbDate) @@ -226,7 +228,7 @@ func setMValExtensions(val *comid.Mval) error { if err != nil { return fmt.Errorf("unable to set isvsvn %w", err) } - err = val.Extensions.Extensions.Set("tcbevalnum", &teeTcbEvalNum) + err = val.Extensions.Extensions.Set("tcbevalnum", &teeTcbEvNum) if err != nil { return fmt.Errorf("unable to set tcbevalnum %w", err) } @@ -239,7 +241,10 @@ func setMValExtensions(val *comid.Mval) error { d.AddDigest(swid.Sha256, comid.MustHexDecode(nil, "e45b72f5c0c0b572db4d8d3ab7e97f368ff74e62347a824decb67a84e5224d75")) d.AddDigest(swid.Sha384, comid.MustHexDecode(nil, "e45b72f5c0c0b572db4d8d3ab7e97f368ff74e62347a824decb67a84e5224d75e45b72f5c0c0b572db4d8d3ab7e97f36")) - val.Extensions.Set("mrsigner", d) + err = val.Extensions.Set("mrsigner", d) + if err != nil { + return fmt.Errorf("unable to set mrsigner %w", err) + } return nil } @@ -277,12 +282,11 @@ func decodeMValExtensions(m comid.Measurement) error { fmt.Printf("\nISVSVN: %d", *tSV) - val, err = m.Val.Extensions.Get("isvprodid") + val, err = m.Val.Extensions.Get("attributes") if err != nil { - return fmt.Errorf("failed to decode isvprodid from measurement extensions") + return fmt.Errorf("failed to decode attributes from measurement extensions") } - val, err = m.Val.Extensions.Get("attributes") tA, ok := val.(*teeAttributes) if !ok { fmt.Printf("val was not pointer to teeAttributes") @@ -300,7 +304,10 @@ func decodeMValExtensions(m comid.Measurement) error { fmt.Printf("val was not pointer to teeDigest") } - extractTEEDigest(tD) + err = extractTEEDigest(tD) + if err != nil { + return fmt.Errorf("unable to extract TEE Digest: %w", err) + } return nil } @@ -329,9 +336,9 @@ func Example_decode_CBOR() { panic(err) } if err := coMID.Valid(); err != nil { - fmt.Errorf("CoMID is invalid %s", err.Error()) - + panic(err) } + if err := extractRefVals(coMID); err != nil { panic(err) } diff --git a/comid/tdx-profile/mval_extensions.go b/comid/tdx-profile/mval_extensions.go index ed66fee..1815cd3 100644 --- a/comid/tdx-profile/mval_extensions.go +++ b/comid/tdx-profile/mval_extensions.go @@ -1,10 +1,6 @@ package tdx import ( - "encoding/hex" - "fmt" - "log" - "github.com/veraison/corim/comid" "github.com/veraison/corim/corim" "github.com/veraison/corim/extensions" @@ -46,8 +42,6 @@ func init() { panic(err) // will not error, as the hard-coded string above is valid } - // DO WE HAVE TO HAVE ALL EXTENSIONS UNDER ONE MAP OR I CAN REPEAT THE SAME STATEMENT - // UNDER TWo extMap statements and call RegisterProfile twice? extMap := extensions.NewMap(). Add(comid.ExtReferenceValue, &MvalExtensions{}). Add(comid.ExtEndorsedValue, &MvalExtensions{}) @@ -58,32 +52,3 @@ func init() { panic(err) } } - -// Now Create CoMID using extensions -func Example_profile_marshal() { - profileID, err := eat.NewProfile("http://intel.com/tdx-profile") - if err != nil { - panic(err) - } - - profile, ok := corim.GetProfile(profileID) - if !ok { - log.Fatalf("profile %v not found", profileID) - } - myCorim := profile.GetUnsignedCorim() - myComid := profile.GetComid().SetLanguage("english") - var refVal comid.ValueTriple - refVal.Measurements.Values[0].Val.Extensions.Set("tcbdate", "123") - - myComid.Triples.ReferenceValues.Add(&refVal) - - myCorim.AddComid(*myComid) - - buf, err := myCorim.ToCBOR() - if err != nil { - log.Fatalf("could not encode CoRIM: %v", err) - } - - fmt.Printf("corim: %v", hex.EncodeToString(buf)) - -} diff --git a/comid/tdx-profile/types.go b/comid/tdx-profile/types.go index dfdb228..0c2cfdf 100644 --- a/comid/tdx-profile/types.go +++ b/comid/tdx-profile/types.go @@ -4,9 +4,6 @@ import "github.com/veraison/corim/comid" type numericType uint -type teeModel string -type teeVendor string - type pceID string type teeSVN numericType