a geicko-2 based round robin ranking system designed to test c++ battleship submissions battleship.dunkirk.sh
1package ssh 2 3import ( 4 "os" 5 6 gossh "golang.org/x/crypto/ssh" 7) 8 9// PasswordAuth returns a functional option that sets PasswordHandler on the server. 10func PasswordAuth(fn PasswordHandler) Option { 11 return func(srv *Server) error { 12 srv.PasswordHandler = fn 13 return nil 14 } 15} 16 17// PublicKeyAuth returns a functional option that sets PublicKeyHandler on the server. 18func PublicKeyAuth(fn PublicKeyHandler) Option { 19 return func(srv *Server) error { 20 srv.PublicKeyHandler = fn 21 return nil 22 } 23} 24 25// HostKeyFile returns a functional option that adds HostSigners to the server 26// from a PEM file at filepath. 27func HostKeyFile(filepath string) Option { 28 return func(srv *Server) error { 29 pemBytes, err := os.ReadFile(filepath) 30 if err != nil { 31 return err 32 } 33 34 signer, err := gossh.ParsePrivateKey(pemBytes) 35 if err != nil { 36 return err 37 } 38 39 srv.AddHostKey(signer) 40 41 return nil 42 } 43} 44 45func KeyboardInteractiveAuth(fn KeyboardInteractiveHandler) Option { 46 return func(srv *Server) error { 47 srv.KeyboardInteractiveHandler = fn 48 return nil 49 } 50} 51 52// HostKeyPEM returns a functional option that adds HostSigners to the server 53// from a PEM file as bytes. 54func HostKeyPEM(bytes []byte) Option { 55 return func(srv *Server) error { 56 signer, err := gossh.ParsePrivateKey(bytes) 57 if err != nil { 58 return err 59 } 60 61 srv.AddHostKey(signer) 62 63 return nil 64 } 65} 66 67// NoPty returns a functional option that sets PtyCallback to return false, 68// denying PTY requests. 69func NoPty() Option { 70 return func(srv *Server) error { 71 srv.PtyCallback = func(Context, Pty) bool { 72 return false 73 } 74 return nil 75 } 76} 77 78// WrapConn returns a functional option that sets ConnCallback on the server. 79func WrapConn(fn ConnCallback) Option { 80 return func(srv *Server) error { 81 srv.ConnCallback = fn 82 return nil 83 } 84} 85 86var contextKeyEmulatePty = &contextKey{"emulate-pty"} 87 88func emulatePtyHandler(ctx Context, _ Session, _ Pty) (func() error, error) { 89 ctx.SetValue(contextKeyEmulatePty, true) 90 return func() error { return nil }, nil 91} 92 93// EmulatePty returns a functional option that fakes a PTY. It uses PtyWriter 94// underneath. 95func EmulatePty() Option { 96 return func(s *Server) error { 97 s.PtyHandler = emulatePtyHandler 98 return nil 99 } 100} 101 102// AllocatePty returns a functional option that allocates a PTY. Implementers 103// who wish to use an actual PTY should use this along with the platform 104// specific PTY implementation defined in pty_*.go. 105func AllocatePty() Option { 106 return func(s *Server) error { 107 s.PtyHandler = func(_ Context, s Session, pty Pty) (func() error, error) { 108 return s.(*session).ptyAllocate(pty.Term, pty.Window, pty.Modes) 109 } 110 return nil 111 } 112}