Skip to content

Commit

Permalink
[WIP] Futher work
Browse files Browse the repository at this point in the history
Signed-off-by: Yogesh Deshpande <[email protected]>
  • Loading branch information
yogeshbdeshpande committed Mar 13, 2024
1 parent 51bedcb commit 893379d
Show file tree
Hide file tree
Showing 16 changed files with 138 additions and 69 deletions.
4 changes: 4 additions & 0 deletions builtin/schemes.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,13 @@ import (
var plugins = []plugin.IPluggable{
&scheme1.EvidenceHandler{},
&scheme1.EndorsementHandler{},
&scheme1.StoreHandler{},
&scheme2.EvidenceHandler{},
&scheme2.StoreHandler{},
&scheme3.EvidenceHandler{},
&scheme3.EndorsementHandler{},
&scheme3.StoreHandler{},
&scheme4.EvidenceHandler{},
&scheme4.EndorsementHandler{},
&scheme4.StoreHandler{},
}
6 changes: 3 additions & 3 deletions handler/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
This package defines [`IEvidenceHandler`](ievidencehandler.go) and
[`IEndorsementHandler`](iendorsementhandler.go) [pluggable](../plugin/README.md)
This package defines [`IEvidenceHandler`](ievidencehandler.go),
[`IEndorsementHandler`](iendorsementhandler.go) and [`IStoreHandler`](istorehandler.go) [pluggable](../plugin/README.md)
interfaces and associated RPC channels. These are used to add new attestation
scheme to Veraison services. Additionally, the package defines a [couple
of wrappers](plugin.go) around `plugin.RegisterImplementation` for registering
implementations of these two interfaces.
implementations of these three interfaces.
2 changes: 1 addition & 1 deletion scheme/psa-iot/plugin/combined/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package main

Expand Down
2 changes: 1 addition & 1 deletion scheme/psa-iot/store_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
type StoreHandler struct{}

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

func (s StoreHandler) GetAttestationScheme() string {
Expand Down
6 changes: 3 additions & 3 deletions scheme/riot/plugin/store-handler/Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Copyright 2021 Contributors to the Veraison project.
# Copyright 2024 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
PLUGIN := ../../../bin/riot.plugin
GOPKG := github.com/veraison/services/scheme/riot
SRCS := main.go

include ../../../../mk/common.mk
Expand Down
40 changes: 1 addition & 39 deletions scheme/tpm-enacttrust/evidence_handler.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 tpm_enacttrust

Expand Down Expand Up @@ -32,44 +32,6 @@ func (s EvidenceHandler) GetSupportedMediaTypes() []string {
return EvidenceMediaTypes
}

func (s EvidenceHandler) SynthKeysFromRefValue(
tenantID string,
swComp *handler.Endorsement,
) ([]string, error) {
return synthKeysFromAttrs("software component", tenantID, swComp.Attributes)
}

func (s EvidenceHandler) SynthKeysFromTrustAnchor(tenantID string, ta *handler.Endorsement) ([]string, error) {
return synthKeysFromAttrs("trust anchor", tenantID, ta.Attributes)
}

func (s EvidenceHandler) GetTrustAnchorIDs(token *proto.AttestationToken) ([]string, error) {
supported := false
for _, mt := range EvidenceMediaTypes {
if token.MediaType == mt {
supported = true
break
}
}

if !supported {
err := handler.BadEvidence(
"wrong media type: expect %q, but found %q",
strings.Join(EvidenceMediaTypes, ", "),
token.MediaType,
)
return []string{""}, err
}

var decoded Token

if err := decoded.Decode(token.Data); err != nil {
return nil, handler.BadEvidence(err)
}

return []string{tpmEnactTrustLookupKey(token.TenantId, decoded.NodeId.String())}, nil
}

func (s EvidenceHandler) ExtractClaims(
token *proto.AttestationToken,
trustAnchors []string,
Expand Down
19 changes: 1 addition & 18 deletions scheme/tpm-enacttrust/evidence_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package tpm_enacttrust

Expand Down Expand Up @@ -27,23 +27,6 @@ func Test_DecodeAttestationData_ok(t *testing.T) {
assert.Equal(t, uint64(0x7), decoded.AttestationData.FirmwareVersion)
}

func Test_GetTrustAnchorIds_ok(t *testing.T) {
data, err := os.ReadFile("test/tokens/basic.token")
require.NoError(t, err)

ta := proto.AttestationToken{
TenantId: "0",
MediaType: "application/vnd.enacttrust.tpm-evidence",
Data: data,
}

var s EvidenceHandler

taIDs, err := s.GetTrustAnchorIDs(&ta)
require.NoError(t, err)
assert.Equal(t, "TPM_ENACTTRUST://0/7df7714e-aa04-4638-bcbf-434b1dd720f1", taIDs[0])
}

func readPublicKeyBytes(path string) ([]byte, error) {
buf, err := os.ReadFile(path)
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions scheme/tpm-enacttrust/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
3 changes: 2 additions & 1 deletion scheme/tpm-enacttrust/plugin/combined/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package main

Expand All @@ -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/tpm-enacttrust/plugin/store-handler/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Copyright 2024 Contributors to the Veraison project.
# SPDX-License-Identifier: Apache-2.0

PLUGIN := ../../../bin/tpm-enacttrust-store-handler.plugin
GOPKG := github.com/veraison/services/scheme/tpm-enacttrust
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/tpm-enacttrust/plugin/store-handler/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Copyright 2022-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/tpm-enacttrust"
)

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

package tpm_enacttrust

import (
"strings"

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

type StoreHandler struct {
}

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

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

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

func (s StoreHandler) GetTrustAnchorIDs(token *proto.AttestationToken) ([]string, error) {
supported := false
for _, mt := range EvidenceMediaTypes {
if token.MediaType == mt {
supported = true
break
}
}

if !supported {
err := handler.BadEvidence(
"wrong media type: expect %q, but found %q",
strings.Join(EvidenceMediaTypes, ", "),
token.MediaType,
)
return []string{""}, err
}

var decoded Token

if err := decoded.Decode(token.Data); err != nil {
return nil, handler.BadEvidence(err)
}

return []string{tpmEnactTrustLookupKey(token.TenantId, decoded.NodeId.String())}, nil
}

func (s StoreHandler) SynthKeysFromRefValue(
tenantID string,
swComp *handler.Endorsement,
) ([]string, error) {
return synthKeysFromAttrs("software component", tenantID, swComp.Attributes)
}

func (s StoreHandler) SynthKeysFromTrustAnchor(tenantID string, ta *handler.Endorsement) ([]string, error) {
return synthKeysFromAttrs("trust anchor", tenantID, ta.Attributes)
}
29 changes: 29 additions & 0 deletions scheme/tpm-enacttrust/store_handler_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package tpm_enacttrust

import (
"os"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/veraison/services/proto"
)

func Test_GetTrustAnchorIds_ok(t *testing.T) {
data, err := os.ReadFile("test/tokens/basic.token")
require.NoError(t, err)

ta := proto.AttestationToken{
TenantId: "0",
MediaType: "application/vnd.enacttrust.tpm-evidence",
Data: data,
}

var s StoreHandler

taIDs, err := s.GetTrustAnchorIDs(&ta)
require.NoError(t, err)
assert.Equal(t, "TPM_ENACTTRUST://0/7df7714e-aa04-4638-bcbf-434b1dd720f1", taIDs[0])
}
2 changes: 1 addition & 1 deletion vts/cmd/vts-service/main.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package main

Expand Down
2 changes: 1 addition & 1 deletion vts/trustedservices/itrustedservices.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package trustedservices

Expand Down
2 changes: 1 addition & 1 deletion vts/trustedservices/trustedservices_grpc.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2022-2023 Contributors to the Veraison project.
// Copyright 2022-2024 Contributors to the Veraison project.
// SPDX-License-Identifier: Apache-2.0
package trustedservices

Expand Down

0 comments on commit 893379d

Please sign in to comment.