Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion coserv/quads.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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"`
}
13 changes: 12 additions & 1 deletion coserv/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
Expand Down Expand Up @@ -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 {
Expand Down
34 changes: 34 additions & 0 deletions coserv/resultset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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)
Expand Down