Delays necessity of a password for outgoing checks so that we could handle the OFFER check ANSWER case.
This commit is contained in:
parent
52541f4adf
commit
75231a7e3e
@ -255,7 +255,7 @@ public class MessageIntegrityAttribute
|
|||||||
binValue[3] = (byte)(getDataLength()&0x00FF);
|
binValue[3] = (byte)(getDataLength()&0x00FF);
|
||||||
|
|
||||||
byte[] key = StunStack.getInstance().getCredentialsManager()
|
byte[] key = StunStack.getInstance().getCredentialsManager()
|
||||||
.getKey(username);
|
.getLocalKey(username);
|
||||||
|
|
||||||
//now calculate the HMAC-SHA1
|
//now calculate the HMAC-SHA1
|
||||||
this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);
|
this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);
|
||||||
|
|||||||
@ -63,7 +63,7 @@ public class ConnectivityCheckServer
|
|||||||
.getAttribute(Attribute.USERNAME);
|
.getAttribute(Attribute.USERNAME);
|
||||||
|
|
||||||
if(uname == null
|
if(uname == null
|
||||||
|| !checkUserName(new String(uname.getUsername())))
|
|| !checkLocalUserName(new String(uname.getUsername())))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -92,7 +92,7 @@ public class ConnectivityCheckServer
|
|||||||
* @return <tt>true</tt> if <tt>username</tt> is known to this
|
* @return <tt>true</tt> if <tt>username</tt> is known to this
|
||||||
* <tt>ConnectivityCheckServer</tt> and <tt>false</tt> otherwise.
|
* <tt>ConnectivityCheckServer</tt> and <tt>false</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean checkUserName(String username)
|
public boolean checkLocalUserName(String username)
|
||||||
{
|
{
|
||||||
boolean accept = false;
|
boolean accept = false;
|
||||||
int colon = username.indexOf(":");
|
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
|
* way that would return this handler's parent agent password if
|
||||||
* <tt>username</tt> is either the local ufrag or the username that the
|
* <tt>username</tt> is either the local ufrag or the username that the
|
||||||
* agent's remote peer was expected to use.
|
* 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>
|
* @return this handler's parent agent local password if <tt>username</tt>
|
||||||
* equals the local ufrag and <tt>null</tt> otherwise.
|
* 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
|
//support both the case where username is the local fragment or the
|
||||||
//entire user name.
|
//entire user name.
|
||||||
@ -142,4 +142,36 @@ public class ConnectivityCheckServer
|
|||||||
|
|
||||||
return null;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -844,7 +844,7 @@ public abstract class Message
|
|||||||
String lfrag = username.substring(0, colon);
|
String lfrag = username.substring(0, colon);
|
||||||
|
|
||||||
byte[] key = StunStack.getInstance()
|
byte[] key = StunStack.getInstance()
|
||||||
.getCredentialsManager().getKey(lfrag);
|
.getCredentialsManager().getLocalKey(lfrag);
|
||||||
|
|
||||||
if(key == null)
|
if(key == null)
|
||||||
return false;
|
return false;
|
||||||
@ -898,7 +898,7 @@ public abstract class Message
|
|||||||
String lfrag = username.substring(0, colon);
|
String lfrag = username.substring(0, colon);
|
||||||
|
|
||||||
return StunStack.getInstance()
|
return StunStack.getInstance()
|
||||||
.getCredentialsManager().checkUserName(lfrag);
|
.getCredentialsManager().checkLocalUserName(lfrag);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -16,19 +16,36 @@ package org.ice4j.security;
|
|||||||
public interface CredentialsAuthority
|
public interface CredentialsAuthority
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* Returns the key (password) that corresponds to the specified username,
|
* Returns the key (password) that corresponds to the specified local
|
||||||
* an empty array if there was no password for that username or
|
* username or user frag, an empty array if there was no password for that
|
||||||
* <tt>null</tt> if the username is not known to this
|
* username or <tt>null</tt> if the username is not a local user name
|
||||||
* <tt>CredentialsAuthority</tt>.
|
* 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,
|
* @return the key (password) that corresponds to the specified local
|
||||||
* an empty array if there was no password for that username or
|
* username or user frag, an empty array if there was no password for that
|
||||||
* <tt>null</tt> if the username is not known to this
|
* username or <tt>null</tt> if the username is not a local user name
|
||||||
* <tt>CredentialsAuthority</tt>.
|
* 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
|
* 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
|
* @return <tt>true</tt> if <tt>username</tt> is known to this
|
||||||
* <tt>CredentialsAuthority</tt> and <tt>false</tt> otherwise.
|
* <tt>CredentialsAuthority</tt> and <tt>false</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean checkUserName(String username);
|
public boolean checkLocalUserName(String username);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,21 +35,50 @@ public class CredentialsManager
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Queries all currently registered {@link CredentialsAuthority}s for a
|
* Queries all currently registered {@link CredentialsAuthority}s for a
|
||||||
* password corresponding to <tt>username</tt> and returns the first
|
* password corresponding to the specified local <tt>username</tt> or user
|
||||||
* non-<tt>null</tt> one.
|
* 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
|
* @return <tt>null</tt> if username was not a recognized local user name
|
||||||
* currently registered <tt>CredentialsAuthority</tt>s or a <tt>byte</tt>
|
* for none of the currently registered <tt>CredentialsAuthority</tt>s or
|
||||||
* array containing the first non-<tt>null</tt> password that one of them
|
* a <tt>byte</tt> array containing the first non-<tt>null</tt> password
|
||||||
* returned.
|
* that one of them returned.
|
||||||
*/
|
*/
|
||||||
public byte[] getKey(String username)
|
public byte[] getLocalKey(String username)
|
||||||
{
|
{
|
||||||
for (CredentialsAuthority auth : authorities)
|
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)
|
if (passwd != null)
|
||||||
{
|
{
|
||||||
@ -72,11 +101,11 @@ public class CredentialsManager
|
|||||||
* <tt>CredentialsAuthority</tt>s registered here and <tt>false</tt>
|
* <tt>CredentialsAuthority</tt>s registered here and <tt>false</tt>
|
||||||
* otherwise.
|
* otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean checkUserName(String username)
|
public boolean checkLocalUserName(String username)
|
||||||
{
|
{
|
||||||
for (CredentialsAuthority auth : authorities)
|
for (CredentialsAuthority auth : authorities)
|
||||||
{
|
{
|
||||||
if( auth.checkUserName(username))
|
if( auth.checkLocalUserName(username))
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user