-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yogesh Deshpande <[email protected]>
- Loading branch information
1 parent
8e55820
commit c5d9aa8
Showing
6 changed files
with
338 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2021-2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package handler | ||
|
||
import ( | ||
"github.com/veraison/services/plugin" | ||
"github.com/veraison/services/proto" | ||
) | ||
|
||
// IStoreHandler defines the interface to functionality for working with | ||
// attestation scheme specific store interfaces. This includes extracting | ||
// Trust Anchor IDs from attestation token, and synthesizing, | ||
// Reference Value and TrustAnchor Keys from supplied endorsements | ||
type IStoreHandler interface { | ||
plugin.IPluggable | ||
|
||
// GetTrustAnchorIDs returns an array of trust anchor identifiers used | ||
// to retrieve the trust anchors associated with this token. The trust anchors may be necessary to validate the | ||
// entire token and/or extract its claims (if it is encrypted). | ||
GetTrustAnchorIDs(token *proto.AttestationToken) ([]string, error) | ||
|
||
// SynthKeysFromRefValue synthesizes lookup key(s) for the | ||
// provided reference value endorsement. | ||
SynthKeysFromRefValue(tenantID string, refVal *Endorsement) ([]string, error) | ||
|
||
// SynthKeysFromTrustAnchor synthesizes lookup key(s) for the provided | ||
// trust anchor. | ||
SynthKeysFromTrustAnchor(tenantID string, ta *Endorsement) ([]string, error) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
// Copyright 2022-2024 Contributors to the Veraison project. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package handler | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/rpc" | ||
|
||
"github.com/veraison/services/plugin" | ||
"github.com/veraison/services/proto" | ||
) | ||
|
||
/* | ||
Server-side RPC adapter around the Decoder plugin implementation | ||
(plugin-side) | ||
*/ | ||
|
||
var StoreHandlerRPC = &plugin.RPCChannel[IStoreHandler]{ | ||
GetClient: getStoreClient, | ||
GetServer: getStoreServer, | ||
} | ||
|
||
func getStoreClient(c *rpc.Client) interface{} { | ||
return &StoreRPCClient{client: c} | ||
} | ||
|
||
func getStoreServer(i IStoreHandler) interface{} { | ||
return &StoreRPCServer{Impl: i} | ||
} | ||
|
||
type StoreRPCServer struct { | ||
Impl IStoreHandler | ||
} | ||
|
||
// TO DO Check, do we need store Init/Close() Methods? | ||
/* | ||
func (s StoreRPCServer) Close(unused0 interface{}, unused1 interface{}) error { | ||
return s.Impl.Close() | ||
} | ||
*/ | ||
|
||
func (s *StoreRPCServer) GetName(args interface{}, resp *string) error { | ||
*resp = s.Impl.GetName() | ||
return nil | ||
} | ||
|
||
func (s *StoreRPCServer) GetAttestationScheme(args interface{}, resp *string) error { | ||
*resp = s.Impl.GetAttestationScheme() | ||
return nil | ||
} | ||
|
||
func (s *StoreRPCServer) GetSupportedMediaTypes(args interface{}, resp *[]string) error { | ||
*resp = s.Impl.GetSupportedMediaTypes() | ||
return nil | ||
} | ||
|
||
// TO DO Retain the Name | ||
type SynthKeysArgs1 struct { | ||
TenantID string | ||
EndorsementJSON []byte | ||
} | ||
|
||
func (s *StoreRPCServer) SynthKeysFromRefValue(args SynthKeysArgs1, resp *[]string) error { | ||
var ( | ||
err error | ||
swComp Endorsement | ||
) | ||
|
||
err = json.Unmarshal(args.EndorsementJSON, &swComp) | ||
if err != nil { | ||
return fmt.Errorf("unmarshaling software component: %w", err) | ||
} | ||
|
||
*resp, err = s.Impl.SynthKeysFromRefValue(args.TenantID, &swComp) | ||
|
||
return err | ||
} | ||
|
||
func (s *StoreRPCServer) SynthKeysFromTrustAnchor(args SynthKeysArgs1, resp *[]string) error { | ||
var ( | ||
err error | ||
ta Endorsement | ||
) | ||
|
||
err = json.Unmarshal(args.EndorsementJSON, &ta) | ||
if err != nil { | ||
return fmt.Errorf("unmarshaling trust anchor: %w", err) | ||
} | ||
|
||
*resp, err = s.Impl.SynthKeysFromTrustAnchor(args.TenantID, &ta) | ||
|
||
return err | ||
} | ||
|
||
func (s *StoreRPCServer) GetTrustAnchorIDs(data []byte, resp *[]string) error { | ||
var ( | ||
err error | ||
token proto.AttestationToken | ||
) | ||
|
||
err = json.Unmarshal(data, &token) | ||
if err != nil { | ||
return fmt.Errorf("unmarshaling attestation token: %w", err) | ||
} | ||
|
||
*resp, err = s.Impl.GetTrustAnchorIDs(&token) | ||
|
||
return err | ||
} | ||
|
||
/* | ||
RPC client | ||
(plugin caller side) | ||
*/ | ||
|
||
type StoreRPCClient struct { | ||
client *rpc.Client | ||
} | ||
|
||
func (c StoreRPCClient) Close() error { | ||
var ( | ||
unused0 interface{} | ||
unused1 interface{} | ||
) | ||
|
||
return c.client.Call("Plugin.Close", unused0, unused1) | ||
} | ||
|
||
func (c StoreRPCClient) GetName() string { | ||
var ( | ||
err error | ||
resp string | ||
unused interface{} | ||
) | ||
|
||
err = c.client.Call("Plugin.GetName", &unused, &resp) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
return resp | ||
} | ||
|
||
func (c StoreRPCClient) GetAttestationScheme() string { | ||
var ( | ||
err error | ||
resp string | ||
unused interface{} | ||
) | ||
|
||
err = c.client.Call("Plugin.GetAttestationScheme", &unused, &resp) | ||
if err != nil { | ||
return "" | ||
} | ||
|
||
return resp | ||
} | ||
|
||
func (c StoreRPCClient) GetSupportedMediaTypes() []string { | ||
var ( | ||
err error | ||
resp []string | ||
unused interface{} | ||
) | ||
|
||
err = c.client.Call("Plugin.GetSupportedMediaTypes", &unused, &resp) | ||
if err != nil { | ||
return nil | ||
} | ||
|
||
return resp | ||
} | ||
|
||
func (s *StoreRPCClient) SynthKeysFromRefValue(tenantID string, swComp *Endorsement) ([]string, error) { | ||
var ( | ||
err error | ||
resp []string | ||
args SynthKeysArgs | ||
) | ||
|
||
args.TenantID = tenantID | ||
|
||
args.EndorsementJSON, err = json.Marshal(swComp) | ||
if err != nil { | ||
return nil, fmt.Errorf("marshaling software component: %w", err) | ||
} | ||
|
||
err = s.client.Call("Plugin.SynthKeysFromRefValue", args, &resp) | ||
if err != nil { | ||
err = ParseError(err) | ||
return nil, fmt.Errorf("Plugin.SynthKeysFromRefValue RPC call failed: %w", err) // nolint | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (s *StoreRPCClient) SynthKeysFromTrustAnchor(tenantID string, ta *Endorsement) ([]string, error) { | ||
var ( | ||
err error | ||
resp []string | ||
args SynthKeysArgs | ||
) | ||
|
||
args.TenantID = tenantID | ||
|
||
args.EndorsementJSON, err = json.Marshal(ta) | ||
if err != nil { | ||
return nil, fmt.Errorf("marshaling trust anchor: %w", err) | ||
} | ||
|
||
err = s.client.Call("Plugin.SynthKeysFromTrustAnchor", args, &resp) | ||
if err != nil { | ||
err = ParseError(err) | ||
return nil, fmt.Errorf("Plugin.SynthKeysFromTrustAnchor RPC call failed: %w", err) // nolint | ||
} | ||
|
||
return resp, nil | ||
} | ||
|
||
func (s *StoreRPCClient) GetTrustAnchorIDs(token *proto.AttestationToken) ([]string, error) { | ||
var ( | ||
err error | ||
data []byte | ||
resp []string | ||
) | ||
|
||
data, err = json.Marshal(token) | ||
if err != nil { | ||
return []string{""}, fmt.Errorf("marshaling token: %w", err) | ||
} | ||
|
||
err = s.client.Call("Plugin.GetTrustAnchorIDs", data, &resp) | ||
if err != nil { | ||
err = ParseError(err) | ||
return []string{""}, fmt.Errorf("Plugin.GetTrustAnchorIDs RPC call failed: %w", err) // nolint | ||
} | ||
|
||
return resp, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.