private SecurityStatus GenerateToken(byte[] input, int offset, int count, ref byte[] output)
{
if ((offset < 0) || (offset > ((input == null) ? 0 : input.Length)))
{
throw new ArgumentOutOfRangeException("offset");
}
if ((count < 0) || (count > ((input == null) ? 0 : (input.Length - offset))))
{
throw new ArgumentOutOfRangeException("count");
}
SecurityBuffer inputBuffer = null;
SecurityBuffer[] inputBuffers = null;
if (input != null)
{
inputBuffer = new SecurityBuffer(input, offset, count, BufferType.Token);
inputBuffers = new SecurityBuffer[] { inputBuffer, new SecurityBuffer(null, 0, 0, BufferType.Empty) };
}
SecurityBuffer outputBuffer = new SecurityBuffer(null, BufferType.Token);
int num = 0;
bool flag = false;
byte[] thumbPrint = null;
try
{
do
{
thumbPrint = null;
if (this.m_RefreshCredentialNeeded)
{
flag = this.m_ServerMode ? this.AcquireServerCredentials(ref thumbPrint) : this.AcquireClientCredentials(ref thumbPrint);
}
if (this.m_ServerMode)
{
num = SSPIWrapper.AcceptSecurityContext(GlobalSSPI.SSPISecureChannel, ref this.m_CredentialsHandle, ref this.m_SecurityContext, (ContextFlags.AcceptStream | ContextFlags.AllocateMemory | ContextFlags.Confidentiality | ContextFlags.SequenceDetect | ContextFlags.ReplayDetect) | (this.m_RemoteCertRequired ? ContextFlags.MutualAuth : ContextFlags.Zero), Endianness.Native, inputBuffer, outputBuffer, ref this.m_Attributes);
}
else if (inputBuffer == null)
{
num = SSPIWrapper.InitializeSecurityContext(GlobalSSPI.SSPISecureChannel, ref this.m_CredentialsHandle, ref this.m_SecurityContext, this.m_Destination, ContextFlags.AcceptIdentify | ContextFlags.AllocateMemory | ContextFlags.Confidentiality | ContextFlags.SequenceDetect | ContextFlags.ReplayDetect, Endianness.Native, inputBuffer, outputBuffer, ref this.m_Attributes);
}
else
{
num = SSPIWrapper.InitializeSecurityContext(GlobalSSPI.SSPISecureChannel, this.m_CredentialsHandle, ref this.m_SecurityContext, this.m_Destination, ContextFlags.AcceptIdentify | ContextFlags.AllocateMemory | ContextFlags.Confidentiality | ContextFlags.SequenceDetect | ContextFlags.ReplayDetect, Endianness.Native, inputBuffers, outputBuffer, ref this.m_Attributes);
}
}while (flag && (this.m_CredentialsHandle == null));
}
finally
{
if (this.m_RefreshCredentialNeeded)
{
this.m_RefreshCredentialNeeded = false;
if (this.m_CredentialsHandle != null)
{
this.m_CredentialsHandle.Close();
}
if ((!flag && (this.m_SecurityContext != null)) && (!this.m_SecurityContext.IsInvalid && !this.m_CredentialsHandle.IsInvalid))
{
SslSessionsCache.CacheCredential(this.m_CredentialsHandle, thumbPrint, this.m_ProtocolFlags, this.m_EncryptionPolicy);
}
}
}
output = outputBuffer.token;
return((SecurityStatus)num);
}