-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_tcpip_test.go
46 lines (34 loc) · 1016 Bytes
/
example_tcpip_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package easyssh_test
import (
"fmt"
"io/ioutil"
"dev.justinjudd.org/justin/easyssh"
"golang.org/x/crypto/ssh"
)
func ExampleDirectPortForwardChannel() {
s := easyssh.Server{Addr: ":2022"}
privateBytes, err := ioutil.ReadFile("id_rsa")
if err != nil {
// Failed to load private key (./id_rsa)
}
private, err := ssh.ParsePrivateKey(privateBytes)
if err != nil {
// Failed to parse private key
}
config := &ssh.ServerConfig{
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
if c.User() == "test" && string(pass) == "test" {
return nil, nil
}
return nil, fmt.Errorf("password rejected for %s", c.User())
},
}
config.AddHostKey(private)
s.Config = config
handler := easyssh.NewStandardSSHServerHandler()
channelHandler := easyssh.NewChannelsMux()
channelHandler.HandleChannel(easyssh.DirectForwardRequest, easyssh.DirectPortForwardHandler())
handler.MultipleChannelsHandler = channelHandler
s.Handler = handler
s.ListenAndServe()
}