Browse Source

Minor SPNEGO structures refactoring

Tal Aloni 8 years ago
parent
commit
14cae2a68c

+ 5 - 2
SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs

@@ -37,13 +37,16 @@ namespace SMBLibrary.Authentication
                     byte[] objectIdentifier = ByteReader.ReadBytes(tokenBytes, ref offset, objectIdentifierLength);
                     if (ByteUtils.AreByteArraysEqual(objectIdentifier, SPNEGOIdentifier))
                     {
-                        return new SimpleProtectedNegotiationTokenInit(tokenBytes, offset);
+                        tag = ByteReader.ReadByte(tokenBytes, ref offset);
+                        if (tag == SimpleProtectedNegotiationTokenInit.NegTokenInitTag)
+                        {
+                            return new SimpleProtectedNegotiationTokenInit(tokenBytes, offset);
+                        }
                     }
                 }
             }
             else if (tag == SimpleProtectedNegotiationTokenResponse.NegTokenRespTag)
             {
-                offset--;
                 return new SimpleProtectedNegotiationTokenResponse(tokenBytes, offset);
             }
             return null;

+ 2 - 6
SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs

@@ -32,16 +32,12 @@ namespace SMBLibrary.Authentication
 
         public List<TokenInitEntry> Tokens = new List<TokenInitEntry>();
 
+        /// <param name="offset">The offset following the NegTokenInit tag</param>
         public SimpleProtectedNegotiationTokenInit(byte[] buffer, int offset)
         {
-            byte tag = ByteReader.ReadByte(buffer, ref offset);
-            if (tag != NegTokenInitTag)
-            {
-                throw new InvalidDataException();
-            }
             int constructionLength = DerEncodingHelper.ReadLength(buffer, ref offset);
             int sequenceEndOffset = offset + constructionLength;
-            tag = ByteReader.ReadByte(buffer, ref offset);
+            byte tag = ByteReader.ReadByte(buffer, ref offset);
             if (tag != (byte)DerEncodingTag.Sequence)
             {
                 throw new InvalidDataException();

+ 2 - 6
SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenResponse.cs

@@ -44,16 +44,12 @@ namespace SMBLibrary.Authentication
         {
         }
 
+        /// <param name="offset">The offset following the NegTokenResp tag</param>
         public SimpleProtectedNegotiationTokenResponse(byte[] buffer, int offset)
         {
-            byte tag = ByteReader.ReadByte(buffer, ref offset);
-            if (tag != NegTokenRespTag)
-            {
-                throw new InvalidDataException();
-            }
             int constuctionLength = DerEncodingHelper.ReadLength(buffer, ref offset);
             int sequenceEndOffset = offset + constuctionLength;
-            tag = ByteReader.ReadByte(buffer, ref offset);
+            byte tag = ByteReader.ReadByte(buffer, ref offset);
             if (tag != (byte)DerEncodingTag.Sequence)
             {
                 throw new InvalidDataException();