From 21cd44045fdc43595b5fbadaa25771c6b84d658c Mon Sep 17 00:00:00 2001 From: emcho Date: Tue, 27 Apr 2010 23:32:34 +0000 Subject: [PATCH] Fixes use of local credentials authority (now that was some tricky stuff to find). --- .../attribute/MessageIntegrityAttribute.java | 2 +- src/org/ice4j/ice/Agent.java | 23 ++++++++++--------- .../ice4j/ice/ConnectivityCheckClient.java | 6 ++--- .../ice4j/ice/ConnectivityCheckServer.java | 2 +- .../ice/harvest/StunCandidateHarvester.java | 3 ++- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/org/ice4j/attribute/MessageIntegrityAttribute.java b/src/org/ice4j/attribute/MessageIntegrityAttribute.java index 799d9df..53ac976 100644 --- a/src/org/ice4j/attribute/MessageIntegrityAttribute.java +++ b/src/org/ice4j/attribute/MessageIntegrityAttribute.java @@ -255,7 +255,7 @@ public class MessageIntegrityAttribute binValue[3] = (byte)(getDataLength()&0x00FF); byte[] key = StunStack.getInstance().getCredentialsManager() - .getLocalKey(username); + .getRemoteKey(username); //now calculate the HMAC-SHA1 this.hmacSha1Content = calculateHmacSha1(content, offset, length, key); diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java index 2e51ba5..3cc5a46 100644 --- a/src/org/ice4j/ice/Agent.java +++ b/src/org/ice4j/ice/Agent.java @@ -406,17 +406,18 @@ public class Agent } /** - * Returns the user name that we should tell a peer Agent to use - * in connectivity checks for outgoing Binding Requests. According to RFC - * 5245, a Binding Request serving as a connectivity check MUST utilize the - * STUN short term credential mechanism. The username for the credential is - * formed by concatenating the username fragment provided by the peer with - * the username fragment of the agent sending the request, separated by a - * colon (":"). The password is equal to the password provided by the peer. - * For example, consider the case where agent L is the offerer, and agent R - * is the answerer. Agent L included a username fragment of LFRAG for its - * candidates, and a password of LPASS. Agent R provided a username - * fragment of RFRAG and a password of RPASS. A connectivity check from L + * Returns the user name that we should expect a peer Agent to use + * in connectivity checks for Binding Requests its sending our way. + * According to RFC 5245, a Binding Request serving as a connectivity check + * MUST utilize the STUN short term credential mechanism. The username for + * the credential is formed by concatenating the username fragment provided + * by the peer with the username fragment of the agent sending the request, + * separated by a colon (":"). The password is equal to the password + * provided by the peer. For example, consider the case where agent + * L is the offerer, and agent R is the answerer. Agent L + * included a username fragment of LFRAG for its candidates, + * and a password of LPASS. Agent R provided a username fragment + * of RFRAG and a password of RPASS. A connectivity check from L * to R (and its response of course) utilize the username RFRAG:LFRAG and a * password of RPASS. A connectivity check from R to L (and its response) * utilize the username LFRAG:RFRAG and a password of LPASS. diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java index 4244da9..090fad7 100644 --- a/src/org/ice4j/ice/ConnectivityCheckClient.java +++ b/src/org/ice4j/ice/ConnectivityCheckClient.java @@ -89,8 +89,9 @@ public class ConnectivityCheckClient } //credentials + String localUserName = parentAgent.generateLocalUserName(); UsernameAttribute unameAttr = AttributeFactory.createUsernameAttribute( - parentAgent.generateLocalUserName()); + localUserName); request.addAttribute(unameAttr); @@ -99,8 +100,7 @@ public class ConnectivityCheckClient //for example. //todo: also implement SASL prepare MessageIntegrityAttribute msgIntegrity = AttributeFactory - .createMessageIntegrityAttribute(parentAgent - .generateRemoteUserName()); + .createMessageIntegrityAttribute(localUserName); request.addAttribute(msgIntegrity); diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java index dd23d92..f192c47 100644 --- a/src/org/ice4j/ice/ConnectivityCheckServer.java +++ b/src/org/ice4j/ice/ConnectivityCheckServer.java @@ -136,7 +136,7 @@ public class ConnectivityCheckServer else { //caller gave us the entire username. - if (username.equals(parentAgent.generateRemoteUserName())) + if(username.substring(0, colon).equals(parentAgent.getLocalUfrag())) return parentAgent.getLocalPassword().getBytes(); } diff --git a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java index 1523f8f..db423dc 100644 --- a/src/org/ice4j/ice/harvest/StunCandidateHarvester.java +++ b/src/org/ice4j/ice/harvest/StunCandidateHarvester.java @@ -384,7 +384,8 @@ public class StunCandidateHarvester Level.INFO, "Failed to send " + request - + " through " + hostCand.getTransportAddress(), + + " through " + hostCand.getTransportAddress() + + " to " + stunServer, exception); return; }