chore: improve SSH_AUTH_SOCK reading on macOS

This commit is contained in:
hstyi
2025-06-15 16:19:41 +08:00
committed by hstyi
parent 51047e60f4
commit 10e7681ac2

View File

@@ -9,6 +9,7 @@ import com.formdev.flatlaf.util.FontUtils
import com.formdev.flatlaf.util.SystemInfo import com.formdev.flatlaf.util.SystemInfo
import com.jgoodies.forms.builder.FormBuilder import com.jgoodies.forms.builder.FormBuilder
import com.jgoodies.forms.layout.FormLayout import com.jgoodies.forms.layout.FormLayout
import org.apache.commons.io.FileUtils
import org.apache.commons.io.IOUtils import org.apache.commons.io.IOUtils
import org.apache.commons.lang3.StringUtils import org.apache.commons.lang3.StringUtils
import org.apache.sshd.client.ClientBuilder import org.apache.sshd.client.ClientBuilder
@@ -231,12 +232,20 @@ object SshClients {
// ssh-agent // ssh-agent
if (host.authentication.type == AuthenticationType.SSHAgent) { if (host.authentication.type == AuthenticationType.SSHAgent) {
if (host.authentication.password.isNotBlank()) if (SystemInfo.isMacOS) {
entry.setProperty(IDENTITY_AGENT, host.authentication.password) val file = FileUtils.getFile(Application.getBaseDataDir(), "config", "ssh_auth_sock.sock")
else if (SystemInfo.isWindows) if (file.exists() && file.isFile) {
entry.setProperty(IDENTITY_AGENT, PageantConnector.DESCRIPTOR.identityAgent) entry.setProperty(IDENTITY_AGENT, file.absolutePath)
else }
entry.setProperty(IDENTITY_AGENT, UnixDomainSocketConnector.DESCRIPTOR.identityAgent) }
if (entry.getProperty(IDENTITY_AGENT).isNullOrBlank()) {
if (host.authentication.password.isNotBlank())
entry.setProperty(IDENTITY_AGENT, host.authentication.password)
else if (SystemInfo.isWindows)
entry.setProperty(IDENTITY_AGENT, PageantConnector.DESCRIPTOR.identityAgent)
else
entry.setProperty(IDENTITY_AGENT, UnixDomainSocketConnector.DESCRIPTOR.identityAgent)
}
} }
val session = client.connect(entry).verify(timeout).session val session = client.connect(entry).verify(timeout).session