[ice4j] r155 committed - Delays necessity of a password for outgoing checks so that we could ha...

ice4j at googlecode.com ice4j at googlecode.com
Wed Apr 28 01:36:35 CEST 2010


Revision: 155
Author: emcho at sip-communicator.org
Date: Tue Apr 27 16:32:18 2010
Log: Delays necessity of a password for outgoing checks so that we could  
handle the OFFER check ANSWER case.
http://code.google.com/p/ice4j/source/detail?r=155

Modified:
  /trunk/src/org/ice4j/attribute/MessageIntegrityAttribute.java
  /trunk/src/org/ice4j/ice/ConnectivityCheckServer.java
  /trunk/src/org/ice4j/message/Message.java
  /trunk/src/org/ice4j/security/CredentialsAuthority.java
  /trunk/src/org/ice4j/security/CredentialsManager.java

=======================================
--- /trunk/src/org/ice4j/attribute/MessageIntegrityAttribute.java	Tue Apr  
27 16:31:58 2010
+++ /trunk/src/org/ice4j/attribute/MessageIntegrityAttribute.java	Tue Apr  
27 16:32:18 2010
@@ -255,7 +255,7 @@
          binValue[3] = (byte)(getDataLength()&0x00FF);

          byte[] key = StunStack.getInstance().getCredentialsManager()
-            .getKey(username);
+            .getLocalKey(username);

          //now calculate the HMAC-SHA1
          this.hmacSha1Content = calculateHmacSha1(content, offset, length,  
key);
=======================================
--- /trunk/src/org/ice4j/ice/ConnectivityCheckServer.java	Tue Apr 27  
16:31:58 2010
+++ /trunk/src/org/ice4j/ice/ConnectivityCheckServer.java	Tue Apr 27  
16:32:18 2010
@@ -63,7 +63,7 @@
              .getAttribute(Attribute.USERNAME);

          if(uname == null
-           || !checkUserName(new String(uname.getUsername())))
+           || !checkLocalUserName(new String(uname.getUsername())))
          {
              return;
          }
@@ -92,7 +92,7 @@
       * @return <tt>true</tt> if <tt>username</tt> is known to this
       * <tt>ConnectivityCheckServer</tt> and <tt>false</tt> otherwise.
       */
-    public boolean checkUserName(String username)
+    public boolean checkLocalUserName(String username)
      {
          boolean accept = false;
          int colon = username.indexOf(":");
@@ -112,7 +112,7 @@
      }

      /**
-     * Implements the {@link CredentialsAuthority#getKey(String)} method  
in a
+     * Implements the {@link CredentialsAuthority#getLocalKey(String)}  
method in a
       * way that would return this handler's parent agent password if
       * <tt>username</tt> is either the local ufrag or the username that the
       * agent's remote peer was expected to use.
@@ -122,7 +122,7 @@
       * @return this handler's parent agent local password if  
<tt>username</tt>
       * equals the local ufrag and <tt>null</tt> otherwise.
       */
-    public byte[] getKey(String username)
+    public byte[] getLocalKey(String username)
      {
          //support both the case where username is the local fragment or the
          //entire user name.
@@ -139,6 +139,38 @@
              if (username.equals(parentAgent.generateRemoteUserName()))
                  return parentAgent.getLocalPassword().getBytes();
          }
+
+        return null;
+    }
+
+    /**
+     * Implements the {@link CredentialsAuthority#getRemoteKey(String)}  
method
+     * in a way that would return this handler's parent agent remote  
password if
+     * <tt>username</tt> is either the remote ufrag or the username that we
+     * are expected to use when querying the remote peer.
+     *
+     * @param username the remote ufrag that we should return a password  
for.
+     *
+     * @return this handler's parent agent remote password if  
<tt>username</tt>
+     * equals the remote ufrag and <tt>null</tt> otherwise.
+     */
+    public byte[] getRemoteKey(String username)
+    {
+        //support both the case where username is the local fragment or the
+        //entire user name.
+        int colon = username.indexOf(":");
+        if( colon < 0)
+        {
+            //caller gave us a ufrag
+            if (username.equals(parentAgent.getRemoteUfrag()))
+                return parentAgent.getRemotePassword().getBytes();
+        }
+        else
+        {
+            //caller gave us the entire username.
+            if (username.equals(parentAgent.generateLocalUserName()))
+                return parentAgent.getRemotePassword().getBytes();
+        }

          return null;
      }
=======================================
--- /trunk/src/org/ice4j/message/Message.java	Tue Apr 27 16:31:58 2010
+++ /trunk/src/org/ice4j/message/Message.java	Tue Apr 27 16:32:18 2010
@@ -844,7 +844,7 @@
          String lfrag = username.substring(0, colon);

          byte[] key = StunStack.getInstance()
-                .getCredentialsManager().getKey(lfrag);
+                .getCredentialsManager().getLocalKey(lfrag);

          if(key == null)
              return false;
@@ -898,7 +898,7 @@
          String lfrag = username.substring(0, colon);

          return StunStack.getInstance()
