Skip to content

Commit

Permalink
[WIP] Work on Introducing Store handlers
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Mar 8, 2024
1 parent c5d9aa8 commit 23b31e2
Show file tree
Hide file tree
Showing 23 changed files with 434 additions and 163 deletions.
2 changes: 1 addition & 1 deletion handler/ievidencehandler.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2021-2023 Contributors to the Veraison project.
// Copyright 2021-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package handler

Expand Down
7 changes: 7 additions & 0 deletions handler/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,10 @@ func RegisterEvidenceHandler(i IEvidenceHandler) {
panic(err)
}
}

func RegisterStoreHandler(i IStoreHandler) {
err := plugin.RegisterImplementation("store-handler", i, StoreHandlerRPC)
if err != nil {
panic(err)
}
}
62 changes: 0 additions & 62 deletions scheme/cca-ssd-platform/evidence_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,71 +12,9 @@ import (
"github.com/stretchr/testify/require"

"github.com/veraison/ear"
"github.com/veraison/services/handler"
"github.com/veraison/services/proto"
)

var testNonce = []byte{
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
}

func Test_GetTrustAnchorIDs_ok(t *testing.T) {
tokenBytes, err := os.ReadFile("test/cca-token.cbor")
require.NoError(t, err)

token := proto.AttestationToken{
TenantId: "1",
Data: tokenBytes,
Nonce: testNonce,
}

expectedTaID := []string{"CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/AQICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC"}

scheme := &EvidenceHandler{}

taID, err := scheme.GetTrustAnchorIDs(&token)
require.NoError(t, err)
assert.Equal(t, expectedTaID, taID)
}

func Test_SynthKeysFromTrustAnchor_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/ta-endorsements.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/Ac7rrnuJJ6MiflMDz14PH3s0u1Qq1yUKwD+83jbsLxUI"

scheme := &EvidenceHandler{}
key_list, err := scheme.SynthKeysFromTrustAnchor("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])

}

func Test_SynthKeysFromRefValue_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/refval-endorsements.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

scheme := &EvidenceHandler{}
key_list, err := scheme.SynthKeysFromRefValue("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])
}

