Improves validation of incoming FINGERPRINT and MESSAGE-INTEGRITY attributes
This commit is contained in:
parent
7485d05891
commit
d6ba672a01
@ -132,19 +132,9 @@ public class AttributeDecoder
|
|||||||
|
|
||||||
decodedAttribute.setAttributeType(attributeType);
|
decodedAttribute.setAttributeType(attributeType);
|
||||||
|
|
||||||
if (decodedAttribute instanceof ContentDependentAttribute)
|
|
||||||
{
|
|
||||||
((ContentDependentAttribute)decodedAttribute).decodeAttributeBody(
|
|
||||||
bytes, (char)(Attribute.HEADER_LENGTH + offset),
|
|
||||||
attributeLength,
|
|
||||||
messageHeadBytes, messageHeadOffset, messageHeadLen );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
decodedAttribute.decodeAttributeBody(bytes,
|
decodedAttribute.decodeAttributeBody(bytes,
|
||||||
(char)(Attribute.HEADER_LENGTH + offset),
|
(char)(Attribute.HEADER_LENGTH + offset),
|
||||||
attributeLength);
|
attributeLength);
|
||||||
}
|
|
||||||
|
|
||||||
return decodedAttribute;
|
return decodedAttribute;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,31 +33,4 @@ public interface ContentDependentAttribute
|
|||||||
* with the specified <tt>content</tt>.
|
* with the specified <tt>content</tt>.
|
||||||
*/
|
*/
|
||||||
public byte[] encode(byte[] content, int offset, int length);
|
public byte[] encode(byte[] content, int offset, int length);
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets this attribute's fields according to the message and attributeValue
|
|
||||||
* arrays. This method allows the stack to validate the content of content
|
|
||||||
* dependent attributes such as the {@link MessageIntegrityAttribute} or
|
|
||||||
* the {@link FingerprintAttribute} and hide invalid ones from the
|
|
||||||
* application.
|
|
||||||
*
|
|
||||||
* @param attributeValue a binary array containing this attribute's field
|
|
||||||
* values and NOT containing the attribute header.
|
|
||||||
* @param offset the position where attribute values begin (most often
|
|
||||||
* offset is equal to the index of the first byte after length)
|
|
||||||
* @param length the length of the binary array.
|
|
||||||
* @param messageHead the bytes of the message that brought this attribute.
|
|
||||||
* @param mhOffset the start of the message that brought this attribute
|
|
||||||
* @param mhLen the length of the message in the messageHead param up until
|
|
||||||
* the start of this attribute.
|
|
||||||
*
|
|
||||||
* @throws StunException if attrubteValue contains invalid data.
|
|
||||||
*/
|
|
||||||
public void decodeAttributeBody( byte[] attributeValue,
|
|
||||||
char offset,
|
|
||||||
char length,
|
|
||||||
byte[] messageHead,
|
|
||||||
char mhOffset,
|
|
||||||
char mhLen)
|
|
||||||
throws StunException;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,7 +6,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.ice4j.attribute;
|
package org.ice4j.attribute;
|
||||||
|
|
||||||
import java.util.*;
|
|
||||||
import java.util.zip.*;
|
import java.util.zip.*;
|
||||||
|
|
||||||
import org.ice4j.*;
|
import org.ice4j.*;
|
||||||
@ -181,29 +180,20 @@ public class FingerprintAttribute
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this attribute's fields according to the message and attributeValue
|
* Sets this attribute's fields according to the message and attributeValue
|
||||||
* arrays. This method allows the stack to validate the content of content
|
* arrays.
|
||||||
* dependent attributes such as the {@link MessageIntegrityAttribute} or
|
|
||||||
* the {@link FingerprintAttribute} and hide invalid ones from the
|
|
||||||
* application.
|
|
||||||
*
|
*
|
||||||
* @param attributeValue a binary array containing this attribute's field
|
* @param attributeValue a binary array containing this attribute's field
|
||||||
* values and NOT containing the attribute header.
|
* values and NOT containing the attribute header.
|
||||||
* @param offset the position where attribute values begin (most often
|
* @param offset the position where attribute values begin (most often
|
||||||
* offset is equal to the index of the first byte after length)
|
* offset is equal to the index of the first byte after length)
|
||||||
* @param length the length of the binary array.
|
* @param length the length of the binary array.
|
||||||
* @param messageHead the bytes of the message that brought this attribute.
|
|
||||||
* @param mhOffset the start of the message that brought this attribute
|
|
||||||
* @param mhLen the length of the message in the messageHead param up until
|
|
||||||
* the start of this attribute.
|
* the start of this attribute.
|
||||||
*
|
*
|
||||||
* @throws StunException if attrubteValue contains invalid data.
|
* @throws StunException if attrubteValue contains invalid data.
|
||||||
*/
|
*/
|
||||||
public void decodeAttributeBody( byte[] attributeValue,
|
public void decodeAttributeBody( byte[] attributeValue,
|
||||||
char offset,
|
char offset,
|
||||||
char length,
|
char length)
|
||||||
byte[] messageHead,
|
|
||||||
char mhOffset,
|
|
||||||
char mhLen)
|
|
||||||
throws StunException
|
throws StunException
|
||||||
{
|
{
|
||||||
if(length != 4)
|
if(length != 4)
|
||||||
@ -250,43 +240,5 @@ public class FingerprintAttribute
|
|||||||
|
|
||||||
return xorCRC32;
|
return xorCRC32;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Creates a <tt>long</tt> CRC value out of the specified <tt>bytes</tt>.
|
|
||||||
*
|
|
||||||
* @param bytes the byte array to convert into a <tt>long</tt>.
|
|
||||||
*
|
|
||||||
* @return the CRC value contained by the <tt>bytes</tt> array.
|
|
||||||
*/
|
|
||||||
private long byteArrayToCRC(byte[] bytes)
|
|
||||||
{
|
|
||||||
long crc = ((bytes[0] << 24) & 0xff000000)
|
|
||||||
+ ((bytes[1] << 16) & 0x00ff0000)
|
|
||||||
+ ((bytes[2] << 8) & 0x0000ff00)
|
|
||||||
+ (bytes[3] & 0x000000ff);
|
|
||||||
|
|
||||||
return crc;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Always throws an {@link UnsupportedOperationException} since this
|
|
||||||
* attribute should be decoded through the content specific decode method.
|
|
||||||
*
|
|
||||||
* @param attributeValue a binary array containing this attribute's
|
|
||||||
* field values and NOT containing the attribute header.
|
|
||||||
* @param offset the position where attribute values begin (most often
|
|
||||||
* offset is equal to the index of the first byte after length)
|
|
||||||
* @param length the length of the binary array.
|
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException since we are supposed to decode
|
|
||||||
* through the content specific decode method.
|
|
||||||
*/
|
|
||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
|
||||||
throws UnsupportedOperationException
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"ContentDependentAttributes should be decoded "
|
|
||||||
+"through the contend-dependent decode method");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -191,62 +191,23 @@ public class MessageIntegrityAttribute
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets this attribute's fields according to the message and attributeValue
|
* Sets this attribute's fields according to the message and attributeValue
|
||||||
* arrays. This method allows the stack to validate the content of content
|
* arrays.
|
||||||
* dependent attributes such as the {@link MessageIntegrityAttribute} or
|
|
||||||
* the {@link FingerprintAttribute} and hide invalid ones from the
|
|
||||||
* application.
|
|
||||||
*
|
*
|
||||||
* @param attributeValue a binary array containing this attribute's field
|
* @param attributeValue a binary array containing this attribute's field
|
||||||
* values and NOT containing the attribute header.
|
* values and NOT containing the attribute header.
|
||||||
* @param offset the position where attribute values begin (most often
|
* @param offset the position where attribute values begin (most often
|
||||||
* offset is equal to the index of the first byte after length)
|
* offset is equal to the index of the first byte after length)
|
||||||
* @param length the length of the binary array.
|
* @param length the length of the binary array.
|
||||||
* @param messageHead the bytes of the message that brought this attribute.
|
|
||||||
* @param mhOffset the start of the message that brought this attribute
|
|
||||||
* @param mhLen the length of the message in the messageHead param up until
|
|
||||||
* the start of this attribute.
|
* the start of this attribute.
|
||||||
*
|
|
||||||
* @throws StunException if attrubteValue contains invalid data.
|
|
||||||
*/
|
*/
|
||||||
public void decodeAttributeBody( byte[] attributeValue,
|
public void decodeAttributeBody( byte[] attributeValue,
|
||||||
char offset,
|
char offset,
|
||||||
char length,
|
char length)
|
||||||
byte[] messageHead,
|
|
||||||
char mhOffset,
|
|
||||||
char mhLen)
|
|
||||||
throws StunException
|
|
||||||
{
|
{
|
||||||
hmacSha1Content = new byte[length];
|
hmacSha1Content = new byte[length];
|
||||||
System.arraycopy(attributeValue, offset, hmacSha1Content, 0, length);
|
System.arraycopy(attributeValue, offset, hmacSha1Content, 0, length);
|
||||||
|
|
||||||
//we can't check the validity of the attribute here since we don't have
|
|
||||||
//the password
|
|
||||||
//todo: we should think of a way to access passwords from here.
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Always throws an {@link UnsupportedOperationException} since this
|
|
||||||
* attribute should be decoded through the content specific decode method.
|
|
||||||
*
|
|
||||||
* @param attributeValue a binary array containing this attribute's
|
|
||||||
* field values and NOT containing the attribute header.
|
|
||||||
* @param offset the position where attribute values begin (most often
|
|
||||||
* offset is equal to the index of the first byte after length)
|
|
||||||
* @param length the length of the binary array.
|
|
||||||
*
|
|
||||||
* @throws UnsupportedOperationException since we are supposed to decode
|
|
||||||
* through the content specific decode method.
|
|
||||||
*/
|
|
||||||
void decodeAttributeBody(byte[] attributeValue, char offset, char length)
|
|
||||||
throws UnsupportedOperationException
|
|
||||||
{
|
|
||||||
throw new UnsupportedOperationException(
|
|
||||||
"ContentDependentAttributes should be decoded "
|
|
||||||
+"through the contend-dependent decode method");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a binary representation of this attribute.
|
* Returns a binary representation of this attribute.
|
||||||
*
|
*
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user