fix: improve private key parsing by handling escaped newlines and whitespace in credentials #3

Merged
jamie merged 4 commits from v1.1.1 into main 2026-06-09 15:31:52 +01:00
Showing only changes of commit 33c26ec310 - Show all commits
+11 -2
View File
@@ -6,6 +6,7 @@ import (
"fmt"
"io"
"path/filepath"
"strings"
"time"
"github.com/pkg/sftp"
@@ -32,8 +33,16 @@ func (e *SFTPExplorer) Connect() error {
}
var authMethod ssh.AuthMethod
signer, err := ssh.ParsePrivateKey([]byte(e.secret))
if err == nil {
secretStr := strings.TrimSpace(e.secret)
// Handle case where newlines might be escaped by mistake
secretStr = strings.ReplaceAll(secretStr, "\\n", "\n")
if strings.Contains(secretStr, "-----BEGIN") {
signer, err := ssh.ParsePrivateKey([]byte(secretStr))
if err != nil {
return fmt.Errorf("failed to parse private key: %w", err)
}
authMethod = ssh.PublicKeys(signer)
} else {
authMethod = ssh.Password(e.secret)