Exemple #1
0
        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification)
        {
            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;

            if (customSSLVerification)
            {
                client.SetHostnameVerifier(new HostnameVerifier());
            }
        }
        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification, NativeCookieHandler cookieHandler = null)
        {
            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;

            if (customSSLVerification)
            {
                client.SetHostnameVerifier(new HostnameVerifier());
            }
            noCacheCacheControl = (new CacheControl.Builder()).NoCache().Build();
        }
        private OkHttpClient GetSafeOkHttpClient()
        {
            OkHttpClient okHttpClient = new OkHttpClient();

            if (customSSLVerification)
            {
                okHttpClient.SetHostnameVerifier(new HostnameVerifier());
            }

            okHttpClient.SetSslSocketFactory(new ImprovedSSLSocketFactory());

            return(okHttpClient);
        }
        public CallTrackerTask(string IpAddress, string deviceId)
        {
            _ipAddress = "https://" + IpAddress;
            _deviceId  = deviceId;

            client.RetryOnConnectionFailure = true;
            SSLContext sslContext = SSLContext.GetInstance("SSL");

            ITrustManager[] trustAllCerfs = new ITrustManager[] { new X509TrustManager() };
            sslContext.Init(null, trustAllCerfs, new Java.Security.SecureRandom());
            client.SetSslSocketFactory(sslContext.SocketFactory);
            client.SetHostnameVerifier(new HostNameVerifier());
        }
Exemple #5
0
        public Communicator()
        {
            trustAllSslContext = SSLContext.GetInstance("SSL");
            trustAllSslContext.Init(null, new ITrustManager[] { new CustomX509TrustManager() }, new SecureRandom());

            client = new OkHttpClient();
            client.SetConnectTimeout(5, Java.Util.Concurrent.TimeUnit.Seconds);
            client.SetSslSocketFactory(trustAllSslContext.SocketFactory);
            client.SetHostnameVerifier(new CustomHostNameVerifier());
            client.SetProtocols(new Protocol[] { Protocol.Http11 });

            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().PermitAll().Build();
            StrictMode.SetThreadPolicy(policy);
        }
        private OkHttpClient GetUnsafeOkHttpClient()
        {
            ITrustManager[] trustAllCerts = new ITrustManager[] { new X509TrustManager() };
            SSLContext      sslContext    = SSLContext.GetInstance("SSL");

            sslContext.Init(null, trustAllCerts, null);
            SSLSocketFactory sslSocketFactory = sslContext.SocketFactory;
            OkHttpClient     okHttpClient     = new OkHttpClient();

            okHttpClient.SetSslSocketFactory(sslSocketFactory);
            okHttpClient.SetHostnameVerifier(new UnsafeHostnameVerifier());

            return(okHttpClient);
        }
Exemple #7
0
        /// <summary>
        /// Provides an OkHttpClient that is set up with the requested
        /// socket factory and hostname provider (if any).
        /// </summary>
        public static OkHttpClient GetHttpClient()
        {
            SetupDangerous();
            // create a new client
            var client = new OkHttpClient();

            // add the socket factory
            client.SetSslSocketFactory(socketFactory);
            // make sure we use the hostname verifier
            if (hostnameVerifier != null)
            {
                client.SetHostnameVerifier(hostnameVerifier);
            }
            return(client);
        }
Exemple #8
0
        public NativeMessageHandler(bool throwOnCaptiveNetwork, bool customSSLVerification, NativeCookieHandler cookieHandler = null)
        {
            this.throwOnCaptiveNetwork = throwOnCaptiveNetwork;

            if (customSSLVerification)
            {
                client.SetHostnameVerifier(new HostnameVerifier());
            }
            noCacheCacheControl = (new CacheControl.Builder()).NoCache().Build();

            // If less than Android Lollipop
            if (((int)Build.VERSION.SdkInt) < 21)
            {
                client.SetSslSocketFactory(new ImprovedSSLSocketFactory());
            }
        }
        private async Task <HttpResponseMessage> HttpGet(string url)
        {
            var client = new OkHttpClient();

            client.SetHostnameVerifier(new HostnameVerifier());
            client.SetSslSocketFactory(GetSocketFactory());

            var builder = new Request.Builder()
                          .Method("GET", null)
                          .Url(url)
                          .CacheControl(new CacheControl.Builder().NoCache().Build())
                          .AddHeader("User-Agent", "Test/1.0");

            var rq   = builder.Build();
            var call = client.NewCall(rq);

            System.Diagnostics.Debug.WriteLine("Sending Call...");

            var resp = await call.EnqueueAsync().ConfigureAwait(false);

            System.Diagnostics.Debug.WriteLine("Got response");

            var respBody = resp.Body();

            var ret = new HttpResponseMessage((HttpStatusCode)resp.Code());

            ret.ReasonPhrase = resp.Message();
            if (respBody != null)
            {
                ret.Content = new StreamContent(respBody.ByteStream());
            }
            else
            {
                ret.Content = new ByteArrayContent(new byte[0]);
            }

            var respHeaders = resp.Headers();

            foreach (var k in respHeaders.Names())
            {
                ret.Headers.TryAddWithoutValidation(k, respHeaders.Get(k));
                ret.Content.Headers.TryAddWithoutValidation(k, respHeaders.Get(k));
            }

            return(ret);
        }