Skip to content

Commit

Permalink
feat(sftp): add suport for passphrase of private key (AlistGo#6624 close
Browse files Browse the repository at this point in the history
 AlistGo#6592)

Co-authored-by: XZB <[email protected]>
  • Loading branch information
2 people authored and ForSourceCodeAnalysis committed Aug 4, 2024
1 parent fc0b404 commit bf51f4e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions drivers/sftp/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ type Addition struct {
Username string `json:"username" required:"true"`
PrivateKey string `json:"private_key" type:"text"`
Password string `json:"password"`
Passphrase string `json:"passphrase"`
driver.RootPath
IgnoreSymlinkError bool `json:"ignore_symlink_error" default:"false" info:"Ignore symlink error"`
}
Expand Down
10 changes: 8 additions & 2 deletions drivers/sftp/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,14 @@ import (

func (d *SFTP) initClient() error {
var auth ssh.AuthMethod
if d.PrivateKey != "" {
signer, err := ssh.ParsePrivateKey([]byte(d.PrivateKey))
if len(d.PrivateKey) > 0 {
var err error
var signer ssh.Signer
if len(d.Passphrase) > 0 {
signer, err = ssh.ParsePrivateKeyWithPassphrase([]byte(d.PrivateKey), []byte(d.Passphrase))
} else {
signer, err = ssh.ParsePrivateKey([]byte(d.PrivateKey))
}
if err != nil {
return err
}
Expand Down

0 comments on commit bf51f4e

Please sign in to comment.