System.Net.SSPIWrapper.CompleteAuthToken C# (CSharp) Method

CompleteAuthToken() static private method

static private CompleteAuthToken ( System.Net.Security.SSPIInterface secModule, SafeDeleteContext &context, SecurityBuffer inputBuffers ) : int
secModule System.Net.Security.SSPIInterface
context SafeDeleteContext
inputBuffers SecurityBuffer
return int
        internal static int CompleteAuthToken(SSPIInterface secModule, ref SafeDeleteContext context, SecurityBuffer[] inputBuffers)
        {
            int errorCode = secModule.CompleteAuthToken(ref context, inputBuffers);

            if (NetEventSource.IsEnabled) NetEventSource.Log.OperationReturnedSomething(nameof(CompleteAuthToken), (Interop.SECURITY_STATUS)errorCode);

            return errorCode;
        }

Usage Example

        internal string GetOutgoingDigestBlob(string incomingBlob, string requestMethod, string requestedUri, string realm, bool isClientPreAuth, bool throwOnError, out SecurityStatus statusCode)
        {
            SecurityBuffer[] inputBuffers = null;
            SecurityBuffer   outputBuffer = new SecurityBuffer(this.m_TokenSize, isClientPreAuth ? BufferType.Parameters : BufferType.Token);
            bool             flag         = this.m_SecurityContext == null;

            try
            {
                if (!this.m_IsServer)
                {
                    if (!isClientPreAuth)
                    {
                        if (incomingBlob != null)
                        {
                            List <SecurityBuffer> list = new List <SecurityBuffer>(5)
                            {
                                new SecurityBuffer(WebHeaderCollection.HeaderEncoding.GetBytes(incomingBlob), 2),
                                new SecurityBuffer(WebHeaderCollection.HeaderEncoding.GetBytes(requestMethod), 3),
                                new SecurityBuffer(null, 3),
                                new SecurityBuffer(Encoding.Unicode.GetBytes(this.m_Spn), 0x10)
                            };
                            if (this.m_ChannelBinding != null)
                            {
                                list.Add(new SecurityBuffer(this.m_ChannelBinding));
                            }
                            inputBuffers = list.ToArray();
                        }
                        statusCode = (SecurityStatus)SSPIWrapper.InitializeSecurityContext(GlobalSSPI.SSPIAuth, this.m_CredentialsHandle, ref this.m_SecurityContext, requestedUri, this.m_RequestedContextFlags, Endianness.Network, inputBuffers, outputBuffer, ref this.m_ContextFlags);
                    }
                    else
                    {
                        statusCode = SecurityStatus.OK;
                    }
                }
                else
                {
                    List <SecurityBuffer> list2 = new List <SecurityBuffer>(6)
                    {
                        (incomingBlob == null) ? new SecurityBuffer(0, BufferType.Token) : new SecurityBuffer(WebHeaderCollection.HeaderEncoding.GetBytes(incomingBlob), BufferType.Token),
                        (requestMethod == null) ? new SecurityBuffer(0, BufferType.Parameters) : new SecurityBuffer(WebHeaderCollection.HeaderEncoding.GetBytes(requestMethod), BufferType.Parameters),
                        (requestedUri == null) ? new SecurityBuffer(0, BufferType.Parameters) : new SecurityBuffer(WebHeaderCollection.HeaderEncoding.GetBytes(requestedUri), BufferType.Parameters),
                        new SecurityBuffer(0, BufferType.Parameters),
                        (realm == null) ? new SecurityBuffer(0, BufferType.Parameters) : new SecurityBuffer(Encoding.Unicode.GetBytes(realm), BufferType.Parameters)
                    };
                    if (this.m_ChannelBinding != null)
                    {
                        list2.Add(new SecurityBuffer(this.m_ChannelBinding));
                    }
                    inputBuffers = list2.ToArray();
                    statusCode   = (SecurityStatus)SSPIWrapper.AcceptSecurityContext(GlobalSSPI.SSPIAuth, this.m_CredentialsHandle, ref this.m_SecurityContext, this.m_RequestedContextFlags, Endianness.Network, inputBuffers, outputBuffer, ref this.m_ContextFlags);
                    if (statusCode == SecurityStatus.CompleteNeeded)
                    {
                        inputBuffers[4]    = outputBuffer;
                        statusCode         = (SecurityStatus)SSPIWrapper.CompleteAuthToken(GlobalSSPI.SSPIAuth, ref this.m_SecurityContext, inputBuffers);
                        outputBuffer.token = null;
                    }
                }
            }
            finally
            {
                if (flag && (this.m_CredentialsHandle != null))
                {
                    this.m_CredentialsHandle.Close();
                }
            }
            if ((statusCode & ((SecurityStatus)(-2147483648))) != SecurityStatus.OK)
            {
                this.CloseContext();
                if (throwOnError)
                {
                    Win32Exception exception = new Win32Exception((int)statusCode);
                    throw exception;
                }
                return(null);
            }
            if (flag && (this.m_CredentialsHandle != null))
            {
                SSPIHandleCache.CacheCredential(this.m_CredentialsHandle);
            }
            if (statusCode == SecurityStatus.OK)
            {
                this.m_IsCompleted = true;
            }
            byte[] token = outputBuffer.token;
            string str   = null;

            if ((token != null) && (token.Length > 0))
            {
                str = WebHeaderCollection.HeaderEncoding.GetString(token, 0, outputBuffer.size);
            }
            return(str);
        }
All Usage Examples Of System.Net.SSPIWrapper::CompleteAuthToken