Delays necessity of a password for outgoing checks so that we could handle the OFFER check ANSWER case.

This commit is contained in:
emcho 2010-04-27 23:32:18 +00:00
parent 52541f4adf
commit 75231a7e3e
5 changed files with 107 additions and 29 deletions

View File

@ -255,7 +255,7 @@ public class MessageIntegrityAttribute
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);

View File

@ -63,7 +63,7 @@ public class ConnectivityCheckServer
.getAttribute(Attribute.USERNAME);
if(uname == null
|| !checkUserName(new String(uname.getUsername())))
|| !checkLocalUserName(new String(uname.getUsername())))
{
return;
}
@ -92,7 +92,7 @@ public class ConnectivityCheckServer
* @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 @@ public class ConnectivityCheckServer
}
/**
* 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 @@ public class ConnectivityCheckServer
* @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.
@ -142,4 +142,36 @@ public class ConnectivityCheckServer
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;
}
}

View File

@ -844,7 +844,7 @@ public abstract class Message
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 @@ public abstract class Message
String lfrag = username.substring(0, colon);
return StunStack.getInstance()
.getCredentialsManager().checkUserName(lfrag);
.getCredentialsManager().checkLocalUserName(lfrag);
}
/**

View File

@ -16,19 +16,36 @@ package org.ice4j.security;
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 @@ public interface CredentialsAuthority
* @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);
}

View File

@ -35,21 +35,50 @@ public class CredentialsManager
/**
* 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 @@ public class CredentialsManager
* <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;
}