git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [JGIT PATCH 1/2] Ignore unreadable SSH private keys when autoloading identities
@ 2008-08-27 23:02 Shawn O. Pearce
  2008-08-27 23:02 ` [JGIT PATCH 2/2] pgm.push: Ensure SSH connections are closed Shawn O. Pearce
  2008-08-27 23:26 ` [JGIT PATCH 1/2] Ignore unreadable SSH private keys when autoloading identities Marek Zawirski
  0 siblings, 2 replies; 5+ messages in thread
From: Shawn O. Pearce @ 2008-08-27 23:02 UTC (permalink / raw)
  To: Robin Rosenberg; +Cc: git

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 <spearce@spearce.org>
---
 .../jgit/transport/DefaultSshSessionFactory.java   |   13 +++++++++++--
 1 files changed, 11 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 a2437c2..aa72357 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,23 @@ private void identities() throws JSchException {
 			final File k = new File(sshdir, n.substring(0, n.length() - 4));
 			if (!k.isFile())
 				continue;
-			addIdentity(k);
+
+			try {
+				addIdentity(k);
+			} catch (JSchException e) {
+				if (e.getMessage().startsWith("invalid privatekey: "))
+					continue;
+				throw e;
+			}
 		}
 	}
 
 	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,
-- 
1.6.0.174.gd789c

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2008-08-28  0:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-27 23:02 [JGIT PATCH 1/2] Ignore unreadable SSH private keys when autoloading identities Shawn O. Pearce
2008-08-27 23:02 ` [JGIT PATCH 2/2] pgm.push: Ensure SSH connections are closed Shawn O. Pearce
2008-08-27 23:26 ` [JGIT PATCH 1/2] Ignore unreadable SSH private keys when autoloading identities Marek Zawirski
2008-08-27 23:29   ` Shawn O. Pearce
2008-08-28  0:24     ` [JGIT PATCH 1/2 v2] " Shawn O. Pearce

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).