package ssh
import (
"os"
gossh "golang.org/x/crypto/ssh"
)
func PasswordAuth (fn PasswordHandler ) Option {
return func (srv *Server ) error {
srv .PasswordHandler = fn
return nil
}
}
func PublicKeyAuth (fn PublicKeyHandler ) Option {
return func (srv *Server ) error {
srv .PublicKeyHandler = fn
return nil
}
}
func HostKeyFile (filepath string ) Option {
return func (srv *Server ) error {
pemBytes , err := os .ReadFile (filepath )
if err != nil {
return err
}
signer , err := gossh .ParsePrivateKey (pemBytes )
if err != nil {
return err
}
srv .AddHostKey (signer )
return nil
}
}
func KeyboardInteractiveAuth (fn KeyboardInteractiveHandler ) Option {
return func (srv *Server ) error {
srv .KeyboardInteractiveHandler = fn
return nil
}
}
func HostKeyPEM (bytes []byte ) Option {
return func (srv *Server ) error {
signer , err := gossh .ParsePrivateKey (bytes )
if err != nil {
return err
}
srv .AddHostKey (signer )
return nil
}
}
func NoPty () Option {
return func (srv *Server ) error {
srv .PtyCallback = func (Context , Pty ) bool {
return false
}
return nil
}
}
func WrapConn (fn ConnCallback ) Option {
return func (srv *Server ) error {
srv .ConnCallback = fn
return nil
}
}
var contextKeyEmulatePty = &contextKey {"emulate-pty" }
func emulatePtyHandler(ctx Context , _ Session , _ Pty ) (func () error , error ) {
ctx .SetValue (contextKeyEmulatePty , true )
return func () error { return nil }, nil
}
func EmulatePty () Option {
return func (s *Server ) error {
s .PtyHandler = emulatePtyHandler
return nil
}
}
func AllocatePty () Option {
return func (s *Server ) error {
s .PtyHandler = func (_ Context , s Session , pty Pty ) (func () error , error ) {
return s .(*session ).ptyAllocate (pty .Term , pty .Window , pty .Modes )
}
return nil
}
}
The pages are generated with Golds v0.8.2 . (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu .
PR and bug reports are welcome and can be submitted to the issue list .
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds .