Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions zedUpload/sftputil/sftp.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,30 @@ type Resp struct {
}

func getSftpClient(host, user, pass string) (*sftp.Client, error) {
// Load allowed host public key from a file and use it to verify the server's host key.
hostKeyBytes, err := os.ReadFile("/etc/ssh/sftp_hostkey.pub")
if err != nil {
return nil, fmt.Errorf("failed to read allowed host key: %w", err)
}
allowedHostKey, _, _, _, err := ssh.ParseAuthorizedKey(hostKeyBytes)
if err != nil {
return nil, fmt.Errorf("failed to parse allowed host key: %w", err)
}

clientConfig := &ssh.ClientConfig{
User: user,
Auth: []ssh.AuthMethod{
ssh.Password(pass),
ssh.KeyboardInteractive(
func(user, instruction string, questions []string, echos []bool) ([]string, error) {
answers := make([]string, len(questions))
for i := range answers {
for i := range answers {
answers[i] = pass
}
return answers, nil
}),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
HostKeyCallback: ssh.FixedHostKey(allowedHostKey),
Timeout: time.Duration(10) * time.Second,
}

Expand Down
Loading