-
Notifications
You must be signed in to change notification settings - Fork 0
/
metadata.go
68 lines (58 loc) · 1.37 KB
/
metadata.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
package ssh
import (
"io/ioutil"
mdata "github.com/go-gost/core/metadata"
mdutil "github.com/go-gost/core/metadata/util"
ssh_util "github.com/wznpp1/gost_x/internal/util/ssh"
"golang.org/x/crypto/ssh"
)
const (
defaultBacklog = 128
)
type metadata struct {
signer ssh.Signer
authorizedKeys map[string]bool
backlog int
}
func (l *sshdListener) parseMetadata(md mdata.Metadata) (err error) {
const (
authorizedKeys = "authorizedKeys"
privateKeyFile = "privateKeyFile"
passphrase = "passphrase"
backlog = "backlog"
)
if key := mdutil.GetString(md, privateKeyFile); key != "" {
data, err := ioutil.ReadFile(key)
if err != nil {
return err
}
pp := mdutil.GetString(md, passphrase)
if pp == "" {
l.md.signer, err = ssh.ParsePrivateKey(data)
} else {
l.md.signer, err = ssh.ParsePrivateKeyWithPassphrase(data, []byte(pp))
}
if err != nil {
return err
}
}
if l.md.signer == nil {
signer, err := ssh.NewSignerFromKey(l.options.TLSConfig.Certificates[0].PrivateKey)
if err != nil {
return err
}
l.md.signer = signer
}
if name := mdutil.GetString(md, authorizedKeys); name != "" {
m, err := ssh_util.ParseAuthorizedKeysFile(name)
if err != nil {
return err
}
l.md.authorizedKeys = m
}
l.md.backlog = mdutil.GetInt(md, backlog)
if l.md.backlog <= 0 {
l.md.backlog = defaultBacklog
}
return
}