Skip to content

Commit

Permalink
Adds checksum validation.
Browse files Browse the repository at this point in the history
Signed-off-by: JU4N98 <[email protected]>
  • Loading branch information
JU4N98 committed Jul 10, 2023
1 parent 2fa371f commit c54b46e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
17 changes: 17 additions & 0 deletions pkg/notifier/shared.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package notifier

import (
context "context"
"crypto/sha256"
"encoding/hex"
"fmt"

"github.com/hashicorp/go-plugin"
grpc "google.golang.org/grpc"
Expand Down Expand Up @@ -70,3 +73,17 @@ func GetHandshakeConfig() plugin.HandshakeConfig {
func GetPluginMap() map[string]plugin.Plugin {
return map[string]plugin.Plugin{"plugin": &GRPCNotifier{}}
}

func GetSecureConfig(checksum string) (*plugin.SecureConfig, error) {
sum, err := hex.DecodeString(checksum)
if err != nil {
return nil, fmt.Errorf("checksum is not a valid hex string")
}

hash := sha256.New()
if len(sum) != hash.Size() {
return nil, fmt.Errorf("expected checksum of length %d; got %d", hash.Size()*2, len(sum)*2)
}

return &plugin.SecureConfig{Checksum: sum, Hash: sha256.New()}, nil
}
25 changes: 19 additions & 6 deletions pkg/sidecar/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,24 @@ func (s *Sidecar) signalProcess() (err error) {

func (s *Sidecar) loadPlugins() {
for pluginName, pluginConfig := range s.config.Plugins {
pluginPath := pluginConfig["path"]
if pluginPath == "" {
s.config.Log.Warnf("Please provide a path for plugin %s", pluginName)
continue
}

checksum := pluginConfig["checksum"]
if checksum == "" {
s.config.Log.Warnf("Please provide a checksum for plugin %s", pluginName)
continue
}

secureConfig, err := pb.GetSecureConfig(checksum)
if err != nil {
s.config.Log.Warnf("Error while trying to create secure config for plugin %s", pluginName)
continue
}

request := &pb.ConfigsRequest{}
request.Configs = pluginConfig
request.Configs["certDir"] = s.config.CertDir
Expand All @@ -141,17 +159,12 @@ func (s *Sidecar) loadPlugins() {
request.Configs["svidKeyFileName"] = s.config.SvidKeyFileName
request.Configs["svidBundleFileName"] = s.config.SvidBundleFileName

pluginPath := pluginConfig["path"]
if pluginPath == "" {
s.config.Log.Warnf("Please provide a path for plugin %s", pluginName)
continue
}

client := plugin.NewClient(&plugin.ClientConfig{
HandshakeConfig: pb.GetHandshakeConfig(),
Plugins: pb.GetPluginMap(),
Cmd: exec.Command(pluginPath),
AllowedProtocols: []plugin.Protocol{plugin.ProtocolGRPC},
SecureConfig: secureConfig,
})

RPCClient, err := client.Client()
Expand Down

0 comments on commit c54b46e

Please sign in to comment.