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

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

View file

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