@@ -2,8 +2,12 @@ package agent
2
2
3
3
import (
4
4
"context"
5
+ "crypto/rand"
6
+ "crypto/rsa"
5
7
"errors"
8
+ "fmt"
6
9
"io"
10
+ "net"
7
11
"sync"
8
12
"time"
9
13
@@ -47,15 +51,37 @@ type server struct {
47
51
48
52
func (s * server ) init (ctx context.Context ) {
49
53
forwardHandler := & ssh.ForwardedTCPHandler {}
54
+ key , err := rsa .GenerateKey (rand .Reader , 2048 )
55
+ if err != nil {
56
+ panic (err )
57
+ }
58
+ signer , err := gossh .NewSignerFromKey (key )
59
+ if err != nil {
60
+ panic (err )
61
+ }
50
62
s .sshServer = & ssh.Server {
63
+ ChannelHandlers : ssh .DefaultChannelHandlers ,
64
+ ConnectionFailedCallback : func (conn net.Conn , err error ) {
65
+ fmt .Printf ("Conn failed: %s\n " , err )
66
+ },
67
+ Handler : func (s ssh.Session ) {
68
+ fmt .Printf ("WE GOT %q %q\n " , s .User (), s .RawCommand ())
69
+ },
70
+ HostSigners : []ssh.Signer {signer },
51
71
LocalPortForwardingCallback : func (ctx ssh.Context , destinationHost string , destinationPort uint32 ) bool {
72
+ // Allow local port forwarding all!
73
+ return true
74
+ },
75
+ PtyCallback : func (ctx ssh.Context , pty ssh.Pty ) bool {
52
76
return false
53
77
},
54
78
ReversePortForwardingCallback : func (ctx ssh.Context , bindHost string , bindPort uint32 ) bool {
55
- return false
79
+ // Allow revere port forwarding all!
80
+ return true
56
81
},
57
- PtyCallback : func (ctx ssh.Context , pty ssh.Pty ) bool {
58
- return false
82
+ RequestHandlers : map [string ]ssh.RequestHandler {
83
+ "tcpip-forward" : forwardHandler .HandleSSHRequest ,
84
+ "cancel-tcpip-forward" : forwardHandler .HandleSSHRequest ,
59
85
},
60
86
ServerConfigCallback : func (ctx ssh.Context ) * gossh.ServerConfig {
61
87
return & gossh.ServerConfig {
@@ -65,13 +91,12 @@ func (s *server) init(ctx context.Context) {
65
91
// encrypted. If possible, we'd disable encryption entirely here.
66
92
Ciphers : []string {"arcfour" },
67
93
},
94
+ PublicKeyCallback : func (conn gossh.ConnMetadata , key gossh.PublicKey ) (* gossh.Permissions , error ) {
95
+ return & gossh.Permissions {}, nil
96
+ },
68
97
NoClientAuth : true ,
69
98
}
70
99
},
71
- RequestHandlers : map [string ]ssh.RequestHandler {
72
- "tcpip-forward" : forwardHandler .HandleSSHRequest ,
73
- "cancel-tcpip-forward" : forwardHandler .HandleSSHRequest ,
74
- },
75
100
}
76
101
77
102
go s .run (ctx )
0 commit comments