ITeye博客

Android with Emulator Shell

sillycat · 2013-03-16 06:05 · Mobile Platform · 移动开发 · Markdown

Android with Emulator Shell

  1. Change the HOSTS First step, start my emulator.

Then, remount the device image as writable

adb remount

Then, save a copy of the hosts file on my own machine

adb pull /system/etc/hosts /Users/carl/data

Then, edit the hosts as I like

Then, save and push back the hosts file to the emulator

adb push /Users/carl/data/hosts /system/etc

  1. Connect to HTTPS Error Message when I try to connect to HTTPS POST: javax.net.ssl.SSLException: Not trusted server certificate javax.net.ssl.SSLException: Not trusted server certificate

Solution: Some solutions are about disable the SSL based on HTTP-Client or KSOAP2. Disable SSL check based on HTTPCLIENT http://blog.syedgakbar.com/2012/07/21/android-https-and-not-trusted-server-certificate-error/ Disable SSL check based on ksoap2 http://lanyan-lan.iteye.com/blog/1523821

But I am planning to install the CERT on my emulator. http://intrepidusgroup.com/insight/2011/08/setting-up-a-persistent-trusted-ca-in-an-android-emulator/

Step 1: Set up OS environment Android is using a specific keystone type called Bouncycastle KeyStore(BKS). I download the jar package and place it in my JAVA_HOME lib directory http://www.bouncycastle.org/archive/141/bcprov-jdk16-141.jar

On my MAC laptop, the directory is here: /System/Library/Frameworks/JavaVM.framework/Home/lib/ext

cd /System/Library/Frameworks/JavaVM.framework/Home/lib/ext sudo cp /Users/carl/data/bcprov-jdk16-141.jar ./

Try to manually install the CERT

adb pull /system/etc/security/cacerts.bks /Users/carl/data/

Prepare the CERT file, open the URL with Firefox. [Add Exception…] ---> [View] ---> [Details] ----> [Export] ----> File name sillycat with [X.509 Certificate (PEM)]

cd /Users/carl/data mv sillycat sillycat.cert Check the certificate file keytool -printcert -file sillycat.cer

Example: keytool -keystore cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -importcert -trustcacerts -alias somealias -file ca.cer -noprompt

keytool -keystore cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -importcert -trustcacerts -alias sillycat -file sillycat.cer -noprompt

I used to think that I do not have password, so I get rid of the line -storepass changeit, I got Error Message: keytool error: java.lang.NullPointerException Solution: The default password is changeit, but not empty.

Change the permission on AVD

adb shell chmod 777 /system/etc/security/cacerts.bks

Push the changed file to AVD

adb push cacerts.bks /system/etc/security/cacerts.bks adb shell ls /system/etc/security/

Restart the AVD and try again.

adb shell stop adb shell start

Much Better, the error message changed Error Message: POST: java.lang.NullPointerException java.lang.NullPointException at org.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:83

Solution: Maybe, that because I get the CER file by wrong way.

echo | openssl s_client -connect api.local.sillycat.com:443 2>&1 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > s1.pem

Import the PEM file again

keytool -keystore cacerts.bks -storetype BKS -provider org.bouncycastle.jce.provider.BouncyCastleProvider -storepass changeit -importcert -trustcacerts -alias s1 -file s1.pem -noprompt

Push the file again

adb push cacerts.bks /system/etc/security/cacerts.bks

Restart the AVD

adb shell stop adb shell start

But still not working.

It is not working for my project which is an old project. Maybe I can try in the newly project in the future. I will just change the https to http on my local machine this time.

References: http://www.bradcurtis.com/2011/02/13/hosts-file-google-android-emulator/ http://stackoverflow.com/questions/14109319/avd-emulator-browser-wont-use-hosts-file

http://stackoverflow.com/questions/5687082/obtain-root-access-via-su-on-the-android-emulator http://allencch.wordpress.com/2012/02/29/learn-to-root-android-using-emulator/

http://androidsu.com/superuser/ http://www.bradcurtis.com/2011/02/13/hosts-file-google-android-emulator/

Disable SSL check based on HTTPCLIENT http://blog.syedgakbar.com/2012/07/21/android-https-and-not-trusted-server-certificate-error/ Disable SSL check based on ksoap2 http://lanyan-lan.iteye.com/blog/1523821

http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。