public NativeMessageHandler(bool throwOnCaptiveNetwork, CustomSSLVerification customSSLVerification, NativeCookieHandler cookieHandler = null)
        {
            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;

            var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;

            // System.Net.ServicePointManager.SecurityProtocol provides a mechanism for specifying supported protocol types
            // for System.Net. Since iOS only provides an API for a minimum and maximum protocol we are not able to port
            // this configuration directly and instead use the specified minimum value when one is specified.
            configuration.TLSMinimumSupportedProtocol = SslProtocol.Tls_1_2;

            this.CertificatePinner = new CertificatePinner();

            foreach (var pin in customSSLVerification.Pins)
            {
                this.CertificatePinner.AddPins(pin.Hostname, pin.PublicKeys);
            }

            SetClientCertificate(customSSLVerification.ClientCertificate);

            var urlSessionDelegate = new DataTaskDelegate(this);

            session = NSUrlSession.FromConfiguration(configuration, (INSUrlSessionDelegate)urlSessionDelegate, null);

            // NSUrlSessionConfiguration.DefaultSessionConfiguration uses the default NSHttpCookieStorage.SharedStorage
        }
Exemple #2
0
        public NativeMessageHandler()
        {
            var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;

            // 两个数据包之间的时间大于该时间则认为超时,默认60秒
            // 为减少服务器推送模式时的重连次数,增大超时限制
            configuration.TimeoutIntervalForRequest = 300;

            // System.Net.ServicePointManager.SecurityProtocol provides a mechanism for specifying supported protocol types
            // for System.Net. Since iOS only provides an API for a minimum and maximum protocol we are not able to port
            // this configuration directly and instead use the specified minimum value when one is specified.
            configuration.TLSMinimumSupportedProtocol = SslProtocol.Tls_1_2;

            var urlSessionDelegate = new DataTaskDelegate(this);

            _session = NSUrlSession.FromConfiguration(configuration, (INSUrlSessionDelegate)urlSessionDelegate, null);
        }
Exemple #3
0
        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification, NativeCookieHandler cookieHandler = null)
        {
            var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;

            // System.Net.ServicePointManager.SecurityProtocol provides a mechanism for specifying supported protocol types
            // for System.Net. Since iOS only provides an API for a minimum and maximum protocol we are not able to port
            // this configuration directly and instead use the specified minimum value when one is specified.
            if (minimumSSLProtocol.HasValue)
            {
                configuration.TLSMinimumSupportedProtocol = minimumSSLProtocol.Value;
            }

            var urlSessionDelegate = new DataTaskDelegate(this);

            session = NSUrlSession.FromConfiguration(NSUrlSessionConfiguration.DefaultSessionConfiguration, (INSUrlSessionDelegate)urlSessionDelegate, null);

            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;
            this.customSSLVerification = customSSLVerification;

            // NSUrlSessionConfiguration.DefaultSessionConfiguration uses the default NSHttpCookieStorage.SharedStorage

            this.DisableCaching = false;
        }
        public NativeMessageHandler(bool throwOnCaptiveNetwork, TLSConfig tLSConfig, NativeCookieHandler cookieHandler = null, IWebProxy proxy = null)
        {
            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;

            var configuration = NSUrlSessionConfiguration.DefaultSessionConfiguration;

            this.TLSConfig = tLSConfig;

            // System.Net.ServicePointManager.SecurityProtocol provides a mechanism for specifying supported protocol types
            // for System.Net. Since iOS only provides an API for a minimum and maximum protocol we are not able to port
            // this configuration directly and instead use the specified minimum value when one is specified.
            configuration.TLSMinimumSupportedProtocol = SslProtocol.Tls_1_2;

            if (!TLSConfig.DangerousAcceptAnyServerCertificateValidator &&
                TLSConfig.Pins != null &&
                TLSConfig.Pins.Count > 0 &&
                TLSConfig.Pins.FirstOrDefault(p => p.PublicKeys.Count() > 0) != null)
            {
                this.PinningMode = "PublicKeysOnly";

                this.CertificatePinner = new CertificatePinner();

                foreach (var pin in TLSConfig.Pins)
                {
                    this.CertificatePinner.AddPins(pin.Hostname, pin.PublicKeys);
                }
            }

            SetClientCertificate(TLSConfig.ClientCertificate);

            // NSUrlSessionConfiguration.DefaultSessionConfiguration uses the default NSHttpCookieStorage.SharedStorage

            // PR: Proxy has been supported on iOS #19
            if (proxy != null && proxy is WebProxy)
            {
                var webProxy = proxy as WebProxy;

                NSObject[] values =
                {
                    NSObject.FromObject(webProxy.Address.Host),
                    NSNumber.FromInt32(webProxy.Address.Port),
                    NSNumber.FromInt32(1)
                };

                NSObject[] keys =
                {
                    NSObject.FromObject("HTTPSProxy"),
                    NSObject.FromObject("HTTPSPort"),
                    NSObject.FromObject("HTTPSEnable")
                };

                var proxyDict = NSDictionary.FromObjectsAndKeys(values, keys);
                configuration.ConnectionProxyDictionary = proxyDict;

                if (webProxy.Credentials != null)
                {
                    var credentials = (NetworkCredential)webProxy.Credentials;

                    var authData        = string.Format("{0}:{1}", credentials.UserName, credentials.Password);
                    var authHeaderValue = Convert.ToBase64String(Encoding.UTF8.GetBytes(authData));

                    NSObject[] hValues =
                    {
                        NSObject.FromObject(authHeaderValue)
                    };

                    NSObject[] hKeys =
                    {
                        NSObject.FromObject("Proxy-Authorization")
                    };

                    var headers = NSDictionary.FromObjectsAndKeys(hValues, hKeys);

                    configuration.HttpAdditionalHeaders = headers;
                }
            }

            var urlSessionDelegate = new DataTaskDelegate(this);

            session = NSUrlSession.FromConfiguration(configuration, (INSUrlSessionDelegate)urlSessionDelegate, null);
        }