diff --git a/src/org/ice4j/attribute/AttributeFactory.java b/src/org/ice4j/attribute/AttributeFactory.java
index ec43eb1..c18acd4 100644
--- a/src/org/ice4j/attribute/AttributeFactory.java
+++ b/src/org/ice4j/attribute/AttributeFactory.java
@@ -335,19 +335,17 @@ public class AttributeFactory
* the HMAC-SHA1 (RFC 2104) would correspond to the actual message that's
* transporting the attribute.
*
- * @param key the key that we should use when creating the HMAC-SHA1.
+ * @param username the username that we should use to obtain an encryption
+ * key (password) that the {@link Attribute#encode()} method should use when
+ * creating the content of this message.
*
* @return the newly created address attribute.
*/
public static MessageIntegrityAttribute createMessageIntegrityAttribute(
- byte[] key)
+ String username)
{
MessageIntegrityAttribute attribute = new MessageIntegrityAttribute();
-
- attribute.setKey(key);
-
- //todo: implement saslprep one day even though I don't think it's
- //necessary for the ICE use case.
+ attribute.setUsername(username);
return attribute;
};
diff --git a/src/org/ice4j/attribute/MessageIntegrityAttribute.java b/src/org/ice4j/attribute/MessageIntegrityAttribute.java
index 5d9f16f..5c5fbfe 100644
--- a/src/org/ice4j/attribute/MessageIntegrityAttribute.java
+++ b/src/org/ice4j/attribute/MessageIntegrityAttribute.java
@@ -14,6 +14,7 @@ import javax.crypto.*;
import javax.crypto.spec.*;
import org.ice4j.*;
+import org.ice4j.stack.*;
/**
* The MESSAGE-INTEGRITY attribute contains an HMAC-SHA1 [RFC2104] of
@@ -100,9 +101,11 @@ public class MessageIntegrityAttribute
private byte[] hmacSha1Content;
/**
- * The key that we should be using when creating the hmacSha1Content.
+ * The username that we should use to obtain an encryption
+ * key (password) that the {@link #encode()} method should use when
+ * creating the content of this message.
*/
- private byte[] key;
+ private String username;
/**
* Creates a MessageIntegrityAttribute.
@@ -113,15 +116,17 @@ public class MessageIntegrityAttribute
}
/**
- * Sets the key that the {@link #encode()} method should use when creating
- * the content of this message.
+ * Sets the username that we should use to obtain an encryption
+ * key (password) that the {@link #encode()} method should use when
+ * creating the content of this message.
*
- * @param key the key that the {@link #encode()} method should use when
+ * @param username the username that we should use to obtain an encryption
+ * key (password) that the {@link #encode()} method should use when
* creating the content of this message.
*/
- public void setKey(byte[] key)
+ public void setUsername(String username)
{
- this.key = key;
+ this.username = username;
}
/**
@@ -249,9 +254,11 @@ public class MessageIntegrityAttribute
binValue[2] = (byte)(getDataLength()>>8);
binValue[3] = (byte)(getDataLength()&0x00FF);
+ byte[] key = StunStack.getInstance().getCredentialsManager()
+ .getKey(username);
+
//now calculate the HMAC-SHA1
- this.hmacSha1Content = calculateHmacSha1(
- content, offset, length, this.key);
+ this.hmacSha1Content = calculateHmacSha1(content, offset, length, key);
//username
System.arraycopy(hmacSha1Content, 0, binValue, 4, getDataLength());
diff --git a/src/org/ice4j/ice/Agent.java b/src/org/ice4j/ice/Agent.java
index 600b13a..2e51ba5 100644
--- a/src/org/ice4j/ice/Agent.java
+++ b/src/org/ice4j/ice/Agent.java
@@ -103,11 +103,16 @@ public class Agent
private boolean isControlling = true;
/**
- * The entity that will be taking care of all incoming and outgoing
- * connectivity checks.
+ * The entity that will be taking care of outgoing connectivity checks.
*/
- private final ConnectivityCheckHandler connCheckHandler
- = new ConnectivityCheckHandler(this);
+ private final ConnectivityCheckClient connCheckHandler
+ = new ConnectivityCheckClient(this);
+
+ /**
+ * The entity that will be taking care of incoming connectivity checks.
+ */
+ private final ConnectivityCheckServer connCheckServer
+ = new ConnectivityCheckServer(this);
/**
* Creates an empty Agent with no streams, and no address
diff --git a/src/org/ice4j/ice/ConnectivityCheckClient.java b/src/org/ice4j/ice/ConnectivityCheckClient.java
new file mode 100644
index 0000000..4244da9
--- /dev/null
+++ b/src/org/ice4j/ice/ConnectivityCheckClient.java
@@ -0,0 +1,142 @@
+/*
+ * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
+ * Maintained by the SIP Communicator community (http://sip-communicator.org).
+ *
+ * Distributable under LGPL license. See terms of license at gnu.org.
+ */
+package org.ice4j.ice;
+
+import java.net.*;
+import java.util.logging.*;
+
+import org.ice4j.*;
+import org.ice4j.attribute.*;
+import org.ice4j.message.*;
+import org.ice4j.stack.*;
+
+/**
+ * @author Emil Ivov
+ */
+public class ConnectivityCheckClient
+ implements ResponseCollector
+{
+ /**
+ * The Logger used by the ConnectivityCheckClient
+ * class and its instances for logging output.
+ */
+ private static final Logger logger = Logger
+ .getLogger(ConnectivityCheckClient.class.getName());
+
+ /**
+ * The agent that created us.
+ */
+ private final Agent parentAgent;
+
+ /**
+ * The stun stack that we will use for connectivity checks.
+ */
+ StunStack stunStack = StunStack.getInstance();
+
+ /**
+ * Creates a new ConnectivityCheckHandler setting
+ * parentAgent as the agent that will be used for retrieving
+ * information such as user fragments for example.
+ *
+ * @param parentAgent the Agent that is creating this instance.
+ */
+ public ConnectivityCheckClient(Agent parentAgent)
+ {
+ this.parentAgent = parentAgent;
+ }
+
+ public void startChecks(CheckList checkList)
+ {
+ for(CandidatePair pair : checkList)
+ {
+ startCheckForPair(pair);
+ }
+ }
+
+
+ private void startCheckForPair(CandidatePair pair)
+ {
+ //we don't need to do a canReach() verification here as it has been
+ //already verified during the gathering process.
+ DatagramSocket stunSocket = ((HostCandidate)pair.getLocalCandidate())
+ .getStunSocket(null);
+
+ Request request = MessageFactory.createBindingRequest();
+
+ //priority
+ PriorityAttribute priority = AttributeFactory.createPriorityAttribute(
+ pair.getLocalCandidate().computePriorityForType(
+ CandidateType.PEER_REFLEXIVE_CANDIDATE));
+
+ request.addAttribute(priority);
+
+ //controlling controlled
+ if (parentAgent.isControlling())
+ {
+ request.addAttribute(AttributeFactory
+ .createIceControllingAttribute(parentAgent
+ .getTieBreaker()));
+ }
+ else
+ {
+ request.addAttribute(AttributeFactory
+ .createIceControlledAttribute(parentAgent
+ .getTieBreaker()));
+ }
+
+ //credentials
+ UsernameAttribute unameAttr = AttributeFactory.createUsernameAttribute(
+ parentAgent.generateLocalUserName());
+
+ request.addAttribute(unameAttr);
+
+ //todo: do this in the stun stack so that we could do the
+ //calculation once the request is ready (we'd need the transaction id
+ //for example.
+ //todo: also implement SASL prepare
+ MessageIntegrityAttribute msgIntegrity = AttributeFactory
+ .createMessageIntegrityAttribute(parentAgent
+ .generateRemoteUserName());
+
+
+ request.addAttribute(msgIntegrity);
+
+ TransactionID tran;
+
+ try
+ {
+ tran = stunStack.sendRequest(request,
+ pair.getRemoteCandidate().getTransportAddress(), stunSocket,
+ this);
+System.out.println("checking pair " + pair + " with tran=" + tran.toString());
+ }
+ catch (Exception exception)
+ {
+ logger.log( Level.INFO,
+ "Failed to send " + request + " through "
+ + stunSocket.getLocalSocketAddress(),
+ exception);
+ return;
+ }
+ }
+
+ public void processResponse(StunMessageEvent response)
+ {
+ }
+
+ public void processTimeout(StunTimeoutEvent event)
+ {
+ System.out.println("timeout event=" + event);
+ }
+
+ public void processUnreachable(StunFailureEvent event)
+ {
+ System.out.println("failure event=" + event);
+ }
+
+
+}
diff --git a/src/org/ice4j/ice/ConnectivityCheckHandler.java b/src/org/ice4j/ice/ConnectivityCheckHandler.java
deleted file mode 100644
index 7cf9b5c..0000000
--- a/src/org/ice4j/ice/ConnectivityCheckHandler.java
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * ice4j, the OpenSource Java Solution for NAT and Firewall Traversal.
- * Maintained by the SIP Communicator community (http://sip-communicator.org).
- *
- * Distributable under LGPL license. See terms of license at gnu.org.
- */
-package org.ice4j.ice;
-
-import java.io.*;
-import java.net.*;
-import java.util.logging.*;
-
-import org.ice4j.*;
-import org.ice4j.attribute.*;
-import org.ice4j.message.*;
-import org.ice4j.security.*;
-import org.ice4j.socket.*;
-import org.ice4j.stack.*;
-
-/**
- * @author Emil Ivov
- */
-public class ConnectivityCheckHandler
- implements ResponseCollector,
- RequestListener,
- CredentialsAuthority
-{
- /**
- * The Logger used by the ConnectivityCheckClient
- * class and its instances for logging output.
- */
- private static final Logger logger = Logger
- .getLogger(ConnectivityCheckHandler.class.getName());
-
- /**
- * The agent that created us.
- */
- private final Agent parentAgent;
-
- /**
- * The stun stack that we will use for connectivity checks.
- */
- StunStack stunStack = StunStack.getInstance();
-
- /**
- * The DatagramPacketFilter that only accepts STUN messages.
- */
- private DatagramPacketFilter stunDatagramPacketFilter;
-
- /**
- * Creates a new ConnectivityCheckHandler setting
- * parentAgent as the agent that will be used for retrieving
- * information such as user fragments for example.
- *
- * @param parentAgent the Agent that is creating this instance.
- */
- public ConnectivityCheckHandler(Agent parentAgent)
- {
- this.parentAgent = parentAgent;
- stunStack.addRequestListener(this);
- stunStack.getCredentialsManager().registerAuthority(this);
- }
-
- public void startChecks(CheckList checkList)
- {
- for(CandidatePair pair : checkList)
- {
- startCheckForPair(pair);
- }
- }
-
-
- private void startCheckForPair(CandidatePair pair)
- {
- //we don't need to do a canReach() verification here as it has been
- //already verified during the gathering process.
- DatagramSocket stunSocket = ((HostCandidate)pair.getLocalCandidate())
- .getStunSocket(null);
-
- Request request = MessageFactory.createBindingRequest();
-
- //priority
- PriorityAttribute priority = AttributeFactory.createPriorityAttribute(
- pair.getLocalCandidate().computePriorityForType(
- CandidateType.PEER_REFLEXIVE_CANDIDATE));
-
- request.addAttribute(priority);
-
- //controlling controlled
- if (parentAgent.isControlling())
- {
- request.addAttribute(AttributeFactory
- .createIceControllingAttribute(parentAgent
- .getTieBreaker()));
- }
- else
- {
- request.addAttribute(AttributeFactory
- .createIceControlledAttribute(parentAgent
- .getTieBreaker()));
- }
-
- //credentials
- UsernameAttribute unameAttr = AttributeFactory.createUsernameAttribute(
- parentAgent.generateLocalUserName());
-
- request.addAttribute(unameAttr);
-
- //todo: do this in the stun stack so that we could do the
- //calculation once the request is ready (we'd need the transaction id
- //for example.
- //todo: also implement SASL prepare
- MessageIntegrityAttribute msgIntegrity
- = AttributeFactory.createMessageIntegrityAttribute(
- parentAgent.getRemotePassword().getBytes());
-
-
- request.addAttribute(msgIntegrity);
-
- TransactionID tran;
-
- try
- {
- tran = stunStack.sendRequest(request,
- pair.getRemoteCandidate().getTransportAddress(), stunSocket,
- this);
-System.out.println("checking pair " + pair + " with tran=" + tran.toString());
- }
- catch (Exception exception)
- {
- logger.log( Level.INFO,
- "Failed to send " + request + " through "
- + stunSocket.getLocalSocketAddress(),
- exception);
- return;
- }
- }
-
- public void processResponse(StunMessageEvent response)
- {
- }
-
- public void processTimeout(StunTimeoutEvent event)
- {
- System.out.println("timeout event=" + event);
- }
-
- public void processUnreachable(StunFailureEvent event)
- {
- System.out.println("failure event=" + event);
- }
-
- public void requestReceived(StunMessageEvent evt)
- {
- Request request = (Request)evt.getMessage();
-
- //check the user name
- if(! checkUserName(request))
- return;
-
- //check message integrity.
-
- Response response = MessageFactory.createBindingResponse(
- request, evt.getRemoteAddress());
- try
- {
- stunStack.sendResponse(evt.getTransactionID().getTransactionID(),
- response, evt.getLocalAddress(), evt.getRemoteAddress());
- }
- catch (Exception e)
- {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- /**
- * Verifies whether request comes with the proper username and
- * returns true if it does and false otherwise.
- *
- * @param request the Request that we'd like to check for a
- * proper username.
- *
- * @return true if the request contains the proper user
- * name and false otherwise.
- */
- public boolean checkUserName(Request request)
- {
- UsernameAttribute unameAttr
- = (UsernameAttribute)request.getAttribute(Attribute.USERNAME);
-
- if (unameAttr == null)
- {
- if(logger.isLoggable(Level.FINE))
- {
- logger.log(Level.FINE, "Received a request without a USERNAME");
- }
- return false;
- }
-
- String username = new String(unameAttr.getUsername());
- int colon = username.indexOf(":");
- if( username.length() < 1
- || colon < 1)
- {
- if(logger.isLoggable(Level.FINE))
- {
- logger.log(Level.FINE, "Received a request with an improperly "
- +"formatted username");
- }
- return false;
- }
-
- String lfrag = username.substring(0, colon);
-
- if( !lfrag.equals(parentAgent.getLocalUfrag()))
- {
- if(logger.isLoggable(Level.FINE))
- {
- logger.log(Level.FINE, "Remote peer using a wrong user name: "
- + username);
- }
- return false;
- }
-
- return true;
- }
-
- /**
- * Implements the {@link CredentialsAuthority#getKey(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.
- *
- * @param username the local ufrag that we should return a password for.
- *
- * @return this handler's parent agent local password if username
- * equals the local ufrag and null otherwise.
- */
- public byte[] getKey(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.getLocalUfrag()))
- return parentAgent.getLocalPassword().getBytes();
- }
- else
- {
- //caller gave us the entire username.
- if (username.equals(parentAgent.generateRemoteUserName()))
- return parentAgent.getLocalPassword().getBytes();
- }
-
- return null;
- }
-}
diff --git a/src/org/ice4j/ice/ConnectivityCheckServer.java b/src/org/ice4j/ice/ConnectivityCheckServer.java
index c331d23..429b0db 100644
--- a/src/org/ice4j/ice/ConnectivityCheckServer.java
+++ b/src/org/ice4j/ice/ConnectivityCheckServer.java
@@ -6,34 +6,140 @@
*/
package org.ice4j.ice;
+import java.util.logging.*;
+
import org.ice4j.*;
+import org.ice4j.attribute.*;
+import org.ice4j.message.*;
+import org.ice4j.security.*;
import org.ice4j.stack.*;
/**
* @author Emil Ivov
*/
public class ConnectivityCheckServer
- implements RequestListener
+ implements RequestListener,
+ CredentialsAuthority
{
+ /**
+ * The Logger used by the ConnectivityCheckServer
+ * class and its instances for logging output.
+ */
+ private static final Logger logger = Logger
+ .getLogger(ConnectivityCheckServer.class.getName());
+
+ /**
+ * The agent that created us.
+ */
+ private final Agent parentAgent;
+
+ /**
+ * The stun stack that we will use for connectivity checks.
+ */
StunStack stunStack = StunStack.getInstance();
- public ConnectivityCheckServer()
+ /**
+ * Creates a new ConnectivityCheckServer setting
+ * parentAgent as the agent that will be used for retrieving
+ * information such as user fragments for example.
+ *
+ * @param parentAgent the Agent that is creating this instance.
+ */
+ public ConnectivityCheckServer(Agent parentAgent)
{
+ this.parentAgent = parentAgent;
stunStack.addRequestListener(this);
- }
-
- public void startListening(LocalCandidate candidate)
- {
- stunStack.addSocket(candidate.getSocket());
- }
-
- public void stopListenint(LocalCandidate candidate)
- {
- stunStack.removeSocket(candidate.getTransportAddress());
+ stunStack.getCredentialsManager().registerAuthority(this);
}
public void requestReceived(StunMessageEvent evt)
{
- System.out.println("evt=" + evt);
+ Request request = (Request)evt.getMessage();
+
+ //ignore incoming requests that are not meant for the local user.
+ //normally the stack will get rid of faulty user names but we could
+ //still see messages not meant for this server if both peers or running
+ //on this same instance of the stack.
+ UsernameAttribute uname = (UsernameAttribute)request
+ .getAttribute(Attribute.USERNAME);
+
+ if(uname == null
+ || !checkUserName(new String(uname.getUsername())))
+ {
+ return;
+ }
+
+ //check message integrity.
+ Response response = MessageFactory.createBindingResponse(
+ request, evt.getRemoteAddress());
+ try
+ {
+ stunStack.sendResponse(evt.getTransactionID().getTransactionID(),
+ response, evt.getLocalAddress(), evt.getRemoteAddress());
+ }
+ catch (Exception e)
+ {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
}
+ /**
+ * Verifies whether username is currently known to this server
+ * and returns true if so. Returns false otherwise.
+ *
+ * @param username the user name whose validity we'd like to check.
+ *
+ * @return true if username is known to this
+ * ConnectivityCheckServer and false otherwise.
+ */
+ public boolean checkUserName(String username)
+ {
+ boolean accept = false;
+ int colon = username.indexOf(":");
+ if( colon < 0)
+ {
+ //caller gave us a ufrag
+ if(username.equals(parentAgent.getLocalUfrag()))
+ accept = true;
+ }
+ else
+ {
+ //caller gave us the entire username.
+ if(username.substring(0, colon).equals(parentAgent.getLocalUfrag()))
+ accept = true;
+ }
+ return accept;
+ }
+
+ /**
+ * Implements the {@link CredentialsAuthority#getKey(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.
+ *
+ * @param username the local ufrag that we should return a password for.
+ *
+ * @return this handler's parent agent local password if username
+ * equals the local ufrag and null otherwise.
+ */
+ public byte[] getKey(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.getLocalUfrag()))
+ return parentAgent.getLocalPassword().getBytes();
+ }
+ else
+ {
+ //caller gave us the entire username.
+ if (username.equals(parentAgent.generateRemoteUserName()))
+ return parentAgent.getLocalPassword().getBytes();
+ }
+
+ return null;
+ }
}
diff --git a/src/org/ice4j/message/Message.java b/src/org/ice4j/message/Message.java
index e147822..dac72b1 100644
--- a/src/org/ice4j/message/Message.java
+++ b/src/org/ice4j/message/Message.java
@@ -678,37 +678,77 @@ public abstract class Message
binMessage, (char)initialOffset,
(char)(offset - initialOffset)); // message head
- //assert Message Integrity
- if (att instanceof MessageIntegrityAttribute)
- {
- if (!message.validateMessageIntegrity(
- (MessageIntegrityAttribute)att,
- binMessage, originalOffset, offset))
- {
- throw new StunException(StunException.ILLEGAL_ARGUMENT,
- "Wrong value in MESSAGE-INTEGRITY");
- }
-
- }
-
- //check finger print CRC
- if (att instanceof FingerprintAttribute)
- {
- if (!validateFingerprint((FingerprintAttribute)att,
- binMessage, originalOffset, offset))
- {
- throw new StunException(StunException.ILLEGAL_ARGUMENT,
- "Wrong value in FINGERPRINT");
- }
-
- }
+ performAttributeSpecificActions(att, binMessage, message,
+ originalOffset, offset);
message.addAttribute(att);
offset += att.getDataLength() + Attribute.HEADER_LENGTH;
}
+
return message;
}
+ /**
+ * Executes actions related specific attributes like asserting proper
+ * checksums or verifying the validity of user names.
+ *
+ * @param attribute the Attribute we'd like to process.
+ * @param binMessage the byte array that the message arrived with.
+ * @param message the Message that we're parsing
+ * binMessage into.
+ * @param offset the index where data starts in binMessage.
+ * @param msgLen the number of message bytes in binMessage.
+ *
+ * @throws StunException if there's something in the attribute
+ * that caused us to discard the whole message (e.g. an invalid checksum
+ * or username)
+ */
+ private static void performAttributeSpecificActions(Attribute attribute,
+ byte[] binMessage,
+ Message message,
+ int offset,
+ int msgLen)
+ throws StunException
+ {
+ //assert valid username
+ if (attribute instanceof UsernameAttribute)
+ {
+ if (!validateUsername( (UsernameAttribute)attribute))
+ {
+ throw new StunException(StunException.ILLEGAL_ARGUMENT,
+ "Non-recognized username: "
+ + new String(((UsernameAttribute)attribute)
+ .getUsername()) );
+ }
+
+ }
+
+ //assert Message Integrity
+ if (attribute instanceof MessageIntegrityAttribute)
+ {
+ if (!message.validateMessageIntegrity(
+ (MessageIntegrityAttribute)attribute,
+ binMessage, offset, msgLen))
+ {
+ throw new StunException(StunException.ILLEGAL_ARGUMENT,
+ "Wrong value in MESSAGE-INTEGRITY");
+ }
+
+ }
+
+ //check finger print CRC
+ if (attribute instanceof FingerprintAttribute)
+ {
+ if (!validateFingerprint((FingerprintAttribute)attribute,
+ binMessage, offset, msgLen))
+ {
+ throw new StunException(StunException.ILLEGAL_ARGUMENT,
+ "Wrong value in FINGERPRINT");
+ }
+
+ }
+ }
+
/**
* Recalculates the fingerprint CRC32 checksum of the message
* array so that we could compare it with the value brought by the
@@ -723,10 +763,10 @@ public abstract class Message
* @return true if fingerprint contains a valid CRC32
* value and false otherwise.
*/
- public static boolean validateFingerprint(FingerprintAttribute fingerprint,
- byte[] message,
- int offset,
- int length)
+ private static boolean validateFingerprint(FingerprintAttribute fingerprint,
+ byte[] message,
+ int offset,
+ int length)
{
byte[] incomingCrcBytes = fingerprint.getChecksum();
@@ -769,10 +809,10 @@ public abstract class Message
* @return true if msgInt contains a valid SHA1 value and
* false otherwise.
*/
- public boolean validateMessageIntegrity(MessageIntegrityAttribute msgInt,
- byte[] message,
- int offset,
- int length)
+ private boolean validateMessageIntegrity(MessageIntegrityAttribute msgInt,
+ byte[] message,
+ int offset,
+ int length)
{
//first get a password for the username specified with this message.
UsernameAttribute unameAttr
@@ -829,6 +869,38 @@ public abstract class Message
return true;
}
+ /**
+ * Asserts the validity of the user name we've received in
+ * unameAttr.
+ *
+ * @param unameAttr the attribute that we need to validate.
+ *
+ * @return true if unameAttr contains a valid user name
+ * and false otherwise.
+ */
+ private static boolean validateUsername(UsernameAttribute unameAttr)
+ {
+ String username = new String(unameAttr.getUsername());
+
+ int colon = username.indexOf(":");
+
+ if( username.length() < 1
+ || colon < 1)
+ {
+ if(logger.isLoggable(Level.FINE))
+ {
+ logger.log(Level.FINE, "Received a message with an improperly "
+ +"formatted username");
+ }
+ return false;
+ }
+
+ String lfrag = username.substring(0, colon);
+
+ return StunStack.getInstance()
+ .getCredentialsManager().checkUserName(lfrag);
+ }
+
/**
* Verify that the message has all obligatory attributes and throw an
* exception if this is not the case.
diff --git a/src/org/ice4j/security/CredentialsAuthority.java b/src/org/ice4j/security/CredentialsAuthority.java
index b8e7b62..7ce4b23 100644
--- a/src/org/ice4j/security/CredentialsAuthority.java
+++ b/src/org/ice4j/security/CredentialsAuthority.java
@@ -29,4 +29,15 @@ public interface CredentialsAuthority
* CredentialsAuthority.
*/
public byte[] getKey(String username);
+
+ /**
+ * Verifies whether username is currently known to this authority
+ * and returns true if so. Returns false otherwise.
+ *
+ * @param username the user name whose validity we'd like to check.
+ *
+ * @return true if username is known to this
+ * CredentialsAuthority and false otherwise.
+ */
+ public boolean checkUserName(String username);
}
diff --git a/src/org/ice4j/security/CredentialsManager.java b/src/org/ice4j/security/CredentialsManager.java
index 2453393..c41ade8 100644
--- a/src/org/ice4j/security/CredentialsManager.java
+++ b/src/org/ice4j/security/CredentialsManager.java
@@ -52,12 +52,37 @@ public class CredentialsManager
byte[] passwd = auth.getKey(username);
if (passwd != null)
+ {
+ /** @todo: we should probably add SASLprep here.*/
return passwd;
+ }
}
return null;
}
+ /**
+ * Verifies whether username is currently known to any of the
+ * {@link CredentialsAuthority}s registered with this manager and
+ * and returns true if so. Returns false otherwise.
+ *
+ * @param username the user name whose validity we'd like to check.
+ *
+ * @return true if username is known to any of the
+ * CredentialsAuthoritys registered here and false
+ * otherwise.
+ */
+ public boolean checkUserName(String username)
+ {
+ for (CredentialsAuthority auth : authorities)
+ {
+ if( auth.checkUserName(username))
+ return true;
+ }
+
+ return false;
+ }
+
/**
* Adds authority to the list of {@link CredentialsAuthority}s
* registered with this manager.
diff --git a/src/org/ice4j/stack/NetAccessManager.java b/src/org/ice4j/stack/NetAccessManager.java
index 988b0d4..f56007b 100644
--- a/src/org/ice4j/stack/NetAccessManager.java
+++ b/src/org/ice4j/stack/NetAccessManager.java
@@ -93,7 +93,10 @@ class NetAccessManager
/**
* apart from logging, i am not sure what else we could do here.
*/
- logger.log( Level.WARNING, "The following error occurred", error);
+ logger.log( Level.FINE,
+ "The following error occurred with "
+ +"an incoming message:",
+ error);
}
/**