You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/02/26 06:10:40 UTC

[1/2] mina-sshd git commit: Provide getter/setter for ModifiedServerKeyAcceptor delegate in KnownHostsServerKeyVerifier

Repository: mina-sshd
Updated Branches:
  refs/heads/master 39a71a151 -> 633def660


Provide getter/setter for ModifiedServerKeyAcceptor delegate in KnownHostsServerKeyVerifier


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

Branch: refs/heads/master
Commit: 91b4990b7241894decded8e1fbc735ee120fa23f
Parents: 39a71a1
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 07:10:42 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 07:10:42 2016 +0200

----------------------------------------------------------------------
 .../java/org/apache/sshd/client/SshClient.java  | 30 ++++++--------------
 .../KnownHostsServerKeyVerifier.java            | 24 ++++++++++++++++
 .../common/util/EventListenerUtilsTest.java     |  1 -
 3 files changed, 33 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/91b4990b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
index a266f6b..80d5aec 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/SshClient.java
@@ -1070,7 +1070,14 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
             return current;
         }
 
-        final ModifiedServerKeyAcceptor acceptor = new ModifiedServerKeyAcceptor() {
+        String filePath = Objects.toString(options.remove(KnownHostsServerKeyVerifier.KNOWN_HOSTS_FILE_OPTION), null);
+        if (GenericUtils.isEmpty(filePath)) {
+            current = new DefaultKnownHostsServerKeyVerifier(current);
+        } else {    // if user specifies a different location than default be lenient
+            current = new DefaultKnownHostsServerKeyVerifier(current, false, Paths.get(filePath));
+        }
+
+        ((KnownHostsServerKeyVerifier) current).setModifiedServerKeyAcceptor(new ModifiedServerKeyAcceptor() {
             @Override
             public boolean acceptModifiedServerKey(ClientSession clientSession, SocketAddress remoteAddress,
                     KnownHostEntry entry, PublicKey expected, PublicKey actual) throws Exception {
@@ -1088,26 +1095,7 @@ public class SshClient extends AbstractFactoryManager implements ClientFactoryMa
                 String ans = GenericUtils.trimToEmpty(stdin.readLine());
                 return (GenericUtils.length(ans) > 0) && (Character.toLowerCase(ans.charAt(0)) == 'y');
             }
-        };
-
-        String filePath = Objects.toString(options.remove(KnownHostsServerKeyVerifier.KNOWN_HOSTS_FILE_OPTION), null);
-        if (GenericUtils.isEmpty(filePath)) {
-            current = new DefaultKnownHostsServerKeyVerifier(current) {
-                @Override
-                public boolean acceptModifiedServerKey(ClientSession clientSession, SocketAddress remoteAddress,
-                        KnownHostEntry entry, PublicKey expected, PublicKey actual) throws Exception {
-                    return acceptor.acceptModifiedServerKey(clientSession, remoteAddress, entry, expected, actual);
-                }
-            };
-        } else {    // if user specifies a different location than default be lenient
-            current = new DefaultKnownHostsServerKeyVerifier(current, false, Paths.get(filePath)) {
-                @Override
-                public boolean acceptModifiedServerKey(ClientSession clientSession, SocketAddress remoteAddress,
-                        KnownHostEntry entry, PublicKey expected, PublicKey actual) throws Exception {
-                    return acceptor.acceptModifiedServerKey(clientSession, remoteAddress, entry, expected, actual);
-                }
-            };
-        }
+        });
 
         manager.setServerKeyVerifier(current);
         return current;

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/91b4990b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
index 5ec9323..1a7c6ce 100644
--- a/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
+++ b/sshd-core/src/main/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifier.java
@@ -118,6 +118,7 @@ public class KnownHostsServerKeyVerifier
     private final ServerKeyVerifier delegate;
     private final AtomicReference<Collection<HostEntryPair>> keysHolder =
             new AtomicReference<Collection<HostEntryPair>>(Collections.<HostEntryPair>emptyList());
+    private ModifiedServerKeyAcceptor modKeyAcceptor;
 
     public KnownHostsServerKeyVerifier(ServerKeyVerifier delegate, Path file) {
         this(delegate, file, IoUtils.EMPTY_LINK_OPTIONS);
@@ -132,6 +133,24 @@ public class KnownHostsServerKeyVerifier
         return delegate;
     }
 
