karaf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgoody...@apache.org
Subject [48/50] git commit: [KARAF-3059] Add -k option to bin/client to specify a key file [KARAF-3140] Upgrade to sshd 0.12.0
Date Sat, 26 Jul 2014 01:55:29 GMT
[KARAF-3059] Add -k option to bin/client to specify a key file
[KARAF-3140] Upgrade to sshd 0.12.0


Project: http://git-wip-us.apache.org/repos/asf/karaf/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf/commit/06043e37
Tree: http://git-wip-us.apache.org/repos/asf/karaf/tree/06043e37
Diff: http://git-wip-us.apache.org/repos/asf/karaf/diff/06043e37

Branch: refs/heads/karaf-2.3.x
Commit: 06043e37b2cffb5b56e737fe044de451b32f7d38
Parents: 7dc1f81
Author: Jean-Baptiste Onofré <jbonofre@apache.org>
Authored: Fri Jul 25 21:45:15 2014 +0200
Committer: Jean-Baptiste Onofré <jbonofre@apache.org>
Committed: Fri Jul 25 21:45:15 2014 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/karaf/client/Main.java | 27 +++++++--
 pom.xml                                         |  2 +-
 .../karaf/shell/ssh/KarafAgentFactory.java      | 11 ++--
 .../karaf/shell/ssh/KarafFileSystemFactory.java | 14 ++++-
 .../karaf/shell/ssh/KarafFileSystemView.java    | 61 --------------------
 .../apache/karaf/shell/ssh/KarafSshFile.java    | 37 ------------
 6 files changed, 40 insertions(+), 112 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/client/src/main/java/org/apache/karaf/client/Main.java
----------------------------------------------------------------------
diff --git a/client/src/main/java/org/apache/karaf/client/Main.java b/client/src/main/java/org/apache/karaf/client/Main.java
index bb7ee85..1f6b3b4 100644
--- a/client/src/main/java/org/apache/karaf/client/Main.java
+++ b/client/src/main/java/org/apache/karaf/client/Main.java
@@ -35,6 +35,7 @@ import org.apache.sshd.agent.local.LocalAgentFactory;
 import org.apache.sshd.client.channel.ChannelShell;
 import org.apache.sshd.client.future.ConnectFuture;
 import org.apache.sshd.common.RuntimeSshException;
+import org.apache.sshd.common.keyprovider.FileKeyPairProvider;
 import org.fusesource.jansi.AnsiConsole;
 import org.slf4j.impl.SimpleLogger;
 
