From 03d2949f823663210049e93a3c9ea4333010659a Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Wed, 27 Aug 2008 17:24:06 -0700 Subject: [PATCH] Ignore unreadable SSH private keys when autoloading identities During SSH startup we read all keys in the user's ~/.ssh, even if we may not need them for this particular transport session. If a file is not really a key, or it contains a key that JSch doesn't recognize we shouldn't crash the transport. Instead we should skip the file and move on. Later on we just don't have that identity available to us, or we'll crash if we try to add that identity file explicitly from ~/.ssh/config. Signed-off-by: Shawn O. Pearce Signed-off-by: Robin Rosenberg --- .../org/spearce/jgit/transport/DefaultSshSessionFactory.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 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 a2437c29..74fca66f 100644 --- a/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java +++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DefaultSshSessionFactory.java @@ -165,14 +165,21 @@ class DefaultSshSessionFactory extends SshSessionFactory { final File k = new File(sshdir, n.substring(0, n.length() - 4)); if (!k.isFile()) continue; - addIdentity(k); + + try { + addIdentity(k); + } catch (JSchException e) { + continue; + } } } private void addIdentity(final File identityFile) throws JSchException { final String path = identityFile.getAbsolutePath(); - if (loadedIdentities.add(path)) + if (!loadedIdentities.contains(path)) { userJSch.addIdentity(path); + loadedIdentities.add(path); + } } private static class AWT_UserInfo implements UserInfo, -- 2.11.4.GIT