{"thread":{"id":"18827","subject":"[JGIT PATCH] Added support for StrictHostKeyChecking property in SSH config","startedAt":"2009-04-10T16:27:31Z","lastAt":"2009-04-10T16:27:31Z","messageCount":1,"participants":["Constantine Plotnikov"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"111013","messageId":"85647ef50904100927k11d36945h1c5b2c63b4f35e26@mail.gmail.com","threadId":"18827","inReplyTo":null,"subject":"[JGIT PATCH] Added support for StrictHostKeyChecking property in SSH config","fromName":"Constantine Plotnikov","fromEmail":"constantine.plotnikov@gmail.com","sentAt":"2009-04-10T16:27:31Z","receivedAt":"2009-04-10T16:27:31Z","isPatch":true,"sender":{"key":"constantine.plotnikov@gmail.com","avatar":null},"body":"StrictHostKeyChecking property allows to specify ssh behavior\nwhen ssh client encounters a new host or a change of the host key.\nThus in addition to the default policy \"ask\", it is now possible to specify\n\"yes\" and \"no\" policies that automatically reject and accept new host\nkeys.\n\nSigned-off-by: Constantine Plotnikov <constantine.plotnikov@gmail.com>\n---\nThis patch is needed for running JGit in the application server context.\nThe property allows suppressing appearance of known hosts message box\nthat does not makes sense in this context.\n\nI'm working on more extensive patch that allows more flexible\nconfiguration of SSH, but this is a minimal change required.\n\n .../jgit/transport/DefaultSshSessionFactory.java   |    4 +++-\n .../org/spearce/jgit/transport/OpenSshConfig.java  |   19 +++++++++++++++++++\n 2 files changed, 22 insertions(+), 1 deletions(-)\n\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java\nb/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java\nindex 0d522df..c9050fa 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java\n@@ -103,7 +103,9 @@ public synchronized Session getSession(String\nuser, String pass,\n \t\t\tsession.setPassword(pass);\n \t\telse if (!hc.isBatchMode())\n \t\t\tsession.setUserInfo(new AWT_UserInfo());\n-\n+\t\tfinal String strictHostKeyCheckingPolicy = hc.getStrictHostKeyChecking();\n+\t\tif (strictHostKeyCheckingPolicy != null)\n+\t\t\tsession.setConfig(\"StrictHostKeyChecking\", strictHostKeyCheckingPolicy);\n \t\tfinal String pauth = hc.getPreferredAuthentications();\n \t\tif (pauth != null)\n \t\t\tsession.setConfig(\"PreferredAuthentications\", pauth);\ndiff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java\nb/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java\nindex 0d9f12f..eadcfd0 100644\n--- a/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java\n+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/OpenSshConfig.java\n@@ -221,6 +221,11 @@ public Host lookup(final String hostName) {\n \t\t\t\tfor (final Host c : current)\n \t\t\t\t\tif (c.batchMode == null)\n \t\t\t\t\t\tc.batchMode = yesno(dequote(argValue));\n+\t\t\t} else if (\"StrictHostKeyChecking\".equalsIgnoreCase(keyword)) {\n+\t\t\t\tString value = dequote(argValue);\n+\t\t\t\tfor (final Host c : current)\n+\t\t\t\t\tif (c.strictHostKeyChecking == null)\n+\t\t\t\t\t\tc.strictHostKeyChecking = value;\n \t\t\t}\n \t\t}\n\n@@ -298,6 +303,8 @@ private File toFile(final String path) {\n\n \t\tBoolean batchMode;\n\n+\t\tString strictHostKeyChecking;\n+\n \t\tvoid copyFrom(final Host src) {\n \t\t\tif (hostName == null)\n \t\t\t\thostName = src.hostName;\n@@ -311,9 +318,21 @@ void copyFrom(final Host src) {\n \t\t\t\tpreferredAuthentications = src.preferredAuthentications;\n \t\t\tif (batchMode == null)\n \t\t\t\tbatchMode = src.batchMode;\n+\t\t\tif (strictHostKeyChecking == null)\n+\t\t\t\tstrictHostKeyChecking = src.strictHostKeyChecking;\n \t\t}\n\n \t\t/**\n+\t\t * @return the value StrictHostKeyChecking property, the valid values\n+\t\t *         are \"yes\" (unknown hosts are not accepted), \"no\" (unknown\n+\t\t *         hosts are always accepted), and \"ask\" (user should be asked\n+\t\t *         before accepting the host)\n+\t\t */\n+\t\tpublic String getStrictHostKeyChecking() {\n+\t\t\treturn strictHostKeyChecking;\n+\t\t}\n+\t\t\n+\t\t/**\n \t\t * @return the real IP address or host name to connect to; never null.\n \t\t */\n \t\tpublic String getHostName() {\n-- \n1.6.0.2.1172.ga5ed0\n"}]}