From 2667b5439e09d26e3e1dcd29c63f4ae3716c4f16 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 6 Jan 2024 15:07:08 +0200 Subject: [PATCH] GSSAPI: SimpleProtectedNegotiationTokenInit: Extracted GetEncodedMechanismTypeListLength method --- .../SimpleProtectedNegotiationTokenInit.cs | 29 ++++++++++++------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/SMBLibrary/Authentication/GSSAPI/SPNEGO/SimpleProtectedNegotiationTokenInit.cs b/SMBLibrary/Authentication/GSSAPI/SPNEGO/SimpleProtectedNegotiationTokenInit.cs index f4e5dfe..b05b8ef 100644 --- a/SMBLibrary/Authentication/GSSAPI/SPNEGO/SimpleProtectedNegotiationTokenInit.cs +++ b/SMBLibrary/Authentication/GSSAPI/SPNEGO/SimpleProtectedNegotiationTokenInit.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2017 Tal Aloni . All rights reserved. +/* Copyright (C) 2017-2024 Tal Aloni . All rights reserved. * * 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, @@ -102,16 +102,7 @@ namespace SMBLibrary.Authentication.GSSAPI protected virtual int GetTokenFieldsLength() { - int result = 0; - 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; - } + int result = GetEncodedMechanismTypeListLength(MechanismTypeList); if (MechanismToken != null) { int mechanismTokenLengthFieldSize = DerEncodingHelper.GetLengthFieldSize(MechanismToken.Length); @@ -229,5 +220,21 @@ namespace SMBLibrary.Authentication.GSSAPI DerEncodingHelper.WriteLength(buffer, ref offset, mechanismListMIC.Length); ByteWriter.WriteBytes(buffer, ref offset, mechanismListMIC); } + + private static int GetEncodedMechanismTypeListLength(List 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; + } + } } }