initial commit
This commit is contained in:
43
dialer/sshd/metadata.go
Normal file
43
dialer/sshd/metadata.go
Normal file
@ -0,0 +1,43 @@
|
||||
package sshd
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"time"
|
||||
|
||||
mdata "github.com/go-gost/gost/v3/pkg/metadata"
|
||||
"golang.org/x/crypto/ssh"
|
||||
)
|
||||
|
||||
type metadata struct {
|
||||
handshakeTimeout time.Duration
|
||||
signer ssh.Signer
|
||||
}
|
||||
|
||||
func (d *sshdDialer) parseMetadata(md mdata.Metadata) (err error) {
|
||||
const (
|
||||
handshakeTimeout = "handshakeTimeout"
|
||||
privateKeyFile = "privateKeyFile"
|
||||
passphrase = "passphrase"
|
||||
)
|
||||
|
||||
if key := mdata.GetString(md, privateKeyFile); key != "" {
|
||||
data, err := ioutil.ReadFile(key)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
pp := mdata.GetString(md, passphrase)
|
||||
if pp == "" {
|
||||
d.md.signer, err = ssh.ParsePrivateKey(data)
|
||||
} else {
|
||||
d.md.signer, err = ssh.ParsePrivateKeyWithPassphrase(data, []byte(pp))
|
||||
}
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
d.md.handshakeTimeout = mdata.GetDuration(md, handshakeTimeout)
|
||||
|
||||
return
|
||||
}
|
Reference in New Issue
Block a user