GSSAPI: SimpleProtectedNegotiationTokenInit: Extracted GetEncodedMechanismTypeListLength method

This commit is contained in:
Tal Aloni 2024-01-06 15:07:08 +02:00
parent dad516b223
commit 2667b5439e

View file

@ -1,4 +1,4 @@
/* Copyright (C) 2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved. /* Copyright (C) 2017-2024 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
* *
* You can redistribute this program and/or modify it under the terms of * You can redistribute this program and/or modify it under the terms of
* the GNU Lesser Public License as published by the Free Software Foundation, * the GNU Lesser Public License as published by the Free Software Foundation,
@ -102,16 +102,7 @@ namespace SMBLibrary.Authentication.GSSAPI
protected virtual int GetTokenFieldsLength() protected virtual int GetTokenFieldsLength()
{ {
int result = 0; int result = GetEncodedMechanismTypeListLength(MechanismTypeList);
if (MechanismTypeList != null)
{
int typeListSequenceLength = GetMechanismTypeListSequenceLength(MechanismTypeList);
int typeListSequenceLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(typeListSequenceLength);
int typeListConstructionLength = 1 + typeListSequenceLengthFieldSize + typeListSequenceLength;
int typeListConstructionLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(typeListConstructionLength);
int entryLength = 1 + typeListConstructionLengthFieldSize + 1 + typeListSequenceLengthFieldSize + typeListSequenceLength;
result += entryLength;
}
if (MechanismToken != null) if (MechanismToken != null)
{ {
int mechanismTokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(MechanismToken.Length); int mechanismTokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(MechanismToken.Length);
@ -229,5 +220,21 @@ namespace SMBLibrary.Authentication.GSSAPI
DerEncodingHelper.WriteLength(buffer, ref offset, mechanismListMIC.Length); DerEncodingHelper.WriteLength(buffer, ref offset, mechanismListMIC.Length);
ByteWriter.WriteBytes(buffer, ref offset, mechanismListMIC); ByteWriter.WriteBytes(buffer, ref offset, mechanismListMIC);
} }
private static int GetEncodedMechanismTypeListLength(List<byte[]> mechanismTypeList)
{
if (mechanismTypeList == null)
{
return 0;
}
else
{
int typeListSequenceLength = GetMechanismTypeListSequenceLength(mechanismTypeList);
int typeListSequenceLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(typeListSequenceLength);
int typeListConstructionLength = 1 + typeListSequenceLengthFieldSize + typeListSequenceLength;
int typeListConstructionLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(typeListConstructionLength);
return 1 + typeListConstructionLengthFieldSize + 1 + typeListSequenceLengthFieldSize + typeListSequenceLength;
}
}
} }
} }