[jboss-cvs] JBossAS SVN: r76839 - in projects/security/security-negotiation/trunk: jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Aug 8 12:49:03 EDT 2008
Author: darran.lofthouse at jboss.com
Date: 2008-08-08 12:49:03 -0400 (Fri, 08 Aug 2008)
New Revision: 76839
Added:
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/Field.java
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoder.java
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/tests/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoderTest.java
Modified:
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.classpath
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.project
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/pom.xml
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlags.java
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlagsDecoder.java
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessage.java
projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessageDecoder.java
projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java
Log:
[SECURITY-270] NTLM message handling.
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.classpath
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.classpath 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.classpath 2008-08-08 16:49:03 UTC (rev 76839)
@@ -6,4 +6,7 @@
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="var" path="M2_REPO/jboss/jboss-common/4.2.2.GA/jboss-common-4.2.2.GA.jar"/>
<classpathentry kind="var" path="M2_REPO/junit/junit/3.8.1/junit-3.8.1.jar"/>
+ <classpathentry kind="src" path="/jboss-negotiation-common"/>
+ <classpathentry kind="var" path="M2_REPO/apache-codec/commons-codec/1.2/commons-codec-1.2.jar"/>
+ <classpathentry kind="var" path="M2_REPO/apache-log4j/log4j/1.2.14/log4j-1.2.14.jar"/>
</classpath>
\ No newline at end of file
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.project
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.project 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/.project 2008-08-08 16:49:03 UTC (rev 76839)
@@ -1,7 +1,9 @@
<projectDescription>
<name>jboss-negotiation-ntlm</name>
<comment>JBoss Negotiation Library</comment>
- <projects/>
+ <projects>
+ <project>jboss-negotiation-common</project>
+ </projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/pom.xml
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/pom.xml 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/pom.xml 2008-08-08 16:49:03 UTC (rev 76839)
@@ -31,10 +31,10 @@
<!-- Do not add version information here, use ../parent/pom.xml instead -->
<dependencies>
<!-- Local Dependencies -->
- <!-- <dependency>
+ <dependency>
<groupId>org.jboss.security</groupId>
- <artifactId>jboss-negotiation</artifactId>
- </dependency> -->
+ <artifactId>jboss-negotiation-common</artifactId>
+ </dependency>
<!-- Global dependencies -->
<dependency>
Added: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/Field.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/Field.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/Field.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -0,0 +1,64 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.ntlm.encoding;
+
+/**
+ * Representation of a field with a length, max length and offset.
+ *
+ * @author darran.lofthouse at jboss.com
+ * @since 8th August 2008
+ */
+public class Field
+{
+
+ private int length;
+
+ private int maxLength;
+
+ private int offset;
+
+ public int getLength()
+ {
+ return length;
+ }
+
+ public void setLength(int length)
+ {
+ this.length = length;
+ }
+
+ public int getMaxLength()
+ {
+ return maxLength;
+ }
+
+ public void setMaxLength(int maxLength)
+ {
+ this.maxLength = maxLength;
+ }
+
+ public int getOffset()
+ {
+ return offset;
+ }
+
+ public void setOffset(int offset)
+ {
+ this.offset = offset;
+ }
+
+}
Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/Field.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Added: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoder.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoder.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -0,0 +1,80 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.ntlm.encoding;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * A Decoder to decode field lengths.
+ *
+ * @author darran.lofthouse at jboss.com
+ * @since 8th August 2008
+ */
+public class FieldDecoder
+{
+ public static final byte MSB_MASK = (byte) 0x80;
+
+ static Field readFieldLengths(final InputStream is, final DecoderData data) throws IOException
+ {
+ Field field = new Field();
+
+ byte[] len = new byte[2];
+ byte[] maxLen = new byte[2];
+ byte[] offset = new byte[4];
+
+ is.read(len);
+ is.read(maxLen);
+ is.read(offset);
+
+ data.read += 8;
+
+ field.setLength(convertToUnsignedInt(len));
+ field.setMaxLength(convertToUnsignedInt(maxLen));
+ field.setOffset(convertToUnsignedInt(offset));
+
+ return field;
+ }
+
+ static int convertToUnsignedInt(final byte[] bytes)
+ {
+ int total = 0;
+
+ for (int i = 0; i < bytes.length; i++)
+ {
+ byte current = bytes[i];
+ boolean msbSet = ((byte) (current & MSB_MASK)) == MSB_MASK;
+
+ int value = current & 127;
+
+ if (msbSet)
+ {
+ value += 128;
+ }
+
+ if (i > 0)
+ {
+ value = value * (int) (Math.pow(2, 8 * i));
+ }
+
+ total += value;
+ }
+
+ return total;
+ }
+
+}
Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoder.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlags.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlags.java 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlags.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -16,6 +16,8 @@
package org.jboss.security.negotiation.ntlm.encoding;
+import java.lang.reflect.Method;
+
/**
* Representation of NTLM NegotiateFlags
*
@@ -25,4 +27,321 @@
public class NegotiateFlags
{
+ private boolean encryption56Bit;
+
+ private boolean explicitKeyExchange;
+
+ private boolean sessionKeyExchange128Bit;
+
+ private boolean negotiateVersion;
+
+ private boolean targetInfo;
+
+ private boolean requestNonNTSessionKey;
+
+ private boolean identify;
+
+ private boolean ntlm2;
+
+ private boolean targetTypeShare;
+
+ private boolean targetTypeServer;
+
+ private boolean targetTypeDomain;
+
+ private boolean alwaysSign;
+
+ private boolean oemWorkstationSupplied;
+
+ private boolean oemDomainSupplied;
+
+ private boolean ntOnly;
+
+ private boolean ntlm;
+
+ private boolean lmKey;
+
+ private boolean datagram;
+
+ private boolean seal;
+
+ private boolean sign;
+
+ private boolean requestTarget;
+
+ private boolean oem;
+
+ private boolean unicode;
+
+ public boolean isEncryption56Bit()
+ {
+ return encryption56Bit;
+ }
+
+ public void setEncryption56Bit(boolean encryption56Bit)
+ {
+ this.encryption56Bit = encryption56Bit;
+ }
+
+ public boolean isExplicitKeyExchange()
+ {
+ return explicitKeyExchange;
+ }
+
+ public void setExplicitKeyExchange(boolean explicitKeyExchange)
+ {
+ this.explicitKeyExchange = explicitKeyExchange;
+ }
+
+ public boolean isSessionKeyExchange128Bit()
+ {
+ return sessionKeyExchange128Bit;
+ }
+
+ public void setSessionKeyExchange128Bit(boolean sessionKeyExchange128Bit)
+ {
+ this.sessionKeyExchange128Bit = sessionKeyExchange128Bit;
+ }
+
+ public boolean isNegotiateVersion()
+ {
+ return negotiateVersion;
+ }
+
+ public void setNegotiateVersion(boolean negotiateVersion)
+ {
+ this.negotiateVersion = negotiateVersion;
+ }
+
+ public boolean isTargetInfo()
+ {
+ return targetInfo;
+ }
+
+ public void setTargetInfo(boolean targetInfo)
+ {
+ this.targetInfo = targetInfo;
+ }
+
+ public boolean isRequestNonNTSessionKey()
+ {
+ return requestNonNTSessionKey;
+ }
+
+ public void setRequestNonNTSessionKey(boolean requestNonNTSessionKey)
+ {
+ this.requestNonNTSessionKey = requestNonNTSessionKey;
+ }
+
+ public boolean isIdentify()
+ {
+ return identify;
+ }
+
+ public void setIdentify(boolean identify)
+ {
+ this.identify = identify;
+ }
+
+ public boolean isNtlm2()
+ {
+ return ntlm2;
+ }
+
+ public void setNtlm2(boolean ntlm2)
+ {
+ this.ntlm2 = ntlm2;
+ }
+
+ public boolean isTargetTypeShare()
+ {
+ return targetTypeShare;
+ }
+
+ public void setTargetTypeShare(boolean targetTypeShare)
+ {
+ this.targetTypeShare = targetTypeShare;
+ }
+
+ public boolean isTargetTypeServer()
+ {
+ return targetTypeServer;
+ }
+
+ public void setTargetTypeServer(boolean targetTypeServer)
+ {
+ this.targetTypeServer = targetTypeServer;
+ }
+
+ public boolean isTargetTypeDomain()
+ {
+ return targetTypeDomain;
+ }
+
+ public void setTargetTypeDomain(boolean targetTypeDomain)
+ {
+ this.targetTypeDomain = targetTypeDomain;
+ }
+
+ public boolean isAlwaysSign()
+ {
+ return alwaysSign;
+ }
+
+ public void setAlwaysSign(boolean alwaysSign)
+ {
+ this.alwaysSign = alwaysSign;
+ }
+
+ public boolean isOemWorkstationSupplied()
+ {
+ return oemWorkstationSupplied;
+ }
+
+ public void setOemWorkstationSupplied(boolean oemWorkstationSupplied)
+ {
+ this.oemWorkstationSupplied = oemWorkstationSupplied;
+ }
+
+ public boolean isOemDomainSupplied()
+ {
+ return oemDomainSupplied;
+ }
+
+ public void setOemDomainSupplied(boolean oemDomainSupplied)
+ {
+ this.oemDomainSupplied = oemDomainSupplied;
+ }
+
+ public boolean isNtOnly()
+ {
+ return ntOnly;
+ }
+
+ public void setNtOnly(boolean ntOnly)
+ {
+ this.ntOnly = ntOnly;
+ }
+
+ public boolean isNtlm()
+ {
+ return ntlm;
+ }
+
+ public void setNtlm(boolean ntlm)
+ {
+ this.ntlm = ntlm;
+ }
+
+ public boolean isLmKey()
+ {
+ return lmKey;
+ }
+
+ public void setLmKey(boolean lmKey)
+ {
+ this.lmKey = lmKey;
+ }
+
+ public boolean isDatagram()
+ {
+ return datagram;
+ }
+
+ public void setDatagram(boolean datagram)
+ {
+ this.datagram = datagram;
+ }
+
+ public boolean isSeal()
+ {
+ return seal;
+ }
+
+ public void setSeal(boolean seal)
+ {
+ this.seal = seal;
+ }
+
+ public boolean isSign()
+ {
+ return sign;
+ }
+
+ public void setSign(boolean sign)
+ {
+ this.sign = sign;
+ }
+
+ public boolean isRequestTarget()
+ {
+ return requestTarget;
+ }
+
+ public void setRequestTarget(boolean requestTarget)
+ {
+ this.requestTarget = requestTarget;
+ }
+
+ public boolean isOem()
+ {
+ return oem;
+ }
+
+ public void setOem(boolean oem)
+ {
+ this.oem = oem;
+ }
+
+ public boolean isUnicode()
+ {
+ return unicode;
+ }
+
+ public void setUnicode(boolean unicode)
+ {
+ this.unicode = unicode;
+ }
+
+ @Override
+ public String toString()
+ {
+ StringBuffer sb = new StringBuffer();
+
+ java.lang.reflect.Field[] fields = getClass().getDeclaredFields();
+
+ for (java.lang.reflect.Field current : fields)
+ {
+ if (current.getType().equals(boolean.class))
+ {
+ try
+ {
+ boolean value = current.getBoolean(this);
+ if (value == true)
+ {
+ sb.append("{").append(current.getName()).append("}");
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ /*Method[] methods = getClass().getMethods();
+
+ for (Method current : methods)
+ {
+ String name = current.getName();
+ if (name.startsWith("is") && current.getReturnType().equals(boolean.class))
+ {
+ boolean value =
+ }
+
+ }*/
+
+ return sb.toString();
+ }
+
}
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlagsDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlagsDecoder.java 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateFlagsDecoder.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -28,19 +28,59 @@
class NegotiateFlagsDecoder
{
- // TODO - Write real decoding once we have a client sending valid flags !!
static void readNegotiateFlags(final InputStream is, final DecoderData data) throws IOException
{
byte[] dataRead = new byte[4];
NegotiateFlags flags = new NegotiateFlags();
+
+ is.read(dataRead);
+
+ readAtoG(flags, dataRead[0]);
+ readHtoL(flags, dataRead[1]);
+ readMtoS(flags, dataRead[2]);
+ readTtoX(flags, dataRead[3]);
+
data.message.setNegotiateFlags(flags);
+ data.read += dataRead.length;
+ }
- System.out.println("\nNegotiateFlags - ");
- for (byte current : dataRead)
- {
- System.out.print("'" + current + "', ");
- }
- System.out.println();
+ private static void readAtoG(final NegotiateFlags flags, final byte b)
+ {
+ flags.setUnicode(((byte) b & 0x01) == 0x01); // 1
+ flags.setOem(((byte) b & 0x02) == 0x02); // 2
+ flags.setRequestTarget(((byte) b & 0x04) == 0x04); // 4
+ flags.setSign(((byte) b & 0x10) == 0x10); // 16
+ flags.setSeal(((byte) b & 0x20) == 0x20); // 32
+ flags.setDatagram(((byte) b & 0x40) == 0x40); // 64
+ flags.setLmKey(((byte) b & 0x80) == 0x80); // 128
}
+ private static void readHtoL(final NegotiateFlags flags, final byte b)
+ {
+ flags.setNtlm(((byte) b & 0x02) == 0x02); // 2
+ flags.setNtOnly(((byte) b & 0x04) == 0x04); // 4
+ flags.setOemDomainSupplied(((byte) b & 0x10) == 0x10); // 16
+ flags.setOemWorkstationSupplied(((byte) b & 0x20) == 0x20); // 32
+ flags.setAlwaysSign(((byte) b & 0x80) == 0x80); // 128
+ }
+
+ private static void readMtoS(final NegotiateFlags flags, final byte b)
+ {
+ flags.setTargetTypeDomain(((byte) b & 0x01) == 0x01); // 1
+ flags.setTargetTypeServer(((byte) b & 0x02) == 0x02); // 2
+ flags.setTargetTypeShare(((byte) b & 0x04) == 0x04); // 4
+ flags.setNtlm2(((byte) b & 0x08) == 0x08); // 8
+ flags.setIdentify(((byte) b & 0x10) == 0x10); // 16
+ flags.setRequestNonNTSessionKey(((byte) b & 0x40) == 0x40); // 64
+ flags.setTargetInfo(((byte) b & 0x80) == 0x80); // 128
+ }
+
+ private static void readTtoX(final NegotiateFlags flags, final byte b)
+ {
+ flags.setNegotiateVersion(((byte) b & 0x02) == 0x02); // 2
+ flags.setSessionKeyExchange128Bit(((byte) b & 0x20) == 0x20); // 32
+ flags.setExplicitKeyExchange(((byte) b & 0x40) == 0x40); // 64
+ flags.setEncryption56Bit(((byte) b & 0x80) == 0x80); // 128
+ }
+
}
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessage.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessage.java 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessage.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -27,8 +27,14 @@
private NegotiateFlags negotiateFlags;
+ private Field domainNameFields;
+
private String domainName;
+ private byte[] version;
+
+ private Field workstationFields;
+
private String workstationName;
public NegotiateFlags getNegotiateFlags()
@@ -41,6 +47,26 @@
this.negotiateFlags = negotiateFlags;
}
+ public byte[] getVersion()
+ {
+ return version;
+ }
+
+ public void setVersion(byte[] version)
+ {
+ this.version = version;
+ }
+
+ public Field getDomainNameFields()
+ {
+ return domainNameFields;
+ }
+
+ public void setDomainNameFields(Field domainNameFields)
+ {
+ this.domainNameFields = domainNameFields;
+ }
+
public String getDomainName()
{
return domainName;
@@ -51,6 +77,16 @@
this.domainName = domainName;
}
+ public Field getWorkstationFields()
+ {
+ return workstationFields;
+ }
+
+ public void setWorkstationFields(Field workstationFields)
+ {
+ this.workstationFields = workstationFields;
+ }
+
public String getWorkstationName()
{
return workstationName;
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessageDecoder.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessageDecoder.java 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/main/java/org/jboss/security/negotiation/ntlm/encoding/NegotiateMessageDecoder.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -21,6 +21,7 @@
import java.io.InputStream;
import java.util.Arrays;
+import org.jboss.security.negotiation.common.DebugHelper;
import org.jboss.security.negotiation.ntlm.Constants;
/**
@@ -60,8 +61,26 @@
data.read += dataRead.length;
}
+ private static void readVersion(final InputStream is, final DecoderData data) throws IOException
+ {
+ byte[] version;
+ if (data.message.getNegotiateFlags().isNegotiateVersion() == true)
+ {
+ version = new byte[8];
+ }
+ else
+ {
+ version = new byte[0];
+ }
+ is.read(version);
+ data.read += version.length;
+
+ data.message.setVersion(version);
+ }
+
public static NegotiateMessage decode(final byte[] token) throws IOException
{
+ System.out.println(DebugHelper.convertToHex(token));
System.out.println("Token - ");
for (byte current : token)
{
@@ -77,7 +96,14 @@
readVerifySignature(bais, data);
readVerifyMessageType(bais, data);
NegotiateFlagsDecoder.readNegotiateFlags(bais, data);
+ data.message.setDomainNameFields(FieldDecoder.readFieldLengths(bais, data));
+ data.message.setWorkstationFields(FieldDecoder.readFieldLengths(bais, data));
+ readVersion(bais, data);
+
+ System.out.println("\n" + data.message.getNegotiateFlags());
+ System.out.println(data.read);
+ System.out.println(bais.available());
return data.message;
}
}
Added: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/tests/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoderTest.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/tests/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoderTest.java (rev 0)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/tests/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoderTest.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -0,0 +1,47 @@
+/*
+ * Copyright © 2008 Red Hat Middleware, LLC. or third-party contributors as indicated
+ * by the @author tags or express copyright attribution statements applied by the
+ * authors. All third-party contributions are distributed under license by Red Hat
+ * Middleware LLC.
+ *
+ * This copyrighted material is made available to anyone wishing to use, modify, copy,
+ * or redistribute it subject to the terms and conditions of the GNU Lesser General
+ * Public License, v. 2.1. This program is distributed in the hope that it will be
+ * useful, but WITHOUT A WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
+ * more details. You should have received a copy of the GNU Lesser General Public License,
+ * v.2.1 along with this distribution; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+package org.jboss.security.negotiation.ntlm.encoding;
+
+import junit.framework.TestCase;
+
+/**
+ * Test case for FieldDecoder.
+ *
+ * @author darran.lofthouse at jboss.com
+ * @since 8th August 2008
+ */
+public class FieldDecoderTest extends TestCase
+{
+
+ public void testConvertToUnsignedInt() throws Exception
+ {
+ assertEquals(6, FieldDecoder.convertToUnsignedInt(new byte[]
+ {0x06}));
+
+ assertEquals(1542, FieldDecoder.convertToUnsignedInt(new byte[]
+ {0x06, 0x06}));
+
+ assertEquals(128, FieldDecoder.convertToUnsignedInt(new byte[]
+ {(byte) 0x80}));
+
+ assertEquals(129, FieldDecoder.convertToUnsignedInt(new byte[]
+ {(byte) 0x81}));
+
+ assertEquals(33153, FieldDecoder.convertToUnsignedInt(new byte[]
+ {(byte) 0x81, (byte) 0x81}));
+ }
+}
Property changes on: projects/security/security-negotiation/trunk/jboss-negotiation-ntlm/src/tests/java/org/jboss/security/negotiation/ntlm/encoding/FieldDecoderTest.java
___________________________________________________________________
Name: svn:keywords
+ Id Revision
Name: svn:eol-style
+ LF
Modified: projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java
===================================================================
--- projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java 2008-08-08 16:29:39 UTC (rev 76838)
+++ projects/security/security-negotiation/trunk/jboss-negotiation-spnego/src/tests/java/org/jboss/security/negotiation/spnego/encoding/NegTokenInitDecoderTest.java 2008-08-08 16:49:03 UTC (rev 76839)
@@ -35,8 +35,6 @@
*/
public void testReadLength() throws Exception
{
- NegTokenInitDecoder decoder = new NegTokenInitDecoder();
-
byte[] b1 = new byte[]
{0x01};
assertEquals(1, NegTokenDecoder.readLength(new ByteArrayInputStream(b1)));
More information about the jboss-cvs-commits
mailing list