git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Constantine Plotnikov <constantine.plotnikov@gmail.com>
To: git@vger.kernel.org
Subject: [JGIT PATCH] Added support for StrictHostKeyChecking property in SSH  config
Date: Fri, 10 Apr 2009 20:27:31 +0400	[thread overview]
Message-ID: <85647ef50904100927k11d36945h1c5b2c63b4f35e26@mail.gmail.com> (raw)

StrictHostKeyChecking property allows to specify ssh behavior
when ssh client encounters a new host or a change of the host key.
Thus in addition to the default policy "ask", it is now possible to specify
"yes" and "no" policies that automatically reject and accept new host
keys.

Signed-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>
---
This patch is needed for running JGit in the application server context.
The property allows suppressing appearance of known hosts message box
that does not makes sense in this context.

I'm working on more extensive patch that allows more flexible
configuration of SSH, but this is a minimal change required.

 .../jgit/transport/DefaultSshSessionFactory.java   |    4 +++-
 .../org/spearce/jgit/transport/OpenSshConfig.java  |   19 +++++++++++++++++++
 2 files changed, 22 insertions(+), 1 deletions(-)

diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
index 0d522df..c9050fa 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java
@@ -103,7 +103,9 @@ public synchronized Session getSession(String
user, String pass,
 			session.setPassword(pass);
 		else if (!hc.isBatchMode())
 			session.setUserInfo(new AWT_UserInfo());
-
+		final String strictHostKeyCheckingPolicy = hc.getStrictHostKeyChecking();
+		if (strictHostKeyCheckingPolicy != null)
+			session.setConfig("StrictHostKeyChecking", strictHostKeyCheckingPolicy);
 		final String pauth = hc.getPreferredAuthentications();
 		if (pauth != null)
 			session.setConfig("PreferredAuthentications", pauth);
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
index 0d9f12f..eadcfd0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java
@@ -221,6 +221,11 @@ public Host lookup(final String hostName) {
 				for (final Host c : current)
 					if (c.batchMode == null)
 						c.batchMode = yesno(dequote(argValue));
+			} else if ("StrictHostKeyChecking".equalsIgnoreCase(keyword)) {
+				String value = dequote(argValue);
+				for (final Host c : current)
+					if (c.strictHostKeyChecking == null)
+						c.strictHostKeyChecking = value;
 			}
 		}

@@ -298,6 +303,8 @@ private File toFile(final String path) {

 		Boolean batchMode;

+		String strictHostKeyChecking;
+
 		void copyFrom(final Host src) {
 			if (hostName == null)
 				hostName = src.hostName;
@@ -311,9 +318,21 @@ void copyFrom(final Host src) {
 				preferredAuthentications = src.preferredAuthentications;
 			if (batchMode == null)
 				batchMode = src.batchMode;
+			if (strictHostKeyChecking == null)
+				strictHostKeyChecking = src.strictHostKeyChecking;
 		}

 		/**
+		 * @return the value StrictHostKeyChecking property, the valid values
+		 *         are "yes" (unknown hosts are not accepted), "no" (unknown
+		 *         hosts are always accepted), and "ask" (user should be asked
+		 *         before accepting the host)
+		 */
+		public String getStrictHostKeyChecking() {
+			return strictHostKeyChecking;
+		}
+		
+		/**
 		 * @return the real IP address or host name to connect to; never null.
 		 */
 		public String getHostName() {
-- 
1.6.0.2.1172.ga5ed0

                 reply	other threads:[~2009-04-10 16:29 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=85647ef50904100927k11d36945h1c5b2c63b4f35e26@mail.gmail.com \
    --to=constantine.plotnikov@gmail.com \
    --cc=git@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).