add remote signer api and e2e test of it (#320)

This commit is contained in:
Boshi Lian 2024-02-11 01:54:55 -08:00 committed by GitHub
parent d8b345eeb7
commit 82ac6a5fff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 72 additions and 4 deletions

View file

@ -3,10 +3,14 @@
package main
import (
"crypto"
"encoding/base64"
"fmt"
"net/rpc"
"github.com/tg123/sshpiper/libplugin"
"github.com/urfave/cli/v2"
"golang.org/x/crypto/ssh"
)
func main() {
@ -23,6 +27,10 @@ func main() {
Name: "testsshserver",
Required: true,
},
&cli.StringFlag{
Name: "testremotekey",
Required: true,
},
},
CreateConfig: func(c *cli.Context) (*libplugin.SshPiperPluginConfig, error) {
@ -36,6 +44,21 @@ func main() {
return nil, err
}
keydata, err := base64.StdEncoding.DecodeString(c.String("testremotekey"))
if err != nil {
return nil, err
}
key, err := ssh.ParseRawPrivateKey(keydata)
if err != nil {
return nil, err
}
_, ok := key.(crypto.Signer)
if !ok {
return nil, fmt.Errorf("key format not supported")
}
return &libplugin.SshPiperPluginConfig{
NewConnectionCallback: func(conn libplugin.ConnMetadata) error {
return rpcclient.Call("TestPlugin.NewConnection", "", nil)
@ -56,10 +79,17 @@ func main() {
return &libplugin.Upstream{
Host: host,
Port: int32(port),
Auth: libplugin.CreatePasswordAuthFromString(newpass),
Auth: libplugin.CreateRemoteSignerAuth("testplugin"),
IgnoreHostKey: true,
}, nil
},
GrpcRemoteSignerFactory: func(metadata string) crypto.Signer {
if metadata != "testplugin" {
panic("metadata mismatch")
}
return key.(crypto.Signer)
},
}, nil
},
})