Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access HTTPS from my Android Emulator

I'm behind a corporate proxy and everything that access the internet needs a special configuration regarding Proxy. I'm on a CentOS 7, using CNTLMD to handle proxy tunneling, developing for mobile with React Native. And I'm using the Android Emulator provided by Android Studio.

I first noticed that my emulator can't access any HTTPS protocol when I tried to open Google in the Browser. Internally google redirects to HTTPS and I always get that "Connection Refused" error. Later (this week), trying to use Axios and Fetch to make HTTP/HTTPS requests, this has become a serious problem, since the APIs I'm trying to connect to are under the HTTPS protocol.

A friend of mine who is working in the same project but using Mac has no problems with HTTPS. I have also tried to start the emulator with the following commands:

emulator -avd myemulator -http-proxy http://127.0.0.1:3128

And

emulator -avd Marshmallow86 -http-proxy http://<network username>:<network password>@<ip>:<port>

And they do nothing.

I tried setting up HTTP and HTTPS proxy on Android Studio but this don't seem to be the way (and also didn't work).

@edit

I set the http_proxy on my host and started the emulator without parameters. Didn't work as well.

What am I missing?

like image 396
Victor Ferreira Avatar asked May 11 '17 13:05

Victor Ferreira


1 Answers

I haven't used the software above that isn't android avd or androidstudio, but it looks like a proxy or CA certificate problem. Since the difference seems to be by OS, I would guess CA certificate first.

This android page has advice on using openssl from the command line to explore that and consider importing certificates.

https://developer.android.com/training/articles/security-config.html

This android page has current suggestions for proxy configurations: https://developer.android.com/studio/run/emulator-networking.html

Note, that the above instructions are updated for new features. In the past I needed a proxy to a non-ssl appengine development server which is slightly different from your problem but here's what I used:

For an SSL proxy, used the apache web server, and configured it to use SSL by installing a self-signed certificate, then added a ProxyPass and ProxyPassReverse in httpd.conf and a ProxyPass in the httpd-ssl.conf. ProxyPass / http://127.0.0.1:8080/

Apache as an SSL proxy receives connections to https://127.0.0.1:443 and passes them to http://127.0.0.1:8080

Then in the application, code that will be running in the emulator can use address 10.0.2.2 to use android subnet routing table to connect to the dev. OS localhost.

like image 185
nichole Avatar answered Oct 09 '22 21:10

nichole