forked from skycoin/skywire
-
Notifications
You must be signed in to change notification settings - Fork 0
/
therealssh.go
73 lines (59 loc) · 1.57 KB
/
therealssh.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
ssh server app for skywire visor
*/
package main
import (
"flag"
"github.com/mitchellh/go-homedir"
"github.com/sirupsen/logrus"
"github.com/SkycoinProject/skycoin/src/util/logging"
"github.com/SkycoinProject/skywire-mainnet/pkg/app"
ssh "github.com/SkycoinProject/skywire-mainnet/pkg/therealssh"
)
var log *logging.MasterLogger
func main() {
log = app.NewLogger("SSH")
ssh.Log = log.PackageLogger("therealssh")
var authFile = flag.String("auth", "~/.therealssh/authorized_keys", "Auth file location. Should contain one PubKey per line.")
var debug = flag.Bool("debug", false, "enable debug messages")
flag.Parse()
config := &app.Config{AppName: "SSH", AppVersion: "1.0", ProtocolVersion: "0.0.1"}
sshApp, err := app.Setup(config)
if err != nil {
log.Fatal("Setup failure: ", err)
}
defer func() {
if err := sshApp.Close(); err != nil {
log.Println("Failed to close app:", err)
}
}()
path, err := homedir.Expand(*authFile)
if err != nil {
log.Fatal("Failed to resolve auth file path: ", err)
}
ssh.Debug = *debug
if !ssh.Debug {
logging.SetLevel(logrus.InfoLevel)
}
auth, err := ssh.NewFileAuthorizer(path)
if err != nil {
log.Fatal("Failed to setup Authorizer: ", err)
}
server := ssh.NewServer(auth, log)
defer func() {
if err := server.Close(); err != nil {
log.Println("Failed to close server:", err)
}
}()
for {
conn, err := sshApp.Accept()
if err != nil {
log.Fatal("failed to receive packet: ", err)
}
go func() {
if err := server.Serve(conn); err != nil {
log.Println("Failed to serve conn:", err)
}
}()
}
}