-                .getCredentialsManager().checkUserName(lfrag);
+                .getCredentialsManager().checkLocalUserName(lfrag);
      }

      /**
=======================================
--- /trunk/src/org/ice4j/security/CredentialsAuthority.java	Tue Apr 27  
16:31:58 2010
+++ /trunk/src/org/ice4j/security/CredentialsAuthority.java	Tue Apr 27  
16:32:18 2010
@@ -16,19 +16,36 @@
  public interface CredentialsAuthority
  {
      /**
-     * Returns the key (password) that corresponds to the specified  
username,
-     * an empty array if there was no password for that username or
-     * <tt>null</tt> if the username is not known to this
-     * <tt>CredentialsAuthority</tt>.
+     * Returns the key (password) that corresponds to the specified local
+     * username or user frag,  an empty array if there was no password for  
that
+     * username or <tt>null</tt> if the username is not a local user name
+     * recognized by this <tt>CredentialsAuthority</tt>.
       *
-     * @param username the user name whose credentials we'd like to obtain.
+     * @param username the local user name or user frag whose credentials  
we'd
+     * like to obtain.
       *
-     * @return the key (password) that corresponds to the specified  
username,
-     * an empty array if there was no password for that username or
-     * <tt>null</tt> if the username is not known to this
-     * <tt>CredentialsAuthority</tt>.
+     * @return the key (password) that corresponds to the specified local
+     * username or user frag,  an empty array if there was no password for  
that
+     * username or <tt>null</tt> if the username is not a local user name
+     * recognized by this <tt>CredentialsAuthority</tt>.
       */
-    public byte[] getKey(String username);
+    public byte[] getLocalKey(String username);
+
+    /**
+     * Returns the key (password) that corresponds to the specified remote
+     * username or user frag,  an empty array if there was no password for  
that
+     * username or <tt>null</tt> if the username is not a remote user name
+     * recognized by this <tt>CredentialsAuthority</tt>.
+     *
+     * @param username the remote user name or user frag whose credentials  
we'd
+     * like to obtain.
+     *
+     * @return the key (password) that corresponds to the specified remote
+     * username or user frag,  an empty array if there was no password for  
that
+     * username or <tt>null</tt> if the username is not a remote user name
+     * recognized by this <tt>CredentialsAuthority</tt>.
+     */
+    public byte[] getRemoteKey(String username);

      /**
       * Verifies whether <tt>username</tt> is currently known to this  
authority
@@ -39,5 +56,5 @@
       * @return <tt>true</tt> if <tt>username</tt> is known to this
       * <tt>CredentialsAuthority</tt> and <tt>false</tt> otherwise.
       */
-    public boolean checkUserName(String username);
-}
+    public boolean checkLocalUserName(String username);
+}
=======================================
--- /trunk/src/org/ice4j/security/CredentialsManager.java	Tue Apr 27  
16:31:58 2010
+++ /trunk/src/org/ice4j/security/CredentialsManager.java	Tue Apr 27  
16:32:18 2010
@@ -35,21 +35,50 @@

      /**
       * Queries all currently registered {@link CredentialsAuthority}s for a
-     * password corresponding to <tt>username</tt> and returns the first
-     * non-<tt>null</tt> one.
+     * password corresponding to the specified local <tt>username</tt> or  
user
+     * frag and returns the first non-<tt>null</tt> one.
       *
-     * @param username the user name whose credentials we'd like to obtain.
+     * @param username a local user name or user frag whose credentials  
we'd
+     * like to obtain.
       *
-     * @return <tt>null</tt> if username was not known to neither of the
-     * currently registered <tt>CredentialsAuthority</tt>s or a  
<tt>byte</tt>
-     * array containing the first non-<tt>null</tt> password that one of  
them
-     * returned.
+     * @return <tt>null</tt> if username was not a recognized local user  
name
+     * for none of the currently registered <tt>CredentialsAuthority</tt>s  
or
+     * a <tt>byte</tt> array containing the first non-<tt>null</tt>  
password
+     * that one of them returned.
       */
-    public byte[] getKey(String username)
+    public byte[] getLocalKey(String username)
      {
          for (CredentialsAuthority auth : authorities)
          {
-            byte[] passwd = auth.getKey(username);
+            byte[] passwd = auth.getLocalKey(username);
+
+            if (passwd != null)
+            {
+                return passwd;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * Queries all currently registered {@link CredentialsAuthority}s for a
+     * password corresponding to the specified remote <tt>username</tt> or  
user
+     * frag and returns the first non-<tt>null</tt> one.
+     *
+     * @param username a remote user name or user frag whose credentials  
we'd
+     * like to obtain.
+     *
+     * @return <tt>null</tt> if username was not a recognized remote user  
name
+     * for none of the currently registered <tt>CredentialsAuthority</tt>s  
or
+     * a <tt>byte</tt> array containing the first non-<tt>null</tt>  
password
+     * that one of them returned.
+     */
+    public byte[] getRemoteKey(String username)
+    {
+        for (CredentialsAuthority auth : authorities)
+        {
+            byte[] passwd = auth.getRemoteKey(username);

              if (passwd != null)
              {
@@ -72,11 +101,11 @@
       * <tt>CredentialsAuthority</tt>s registered here and <tt>false</tt>
       * otherwise.
       */
-    public boolean checkUserName(String username)
+    public boolean checkLocalUserName(String username)
      {
          for (CredentialsAuthority auth : authorities)
          {
-            if( auth.checkUserName(username))
+            if( auth.checkLocalUserName(username))
                  return true;
          }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe at sip-communicator.dev.java.net
For additional commands, e-mail: commits-help at sip-communicator.dev.java.net





More information about the commits mailing list