@@ -54,6 +55,7 @@ public class Main {
         int retryDelay = 2;
         boolean batch = false;
         String file = null;
+        String keyFile = null;
 
         for (int i = 0; i < args.length; i++) {
             if (args[i].charAt(0) == '-') {
@@ -75,6 +77,8 @@ public class Main {
                     batch = true;
                 } else if (args[i].equals("-f")) {
                     file = args[++i];
+                } else if (args[i].equals("-k")) {
+                    keyFile = args[++i];
                 } else if (args[i].equals("--help")) {
                     System.out.println("Apache Karaf client");
                     System.out.println("  -a [port]     specify the port to connect to");
@@ -87,7 +91,8 @@ public class Main {
                     System.out.println("  -r [attempts] retry connection establishment (up
to attempts times)");
                     System.out.println("  -d [delay]    intra-retry delay (defaults to 2
seconds)");
                     System.out.println("  -b            batch mode, specify multiple commands
via standard input");
-                    System.out.println("  -f [file]    read commands from the specified file");
+                    System.out.println("  -f [file]     read commands from the specified
file");
+                    System.out.println("  -k [keyFile]  specify the private keyFile location
when using key login, need have BouncyCastle registered as security provider using this flag");
                     System.out.println("  [commands]    commands to run");
                     System.out.println("If no commands are specified, the client will be
put in an interactive mode");
                     System.exit(0);
@@ -127,7 +132,7 @@ public class Main {
         SshAgent agent = null;
         int exitStatus = 0;
         try {
-            agent = startAgent(user);
+            agent = startAgent(user, keyFile);
             client = SshClient.setUpDefaultClient();
             client.setAgentFactory(new LocalAgentFactory(agent));
             client.getProperties().put(SshAgent.SSH_AUTHSOCKET_ENV_NAME, "local");
@@ -211,14 +216,24 @@ public class Main {
         System.exit(exitStatus);
     }
 
-    protected static SshAgent startAgent(String user) {
+    protected static SshAgent startAgent(String user, String keyFile) {
         try {
             SshAgent local = new AgentImpl();
-            URL url = Main.class.getClassLoader().getResource("karaf.key");
-            InputStream is = url.openStream();
+
+            URL builtInPrivateKey = Main.class.getClassLoader().getResource("karaf.key");
+            InputStream is = builtInPrivateKey.openStream();
             ObjectInputStream r = new ObjectInputStream(is);
             KeyPair keyPair = (KeyPair) r.readObject();
-            local.addIdentity(keyPair, "karaf");
+            is.close();
+            local.addIdentity(keyPair, user);
+
+            if (keyFile != null) {
+                String[] keyFiles = new String[]{ keyFile };
+                FileKeyPairProvider fileKeyPairProvider = new FileKeyPairProvider(keyFiles);
+                for (KeyPair key : fileKeyPairProvider.loadKeys()) {
+                    local.addIdentity(key, user);
+                }
+            }
             return local;
         } catch (Throwable e) {
             System.err.println("Error starting ssh agent for: " + e.getMessage());

http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index 75ec479..e1968cc 100644
--- a/pom.xml
+++ b/pom.xml
@@ -220,7 +220,7 @@
         <spring40.version>4.0.5.RELEASE_1</spring40.version>
         <spring.security31.version>3.1.4.RELEASE</spring.security31.version>
 
-        <sshd.version>0.8.0</sshd.version>
+        <sshd.version>0.12.0</sshd.version>
         <directory-version>2.0.0-M16</directory-version>
         <struts.bundle.version>1.3.10_1</struts.bundle.version>
         <weld.version>2.1.1.Final</weld.version>

http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
index e814000..3543484 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafAgentFactory.java
@@ -29,8 +29,10 @@ import org.apache.sshd.agent.common.AgentDelegate;
 import org.apache.sshd.agent.local.AgentServerProxy;
 import org.apache.sshd.agent.local.ChannelAgentForwarding;
 import org.apache.sshd.common.Channel;
+import org.apache.sshd.common.FactoryManager;
 import org.apache.sshd.common.NamedFactory;
 import org.apache.sshd.common.Session;
+import org.apache.sshd.common.session.ConnectionService;
 import org.apache.sshd.server.session.ServerSession;
 
 public class KarafAgentFactory implements SshAgentFactory {
@@ -42,8 +44,8 @@ public class KarafAgentFactory implements SshAgentFactory {
         return new ChannelAgentForwarding.Factory();
     }
 
-    public SshAgent createClient(Session session) throws IOException {
-        String proxyId = session.getFactoryManager().getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
+    public SshAgent createClient(FactoryManager manager) throws IOException {
+        String proxyId = manager.getProperties().get(SshAgent.SSH_AUTHSOCKET_ENV_NAME);
         if (proxyId == null) {
             throw new IllegalStateException("No " + SshAgent.SSH_AUTHSOCKET_ENV_NAME + "
environment variable set");
         }
@@ -58,11 +60,12 @@ public class KarafAgentFactory implements SshAgentFactory {
         throw new IllegalStateException("No ssh agent found");
     }
 
-    public SshAgentServer createServer(Session session) throws IOException {
+    public SshAgentServer createServer(ConnectionService service) throws IOException {
+        Session session = service.getSession();
         if (!(session instanceof ServerSession)) {
             throw new IllegalStateException("The session used to create an agent server proxy
must be a server session");
         }
-        final AgentServerProxy proxy = new AgentServerProxy((ServerSession) session);
+        final AgentServerProxy proxy = new AgentServerProxy(service);
         proxies.put(proxy.getId(), proxy);
         return new SshAgentServer() {
             public String getId() {

http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java
b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java
index d728ec5..3374575 100644
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java
+++ b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemFactory.java
@@ -19,8 +19,13 @@
 package org.apache.karaf.shell.ssh;
 
 import org.apache.sshd.common.Session;
-import org.apache.sshd.server.FileSystemFactory;
-import org.apache.sshd.server.FileSystemView;
+import org.apache.sshd.common.file.FileSystemFactory;
+import org.apache.sshd.common.file.FileSystemView;
+import org.apache.sshd.common.file.nativefs.NativeFileSystemView;
+
+import java.io.File;
+import java.util.HashMap;
+import java.util.Map;
 
 /**
  * SSHd file system factory to reduce the visibility to the KARAF_BASE.
@@ -28,7 +33,10 @@ import org.apache.sshd.server.FileSystemView;
 public class KarafFileSystemFactory implements FileSystemFactory {
 
     public FileSystemView createFileSystemView(Session session) {
-        return new KarafFileSystemView();
+        Map<String, String> roots = new HashMap<String, String>();
+        String dir = new File(System.getProperty("karaf.base")).getAbsolutePath();
+        roots.put("/", dir);
+        return new NativeFileSystemView(session.getUsername(), roots, "/");
     }
 
 }

http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java
deleted file mode 100644
index 33b64fe..0000000
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafFileSystemView.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.karaf.shell.ssh;
-
-import org.apache.sshd.server.FileSystemView;
-import org.apache.sshd.server.SshFile;
-import org.apache.sshd.server.filesystem.NativeSshFile;
-
-import java.io.File;
-
-/**
- * Karaf file system view reduced to the KARAF_BASE location
- */
-public class KarafFileSystemView implements FileSystemView {
-
-    private String location;
-
-    public KarafFileSystemView() {
-        location = System.getProperty("karaf.base");
-    }
-
-    public SshFile getFile(String file) {
-        return getFile(location, file);
-    }
-
-    public SshFile getFile(SshFile baseDir, String file) {
-        return getFile(baseDir.getAbsolutePath(), file);
-    }
-
-    protected SshFile getFile(String dir, String file) {
-        // get actual file object
-        String physicalName = NativeSshFile.getPhysicalName("/", dir, file, false);
-
-        if (!physicalName.startsWith(location)) {
-            throw new IllegalArgumentException("The path is not relative to KARAF_BASE. For
security reason, it's not allowed.");
-        }
-
-        File fileObj = new File(physicalName);
-
-        // strip the root directory and return
-        String karafFileName = physicalName.substring("/".length() - 1);
-        return new KarafSshFile(karafFileName, fileObj);
-    }
-
-}

http://git-wip-us.apache.org/repos/asf/karaf/blob/06043e37/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafSshFile.java
----------------------------------------------------------------------
diff --git a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafSshFile.java b/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafSshFile.java
deleted file mode 100644
index fed7c91..0000000
--- a/shell/ssh/src/main/java/org/apache/karaf/shell/ssh/KarafSshFile.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *  http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.karaf.shell.ssh;
-
-import org.apache.sshd.server.filesystem.NativeSshFile;
-
-import java.io.File;
-
-/**
- * Karaf ssh file support.
- */
-public class KarafSshFile extends NativeSshFile {
-
-    /**
-     * Constructor, internal do not use directly.
-     */
-    public KarafSshFile(String fileName, final File file) {
-        super(fileName, file, null);
-    }
-
-}
\ No newline at end of file


Mime
View raw message