Example #1
0
 internal DelegationRule(string queueName, string urlPrefix, ILogger logger)
 {
     _logger   = logger;
     QueueName = queueName;
     UrlPrefix = urlPrefix;
     Queue     = new RequestQueue(queueName, UrlPrefix, _logger, receiver: true);
 }
Example #2
0
        internal unsafe void UnSetDelegationProperty(RequestQueue destination, bool throwOnError = true)
        {
            var propertyInfo = new HttpApiTypes.HTTP_BINDING_INFO();

            propertyInfo.Flags = HttpApiTypes.HTTP_FLAGS.NONE;
            propertyInfo.RequestQueueHandle = destination.Handle.DangerousGetHandle();

            SetProperty(HttpApiTypes.HTTP_SERVER_PROPERTY.HttpServerDelegationProperty, new IntPtr(&propertyInfo), (uint)RequestPropertyInfoSize, throwOnError);
        }
Example #3
0
        internal unsafe void SetDelegationProperty(RequestQueue destination)
        {
            var propertyInfo = new HttpApiTypes.HTTP_BINDING_INFO();

            propertyInfo.Flags = HttpApiTypes.HTTP_FLAGS.HTTP_PROPERTY_FLAG_PRESENT;
            propertyInfo.RequestQueueHandle = destination.Handle.DangerousGetHandle();

            SetProperty(HttpApiTypes.HTTP_SERVER_PROPERTY.HttpServerDelegationProperty, new IntPtr(&propertyInfo), (uint)RequestPropertyInfoSize);
        }
Example #4
0
 internal DelegationRule(UrlGroup sourceQueueUrlGroup, string queueName, string urlPrefix, ILogger logger)
 {
     _sourceQueueUrlGroup = sourceQueueUrlGroup;
     _logger   = logger;
     QueueName = queueName;
     UrlPrefix = urlPrefix;
     Queue     = new RequestQueue(queueName, UrlPrefix, _logger, receiver: true);
     _urlGroup = Queue.UrlGroup;
 }
Example #5
0
        public HttpSysListener(HttpSysOptions options, ILoggerFactory loggerFactory)
        {
            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }
            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (!HttpApi.Supported)
            {
                throw new PlatformNotSupportedException();
            }

            Debug.Assert(HttpApi.ApiVersion == HttpApiTypes.HTTP_API_VERSION.Version20, "Invalid Http api version");

            Options = options;

            Logger = loggerFactory.CreateLogger <HttpSysListener>();

            _state        = State.Stopped;
            _internalLock = new object();

            // V2 initialization sequence:
            // 1. Create server session
            // 2. Create url group
            // 3. Create request queue
            // 4. Add urls to url group - Done in Start()
            // 5. Attach request queue to url group - Done in Start()

            try
            {
                _serverSession = new ServerSession();

                _urlGroup = new UrlGroup(_serverSession, Logger);

                _requestQueue = new RequestQueue(_urlGroup, options.RequestQueueName, options.RequestQueueMode, Logger);

                _disconnectListener = new DisconnectListener(_requestQueue, Logger);
            }
            catch (Exception exception)
            {
                // If Url group or request queue creation failed, close server session before throwing.
                _requestQueue?.Dispose();
                _urlGroup?.Dispose();
                _serverSession?.Dispose();
                Log.HttpSysListenerCtorError(Logger, exception);
                throw;
            }
        }
Example #6
0
        internal unsafe UrlGroup(RequestQueue requestQueue, UrlPrefix url)
        {
            ulong urlGroupId = 0;
            var   statusCode = HttpApi.HttpFindUrlGroupId(
                url.FullPrefix, requestQueue.Handle, &urlGroupId);

            if (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
            {
                throw new HttpSysException((int)statusCode);
            }

            Debug.Assert(urlGroupId != 0, "Invalid id returned by HttpCreateUrlGroup");
            Id = urlGroupId;
        }
 internal DisconnectListener(RequestQueue requestQueue, ILogger logger)
 {
     _requestQueue = requestQueue;
     _logger       = logger;
 }
Example #8
0
 public ServerDelegationPropertyFeature(RequestQueue queue, ILogger logger)
 {
     _queue  = queue;
     _logger = logger;
 }
Example #9
0
        internal static unsafe ChannelBinding?GetChannelBindingFromTls(RequestQueue requestQueue, ulong connectionId, ILogger logger)
        {
            // +128 since a CBT is usually <128 thus we need to call HRCC just once. If the CBT
            // is >128 we will get ERROR_MORE_DATA and call again
            int size = RequestChannelBindStatusSize + 128;

            Debug.Assert(size >= 0);

            byte[]? blob = null;
            SafeLocalFreeChannelBinding?token = null;

            uint bytesReceived = 0;;
            uint statusCode;

            do
            {
                blob = new byte[size];
                fixed(byte *blobPtr = blob)
                {
                    // Http.sys team: ServiceName will always be null if
                    // HTTP_RECEIVE_SECURE_CHANNEL_TOKEN flag is set.
                    statusCode = HttpApi.HttpReceiveClientCertificate(
                        requestQueue.Handle,
                        connectionId,
                        (uint)HttpApiTypes.HTTP_FLAGS.HTTP_RECEIVE_SECURE_CHANNEL_TOKEN,
                        blobPtr,
                        (uint)size,
                        &bytesReceived,
                        SafeNativeOverlapped.Zero);

                    if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS)
                    {
                        int tokenOffset = GetTokenOffsetFromBlob((IntPtr)blobPtr);
                        int tokenSize   = GetTokenSizeFromBlob((IntPtr)blobPtr);
                        Debug.Assert(tokenSize < Int32.MaxValue);

                        token = SafeLocalFreeChannelBinding.LocalAlloc(tokenSize);

                        Marshal.Copy(blob, tokenOffset, token.DangerousGetHandle(), tokenSize);
                    }
                    else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_MORE_DATA)
                    {
                        int tokenSize = GetTokenSizeFromBlob((IntPtr)blobPtr);
                        Debug.Assert(tokenSize < Int32.MaxValue);

                        size = RequestChannelBindStatusSize + tokenSize;
                    }
                    else if (statusCode == UnsafeNclNativeMethods.ErrorCodes.ERROR_INVALID_PARAMETER)
                    {
                        logger.LogError(LoggerEventIds.ChannelBindingUnSupported, "GetChannelBindingFromTls; Channel binding is not supported.");
                        return(null); // old schannel library which doesn't support CBT
                    }
                    else
                    {
                        // It's up to the consumer to fail if the missing ChannelBinding matters to them.
                        logger.LogError(LoggerEventIds.ChannelBindingMissing, new HttpSysException((int)statusCode), "GetChannelBindingFromTls");
                        break;
                    }
                }
            }while (statusCode != UnsafeNclNativeMethods.ErrorCodes.ERROR_SUCCESS);

            return(token);
        }