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,7 +382,10 @@ class ConnectivityCheckServer
{
//caller gave us the entire username.
if (username.equals(parentAgent.generateLocalUserName()))
return parentAgent.getRemotePassword().getBytes();
{
if(parentAgent.getRemotePassword() != null)
return parentAgent.getRemotePassword().getBytes();
}
}
return null;
}

View File

@ -872,7 +872,7 @@ public class StunStack
* supposed to have been built for.
* @param shortTermCredentialMechanism <tt>true</tt> if <tt>msgInt</tt> is
* to be validated as part of the STUN short-term credential mechanism or
* <tt>false</tt> for the STUN long-term credential mechanism
* <tt>false</tt> for the STUN long-term credential mechanism
* @param message the message whose SHA1 checksum we'd need to recalculate.
*
* @return <tt>true</tt> if <tt>msgInt</tt> contains a valid SHA1 value and
@ -972,7 +972,7 @@ public class StunStack
/**
* Returns a <tt>String</tt> representation of a specific <tt>byte</tt>
* array as an unsigned integer in base 16.
*
*
* @param bytes the <tt>byte</tt> to get the <tt>String</tt> representation
* of as an unsigned integer in base 16
* @return a <tt>String</tt> representation of the specified <tt>byte</tt>