mirror of
https://github.com/gilbertchen/duplicacy
synced 2025-12-10 13:23:17 +00:00
If we have a sftp key file in the environment/preferences, then don't attempt a password login to avoid bad login errors.
This commit is contained in:
@@ -199,6 +199,7 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
if username != "" {
|
if username != "" {
|
||||||
username = username[:len(username) - 1]
|
username = username[:len(username) - 1]
|
||||||
}
|
}
|
||||||
|
keyFile := GetPasswordFromPreference(preference, "ssh_key_file")
|
||||||
|
|
||||||
password := ""
|
password := ""
|
||||||
passwordCallback := func() (string, error) {
|
passwordCallback := func() (string, error) {
|
||||||
@@ -219,7 +220,6 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
keyFile := ""
|
|
||||||
publicKeysCallback := func() ([]ssh.Signer, error) {
|
publicKeysCallback := func() ([]ssh.Signer, error) {
|
||||||
LOG_DEBUG("SSH_PUBLICKEY", "Attempting public key authentication")
|
LOG_DEBUG("SSH_PUBLICKEY", "Attempting public key authentication")
|
||||||
|
|
||||||
@@ -273,10 +273,19 @@ func CreateStorage(preference Preference, resetPassword bool, threads int) (stor
|
|||||||
}
|
}
|
||||||
|
|
||||||
authMethods := [] ssh.AuthMethod {
|
authMethods := [] ssh.AuthMethod {
|
||||||
|
}
|
||||||
|
passwordAuthMethods := [] ssh.AuthMethod {
|
||||||
ssh.PasswordCallback(passwordCallback),
|
ssh.PasswordCallback(passwordCallback),
|
||||||
ssh.KeyboardInteractive(keyboardInteractive),
|
ssh.KeyboardInteractive(keyboardInteractive),
|
||||||
|
}
|
||||||
|
keyFileAuthMethods := [] ssh.AuthMethod {
|
||||||
ssh.PublicKeysCallback(publicKeysCallback),
|
ssh.PublicKeysCallback(publicKeysCallback),
|
||||||
}
|
}
|
||||||
|
if keyFile!="" {
|
||||||
|
authMethods = append(keyFileAuthMethods,passwordAuthMethods...)
|
||||||
|
} else {
|
||||||
|
authMethods = append(passwordAuthMethods,keyFileAuthMethods...)
|
||||||
|
}
|
||||||
|
|
||||||
if RunInBackground {
|
if RunInBackground {
|
||||||
|
|
||||||
|
|||||||
@@ -118,10 +118,8 @@ func GenerateKeyFromPassword(password string) []byte {
|
|||||||
return pbkdf2.Key([]byte(password), DEFAULT_KEY, 16384, 32, sha256.New)
|
return pbkdf2.Key([]byte(password), DEFAULT_KEY, 16384, 32, sha256.New)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPassword attempts to get the password from KeyChain/KeyRing, environment variables, or keyboard input.
|
// Get password from preference, env, but don't start any keyring request
|
||||||
func GetPassword(preference Preference, passwordType string, prompt string,
|
func GetPasswordFromPreference(preference Preference, passwordType string) (string) {
|
||||||
showPassword bool, resetPassword bool) (string) {
|
|
||||||
|
|
||||||
passwordID := passwordType
|
passwordID := passwordType
|
||||||
if preference.Name != "default" {
|
if preference.Name != "default" {
|
||||||
passwordID = preference.Name + "_" + passwordID
|
passwordID = preference.Name + "_" + passwordID
|
||||||
@@ -139,6 +137,17 @@ func GetPassword(preference Preference, passwordType string, prompt string,
|
|||||||
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordID)
|
LOG_DEBUG("PASSWORD_KEYCHAIN", "Reading %s from preferences", passwordID)
|
||||||
return preference.Keys[passwordID]
|
return preference.Keys[passwordID]
|
||||||
}
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetPassword attempts to get the password from KeyChain/KeyRing, environment variables, or keyboard input.
|
||||||
|
func GetPassword(preference Preference, passwordType string, prompt string,
|
||||||
|
showPassword bool, resetPassword bool) (string) {
|
||||||
|
passwordID := passwordType
|
||||||
|
password := GetPasswordFromPreference(preference,passwordType)
|
||||||
|
if password != "" {
|
||||||
|
return password
|
||||||
|
}
|
||||||
|
|
||||||
if resetPassword && !RunInBackground {
|
if resetPassword && !RunInBackground {
|
||||||
keyringSet(passwordID, "")
|
keyringSet(passwordID, "")
|
||||||
@@ -155,7 +164,7 @@ func GetPassword(preference Preference, passwordType string, prompt string,
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
password := ""
|
password = ""
|
||||||
fmt.Printf("%s", prompt)
|
fmt.Printf("%s", prompt)
|
||||||
if showPassword {
|
if showPassword {
|
||||||
scanner := bufio.NewScanner(os.Stdin)
|
scanner := bufio.NewScanner(os.Stdin)
|
||||||
|
|||||||
Reference in New Issue
Block a user