Fixes warnings, javadocs, formatting. Simplifies a few instances of cloning arrays.
This commit is contained in:
parent
5dd7a39257
commit
316e524a0f
@ -96,9 +96,11 @@ public class StunException extends Exception
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a StunException, setting an error message an error id and a cause.
|
* Creates a StunException, setting an error message an error id and a
|
||||||
* @param message an error message.
|
* cause.
|
||||||
|
*
|
||||||
* @param id an error id.
|
* @param id an error id.
|
||||||
|
* @param message an error message.
|
||||||
* @param cause the error that caused this exception.
|
* @param cause the error that caused this exception.
|
||||||
*/
|
*/
|
||||||
public StunException(int id, String message, Throwable cause)
|
public StunException(int id, String message, Throwable cause)
|
||||||
|
|||||||
@ -6,8 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.attribute;
|
package org.ice4j.attribute;
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <tt>ContentDependentAttribute</tt>s have a value that depend on the content
|
* <tt>ContentDependentAttribute</tt>s have a value that depend on the content
|
||||||
* of the message. The {@link MessageIntegrityAttribute} and {@link
|
* of the message. The {@link MessageIntegrityAttribute} and {@link
|
||||||
|
|||||||
@ -6,10 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.attribute;
|
package org.ice4j.attribute;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The ERROR-CODE attribute is present in the Binding Error Response and
|
* The ERROR-CODE attribute is present in the Binding Error Response and
|
||||||
* Shared Secret Error Response. It is a numeric value in the range of
|
* Shared Secret Error Response. It is a numeric value in the range of
|
||||||
@ -142,7 +138,6 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
return (char)(getErrorClass()*100 + getErrorNumber());
|
return (char)(getErrorClass()*100 + getErrorNumber());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this attribute's error number.
|
* Sets this attribute's error number.
|
||||||
* @param errorNumber the error number to assign this attribute.
|
* @param errorNumber the error number to assign this attribute.
|
||||||
@ -190,7 +185,6 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
return errorClass;
|
return errorClass;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a default reason phrase corresponding to the specified error
|
* Returns a default reason phrase corresponding to the specified error
|
||||||
* code, as described by rfc 3489.
|
* code, as described by rfc 3489.
|
||||||
@ -371,6 +365,4 @@ public class ErrorCodeAttribute extends Attribute
|
|||||||
setReasonPhrase(new String(reasonBytes));
|
setReasonPhrase(new String(reasonBytes));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,14 +6,11 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.attribute;
|
package org.ice4j.attribute;
|
||||||
|
|
||||||
import java.nio.channels.*;
|
|
||||||
import java.security.*;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.crypto.*;
|
import javax.crypto.*;
|
||||||
import javax.crypto.spec.*;
|
import javax.crypto.spec.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -11,7 +11,7 @@ import java.util.*;
|
|||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The NONCE attribute is used for authentification.
|
* The NONCE attribute is used for authentication.
|
||||||
*
|
*
|
||||||
* @author Sebastien Vincent
|
* @author Sebastien Vincent
|
||||||
*/
|
*/
|
||||||
@ -45,7 +45,8 @@ public class NonceAttribute extends Attribute
|
|||||||
* @param length the length of the binary array.
|
* @param length the length of the binary array.
|
||||||
* @throws StunException if attributeValue contains invalid data.
|
* @throws StunException if attributeValue contains invalid data.
|
||||||
*/
|
*/
|
||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length) throws StunException
|
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
||||||
|
throws StunException
|
||||||
{
|
{
|
||||||
nonce = new byte[length];
|
nonce = new byte[length];
|
||||||
System.arraycopy(attributeValue, offset, nonce, 0, length);
|
System.arraycopy(attributeValue, offset, nonce, 0, length);
|
||||||
@ -58,7 +59,8 @@ public class NonceAttribute extends Attribute
|
|||||||
public byte[] encode()
|
public byte[] encode()
|
||||||
{
|
{
|
||||||
char type = getAttributeType();
|
char type = getAttributeType();
|
||||||
byte binValue[] = new byte[HEADER_LENGTH + getDataLength() + (getDataLength() % 4)];
|
byte binValue[]
|
||||||
|
= new byte[HEADER_LENGTH + getDataLength() + (getDataLength() % 4)];
|
||||||
|
|
||||||
//Type
|
//Type
|
||||||
binValue[0] = (byte)(type>>8);
|
binValue[0] = (byte)(type>>8);
|
||||||
@ -93,18 +95,13 @@ public class NonceAttribute extends Attribute
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a (cloned) byte array containg the data value of the nonce
|
* Returns a (cloned) byte array containing the data value of the nonce
|
||||||
* attribute.
|
* attribute.
|
||||||
* @return the binary array containing the nonce.
|
* @return the binary array containing the nonce.
|
||||||
*/
|
*/
|
||||||
public byte[] getNonce()
|
public byte[] getNonce()
|
||||||
{
|
{
|
||||||
if (nonce == null)
|
return (nonce == null) ? null : nonce.clone();
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] copy = new byte[nonce.length];
|
|
||||||
System.arraycopy(nonce, 0, copy, 0, nonce.length);
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -114,14 +111,7 @@ public class NonceAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public void setNonce(byte[] nonce)
|
public void setNonce(byte[] nonce)
|
||||||
{
|
{
|
||||||
if (nonce == null)
|
this.nonce = (nonce == null) ? null : nonce.clone();
|
||||||
{
|
|
||||||
this.nonce = null;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.nonce = new byte[nonce.length];
|
|
||||||
System.arraycopy(nonce, 0, this.nonce, 0, nonce.length);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -132,19 +122,16 @@ public class NonceAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public boolean equals(Object obj)
|
public boolean equals(Object obj)
|
||||||
{
|
{
|
||||||
if (! (obj instanceof NonceAttribute) || obj == null)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (obj == this)
|
if (obj == this)
|
||||||
return true;
|
return true;
|
||||||
|
if (! (obj instanceof NonceAttribute))
|
||||||
NonceAttribute att = (NonceAttribute) obj;
|
|
||||||
if (att.getAttributeType() != getAttributeType()
|
|
||||||
|| att.getDataLength() != getDataLength()
|
|
||||||
|| !Arrays.equals( att.nonce, nonce))
|
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
NonceAttribute att = (NonceAttribute) obj;
|
||||||
|
|
||||||
|
return
|
||||||
|
(att.getAttributeType() == getAttributeType()
|
||||||
|
&& att.getDataLength() == getDataLength()
|
||||||
|
&& Arrays.equals(att.nonce, nonce));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -95,18 +95,13 @@ public class RealmAttribute extends Attribute
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a (cloned) byte array containg the data value of the realm
|
* Returns a (cloned) byte array containing the data value of the realm
|
||||||
* attribute.
|
* attribute.
|
||||||
* @return the binary array containing the realm.
|
* @return the binary array containing the realm.
|
||||||
*/
|
*/
|
||||||
public byte[] getRealm()
|
public byte[] getRealm()
|
||||||
{
|
{
|
||||||
if (realm == null)
|
return (realm == null) ? null : realm.clone();
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] copy = new byte[realm.length];
|
|
||||||
System.arraycopy(realm, 0, copy, 0, realm.length);
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -8,8 +8,6 @@ package org.ice4j.attribute;
|
|||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The SOFTWARE attribute contains a textual description of the software
|
* The SOFTWARE attribute contains a textual description of the software
|
||||||
* being used by the software or the client, including manufacturer and version number.
|
* being used by the software or the client, including manufacturer and version number.
|
||||||
|
|||||||
@ -105,12 +105,7 @@ public class UsernameAttribute extends Attribute
|
|||||||
*/
|
*/
|
||||||
public byte[] getUsername()
|
public byte[] getUsername()
|
||||||
{
|
{
|
||||||
if (username == null)
|
return (username == null) ? null : username.clone();
|
||||||
return null;
|
|
||||||
|
|
||||||
byte[] copy = new byte[username.length];
|
|
||||||
System.arraycopy(username, 0, copy, 0, username.length);
|
|
||||||
return copy;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -202,7 +202,7 @@ class ConnectivityCheckClient
|
|||||||
else if(evt.getResponse().getMessageType()
|
else if(evt.getResponse().getMessageType()
|
||||||
== Response.BINDING_ERROR_RESPONSE)
|
== Response.BINDING_ERROR_RESPONSE)
|
||||||
{
|
{
|
||||||
if(! evt.getResponse().contains(Attribute.ERROR_CODE))
|
if(! evt.getResponse().containsAttribute(Attribute.ERROR_CODE))
|
||||||
{
|
{
|
||||||
logger.fine("Received a malformed error response.");
|
logger.fine("Received a malformed error response.");
|
||||||
return; //malformed error response
|
return; //malformed error response
|
||||||
@ -298,7 +298,7 @@ class ConnectivityCheckClient
|
|||||||
CandidatePair checkedPair = ((CandidatePair)evt.getTransactionID()
|
CandidatePair checkedPair = ((CandidatePair)evt.getTransactionID()
|
||||||
.getApplicationData());
|
.getApplicationData());
|
||||||
|
|
||||||
if(! response.contains(Attribute.XOR_MAPPED_ADDRESS))
|
if(! response.containsAttribute(Attribute.XOR_MAPPED_ADDRESS))
|
||||||
{
|
{
|
||||||
logger.fine("Received a success response with no "
|
logger.fine("Received a success response with no "
|
||||||
+"XOR_MAPPED_ADDRESS attribute.");
|
+"XOR_MAPPED_ADDRESS attribute.");
|
||||||
@ -432,7 +432,7 @@ class ConnectivityCheckClient
|
|||||||
//CANDIDATE attribute in the Binding request, the valid pair generated
|
//CANDIDATE attribute in the Binding request, the valid pair generated
|
||||||
//from that check has its nominated flag set to true.
|
//from that check has its nominated flag set to true.
|
||||||
if(parentAgent.isControlling()
|
if(parentAgent.isControlling()
|
||||||
&& request.contains(Attribute.USE_CANDIDATE))
|
&& request.containsAttribute(Attribute.USE_CANDIDATE))
|
||||||
{
|
{
|
||||||
parentAgent.nominationConfirmed( validPair );
|
parentAgent.nominationConfirmed( validPair );
|
||||||
}
|
}
|
||||||
@ -504,7 +504,7 @@ class ConnectivityCheckClient
|
|||||||
if(errorCode.getErrorCode() == ErrorCodeAttribute.ROLE_CONFLICT)
|
if(errorCode.getErrorCode() == ErrorCodeAttribute.ROLE_CONFLICT)
|
||||||
{
|
{
|
||||||
boolean wasControlling = originalRequest
|
boolean wasControlling = originalRequest
|
||||||
.contains(Attribute.ICE_CONTROLLING);
|
.containsAttribute(Attribute.ICE_CONTROLLING);
|
||||||
|
|
||||||
logger.finer("Swithing to isControlling=" + !wasControlling);
|
logger.finer("Swithing to isControlling=" + !wasControlling);
|
||||||
parentAgent.setControlling(!wasControlling);
|
parentAgent.setControlling(!wasControlling);
|
||||||
|
|||||||
@ -13,6 +13,7 @@ import org.ice4j.attribute.*;
|
|||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.security.*;
|
import org.ice4j.security.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The class that would be handling and responding to incoming connectivity
|
* The class that would be handling and responding to incoming connectivity
|
||||||
* checks.
|
* checks.
|
||||||
@ -56,7 +57,7 @@ class ConnectivityCheckServer
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles the {@link Request} delivered in <tt>evt</tt> by possibly
|
* Handles the {@link Request} delivered in <tt>evt</tt> by possibly
|
||||||
* queueing a triggered check and sending a success or or error response
|
* queuing a triggered check and sending a success or an error response
|
||||||
* depending on how processing goes.
|
* depending on how processing goes.
|
||||||
*
|
*
|
||||||
* @param evt the {@link StunMessageEvent} containing the {@link Request}
|
* @param evt the {@link StunMessageEvent} containing the {@link Request}
|
||||||
@ -94,16 +95,17 @@ class ConnectivityCheckServer
|
|||||||
|
|
||||||
//detect role conflicts
|
//detect role conflicts
|
||||||
if( ( parentAgent.isControlling()
|
if( ( parentAgent.isControlling()
|
||||||
&& request.contains(Attribute.ICE_CONTROLLING))
|
&& request.containsAttribute(Attribute.ICE_CONTROLLING))
|
||||||
|| ( ! parentAgent.isControlling()
|
|| ( ! parentAgent.isControlling()
|
||||||
&& request.contains(Attribute.ICE_CONTROLLED)))
|
&& request.containsAttribute(Attribute.ICE_CONTROLLED)))
|
||||||
{
|
{
|
||||||
if (!repairRoleConflict(evt))
|
if (!repairRoleConflict(evt))
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
long priority = extractPriority(request);
|
long priority = extractPriority(request);
|
||||||
boolean useCandidate = request.contains(Attribute.USE_CANDIDATE);
|
boolean useCandidate
|
||||||
|
= request.containsAttribute(Attribute.USE_CANDIDATE);
|
||||||
|
|
||||||
//tell our address handler we saw a new remote address;
|
//tell our address handler we saw a new remote address;
|
||||||
parentAgent.incomingCheckReceived(evt.getRemoteAddress(),
|
parentAgent.incomingCheckReceived(evt.getRemoteAddress(),
|
||||||
@ -187,7 +189,7 @@ class ConnectivityCheckServer
|
|||||||
// If the agent is in the controlling role, and the
|
// If the agent is in the controlling role, and the
|
||||||
// ICE-CONTROLLING attribute is present in the request:
|
// ICE-CONTROLLING attribute is present in the request:
|
||||||
if(parentAgent.isControlling()
|
if(parentAgent.isControlling()
|
||||||
&& req.contains(Attribute.ICE_CONTROLLING))
|
&& req.containsAttribute(Attribute.ICE_CONTROLLING))
|
||||||
{
|
{
|
||||||
IceControllingAttribute controlling = (IceControllingAttribute)
|
IceControllingAttribute controlling = (IceControllingAttribute)
|
||||||
req.getAttribute(Attribute.ICE_CONTROLLING);
|
req.getAttribute(Attribute.ICE_CONTROLLING);
|
||||||
@ -234,7 +236,7 @@ class ConnectivityCheckServer
|
|||||||
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
// If the agent is in the controlled role, and the ICE-CONTROLLED
|
||||||
// attribute is present in the request:
|
// attribute is present in the request:
|
||||||
else if(!parentAgent.isControlling()
|
else if(!parentAgent.isControlling()
|
||||||
&& req.contains(Attribute.ICE_CONTROLLED))
|
&& req.containsAttribute(Attribute.ICE_CONTROLLED))
|
||||||
{
|
{
|
||||||
IceControlledAttribute controlled = (IceControlledAttribute)
|
IceControlledAttribute controlled = (IceControlledAttribute)
|
||||||
req.getAttribute(Attribute.ICE_CONTROLLED);
|
req.getAttribute(Attribute.ICE_CONTROLLED);
|
||||||
|
|||||||
@ -42,11 +42,6 @@ public class HostCandidate extends LocalCandidate
|
|||||||
*/
|
*/
|
||||||
private final DatagramSocket socket;
|
private final DatagramSocket socket;
|
||||||
|
|
||||||
/**
|
|
||||||
* The <tt>DatagramPacketFilter</tt> that only accepts STUN messages.
|
|
||||||
*/
|
|
||||||
private DatagramPacketFilter stunDatagramPacketFilter;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a HostCandidate for the specified transport address.
|
* Creates a HostCandidate for the specified transport address.
|
||||||
*
|
*
|
||||||
@ -99,6 +94,7 @@ public class HostCandidate extends LocalCandidate
|
|||||||
Throwable exception = null;
|
Throwable exception = null;
|
||||||
|
|
||||||
if (hostSocket instanceof MultiplexingDatagramSocket)
|
if (hostSocket instanceof MultiplexingDatagramSocket)
|
||||||
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
stunSocket
|
stunSocket
|
||||||
@ -108,12 +104,13 @@ public class HostCandidate extends LocalCandidate
|
|||||||
}
|
}
|
||||||
catch (SocketException sex)//don't u just luv da name? ;)
|
catch (SocketException sex)//don't u just luv da name? ;)
|
||||||
{
|
{
|
||||||
logger.log( Level.SEVERE,
|
logger.log(Level.SEVERE,
|
||||||
"Failed to acquire DatagramSocket"
|
"Failed to acquire DatagramSocket"
|
||||||
+ " specific to STUN communication.",
|
+ " specific to STUN communication.",
|
||||||
sex);
|
sex);
|
||||||
exception = sex;
|
exception = sex;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (stunSocket == null)
|
if (stunSocket == null)
|
||||||
throw new IllegalArgumentException("hostCand", exception);
|
throw new IllegalArgumentException("hostCand", exception);
|
||||||
else
|
else
|
||||||
|
|||||||
@ -13,8 +13,6 @@ import org.ice4j.*;
|
|||||||
import org.ice4j.attribute.*;
|
import org.ice4j.attribute.*;
|
||||||
import org.ice4j.stack.*;
|
import org.ice4j.stack.*;
|
||||||
|
|
||||||
import sun.tools.tree.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents a STUN message. STUN messages are TLV (type-length-value)
|
* This class represents a STUN message. STUN messages are TLV (type-length-value)
|
||||||
* encoded using big endian (network ordered) binary. All STUN messages start
|
* encoded using big endian (network ordered) binary. All STUN messages start
|
||||||
@ -308,7 +306,7 @@ public abstract class Message
|
|||||||
* @return <tt>true</tt> if the this <tt>Message</tt> contains an attribute
|
* @return <tt>true</tt> if the this <tt>Message</tt> contains an attribute
|
||||||
* with the specified type or <tt>false</tt> otherwise.
|
* with the specified type or <tt>false</tt> otherwise.
|
||||||
*/
|
*/
|
||||||
public boolean contains(char attributeType)
|
public boolean containsAttribute(char attributeType)
|
||||||
{
|
{
|
||||||
return attributes.containsKey(attributeType);
|
return attributes.containsKey(attributeType);
|
||||||
}
|
}
|
||||||
@ -491,6 +489,7 @@ public abstract class Message
|
|||||||
{
|
{
|
||||||
switch (messageType)
|
switch (messageType)
|
||||||
{
|
{
|
||||||
|
case ALLOCATE_REQUEST: return "ALLOCATE-REQUEST";
|
||||||
case BINDING_REQUEST: return "BINDING-REQUEST";
|
case BINDING_REQUEST: return "BINDING-REQUEST";
|
||||||
case BINDING_SUCCESS_RESPONSE: return "BINDING-RESPONSE";
|
case BINDING_SUCCESS_RESPONSE: return "BINDING-RESPONSE";
|
||||||
case BINDING_ERROR_RESPONSE: return "BINDING-ERROR-RESPONSE";
|
case BINDING_ERROR_RESPONSE: return "BINDING-ERROR-RESPONSE";
|
||||||
@ -705,7 +704,7 @@ public abstract class Message
|
|||||||
|
|
||||||
offset+=TRANSACTION_ID_LENGTH;
|
offset+=TRANSACTION_ID_LENGTH;
|
||||||
|
|
||||||
while(offset - Message.HEADER_LENGTH< length)
|
while(offset - Message.HEADER_LENGTH < length)
|
||||||
{
|
{
|
||||||
Attribute att = AttributeDecoder.decode(
|
Attribute att = AttributeDecoder.decode(
|
||||||
binMessage, offset, (char)(length - offset));
|
binMessage, offset, (char)(length - offset));
|
||||||
@ -824,7 +823,6 @@ public abstract class Message
|
|||||||
if(getAttributePresentity(i) == M && getAttribute(i) == null)
|
if(getAttributePresentity(i) == M && getAttribute(i) == null)
|
||||||
throw new IllegalStateException(
|
throw new IllegalStateException(
|
||||||
"A mandatory attribute (type=" +(int)i + ") is missing!");
|
"A mandatory attribute (type=" +(int)i + ") is missing!");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -886,12 +884,27 @@ public abstract class Message
|
|||||||
*
|
*
|
||||||
* @return a <tt>String</tt> representation of this message.
|
* @return a <tt>String</tt> representation of this message.
|
||||||
*/
|
*/
|
||||||
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
return getName()+"(0x"+Integer.toHexString(getMessageType())
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
+")[attrib.count=" + getAttributeCount()
|
|
||||||
+" len=" + (int) this.getDataLength()
|
|
||||||
+" tranID=" + TransactionID.toString(getTransactionID()) + "]";
|
|
||||||
}
|
|
||||||
|
|
||||||
|
stringBuilder.append(getName());
|
||||||
|
stringBuilder.append("(0x");
|
||||||
|
stringBuilder.append(Integer.toHexString(getMessageType()));
|
||||||
|
stringBuilder.append(")[attrib.count=");
|
||||||
|
stringBuilder.append(getAttributeCount());
|
||||||
|
stringBuilder.append(" len=");
|
||||||
|
stringBuilder.append((int) this.getDataLength());
|
||||||
|
|
||||||
|
byte[] transactionID = getTransactionID();
|
||||||
|
|
||||||
|
if (transactionID != null)
|
||||||
|
{
|
||||||
|
stringBuilder.append(" tranID=");
|
||||||
|
stringBuilder.append(TransactionID.toString(transactionID));
|
||||||
|
}
|
||||||
|
stringBuilder.append("]");
|
||||||
|
return stringBuilder.toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.message;
|
package org.ice4j.message;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
@ -20,9 +21,8 @@ import org.ice4j.attribute.*;
|
|||||||
*/
|
*/
|
||||||
public class MessageFactory
|
public class MessageFactory
|
||||||
{
|
{
|
||||||
private static final Logger logger = Logger
|
private static final Logger logger
|
||||||
.getLogger(MessageFactory.class
|
= Logger.getLogger(MessageFactory.class.getName());
|
||||||
.getName());
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a default binding request. The request DOES NOT contains a
|
* Creates a default binding request. The request DOES NOT contains a
|
||||||
@ -374,34 +374,64 @@ public class MessageFactory
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add the required attributes for long-term authentication.<br/>
|
* Adds the <tt>Attribute</tt>s to a specific <tt>Request</tt> which support
|
||||||
* This will also add a MESSAGE-INTEGRITY and FINGERPRINT attribute.<br/>
|
* the STUN long-term credential mechanism.
|
||||||
* Do not add another attributes after called this method.
|
* <p>
|
||||||
|
* <b>Warning</b>: The MESSAGE-INTEGRITY <tt>Attribute</tt> will also be
|
||||||
|
* added so <tt>Attribute</tt>s added afterwards will not be taken into
|
||||||
|
* account for the calculation of the MESSAGE-INTEGRITY value. For example,
|
||||||
|
* the FINGERPRINT <tt>Attribute</tt> may still safely be added afterwards,
|
||||||
|
* because it is known to appear after the MESSAGE-INTEGRITY.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @param request the original request
|
* @param request the <tt>Request</tt> in which the <tt>Attribute</tt>s of
|
||||||
* @param username username value
|
* the STUN long-term credential mechanism are to be added
|
||||||
* @param realm realm value
|
* @param username the value for the USERNAME <tt>Attribute</tt> to be added
|
||||||
* @param nonce nonce value
|
* to <tt>request</tt>
|
||||||
|
* @param realm the value for the REALM <tt>Attribute</tt> to be added to
|
||||||
|
* <tt>request</tt>
|
||||||
|
* @param nonce the value for the NONCE <tt>Attribute</tt> to be added to
|
||||||
|
* <tt>request</tt>
|
||||||
*
|
*
|
||||||
* @throws StunException in case we have a problem creating the username
|
* @throws StunException if anything goes wrong while adding the
|
||||||
* realm or nonce attributes.
|
* <tt>Attribute</tt>s to <tt>request</tt> which support the STUN long-term
|
||||||
|
* credential mechanism
|
||||||
*/
|
*/
|
||||||
public static void addLongTermAuthentifcationAttribute(
|
public static void addLongTermCredentialAttributes(
|
||||||
Request request, byte username[], byte realm[],
|
Request request,
|
||||||
byte nonce[]) throws StunException
|
byte username[], byte realm[], byte nonce[])
|
||||||
|
throws StunException
|
||||||
{
|
{
|
||||||
UsernameAttribute usernameAttr = AttributeFactory
|
UsernameAttribute usernameAttribute
|
||||||
.createUsernameAttribute(username);
|
= AttributeFactory.createUsernameAttribute(username);
|
||||||
RealmAttribute realmAttr = AttributeFactory
|
RealmAttribute realmAttribute
|
||||||
.createRealmAttribute(realm);
|
= AttributeFactory.createRealmAttribute(realm);
|
||||||
NonceAttribute nonceAttr = AttributeFactory
|
NonceAttribute nonceAttribute
|
||||||
.createNonceAttribute(nonce);
|
= AttributeFactory.createNonceAttribute(nonce);
|
||||||
|
|
||||||
request.addAttribute(usernameAttr);
|
request.addAttribute(usernameAttribute);
|
||||||
request.addAttribute(realmAttr);
|
request.addAttribute(realmAttribute);
|
||||||
request.addAttribute(nonceAttr);
|
request.addAttribute(nonceAttribute);
|
||||||
|
|
||||||
/* TODO calculate MESSAGE-INTEGRITY and FINGERPRINT */
|
// MESSAGE-INTEGRITY
|
||||||
|
MessageIntegrityAttribute messageIntegrityAttribute;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* The value of USERNAME is a variable-length value. It MUST contain
|
||||||
|
* a UTF-8 [RFC3629] encoded sequence of less than 513 bytes, and
|
||||||
|
* MUST have been processed using SASLprep [RFC4013].
|
||||||
|
*/
|
||||||
|
messageIntegrityAttribute
|
||||||
|
= AttributeFactory.createMessageIntegrityAttribute(
|
||||||
|
new String(username, "UTF-8"));
|
||||||
|
}
|
||||||
|
catch (UnsupportedEncodingException ueex)
|
||||||
|
{
|
||||||
|
throw new StunException("username", ueex);
|
||||||
|
}
|
||||||
|
request.addAttribute(messageIntegrityAttribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -13,7 +13,6 @@ package org.ice4j.message;
|
|||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Request extends Message
|
public class Request extends Message
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -22,7 +21,6 @@ public class Request extends Message
|
|||||||
*/
|
*/
|
||||||
Request()
|
Request()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,5 +41,4 @@ public class Request extends Message
|
|||||||
|
|
||||||
super.setMessageType(requestType);
|
super.setMessageType(requestType);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,16 +6,16 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.message;
|
package org.ice4j.message;
|
||||||
|
|
||||||
import org.ice4j.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A response descendant of the message class. The primary purpose of the
|
* A response descendant of the message class. The primary purpose of the
|
||||||
* Response class is to allow better functional definition of the classes in the
|
* Response class is to allow better functional definition of the classes in the
|
||||||
* stack package.
|
* stack package.
|
||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
|
* @author Lubomir Marinov
|
||||||
*/
|
*/
|
||||||
public class Response extends Message
|
public class Response
|
||||||
|
extends Message
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -25,6 +25,28 @@ public class Response extends Message
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this instance represents a STUN error response.
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> if this instance represents a STUN error response;
|
||||||
|
* otherwise, <tt>false</tt>
|
||||||
|
*/
|
||||||
|
public boolean isErrorResponse()
|
||||||
|
{
|
||||||
|
return isErrorResponseType(getMessageType());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Determines whether this instance represents a STUN success response.
|
||||||
|
*
|
||||||
|
* @return <tt>true</tt> if this instance represents a STUN success
|
||||||
|
* response; otherwise, <tt>false</tt>
|
||||||
|
*/
|
||||||
|
public boolean isSuccessResponse()
|
||||||
|
{
|
||||||
|
return isSuccessResponseType(getMessageType());
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks whether responseType is a valid response type and if yes sets it
|
* Checks whether responseType is a valid response type and if yes sets it
|
||||||
* as the type of the current instance.
|
* as the type of the current instance.
|
||||||
@ -37,8 +59,8 @@ public class Response extends Message
|
|||||||
{
|
{
|
||||||
if(!isResponseType(responseType))
|
if(!isResponseType(responseType))
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
(int)(responseType)
|
Integer.toString(responseType)
|
||||||
+ " - is not a valid response type.");
|
+ " is not a valid response type.");
|
||||||
|
|
||||||
|
|
||||||
super.setMessageType(responseType);
|
super.setMessageType(responseType);
|
||||||
|
|||||||
@ -9,7 +9,7 @@ package org.ice4j.security;
|
|||||||
/**
|
/**
|
||||||
* The {@link CredentialsAuthority} interface is implemented by applications
|
* The {@link CredentialsAuthority} interface is implemented by applications
|
||||||
* in order to allow the stack to verify the integrity of incoming messages
|
* in order to allow the stack to verify the integrity of incoming messages
|
||||||
* containing the <tt>MessageIntegrity</tt> attribute.
|
* containing the <tt>MessageIntegrityAttribute</tt>.
|
||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -7,7 +7,6 @@
|
|||||||
package org.ice4j.security;
|
package org.ice4j.security;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.logging.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The <tt>CredentialsManager</tt> allows an application to handle verification
|
* The <tt>CredentialsManager</tt> allows an application to handle verification
|
||||||
|
|||||||
@ -9,7 +9,6 @@ package org.ice4j.stack;
|
|||||||
import java.util.logging.*;
|
import java.util.logging.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.attribute.*;
|
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -9,14 +9,11 @@ package org.ice4j.stack;
|
|||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
|
|
||||||
import com.sun.corba.se.impl.protocol.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles incoming requests.
|
* Handles incoming requests.
|
||||||
*
|
*
|
||||||
* @author Emil Ivov
|
* @author Emil Ivov
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public interface RequestListener
|
public interface RequestListener
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -19,8 +19,6 @@ import org.ice4j.attribute.*;
|
|||||||
import org.ice4j.message.*;
|
import org.ice4j.message.*;
|
||||||
import org.ice4j.security.*;
|
import org.ice4j.security.*;
|
||||||
|
|
||||||
import com.sun.corba.se.impl.protocol.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The entry point to the Stun4J stack. The class is used to start, stop and
|
* The entry point to the Stun4J stack. The class is used to start, stop and
|
||||||
* configure the stack.
|
* configure the stack.
|
||||||
@ -693,7 +691,8 @@ public class StunStack
|
|||||||
}
|
}
|
||||||
|
|
||||||
//assert Message Integrity
|
//assert Message Integrity
|
||||||
MessageIntegrityAttribute msgIntAttr = (MessageIntegrityAttribute)
|
MessageIntegrityAttribute msgIntAttr
|
||||||
|
= (MessageIntegrityAttribute)
|
||||||
request.getAttribute(Attribute.MESSAGE_INTEGRITY);
|
request.getAttribute(Attribute.MESSAGE_INTEGRITY);
|
||||||
|
|
||||||
if (msgIntAttr != null)
|
if (msgIntAttr != null)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user