ssh: Implement authentication for new ssh server

This commit is contained in:
Tom Wiesing 2022-11-11 14:47:10 +01:00
parent 66b397e9da
commit 45f63935cd
No known key found for this signature in database
10 changed files with 259 additions and 1 deletions

54
cmd/ssh.go Normal file
View file

@ -0,0 +1,54 @@
package cmd
import (
wisski_distillery "github.com/FAU-CDI/wisski-distillery"
"github.com/FAU-CDI/wisski-distillery/internal/cli"
"github.com/tkw1536/goprogram/exit"
)
// SSH is the 'ssh' command
var SSH wisski_distillery.Command = ssh{}
type ssh struct {
Bind string `short:"b" long:"bind" description:"address to listen on" default:"127.0.0.1:2223"`
}
func (s ssh) Description() wisski_distillery.Description {
return wisski_distillery.Description{
Requirements: cli.Requirements{
NeedsDistillery: true,
},
Command: "ssh",
Description: "Starts the ssh server to allow clients to connect to this distillery",
}
}
var errSSHListen = exit.Error{
ExitCode: exit.ExitGeneric,
Message: "Unable to listen",
}
func (s ssh) Run(context wisski_distillery.Context) error {
dis := context.Environment
server, err := dis.SSH().Server(dis.Context(), context.IOStream)
if err != nil {
return err
}
context.Printf("Listening on %s\n", s.Bind)
// make a new listener
listener, err := dis.Still.Environment.Listen("tcp", s.Bind)
if err != nil {
return errServerListen.Wrap(err)
}
go func() {
<-dis.Context().Done()
listener.Close()
}()
// and serve that listener
err = server.Serve(listener)
return errServerListen.Wrap(err)
}