示例#1
0
        /// <summary>
        /// Creates a new proxy server instance. Really there should only ever be a single instance
        /// created at a time.
        /// </summary>
        /// <param name="configuration">
        /// The proxy server configuration to use.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Will throw if any one of the callbacks in the supplied configuration are not defined.
        /// </exception>
        public ProxyServer(ProxyServerConfiguration configuration)
        {
            _tlsConnAdapter = new TlsSniConnectionAdapter(CreateCertificateStore(configuration.AuthorityName ?? "CitadelCore"));
            _fwCallback     = configuration.FirewallCheckCallback ?? throw new ArgumentException("The firewall callback MUST be defined.", nameof(configuration));
            FilterResponseHandlerFactory.Default.NewMessageCallback          = configuration.NewHttpMessageHandler ?? throw new ArgumentException("The new message callback MUST be defined.", nameof(configuration));
            FilterResponseHandlerFactory.Default.WholeBodyInspectionCallback = configuration.HttpMessageWholeBodyInspectionHandler ?? throw new ArgumentException("The whole-body content inspection callback MUST be defined.", nameof(configuration));
            FilterResponseHandlerFactory.Default.StreamedInspectionCallback  = configuration.HttpMessageStreamedInspectionHandler ?? throw new ArgumentException("The streaming content inspection callback MUST be defined.", nameof(configuration));
            FilterResponseHandlerFactory.Default.BadCertificateCallback      = configuration.BadCertificateHandler ?? throw new ArgumentException("The bad certificate callback MUST be defined.", nameof(configuration));

            // Hook the cert verification callback.
            ServicePointManager.ServerCertificateValidationCallback += CertificateVerificationHandler;
        }
示例#2
0
        /// <summary>
        /// Creates a new proxy server instance. Really there should only ever be a single instance
        /// created at a time.
        /// </summary>
        /// <param name="configuration">
        /// The proxy server configuration to use.
        /// </param>
        /// <exception cref="ArgumentException">
        /// Will throw if any one of the callbacks in the supplied configuration are not defined.
        /// </exception>
        public ProxyServer(ProxyServerConfiguration configuration)
        {
            _configuration = configuration;

            if (_configuration == null || !_configuration.IsValid)
            {
                throw new ArgumentException("Configuration is null or invalid. Ensure that all callbacks are defined.");
            }

            _tlsConnAdapter = new TlsSniConnectionAdapter(CreateCertificateStore(configuration.AuthorityName ?? "CitadelCore"));
            _fwCallback     = configuration.FirewallCheckCallback ?? throw new ArgumentException("The firewall callback MUST be defined.", nameof(configuration));

            _replayResponseFactory = new ReplayResponseHandlerFactory();
            _httpResponseFactory   = new FilterResponseHandlerFactory(_configuration, _replayResponseFactory);

            // Hook the cert verification callback.
            ServicePointManager.ServerCertificateValidationCallback += CertificateVerificationHandler;
        }