From fe7adb5a339122f5b2fb4b23282ab16b6b2af62c Mon Sep 17 00:00:00 2001 From: Michal Sidor Date: Mon, 17 Sep 2018 12:05:35 +0200 Subject: [PATCH] Fix inability to send SSH keys over RPC Gob is used by auto-generated RPC services to (de)serialize structures used in method calls. Because ssh.PublicKey is an interface, gob is unable to serialize it, unless its underlying concrete types are registered using `gob.Register(anythingOfAforementionedType)`. Change-Id: I0e28e5d58a2b69a6d726bb1ddb73e2f6d8e3f99e Signed-off-by: Michal Sidor --- rpc/dryad/clientmanager.go | 2 ++ rpc/superviser/reception.go | 2 ++ rpc/types/init.go | 39 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+) create mode 100644 rpc/types/init.go diff --git a/rpc/dryad/clientmanager.go b/rpc/dryad/clientmanager.go index f8c6a55..be7c906 100644 --- a/rpc/dryad/clientmanager.go +++ b/rpc/dryad/clientmanager.go @@ -25,6 +25,8 @@ import ( "net" "git.tizen.org/tools/boruta" + // Needed for SSH public key serialization. + _ "git.tizen.org/tools/boruta/rpc/types" ) // ClientManager defines API for managing client RPC calls to Dryad. diff --git a/rpc/superviser/reception.go b/rpc/superviser/reception.go index 6d022dd..b70552c 100644 --- a/rpc/superviser/reception.go +++ b/rpc/superviser/reception.go @@ -28,6 +28,8 @@ import ( "net/rpc" "git.tizen.org/tools/boruta" + // Needed for SSH public key serialization. + _ "git.tizen.org/tools/boruta/rpc/types" ) type superviserReception struct { diff --git a/rpc/types/init.go b/rpc/types/init.go new file mode 100644 index 0000000..360bda1 --- /dev/null +++ b/rpc/types/init.go @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License + */ + +// Package types contains gob registration of types needed for RPC +// communication between dryad and supervisor. +package types + +import ( + "crypto/rsa" + "encoding/gob" + + "golang.org/x/crypto/ed25519" + "golang.org/x/crypto/ssh" +) + +func init() { + var rsaKey rsa.PublicKey + var ed25519Key ed25519.PublicKey + for _, foreignKey := range []interface{}{&rsaKey, ed25519Key} { + sshKey, err := ssh.NewPublicKey(foreignKey) + if err != nil { + panic("this should never happen: arbitrary ssh key preparation failed: " + err.Error()) + } + gob.Register(sshKey) + } +} -- 2.7.4