You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by gn...@apache.org on 2014/02/26 13:48:51 UTC

git commit: [SSHD-292] The SshClient class has a strong dependency on BoucyCastle

Repository: mina-sshd
Updated Branches:
  refs/heads/master cbb523dc2 -> c9a6c163c


[SSHD-292] The SshClient class has a strong dependency on BoucyCastle

Project: http://git-wip-us.apache.org/repos/asf/mina-sshd/repo
Commit: http://git-wip-us.apache.org/repos/asf/mina-sshd/commit/c9a6c163
Tree: http://git-wip-us.apache.org/repos/asf/mina-sshd/tree/c9a6c163
Diff: http://git-wip-us.apache.org/repos/asf/mina-sshd/diff/c9a6c163

Branch: refs/heads/master
Commit: c9a6c163c3928ea137597a6e665a480a426b1a30
Parents: cbb523d
Author: Guillaume Nodet <gn...@apache.org>
Authored: Wed Feb 26 13:48:39 2014 +0100
Committer: Guillaume Nodet <gn...@apache.org>
Committed: Wed Feb 26 13:48:39 2014 +0100

----------------------------------------------------------------------
 .../main/java/org/apache/sshd/SshClient.java    | 38 +++++++++++++-------
 1 file changed, 26 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/c9a6c163/sshd-core/src/main/java/org/apache/sshd/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
index 75eb2ed..967d020 100644
--- a/sshd-core/src/main/java/org/apache/sshd/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/SshClient.java
@@ -37,6 +37,7 @@ import java.util.Date;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
+import java.util.concurrent.Callable;
 import java.util.concurrent.Executors;
 import java.util.logging.ConsoleHandler;
 import java.util.logging.Formatter;
@@ -560,7 +561,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
         }
 
         KeyPairProvider provider = null;
-        List<String> files = new ArrayList<String>();
+        final List<String> files = new ArrayList<String>();
         File f = new File(System.getProperty("user.home"), ".ssh/id_dsa");
         if (f.exists() && f.isFile() && f.canRead()) {
             files.add(f.getAbsolutePath());
@@ -570,18 +571,31 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
             files.add(f.getAbsolutePath());
         }
         if (files.size() > 0) {
-            provider = new FileKeyPairProvider(files.toArray(new String[files.size()]), new PasswordFinder() {
-                public char[] getPassword() {
-                    try {
-                        System.out.println("Enter password for private key: ");
-                        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
-                        String password = r.readLine();
-                        return password.toCharArray();
-                    } catch (IOException e) {
-                        return null;
-                    }
+            // SSHD-292: we need to use a different class to load the FileKeyPairProvider
+            //  in order to break the link between SshClient and BouncyCastle
+            try {
+                if (SecurityUtils.isBouncyCastleRegistered()) {
+                    class KeyPairProviderLoader implements Callable<KeyPairProvider> {
+                        public KeyPairProvider call() throws Exception {
+                            return new FileKeyPairProvider(files.toArray(new String[files.size()]), new PasswordFinder() {
+                                public char[] getPassword() {
+                                    try {
+                                        System.out.println("Enter password for private key: ");
+                                        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
+                                        String password = r.readLine();
+                                        return password.toCharArray();
+                                    } catch (IOException e) {
+                                        return null;
+                                    }
+                                }
+                            });
+                        }
+                    };
+                    provider = new KeyPairProviderLoader().call();
                 }
-            });
+            } catch (Throwable t) {
+                System.out.println("Error loading user keys: " + t.getMessage());
+            }
         }
 
         SshClient client = SshClient.setUpDefaultClient();