-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrequests.go
55 lines (48 loc) · 1.63 KB
/
requests.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
47
48
49
50
51
52
53
54
55
package revssh
import (
"fmt"
"log"
"golang.org/x/crypto/ssh"
)
type requestHandler func(srv *Server, sshConn *ssh.ServerConn, req *ssh.Request)
// ReverseClientData contains the ssh reverse channel data,
// as per RFC 4254 Section 4
type ReverseClientData struct {
Version string // Implementation version.
Hostname string // Hostname to register.
Username string // Username to register the ssh keys under.
PublicKeysHex []string // list of ssh Publickeys, in hex. (for marshalling purposes)
}
func reverseClientRequestHandler(srv *Server, sshConn *ssh.ServerConn, req *ssh.Request) {
log.Printf("Reverse client registration received for client: %s", sshConn.User())
d := &ReverseClientData{}
if err := ssh.Unmarshal(req.Payload, d); err != nil {
log.Printf("%+v", err)
}
sessionKey := srv.GetSession(sshConn.SessionID())
// TODO: normalize hostname / port
err := srv.Settings.IsKnownHost(fmt.Sprintf("%s:22", d.Hostname), sshConn.RemoteAddr(), sessionKey)
if err != nil {
log.Printf("%+v", err)
req.Reply(false, []byte("v1"))
return
}
// if knownKey == nil {
// _ = srv.Settings.AddKnownHost(d.Hostname, sessionKey)
// }
// if !revutil.KeysEqual(sessionKey, knownKey) && knownKey != nil {
// log.Printf("hostname already registered")
// req.Reply(false, []byte("v1"))
// }
err = srv.NewReverseClient(sshConn, d)
if err != nil {
log.Printf("%+v", err)
req.Reply(false, []byte("v1"))
return
}
req.Reply(true, []byte("v1"))
}
func keepaliveRequestHandler(srv *Server, sshConn *ssh.ServerConn, req *ssh.Request) {
// log.Printf("keepalive request from %s", sshConn.User())
req.Reply(true, nil)
}