Initialize the Binding Response's MESSAGE-INTEGRITY attribute with the same username as the request. Now ice4j should correctly work with Empathy.

This commit is contained in:
seb 2010-11-29 16:22:54 +00:00
parent a16b8afe12
commit fc3e411657
3 changed files with 27 additions and 7 deletions

View File

@ -11,6 +11,7 @@ import java.util.*;
import javax.crypto.*;
import javax.crypto.spec.*;
import org.ice4j.message.*;
import org.ice4j.stack.*;
/**
@ -254,7 +255,20 @@ public class MessageIntegrityAttribute
binValue[2] = (byte)(getDataLength()>>8);
binValue[3] = (byte)(getDataLength()&0x00FF);
byte[] key = stunStack.getCredentialsManager().getRemoteKey(username);
byte[] key = null;
char msgType = (char)((content[0] << 8) + content[1]);
if(Message.isRequestType(msgType))
{
/* attribute part of a request, use the remote key */
key = stunStack.getCredentialsManager().getRemoteKey(username);
}
else if(Message.isSuccessResponseType(msgType) ||
Message.isErrorResponseType(msgType))
{
/* attribute part of a response, use the local key */
key = stunStack.getCredentialsManager().getLocalKey(username);
}
//now calculate the HMAC-SHA1
this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);

View File

@ -128,9 +128,12 @@ class ConnectivityCheckServer
Attribute usernameAttribute = AttributeFactory.createUsernameAttribute(
parentAgent.generateLocalUserName());
/* The responses utilize the same usernames and passwords as the
* requests
*/
Attribute messageIntegrityAttribute =
AttributeFactory.createMessageIntegrityAttribute(
parentAgent.generateLocalUserName());
new String(uname.getUsername()));
response.addAttribute(usernameAttribute);
response.addAttribute(messageIntegrityAttribute);
@ -334,8 +337,8 @@ class ConnectivityCheckServer
}
/**
* Implements the {@link CredentialsAuthority#getLocalKey(String)} method in a
* way that would return this handler's parent agent password if
* 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.
*
@ -379,8 +382,11 @@ class ConnectivityCheckServer
{
//caller gave us the entire username.
if (username.equals(parentAgent.generateLocalUserName()))
{
if(parentAgent.getRemotePassword() != null)
return parentAgent.getRemotePassword().getBytes();
}
}
return null;
}