From 9ea2438ded34e273465b8fc3514416839d04ece2 Mon Sep 17 00:00:00 2001 From: Michael Golubev Date: Mon, 2 Jun 2014 15:52:32 +0200 Subject: [PATCH] IDEA-125609 - Built-in Git SSH executable ignores IDEA http proxy settings --- .../jetbrains/git4idea/ssh/GitSSHHandler.java | 10 +++++++++- .../src/org/jetbrains/git4idea/ssh/SSHMain.java | 15 +++++++++++++++ .../src/git4idea/commands/GitHandler.java | 17 +++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) diff --git a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHHandler.java b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHHandler.java index 0ddcffa0ddd3..2bc849d83fb0 100644 --- a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHHandler.java +++ b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/GitSSHHandler.java @@ -48,7 +48,15 @@ public interface GitSSHHandler { * Name of the handler */ @NonNls String HANDLER_NAME = "Git4ideaSSHHandler"; - + /** + * Proxy settings + */ + @NonNls String SSH_USE_PROXY_ENV = "GIT4IDEA_SSH_USE_PROXY"; + @NonNls String SSH_PROXY_HOST_ENV = "GIT4IDEA_SSH_PROXY_HOST"; + @NonNls String SSH_PROXY_PORT_ENV = "GIT4IDEA_SSH_PROXY_PORT"; + @NonNls String SSH_PROXY_AUTHENTICATION_ENV = "GIT4IDEA_SSH_PROXY_AUTHENTICATION"; + @NonNls String SSH_PROXY_USER_ENV = "GIT4IDEA_SSH_PROXY_USER"; + @NonNls String SSH_PROXY_PASSWORD_ENV = "GIT4IDEA_SSH_PROXY_PASSWORD"; /** * Verify server host key * diff --git a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMain.java b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMain.java index 29a6b58ead19..efe567fb52cb 100644 --- a/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMain.java +++ b/plugins/git4idea/rt/src/org/jetbrains/git4idea/ssh/SSHMain.java @@ -153,6 +153,21 @@ public class SSHMain implements GitExternalApp { Connection c = new Connection(myHost.getHostName(), myHost.getPort()); try { configureKnownHosts(c); + + boolean useHttpProxy = Boolean.valueOf(System.getenv(GitSSHHandler.SSH_USE_PROXY_ENV)); + if (useHttpProxy) { + String proxyHost = System.getenv(GitSSHHandler.SSH_PROXY_HOST_ENV); + Integer proxyPort = Integer.valueOf(System.getenv(GitSSHHandler.SSH_PROXY_PORT_ENV)); + boolean proxyAuthentication = Boolean.valueOf(System.getenv(GitSSHHandler.SSH_PROXY_AUTHENTICATION_ENV)); + String proxyUser = null; + String proxyPassword = null; + if (proxyAuthentication) { + proxyUser = System.getenv(GitSSHHandler.SSH_PROXY_USER_ENV); + proxyPassword = System.getenv(GitSSHHandler.SSH_PROXY_PASSWORD_ENV); + } + c.setProxyData(new HTTPProxyData(proxyHost, proxyPort, proxyUser, proxyPassword)); + } + c.connect(new HostKeyVerifier()); authenticate(c); final Session s = c.openSession(); diff --git a/plugins/git4idea/src/git4idea/commands/GitHandler.java b/plugins/git4idea/src/git4idea/commands/GitHandler.java index 283c94108d8e..3350b74b1c6a 100644 --- a/plugins/git4idea/src/git4idea/commands/GitHandler.java +++ b/plugins/git4idea/src/git4idea/commands/GitHandler.java @@ -32,6 +32,7 @@ import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.EventDispatcher; import com.intellij.util.Processor; +import com.intellij.util.net.HttpConfigurable; import com.intellij.vcsUtil.VcsFileUtil; import git4idea.GitVcs; import git4idea.config.GitVcsApplicationSettings; @@ -436,6 +437,22 @@ public abstract class GitHandler { int port = ssh.getXmlRcpPort(); myEnv.put(GitSSHHandler.SSH_PORT_ENV, Integer.toString(port)); LOG.debug(String.format("handler=%s, port=%s", myHandlerNo, port)); + + final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance(); + boolean useHttpProxy = httpConfigurable.USE_HTTP_PROXY; + myEnv.put(GitSSHHandler.SSH_USE_PROXY_ENV, String.valueOf(useHttpProxy)); + + if (useHttpProxy) { + myEnv.put(GitSSHHandler.SSH_PROXY_HOST_ENV, httpConfigurable.PROXY_HOST); + myEnv.put(GitSSHHandler.SSH_PROXY_PORT_ENV, String.valueOf(httpConfigurable.PROXY_PORT)); + boolean proxyAuthentication = httpConfigurable.PROXY_AUTHENTICATION; + myEnv.put(GitSSHHandler.SSH_PROXY_AUTHENTICATION_ENV, String.valueOf(proxyAuthentication)); + + if (proxyAuthentication) { + myEnv.put(GitSSHHandler.SSH_PROXY_USER_ENV, httpConfigurable.PROXY_LOGIN); + myEnv.put(GitSSHHandler.SSH_PROXY_PASSWORD_ENV, httpConfigurable.getPlainProxyPassword()); + } + } } else if (remoteProtocol == GitRemoteProtocol.HTTP) { GitHttpAuthService service = ServiceManager.getService(GitHttpAuthService.class);