From 14cae2a68c1916016d05db47887603682fa2fceb Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Thu, 19 Jan 2017 00:21:50 +0200 Subject: [PATCH] Minor SPNEGO structures refactoring --- .../GSSAPI/SimpleProtectedNegotiationToken.cs | 7 +++++-- .../GSSAPI/SimpleProtectedNegotiationTokenInit.cs | 8 ++------ .../GSSAPI/SimpleProtectedNegotiationTokenResponse.cs | 8 ++------ 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs index f2dd9f5..6b4193e 100644 --- a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationToken.cs +++ b/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; diff --git a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs index e5f2665..31d7219 100644 --- a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs +++ b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenInit.cs @@ -32,16 +32,12 @@ namespace SMBLibrary.Authentication public List Tokens = new List(); + /// The offset following the NegTokenInit tag 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(); diff --git a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenResponse.cs b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenResponse.cs index 5103e01..6a3e5d2 100644 --- a/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenResponse.cs +++ b/SMBLibrary/Authentication/GSSAPI/SimpleProtectedNegotiationTokenResponse.cs @@ -44,16 +44,12 @@ namespace SMBLibrary.Authentication { } + /// The offset following the NegTokenResp tag 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();