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 2009/11/13 08:30:25 UTC

svn commit: r835766 - in /mina/sshd/trunk/sshd-core/src: main/java/org/apache/sshd/server/ main/java/org/apache/sshd/server/auth/ test/java/org/apache/sshd/util/

Author: gnodet
Date: Fri Nov 13 07:30:24 2009
New Revision: 835766

URL: http://svn.apache.org/viewvc?rev=835766&view=rev
Log:
SSHD-53: PublickeyAuthenticator should return an Object instead of a boolean to be consistent with PasswordAuthenticator

Modified:
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PasswordAuthenticator.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
    mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
    mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PasswordAuthenticator.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PasswordAuthenticator.java?rev=835766&r1=835765&r2=835766&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PasswordAuthenticator.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PasswordAuthenticator.java Fri Nov 13 07:30:24 2009
@@ -34,6 +34,7 @@
      *
      * @param username the username
      * @param password the password
+     * @param session the server session
      * @return a non null identity object or <code>null</code if authentication fail
      */
     Object authenticate(String username, String password, ServerSession session);

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java?rev=835766&r1=835765&r2=835766&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/PublickeyAuthenticator.java Fri Nov 13 07:30:24 2009
@@ -30,6 +30,14 @@
  */
 public interface PublickeyAuthenticator {
 
-    boolean hasKey(String username, PublicKey key, ServerSession session);
+    /**
+     * Check the validity of a public key.
+     *
+     * @param username the username
+     * @param key the key
+     * @param session the server session
+     * @return a non null identity object or <code>null</code if authentication fail
+     */
+    Object hasKey(String username, PublicKey key, ServerSession session);
 
 }

Modified: mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java?rev=835766&r1=835765&r2=835766&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java (original)
+++ mina/sshd/trunk/sshd-core/src/main/java/org/apache/sshd/server/auth/UserAuthPublicKey.java Fri Nov 13 07:30:24 2009
@@ -68,20 +68,17 @@
             throw new Exception("No PublickeyAuthenticator configured");
         }
 
+        Object ident = authenticator.hasKey(username, key, session);
+        if (ident == null) {
+            throw new Exception("Unsupported key for user");
+        }
         if (!hasSig) {
-            if (authenticator.hasKey(username, key, session)) {
-                Buffer buf = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_PK_OK);
-                buf.putString(alg);
-                buf.putRawBytes(buffer.array(), oldPos, 4 + len);
-                session.writePacket(buf);
-                return null;
-            } else {
-                throw new Exception("Unsupported key for user");
-            }
+            Buffer buf = session.createBuffer(SshConstants.Message.SSH_MSG_USERAUTH_PK_OK);
+            buf.putString(alg);
+            buf.putRawBytes(buffer.array(), oldPos, 4 + len);
+            session.writePacket(buf);
+            return null;
         } else {
-            if (!authenticator.hasKey(username, key, session)) {
-                throw new Exception("Unsupported key for user");
-            }
             Buffer buf = new Buffer();
             buf.putString(session.getKex().getH());
             buf.putCommand(SshConstants.Message.SSH_MSG_USERAUTH_REQUEST);
@@ -94,11 +91,10 @@
             buffer.wpos(oldPos + 4 + len);
             buf.putBuffer(buffer);
             verif.update(buf.array(), buf.rpos(), buf.available());
-            if (verif.verify(sig)) {
-                return username;
-            } else {
+            if (!verif.verify(sig)) {
                 throw new Exception("Key verification failed");
             }
+            return ident;
         }
     }
 }

Modified: mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java
URL: http://svn.apache.org/viewvc/mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java?rev=835766&r1=835765&r2=835766&view=diff
==============================================================================
--- mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java (original)
+++ mina/sshd/trunk/sshd-core/src/test/java/org/apache/sshd/util/BogusPublickeyAuthenticator.java Fri Nov 13 07:30:24 2009
@@ -30,7 +30,7 @@
  */
 public class BogusPublickeyAuthenticator implements PublickeyAuthenticator {
 
-    public boolean hasKey(String username, PublicKey key, ServerSession session) {
-        return true;
+    public Object hasKey(String username, PublicKey key, ServerSession session) {
+        return username;
     }
 }