Passwort nutzen: Auto-Login via sshpass + Keychain, Editor mit Anzeige/Loeschen, Doku
This commit is contained in:
@@ -39,6 +39,43 @@ enum SSHService {
|
||||
NSPasteboard.general.clearContents()
|
||||
NSPasteboard.general.setString(cmd, forType: .string)
|
||||
}
|
||||
|
||||
// MARK: - Passwort / Auto-Login
|
||||
|
||||
/// Gespeichertes Login-Secret: erst Profil-Passwort, dann Key-Passphrase (Keychain, nie JSON).
|
||||
static func loginSecret(for profile: ConnectionProfile, key: StoredSSHKey?) -> String? {
|
||||
if let acct = profile.passwordAccount,
|
||||
let pw = KeychainHelper.load(account: acct), !pw.isEmpty {
|
||||
return pw
|
||||
}
|
||||
if let key, let acct = key.passphraseAccount,
|
||||
let pp = KeychainHelper.load(account: acct), !pp.isEmpty {
|
||||
return pp
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
static func findSshpass() -> String? {
|
||||
for p in ["/opt/homebrew/bin/sshpass", "/usr/local/bin/sshpass", "/usr/bin/sshpass"] {
|
||||
if FileManager.default.isExecutableFile(atPath: p) { return p }
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
/// true = beim Verbinden wird ohne Tippen eingeloggt (sshpass + Keychain-Secret).
|
||||
static func willAutoLogin(profile: ConnectionProfile, key: StoredSSHKey?) -> Bool {
|
||||
loginSecret(for: profile, key: key) != nil && findSshpass() != nil
|
||||
}
|
||||
|
||||
/// Reine Funktion (testbar): mit Secret+sshpass -> sshpass -e … + SSHPASS-Env,
|
||||
/// sonst direkter Aufruf. Passwort steht NIE in der Befehlszeile (nur im Env).
|
||||
static func sessionConfig(executable: String, args: [String], password: String?, sshpassPath: String?)
|
||||
-> (executable: String, arguments: [String], extraEnv: [String: String], autoLogin: Bool) {
|
||||
if let password, !password.isEmpty, let sshpass = sshpassPath, !sshpass.isEmpty {
|
||||
return (sshpass, ["-e", executable] + args, ["SSHPASS": password], true)
|
||||
}
|
||||
return (executable, args, [:], false)
|
||||
}
|
||||
}
|
||||
|
||||
enum RDPService {
|
||||
|
||||
Reference in New Issue
Block a user