Skip to content

Commit fe7adb5

Browse files
author
Michal Sidor
committed
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 <m.sidor@samsung.com>
1 parent 32cb659 commit fe7adb5

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

rpc/dryad/clientmanager.go

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ import (
2525
"net"
2626

2727
"git.tizen.org/tools/boruta"
28+
// Needed for SSH public key serialization.
29+
_ "git.tizen.org/tools/boruta/rpc/types"
2830
)
2931

3032
// ClientManager defines API for managing client RPC calls to Dryad.

rpc/superviser/reception.go

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ import (
2828
"net/rpc"
2929

3030
"git.tizen.org/tools/boruta"
31+
// Needed for SSH public key serialization.
32+
_ "git.tizen.org/tools/boruta/rpc/types"
3133
)
3234

3335
type superviserReception struct {

rpc/types/init.go

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2018 Samsung Electronics Co., Ltd All Rights Reserved
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License
15+
*/
16+
17+
// Package types contains gob registration of types needed for RPC
18+
// communication between dryad and supervisor.
19+
package types
20+
21+
import (
22+
"crypto/rsa"
23+
"encoding/gob"
24+
25+
"golang.org/x/crypto/ed25519"
26+
"golang.org/x/crypto/ssh"
27+
)
28+
29+
func init() {
30+
var rsaKey rsa.PublicKey
31+
var ed25519Key ed25519.PublicKey
32+
for _, foreignKey := range []interface{}{&rsaKey, ed25519Key} {
33+
sshKey, err := ssh.NewPublicKey(foreignKey)
34+
if err != nil {
35+
panic("this should never happen: arbitrary ssh key preparation failed: " + err.Error())
36+
}
37+
gob.Register(sshKey)
38+
}
39+
}

0 commit comments

Comments
 (0)