diff --git a/coserv/quads.go b/coserv/quads.go index 69a29cad..f5f8d25f 100644 --- a/coserv/quads.go +++ b/coserv/quads.go @@ -3,7 +3,10 @@ package coserv -import "github.com/veraison/corim/comid" +import ( + "github.com/veraison/corim/comid" + "github.com/veraison/corim/cots" +) type RefValQuad struct { Authorities *comid.CryptoKeys `cbor:"1,keyasint"` @@ -14,3 +17,8 @@ type AKQuad struct { Authorities *comid.CryptoKeys `cbor:"1,keyasint"` AKTriple *comid.KeyTriple `cbor:"2,keyasint"` } + +type CoTSStmt struct { + Authorities *comid.CryptoKeys `cbor:"1,keyasint"` + CoTS *cots.ConciseTaStore `cbor:"2,keyasint"` +} diff --git a/coserv/resultset.go b/coserv/resultset.go index 87d9b711..1dd5ccf4 100644 --- a/coserv/resultset.go +++ b/coserv/resultset.go @@ -13,8 +13,8 @@ import ( type ResultSet struct { RVQ *[]RefValQuad `cbor:"0,keyasint,omitempty"` AKQ *[]AKQuad `cbor:"3,keyasint,omitempty"` + TAS *[]CoTSStmt `cbor:"4,keyasint,omitempty"` // TODO(tho) add endorsed values - // TODO(tho) add CoTS Expiry *time.Time `cbor:"10,keyasint"` SourceArtifacts *[]cmw.CMW `cbor:"11,keyasint,omitempty"` } @@ -46,6 +46,17 @@ func (o *ResultSet) AddAttestationKeys(v AKQuad) *ResultSet { return o } +// AddCoTS adds the supplied CoTS statement to the target ResultSet +func (o *ResultSet) AddCoTS(v CoTSStmt) *ResultSet { + if o.TAS == nil { + o.TAS = new([]CoTSStmt) + } + + *o.TAS = append(*o.TAS, v) + + return o +} + // AddSourceArtifacts adds the supplied CMW to the target ResultSet func (o *ResultSet) AddSourceArtifacts(v cmw.CMW) *ResultSet { // nolint:gocritic if o.SourceArtifacts == nil { diff --git a/coserv/resultset_test.go b/coserv/resultset_test.go index 96e831e3..eb1a951c 100644 --- a/coserv/resultset_test.go +++ b/coserv/resultset_test.go @@ -10,6 +10,7 @@ import ( "github.com/stretchr/testify/require" "github.com/veraison/cmw" "github.com/veraison/corim/comid" + "github.com/veraison/corim/cots" ) func TestResultSet_AddAttestationKeys(t *testing.T) { @@ -32,6 +33,39 @@ func TestResultSet_AddAttestationKeys(t *testing.T) { assert.NotNil(t, rset) } +func TestResultSet_AddCoTS(t *testing.T) { + authority, err := comid.NewCryptoKeyTaggedBytes(testAuthority) + require.NoError(t, err) + + // Create a simple CoTS structure for testing + cotsStore := cots.NewConciseTaStore() + + // Add a basic environment group with a class + class := comid.NewClassBytes(testBytes) + env := comid.Environment{ + Class: class, + } + eg := cots.EnvironmentGroup{} + eg.SetEnvironment(env) + cotsStore.AddEnvironmentGroup(eg) + + // Add trust anchor keys + testCert := []byte{0x30, 0x82, 0x01, 0x00} // Simple test cert bytes + tas := cots.NewTasAndCas() + tas.AddTaCert(testCert) + cotsStore.SetKeys(*tas) + + cotsStmt := CoTSStmt{ + Authorities: comid.NewCryptoKeys().Add(authority), + CoTS: cotsStore, + } + + rset := NewResultSet().SetExpiry(testExpiry).AddCoTS(cotsStmt) + assert.NotNil(t, rset) + assert.NotNil(t, rset.TAS) + assert.Equal(t, 1, len(*rset.TAS)) +} + func TestResultSet_AddSourceArtifacts(t *testing.T) { cmw0, err := cmw.NewMonad("application/vnd.example.refvals", []byte{0x00, 0x01, 0x02, 0x03}) require.NoError(t, err)