+    /**
+     * @return The delegate {@link ModifiedServerKeyAcceptor} to consult
+     * if a server presents a modified key. If {@code null} then assumed
+     * to reject such a modification
+     */
+    public ModifiedServerKeyAcceptor getModifiedServerKeyAcceptor() {
+        return modKeyAcceptor;
+    }
+
+    /**
+     * @param acceptor The delegate {@link ModifiedServerKeyAcceptor} to
+     * consult if a server presents a modified key. If {@code null} then
+     * assumed to reject such a modification
+     */
+    public void setModifiedServerKeyAcceptor(ModifiedServerKeyAcceptor acceptor) {
+        modKeyAcceptor = acceptor;
+    }
+
     @Override
     public boolean verifyServerKey(ClientSession clientSession, SocketAddress remoteAddress, PublicKey serverKey) {
         Collection<HostEntryPair> knownHosts = getLoadedHostsEntries();
@@ -725,6 +744,11 @@ public class KnownHostsServerKeyVerifier
     public boolean acceptModifiedServerKey(ClientSession clientSession, SocketAddress remoteAddress,
             KnownHostEntry entry, PublicKey expected, PublicKey actual)
                     throws Exception {
+        ModifiedServerKeyAcceptor acceptor = getModifiedServerKeyAcceptor();
+        if (acceptor != null) {
+            return acceptor.acceptModifiedServerKey(clientSession, remoteAddress, entry, expected, actual);
+        }
+
         log.warn("acceptModifiedServerKey({}) mismatched keys presented by {} for entry={}: expected={}-{}, actual={}-{}",
                 clientSession, remoteAddress, entry,
                 KeyUtils.getKeyType(expected), KeyUtils.getFingerPrint(expected),

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/91b4990b/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
index 772518b..fdf7656 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/EventListenerUtilsTest.java
@@ -38,7 +38,6 @@ public class EventListenerUtilsTest extends BaseTestSupport {
     }
 
     @Test
-    @SuppressWarnings("synthetic-access")
     public void testProxyWrapper() {
         List<ProxyListenerImpl> impls = new ArrayList<ProxyListenerImpl>();
         for (int index = 0; index < Byte.SIZE; index++) {


[2/2] mina-sshd git commit: Marked current version as 1.2.0-SNAPSHOT in case 1.1.1 is released

Posted by lg...@apache.org.
Marked current version as 1.2.0-SNAPSHOT in case 1.1.1 is released


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

Branch: refs/heads/master
Commit: 633def66029a0869d6e24cb46b930def57f47544
Parents: 91b4990
Author: Lyor Goldstein <ly...@gmail.com>
Authored: Fri Feb 26 07:11:27 2016 +0200
Committer: Lyor Goldstein <ly...@gmail.com>
Committed: Fri Feb 26 07:11:27 2016 +0200

----------------------------------------------------------------------
 assembly/pom.xml  | 2 +-
 pom.xml           | 2 +-
 sshd-core/pom.xml | 2 +-
 sshd-git/pom.xml  | 2 +-
 sshd-ldap/pom.xml | 2 +-
 5 files changed, 5 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/633def66/assembly/pom.xml
----------------------------------------------------------------------
diff --git a/assembly/pom.xml b/assembly/pom.xml
index e5036e7..e6cea64 100644
--- a/assembly/pom.xml
+++ b/assembly/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.sshd</groupId>
         <artifactId>sshd</artifactId>
-        <version>1.1.1-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>apache-sshd</artifactId>

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/633def66/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index c80533c..1b83f2e 100644
--- a/pom.xml
+++ b/pom.xml
@@ -28,7 +28,7 @@
 
     <groupId>org.apache.sshd</groupId>
     <artifactId>sshd</artifactId>
-    <version>1.1.1-SNAPSHOT</version>
+    <version>1.2.0-SNAPSHOT</version>
     <name>Apache Mina SSHD</name>
     <packaging>pom</packaging>
     <inceptionYear>2008</inceptionYear>

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/633def66/sshd-core/pom.xml
----------------------------------------------------------------------
diff --git a/sshd-core/pom.xml b/sshd-core/pom.xml
index 8e44ba5..95a4111 100644
--- a/sshd-core/pom.xml
+++ b/sshd-core/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.sshd</groupId>
         <artifactId>sshd</artifactId>
-        <version>1.1.1-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
         <relativePath>..</relativePath>
     </parent>
 

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/633def66/sshd-git/pom.xml
----------------------------------------------------------------------
diff --git a/sshd-git/pom.xml b/sshd-git/pom.xml
index 9c99505..c6bee29 100644
--- a/sshd-git/pom.xml
+++ b/sshd-git/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.sshd</groupId>
         <artifactId>sshd</artifactId>
-        <version>1.1.1-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>sshd-git</artifactId>

http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/633def66/sshd-ldap/pom.xml
----------------------------------------------------------------------
diff --git a/sshd-ldap/pom.xml b/sshd-ldap/pom.xml
index 5921ccb..83e40cf 100644
--- a/sshd-ldap/pom.xml
+++ b/sshd-ldap/pom.xml
@@ -24,7 +24,7 @@
     <parent>
         <groupId>org.apache.sshd</groupId>
         <artifactId>sshd</artifactId>
-        <version>1.1.1-SNAPSHOT</version>
+        <version>1.2.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>sshd-ldap</artifactId>