Android with Emulator Shell

AndroidwithEmulatorShell

1.ChangetheHOSTS

Firststep,startmyemulator.

Then,remountthedeviceimageaswritable

>adbremount

Then,saveacopyofthehostsfileonmyownmachine

>adbpull/system/etc/hosts/Users/carl/data

Then,editthehostsasIlike

Then,saveandpushbackthehostsfiletotheemulator

>adbpush/Users/carl/data/hosts/system/etc

2.ConnecttoHTTPS

ErrorMessagewhenItrytoconnecttoHTTPS

POST:javax.net.ssl.SSLException:Nottrustedservercertificate

javax.net.ssl.SSLException:Nottrustedservercertificate

Solution:

SomesolutionsareaboutdisabletheSSLbasedonHTTP-ClientorKSOAP2.

DisableSSLcheckbasedonHTTPCLIENT

http://blog.syedgakbar.com/2012/07/21/android-https-and-not-trusted-server-certificate-error/

DisableSSLcheckbasedonksoap2

ButIamplanningtoinstalltheCERTonmyemulator.

http://intrepidusgroup.com/insight/2011/08/setting-up-a-persistent-trusted-ca-in-an-android-emulator/

Step1:SetupOSenvironment

AndroidisusingaspecifickeystonetypecalledBouncycastleKeyStore(BKS).

IdownloadthejarpackageandplaceitinmyJAVA_HOMElibdirectory

http://www.bouncycastle.org/archive/141/bcprov-jdk16-141.jar

OnmyMAClaptop,thedirectoryishere:

/System/Library/Frameworks/JavaVM.framework/Home/lib/ext

>cd/System/Library/Frameworks/JavaVM.framework/Home/lib/ext

>sudocp/Users/carl/data/bcprov-jdk16-141.jar./

TrytomanuallyinstalltheCERT

>adbpull/system/etc/security/cacerts.bks/Users/carl/data/

PreparetheCERTfile,opentheURLwithFirefox.

[AddException…]--->[View]--->[Details]---->[Export]---->Filenamesillycatwith[X.509Certificate(PEM)]

>cd/Users/carl/data

>mvsillycatsillycat.cert

Checkthecertificatefile

>keytool-printcert-filesillycat.cer

Example:

keytool-keystorecacerts.bks-storetypeBKS-providerorg.bouncycastle.jce.provider.BouncyCastleProvider-storepasschangeit-importcert-trustcacerts-aliassomealias-fileca.cer-noprompt

>keytool-keystorecacerts.bks-storetypeBKS-providerorg.bouncycastle.jce.provider.BouncyCastleProvider-storepasschangeit-importcert-trustcacerts-aliassillycat-filesillycat.cer-noprompt

IusedtothinkthatIdonothavepassword,soIgetridoftheline-storepasschangeit,Igot

ErrorMessage:

keytoolerror:java.lang.NullPointerException

Solution:

Thedefaultpasswordischangeit,butnotempty.

ChangethepermissiononAVD

>adbshellchmod777/system/etc/security/cacerts.bks

PushthechangedfiletoAVD

>adbpushcacerts.bks/system/etc/security/cacerts.bks

>adbshellls/system/etc/security/

RestarttheAVDandtryagain.

>adbshellstop

>adbshellstart

MuchBetter,theerrormessagechanged

ErrorMessage:

POST:java.lang.NullPointerException

java.lang.NullPointException

atorg.apache.harmony.xnet.provider.jsse.OpenSSLSocketFactoryImpl.createSocket(OpenSSLSocketFactoryImpl.java:83

Solution:

Maybe,thatbecauseIgettheCERfilebywrongway.

>echo|openssls_client-connectapi.local.sillycat.com:4432>&1|sed-ne'/-BEGINCERTIFICATE-/,/-ENDCERTIFICATE-/p'>s1.pem

ImportthePEMfileagain

>keytool-keystorecacerts.bks-storetypeBKS-providerorg.bouncycastle.jce.provider.BouncyCastleProvider-storepasschangeit-importcert-trustcacerts-aliass1-files1.pem-noprompt

Pushthefileagain

>adbpushcacerts.bks/system/etc/security/cacerts.bks

RestarttheAVD

>adbshellstop

>adbshellstart

Butstillnotworking.

Itisnotworkingformyprojectwhichisanoldproject.MaybeIcantryinthenewlyprojectinthefuture.

Iwilljustchangethehttpstohttponmylocalmachinethistime.

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/

DisableSSLcheckbasedonHTTPCLIENT

http://blog.syedgakbar.com/2012/07/21/android-https-and-not-trusted-server-certificate-error/

DisableSSLcheckbasedonksoap2

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

相关推荐