Move password handling so we can extract it

This commit is contained in:
Anders Pitman
2020-10-01 17:42:38 -06:00
parent 59c824bfca
commit 95ab97f043

View File

@@ -16,14 +16,7 @@ type SshServer struct {
func NewSshServer() *SshServer {
config := &ssh.ServerConfig{
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
if c.User() == "user" && string(pass) == "yolo" {
return nil, nil
}
return nil, fmt.Errorf("password rejected for %q", c.User())
},
}
config := &ssh.ServerConfig{}
privateBytes, err := ioutil.ReadFile("id_rsa_boringproxy")
if err != nil {
@@ -63,12 +56,24 @@ func (s *SshServer) acceptAll() {
func (s *SshServer) handleServerConn(nConn net.Conn) {
var password string
s.config.PasswordCallback = func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
password = string(pass)
if c.User() == "user" && string(pass) == "yolo" {
return nil, nil
}
return nil, fmt.Errorf("password rejected for %q", c.User())
}
conn, chans, reqs, err := ssh.NewServerConn(nConn, s.config)
if err != nil {
log.Print("failed to handshake: ", err)
return
}
fmt.Println(password)
go ssh.DiscardRequests(reqs)
go func() {