Minor SPNEGO structures refactoring

This commit is contained in:
Tal Aloni 2017-01-19 00:21:50 +02:00
parent 4ac83f6d97
commit 14cae2a68c
3 changed files with 9 additions and 14 deletions

View file

@ -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;

View file

@ -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();

View file

@ -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();