From d6ba672a011486d63096d5a0c1219f9e5d857476 Mon Sep 17 00:00:00 2001 From: emcho Date: Mon, 26 Apr 2010 21:34:03 +0000 Subject: [PATCH] Improves validation of incoming FINGERPRINT and MESSAGE-INTEGRITY attributes --- src/org/ice4j/attribute/AttributeDecoder.java | 12 +---- .../attribute/ContentDependentAttribute.java | 27 ---------- .../ice4j/attribute/FingerprintAttribute.java | 52 +------------------ .../attribute/MessageIntegrityAttribute.java | 43 +-------------- 4 files changed, 5 insertions(+), 129 deletions(-) diff --git a/src/org/ice4j/attribute/AttributeDecoder.java b/src/org/ice4j/attribute/AttributeDecoder.java index 96b341b..7795e40 100644 --- a/src/org/ice4j/attribute/AttributeDecoder.java +++ b/src/org/ice4j/attribute/AttributeDecoder.java @@ -132,19 +132,9 @@ public class AttributeDecoder 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), attributeLength); - } return decodedAttribute; } diff --git a/src/org/ice4j/attribute/ContentDependentAttribute.java b/src/org/ice4j/attribute/ContentDependentAttribute.java index e935ed3..90950c6 100644 --- a/src/org/ice4j/attribute/ContentDependentAttribute.java +++ b/src/org/ice4j/attribute/ContentDependentAttribute.java @@ -33,31 +33,4 @@ public interface ContentDependentAttribute * with the specified content. */ 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; } diff --git a/src/org/ice4j/attribute/FingerprintAttribute.java b/src/org/ice4j/attribute/FingerprintAttribute.java index 5abdb2a..4d4bbca 100644 --- a/src/org/ice4j/attribute/FingerprintAttribute.java +++ b/src/org/ice4j/attribute/FingerprintAttribute.java @@ -6,7 +6,6 @@ */ package org.ice4j.attribute; -import java.util.*; import java.util.zip.*; import org.ice4j.*; @@ -181,29 +180,20 @@ public class FingerprintAttribute /** * 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. + * arrays. * * @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) + char length) throws StunException { if(length != 4) @@ -250,43 +240,5 @@ public class FingerprintAttribute return xorCRC32; } - - /** - * Creates a long CRC value out of the specified bytes. - * - * @param bytes the byte array to convert into a long. - * - * @return the CRC value contained by the bytes 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"); - } } diff --git a/src/org/ice4j/attribute/MessageIntegrityAttribute.java b/src/org/ice4j/attribute/MessageIntegrityAttribute.java index cfafef8..5d9f16f 100644 --- a/src/org/ice4j/attribute/MessageIntegrityAttribute.java +++ b/src/org/ice4j/attribute/MessageIntegrityAttribute.java @@ -191,62 +191,23 @@ public class MessageIntegrityAttribute /** * 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. + * arrays. * * @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 + char length) { hmacSha1Content = new byte[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. *