func Test_AppraiseEvidence_ok(t *testing.T) { // nolint: dupl
extractedBytes, err := os.ReadFile("test/extracted.json")
require.NoError(t, err)
Expand Down
1 change: 1 addition & 0 deletions scheme/cca-ssd-platform/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
ifndef COMBINED_PLUGINS
SUBDIR += endorsement-handler
SUBDIR += evidence-handler
SUBDIR += store-handler
else
SUBDIR += combined
endif
Expand Down
1 change: 1 addition & 0 deletions scheme/cca-ssd-platform/plugin/combined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import (
func main() {
handler.RegisterEndorsementHandler(&scheme.EndorsementHandler{})
handler.RegisterEvidenceHandler(&scheme.EvidenceHandler{})
handler.RegisterStoreHandler(&scheme.StoreHandler{})
plugin.Serve()
}
11 changes: 11 additions & 0 deletions scheme/cca-ssd-platform/plugin/store-handler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2021 Contributors to the Veraison project.
# SPDX-License-Identifier: Apache-2.0

PLUGIN := ../../../bin/cca-store-handler.plugin
GOPKG := github.com/veraison/services/scheme/cca-ssd-platform
SRCS := main.go

include ../../../../mk/common.mk
include ../../../../mk/plugin.mk
include ../../../../mk/lint.mk
include ../../../../mk/test.mk
14 changes: 14 additions & 0 deletions scheme/cca-ssd-platform/plugin/store-handler/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package main

import (
"github.com/veraison/services/handler"
"github.com/veraison/services/plugin"
scheme "github.com/veraison/services/scheme/cca-ssd-platform"
)

func main() {
handler.RegisterStoreHandler(&scheme.StoreHandler{})
plugin.Serve()
}
45 changes: 45 additions & 0 deletions scheme/cca-ssd-platform/store_handler.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021-2023 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0

package cca_ssd_platform

import (
"github.com/veraison/services/handler"
"github.com/veraison/services/proto"
"github.com/veraison/services/scheme/common/arm"
)

type StoreHandler struct{}

func (s StoreHandler) GetName() string {
return "cca-store-handler"
}

func (s StoreHandler) GetAttestationScheme() string {
return SchemeName
}

func (s StoreHandler) GetSupportedMediaTypes() []string {
return nil
}

func (s StoreHandler) SynthKeysFromRefValue(
tenantID string,
refVal *handler.Endorsement,
) ([]string, error) {
return arm.SynthKeysFromRefValue(SchemeName, tenantID, refVal)

}

func (s StoreHandler) SynthKeysFromTrustAnchor(tenantID string, ta *handler.Endorsement) ([]string, error) {

return arm.SynthKeysFromTrustAnchors(SchemeName, tenantID, ta)
}

func (s StoreHandler) GetTrustAnchorIDs(token *proto.AttestationToken) ([]string, error) {
ta, err := arm.GetTrustAnchorID(SchemeName, token)
if err != nil {
return []string{""}, err
}
return []string{ta}, nil
}
77 changes: 77 additions & 0 deletions scheme/cca-ssd-platform/store_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2021-2023 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0

package cca_ssd_platform

import (
"encoding/json"
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/veraison/services/handler"
"github.com/veraison/services/proto"
)

var testNonce = []byte{
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
0x41, 0x42, 0x41, 0x42, 0x41, 0x42, 0x41, 0x42,
}

func Test_GetTrustAnchorIDs_ok(t *testing.T) {
tokenBytes, err := os.ReadFile("test/cca-token.cbor")
require.NoError(t, err)

token := proto.AttestationToken{
TenantId: "1",
Data: tokenBytes,
Nonce: testNonce,
}

expectedTaID := []string{"CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/AQICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIC"}

scheme := &StoreHandler{}

taID, err := scheme.GetTrustAnchorIDs(&token)
require.NoError(t, err)
assert.Equal(t, expectedTaID, taID)
}

func Test_SynthKeysFromTrustAnchor_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/ta-endorsements.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/Ac7rrnuJJ6MiflMDz14PH3s0u1Qq1yUKwD+83jbsLxUI"

scheme := &StoreHandler{}
key_list, err := scheme.SynthKeysFromTrustAnchor("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])

}

func Test_SynthKeysFromRefValue_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/refval-endorsements.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "CCA_SSD_PLATFORM://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

scheme := &StoreHandler{}
key_list, err := scheme.SynthKeysFromRefValue("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])
}
50 changes: 0 additions & 50 deletions scheme/parsec-cca/evidence_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,9 @@ import (
"github.com/stretchr/testify/require"

"github.com/veraison/ear"
"github.com/veraison/services/handler"
"github.com/veraison/services/proto"
)

func Test_GetTrustAnchorIDs_ok(t *testing.T) {
tokenBytes, err := os.ReadFile("test/evidence/evidence.cbor")
require.NoError(t, err)

token := proto.AttestationToken{
TenantId: "1",
Data: tokenBytes,
}

expectedTaID := "PARSEC_CCA://1/f0VMRgIBAQAAAAAAAAAAAAMAPgABAAAAUFgAAAAAAAA=/AQcGBQQDAgEADw4NDAsKCQgXFhUUExIREB8eHRwbGhkY"

handler := &EvidenceHandler{}

taIDs, err := handler.GetTrustAnchorIDs(&token)
require.NoError(t, err)
assert.Equal(t, expectedTaID, taIDs[0])
}

func Test_ExtractClaims_ok(t *testing.T) {
tokenBytes, err := os.ReadFile("test/evidence/evidence.cbor")
require.NoError(t, err)
Expand Down Expand Up @@ -206,37 +187,6 @@ func Test_AppraiseEvidence_ok(t *testing.T) {
assert.Equal(t, attestation.TrustVector.Configuration, ear.ApprovedConfigClaim)
}

func Test_SynthKeysFromTrustAnchor_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/evidence/ta_endorsements.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "PARSEC_CCA://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=/Ac7rrnuJJ6MiflMDz14PH3s0u1Qq1yUKwD+83jbsLxUI"

scheme := &EvidenceHandler{}
key_list, err := scheme.SynthKeysFromTrustAnchor("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])

}

func Test_SynthKeysFromRefValue_ok(t *testing.T) {
endorsementsBytes, err := os.ReadFile("test/evidence/refval_endorsement.json")
require.NoError(t, err)

var endors handler.Endorsement
err = json.Unmarshal(endorsementsBytes, &endors)
require.NoError(t, err)
expectedKey := "PARSEC_CCA://1/AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA="

scheme := &EvidenceHandler{}
key_list, err := scheme.SynthKeysFromRefValue("1", &endors)
require.NoError(t, err)
assert.Equal(t, expectedKey, key_list[0])
}

func Test_GetName_ok(t *testing.T) {
scheme := &EvidenceHandler{}
expectedName := "parsec-cca-evidence-handler"
Expand Down
1 change: 1 addition & 0 deletions scheme/parsec-cca/plugin/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
ifndef COMBINED_PLUGINS
SUBDIR += endorsement-handler
SUBDIR += evidence-handler
SUBDIR += store-handler
else
SUBDIR += combined
endif
Expand Down
1 change: 1 addition & 0 deletions scheme/parsec-cca/plugin/combined/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ import (
func main() {
handler.RegisterEndorsementHandler(&scheme.EndorsementHandler{})
handler.RegisterEvidenceHandler(&scheme.EvidenceHandler{})
handler.RegisterStoreHandler(&scheme.StoreHandler{})
plugin.Serve()
}
11 changes: 11 additions & 0 deletions scheme/parsec-cca/plugin/store-handler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2021 Contributors to the Veraison project.
# SPDX-License-Identifier: Apache-2.0

PLUGIN := ../../../bin/parsec-cca-store-handler.plugin
GOPKG := github.com/veraison/services/scheme/parsec-cca
SRCS := main.go

include ../../../../mk/common.mk
include ../../../../mk/plugin.mk
include ../../../../mk/lint.mk
include ../../../../mk/test.mk
14 changes: 14 additions & 0 deletions scheme/parsec-cca/plugin/store-handler/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package main

import (
"github.com/veraison/services/handler"
"github.com/veraison/services/plugin"
scheme "github.com/veraison/services/scheme/parsec-cca"
)

func main() {
handler.RegisterStoreHandler(&scheme.StoreHandler{})
plugin.Serve()
}
Loading

0 comments on commit 23b31e2

Please sign in to comment.