Пример #1
0
        /// <summary>
        /// Marks context state as comleted
        /// </summary>
        internal void SetCompleted()
        {
            // check object state
            if (_disposed)
            {
                throw new ObjectDisposedException(GetType().FullName);
            }

            // set state
            _contextState = SecurityContextState.Completed;
        }
Пример #2
0
		internal SecurityContext(
			SecurityCredentials credentials,
			Int64 contextHandle,
			Int64 contextExpiry,
			SecurityContextType contextType,
			SecurityContextState contextState)
		{
			// parameters validation
			if (credentials == null)
				throw new ArgumentNullException("credentials");
			if (contextHandle == 0)
				throw new ArgumentNullException("contextHandle");

			_credentials = credentials;

			_contextHandle = contextHandle;
			_contextExpiry = contextExpiry;
			_contextType = contextType;
			_contextState = contextState;
		}
Пример #3
0
        internal SecurityContext(
            SecurityCredentials credentials,
            Int64 contextHandle,
            Int64 contextExpiry,
            SecurityContextType contextType,
            SecurityContextState contextState)
        {
            // parameters validation
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (contextHandle == 0)
            {
                throw new ArgumentNullException("contextHandle");
            }

            _credentials = credentials;

            _contextHandle = contextHandle;
            _contextExpiry = contextExpiry;
            _contextType   = contextType;
            _contextState  = contextState;
        }
Пример #4
0
		/// <summary>
		/// Marks context state as comleted
		/// </summary>
		internal void SetCompleted()
		{
			// check object state
			if (_disposed)
				throw new ObjectDisposedException(GetType().FullName);

			// set state
			_contextState = SecurityContextState.Completed;
		}
Пример #5
0
        /// <summary>
        /// Creates security context, proceeds client token and generates server token
        /// </summary>
        public SecurityContext AcceptSecurityContext(
            SecurityCredentials credentials,
            SecurityContextAttributes contextAttributes,
            byte[] inputToken,
            out byte[] outputToken)
        {
            // parameters validation
            if (credentials == null)
            {
                throw new ArgumentNullException("credentials");
            }
            if (inputToken == null)
            {
                throw new ArgumentNullException("inputToken");
            }

            // prepare requirements for context
            uint contextReq = GetContextRequirements(true, contextAttributes);

            // prepare buffers
            SecurityBuffers inputBuffers = new SecurityBuffers(1);

            inputBuffers.SetBuffer(0, (int)SSPINative.SECBUFFER_TOKEN, inputToken);

            SecurityBuffers outputBuffers = new SecurityBuffers(1);

            outputBuffers.SetBuffer(0, (int)SSPINative.SECBUFFER_TOKEN, _secPackage.MaxToken);

            // create context
            Int64 credHandle = credentials.Handle;
            Int64 newContextHandle;
            Int64 contextExpiry;
            uint  contextAttribs;

            int error = SSPINative.AcceptSecurityContext(
                ref credHandle,
                IntPtr.Zero,
                inputBuffers,
                contextReq,
                SSPINative.SECURITY_NETWORK_DREP,
                out newContextHandle,
                outputBuffers,
                out contextAttribs,
                out contextExpiry);

            inputBuffers.Dispose();

            // check context state
            bool continueNeeded = false;
            bool completeNeeded = false;

            switch (error)
            {
            case Win32.ERROR_SUCCESS:
                break;

            case SSPINative.SEC_I_CONTINUE_NEEDED:
                continueNeeded = true;
                break;

            case SSPINative.SEC_I_COMPLETE_NEEDED:
                completeNeeded = true;
                break;

            case SSPINative.SEC_I_COMPLETE_AND_CONTINUE:
                continueNeeded = true;
                completeNeeded = true;
                break;

            default:
                throw new SSPIException(error, "Could not accept security context");
            }

            if (completeNeeded)
            {
                // complete context
                error = SSPINative.CompleteAuthToken(ref newContextHandle, outputBuffers);
                if (error < 0)
                {
                    throw new SSPIException(error, "Could not complete security context");
                }
            }

            // get output token
            outputToken = outputBuffers.GetBuffer(0);
            outputBuffers.Dispose();

            // create context object
            SecurityContextState contextState = (continueNeeded ? SecurityContextState.ContinueNeeded : SecurityContextState.Completed);

            return(new SecurityContext(credentials, newContextHandle, contextExpiry, SecurityContextType.Server, contextState));
        }