From fc3e4116575d5b252c23c783676fea32db57e473 Mon Sep 17 00:00:00 2001 From: seb Date: Mon, 29 Nov 2010 16:22:54 +0000 Subject: [PATCH] Initialize the Binding Response's MESSAGE-INTEGRITY attribute with the same username as the request. Now ice4j should correctly work with Empathy. --- .../attribute/MessageIntegrityAttribute.java | 16 +++++++++++++++- src/org/ice4j/ice/ConnectivityCheckServer.java | 14 ++++++++++---- src/org/ice4j/stack/StunStack.java | 4 ++-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/org/ice4j/attribute/MessageIntegrityAttribute.java b/src/org/ice4j/attribute/MessageIntegrityAttribute.java index dcdfa89..40da05c 100644 --- a/src/org/ice4j/attribute/MessageIntegrityAttribute.java +++ b/src/org/ice4j/attribute/MessageIntegrityAttribute.java @@ -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); diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java index 6dc0699..70af6ef 100644 --- a/src/org/ice4j/ice/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/ConnectivityCheckServer.java @@ -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 * username 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; } diff --git a/src/org/ice4j/stack/StunStack.java b/src/org/ice4j/stack/StunStack.java index 095b0ee..ee6fa30 100644 --- a/src/org/ice4j/stack/StunStack.java +++ b/src/org/ice4j/stack/StunStack.java @@ -872,7 +872,7 @@ public class StunStack * supposed to have been built for. * @param shortTermCredentialMechanism true if msgInt is * to be validated as part of the STUN short-term credential mechanism or - * false for the STUN long-term credential mechanism + * false for the STUN long-term credential mechanism * @param message the message whose SHA1 checksum we'd need to recalculate. * * @return true if msgInt contains a valid SHA1 value and @@ -972,7 +972,7 @@ public class StunStack /** * Returns a String representation of a specific byte * array as an unsigned integer in base 16. - * + * * @param bytes the byte to get the String representation * of as an unsigned integer in base 16 * @return a String representation of the specified byte