mirror of
https://github.com/edgelesssys/constellation.git
synced 2024-10-01 01:36:09 -04:00
AB#1903 Debug keypushing util program
Signed-off-by: Daniel Weiße <dw@edgeless.systems>
This commit is contained in:
parent
37aff14cab
commit
090afe499d
60
util/keypusher/main.go
Normal file
60
util/keypusher/main.go
Normal file
@ -0,0 +1,60 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"flag"
|
||||
"log"
|
||||
"net"
|
||||
"os"
|
||||
"time"
|
||||
|
||||
"github.com/edgelesssys/constellation/coordinator/atls"
|
||||
"github.com/edgelesssys/constellation/state/keyservice/keyproto"
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/credentials"
|
||||
)
|
||||
|
||||
var (
|
||||
ip = flag.String("ip", "", "IP of the node to push the key to (required)")
|
||||
port = flag.String("port", "9000", "Port of the node to push the key to (required)")
|
||||
key = flag.String("key", "QUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUFBQUE=", "base64 encoded state disk key")
|
||||
)
|
||||
|
||||
func main() {
|
||||
flag.Parse()
|
||||
|
||||
if *ip == "" || *port == "" || *key == "" {
|
||||
flag.Usage()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
decryptionKey, err := base64.StdEncoding.DecodeString(*key)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
addr := net.JoinHostPort(*ip, *port)
|
||||
log.Printf("Pushing key %v to node at %s", decryptionKey, addr)
|
||||
|
||||
clientCfg, err := atls.CreateUnverifiedClientTLSConfig()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
conn, err := grpc.Dial(addr, grpc.WithTransportCredentials(credentials.NewTLS(clientCfg)))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
client := keyproto.NewAPIClient(conn)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second)
|
||||
defer cancel()
|
||||
if _, err := client.PushStateDiskKey(ctx, &keyproto.PushStateDiskKeyRequest{
|
||||
StateDiskKey: decryptionKey,
|
||||
}); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
log.Println("Successfully pushed key to node")
|
||||
}
|
Loading…
Reference in New Issue
Block a user