{"id":715,"date":"2014-10-20T08:36:40","date_gmt":"2014-10-20T08:36:40","guid":{"rendered":"https:\/\/www.rapidsslonline.com\/blog\/?p=715"},"modified":"2022-04-22T01:09:48","modified_gmt":"2022-04-22T06:39:48","slug":"android-apps-must-ssl-certificates","status":"publish","type":"post","link":"https:\/\/www.rapidsslonline.com\/blog\/android-apps-must-ssl-certificates\/","title":{"rendered":"Why Android Apps Must Have SSL Certificates?"},"content":{"rendered":"<h2>Stay Secure for Android Base Smart Phone Applications with SSL Certificates<\/h2>\n<p>Shocking results awaited us when a survey was carried out recently by a digital security firm, FireEye, on the Android applications. As per the findings, almost 68% of the top 1000 applications in Google Play store are vulnerable to at least one major SSL security flaw.<\/p>\n<p><!--more--><\/p>\n<p>These flaws can range from applications not checking SSL certificates or using obsolete host name verifiers or simply ignoring SSL errors in the Webkit engine that generally signals the security problems. Any single flaw mentioned here is capable enough to enable \/ permit hackers to carry out Man-in-The-Middle attacks, where the attackers can easily compromise a user\u2019s private data by a malicious party without the developers or the users knowing it.<\/p>\n<h3>Android Under Attack<\/h3>\n<p>Android is skillfully designed to be a modern, open-platform for the users. The wealth of Apps available on the Google Play Store is one of the main reason behind the popularity of the Android platform. Android applications use their devices advanced hardware and software along with local and served data, which is exposed through the platform to bring innovation and value to the customers. Now, to sustain this value, the platform needs to offer an application environment, which ensures the security of users&#8217; identity, data, applications, device and the network they are using.<\/p>\n<p>However, with each passing day, the number of malicious mobile applications are increasing. These infected\/ affected applications can easily access the sensitive information stored on a mobile device. Such compromised information can be used by the hackers to carry out more such attacks with the help of different threat vectors.<\/p>\n<p>Applications, as we know, interact with remote servers for their functionality. They normally communicate using either the:<\/p>\n<ul>\n<li>HTTP Protocol: This makes the data-interception for others very easy<\/li>\n<li>HTTPS Protocol: Due to the security measures involved in this, the data-interception becomes difficult. These security properties in HTTPS stem from the SSL &amp; TLS certificates.<\/li>\n<\/ul>\n<p>The Android platform provides libraries and methods to communicate with the servers by using secure network protocols such as HTTPS, and forming the underpinnings of PKI (Public-Key Infrastructure) implementations. The protocol of SSL\/TLS is designed to enhance the security, but incorrect use of the libraries of Android platform can expose applications to MiTM attacks. In such attacks, the attackers can interpret the traffic flowing from the application to the server or vice versa and may:<\/p>\n<ul>\n<li>be eavesdropping and accessing the data sent by the server or the application<\/li>\n<li>modify the intercepted data or replace it with malicious code or data and re-introduce it in the application and redirect the traffic to an entirely new destination, which is controlled by the attacker.<\/li>\n<\/ul>\n<h3>Vulnerable Play Store<\/h3>\n<p>On July 17 2014, a team of experts at FireEye, reviewed as many as 1000 free applications from Google Play, which are very popular and are downloaded the most. Out of these 1000 applications, 68% (~ 614 applications) had at least one out of three SSL vulnerabilities. The number of vulnerable applications found in each category is presented in the image below:<\/p>\n<p><img decoding=\"async\" class=\"alignleft size-full wp-image-717\" src=\"https:\/\/www.rapidsslonline.com\/blog\/wp-content\/uploads\/2014\/10\/ssl-vulnerabilities-in-top-100-google-play-store-applications1.png\" alt=\"ssl vulnerabilities in top 100 google play store applications\" width=\"432\" height=\"175\" srcset=\"https:\/\/www.rapidsslonline.com\/blog\/wp-content\/uploads\/2014\/10\/ssl-vulnerabilities-in-top-100-google-play-store-applications1.png 432w, https:\/\/www.rapidsslonline.com\/blog\/wp-content\/uploads\/2014\/10\/ssl-vulnerabilities-in-top-100-google-play-store-applications1-300x121.png 300w\" sizes=\"(max-width: 432px) 100vw, 432px\" \/><\/p>\n<h3>How to Secure An Android App?<\/h3>\n<p>Following main steps are involved in securing the connection from a trusted Certificate Authorities CA:<\/p>\n<p><strong>Step 1<\/strong> \u2013 Obtain all the required certificates (including root and any intermediate Certificate Authorities)<br \/>\n<strong>Step 2<\/strong> \u2013 Next, create a keystore with a keytool and the BouncyCastle provider and import the certificates.<br \/>\n<strong>Step 3<\/strong> \u2013 Load the keystore into the Android applications and establish secure connections<\/p>\n<p><strong>NOTE:<\/strong> Experts recommend not to use the standard <strong><em>java.net.ssl.HttpsURLConnection<\/em><\/strong> for securing the connection. Instead, it is advisable to use the <em><strong>Apache HttpClient<\/strong><\/em> (currently at Version 4) library, as it is already a built-in feature in Android. It is built on top of the java connection libraries and is considered faster, well modularized, and easy to understand.<\/p>\n<h3>Step 1 \u2013 Obtain the Certificates<\/h3>\n<p>In this step, you have to obtain all the certificates that are involved in building a chain from the endpoint certificate until Root CA, including Intermediate certificates as well, if any. However, it is not necessary to obtain the endpoint certificate.<\/p>\n<p>If provided, users can obtain those certificates from the chain included in the endpoint certificate. Alternatively, they can obtain the certificates from the official site of the issuer.<\/p>\n<p>Please make sure to save all the obtained certificates in the Base64 encoded X.509 format. The content should be looking like this:<\/p>\n<pre>1-----BEGIN CERTIFICATE-----\r\n2MIIGqTC.....(continues)\r\n3-----END CERTIFICATE-----\r\n<\/pre>\n<h3>Step 2 \u2013 Keystore Creation<\/h3>\n<p>To start with, download the <em>BouncyCastle<\/em> package and carefully store it at a known location. At this stage, please make sure you can invoke the <em>keytool<\/em> command, which is usually located under the bin folder of the JRE installation.<\/p>\n<p>Next, import the obtained certificates (not the endpoint certificate) into a <em>BouncyCastle<\/em> formatted keystore. It is advisable to import the certificates starting with the lowermost Intermediate certificate and then gradually moving all the way up to the Root CA certificate.<\/p>\n<p>After giving the following command, a new keystore with password \u2018<em>mysecret<\/em>\u2019 will be created and the Intermediate CA certificate will be imported. Please execute this command for all the certificates:<\/p>\n<pre>keytool -importcert -v -trustcacerts -file \"path_to_cert\/interm_ca.cer\" -alias IntermediateCA -keystore \"res\/raw\/myKeystore.bks\" -provider org.bouncycastle.jce.provider.BouncyCastleProvider -providerpath \"path_to_bouncycastle\/bcprov-jdk16-145.jar\" -storetype BKS -storepass mysecret\r\n<\/pre>\n<p>Now verify if the certificates are imported in a correct manner into the keystore:<\/p>\n<pre>keytool -list -keystore \"res\/raw\/myKeystore.bks\" -provider\r\norg.bouncycastle.jce.provider.BouncyCastleProvider -providerpath \"path_to_bouncycastle\/bcprov-jdk16-145.jar\" -storetype BKS -storepass mysecret\r\n<\/pre>\n<p>Should output the whole chain<\/p>\n<pre>RootCA, 22.10.2010, trustedCertEntry, Thumbprint (MD5): 24:77:D9:A8:91:D1:3B:FA:88:2D:C2:FF:F8:CD:33:93\r\nIntermediateCA, 22.10.2010, trustedCertEntry, Thumbprint (MD5): 98:0F:C3:F8:39:F7:D8:05:07:02:0D:E3:14:5B:29:43\r\n<\/pre>\n<p>Now, the keystore can be copied as a raw resource in the android application under res\/raw\/<\/p>\n<h3>Step 3 \u2013 Use the Keystore in the Application<\/h3>\n<p>First, the user needs to create a custom Apache HttpClient that uses this keystore for HTTPS connections:<\/p>\n<pre>public class MyHttpClient extends DefaultHttpClient {\r\n\r\nfinal Context context;\r\n\r\npublic MyHttpClient(Context context) {\r\nthis.context = context;\r\n}\r\n\r\n@Override\r\nprotected ClientConnectionManager createClientConnectionManager() {\r\nSchemeRegistry registry = new SchemeRegistry();\r\nregistry.register(new Scheme(\"http\", PlainSocketFactory.getSocketFactory(), 80));\r\n\/\/ Register for port 443 our SSLSocketFactory with our keystore\r\n\/\/ to the ConnectionManager\r\nregistry.register(new Scheme(\"https\", newSslSocketFactory(), 443));\r\nreturn new SingleClientConnManager(getParams(), registry);\r\n}\r\n\r\nprivate SSLSocketFactory newSslSocketFactory() {\r\ntry {\r\n\/\/ Get an instance of the Bouncy Castle KeyStore format\r\nKeyStore trusted = KeyStore.getInstance(\"BKS\");\r\n\/\/ Get the raw resource, which contains the keystore with\r\n\/\/ your trusted certificates (root and any intermediate certs)\r\nInputStream in = context.getResources().openRawResource(R.raw.mykeystore);\r\ntry {\r\n\/\/ Initialize the keystore with the provided trusted certificates\r\n\/\/ Also provide the password of the keystore\r\ntrusted.load(in, \"mysecret\".toCharArray());\r\n} finally {\r\nin.close();\r\n}\r\n\/\/ Pass the keystore to the SSLSocketFactory. The factory is responsible\r\n\/\/ for the verification of the server certificate.\r\nSSLSocketFactory sf = new SSLSocketFactory(trusted);\r\n\/\/ Hostname verification from certificate\r\n\/\/ http:\/\/hc.apache.org\/httpcomponents-client-ga\/tutorial\/html\/connmgmt.html#d4e506\r\nsf.setHostnameVerifier(SSLSocketFactory.STRICT_HOSTNAME_VERIFIER);\r\nreturn sf;\r\n} catch (Exception e) {\r\nthrow new AssertionError(e);\r\n}\r\n}\r\n}\r\n<\/pre>\n<p>With this step, the custom HttpClient is created, which can be used for secure connections.<\/p>\n<h3>Read Other Important Resources<\/h3>\n<ul>\n<li><a href=\"https:\/\/www.rapidsslonline.com\/blog\/how-to-reduce-vulnerabilities-online-malware-attacks-on-android-devices\/\">How to Reduce Vulnerabilities &amp; Online Malware Attacks on Android Devices<\/a><\/li>\n<li><a href=\"https:\/\/www.rapidsslonline.com\/blog\/understanding-wildcard-ssl-validation-for-the-android-platform\/\">Understanding WildCard SSL validation for the Android Platform<\/a><\/li>\n<li><a href=\"https:\/\/www.rapidsslonline.com\/blog\/mobile-cloud-computing-future-mobile-applications\/\">Mobile Cloud Computing \u2013 The Future of Mobile Applications<\/a><\/li>\n<li><a href=\"https:\/\/www.rapidsslonline.com\/blog\/enable-two-factor-authentication-an-all-in-one-guide\/\">Enable Two-Factor Authentication \u2013 An All-in-One Guide<\/a><\/li>\n<\/ul>\n<p><\/br><\/p>\n<h3>SSL Certificates for Android Apps<\/h3>\n<div style=\"margin-bottom: 20px;\">\n<div style=\"float: left; margin-right: 20px;\"><img decoding=\"async\" src=\"\/blog\/wp-content\/uploads\/2018\/09\/rapidssl-small-logo.png\" alt=\"RapidSSL Logo\" align=\"left\" \/><\/div>\n<div>\n<p>Secure Android Webstore through an SSL Certificate from the most popular SSL brands like RapidSSL, GeoTrust, Thawte, and Symantec.<\/p>\n<div style=\"text-align: right; float: right;\"><a class=\"more-link\" href=\"https:\/\/www.rapidsslonline.com\/ssl-types\/single-domain.aspx\">75% Off SSL Certificates<\/a><\/div>\n<\/div>\n<div class=\"clear\"><\/div>\n<\/div>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Stay Secure for Android Base Smart Phone Applications with SSL Certificates Shocking results awaited us when a survey was carried out recently by a digital security firm, FireEye, on the &hellip; <span class=\"d-flex justify-content-end\"><a href=\"https:\/\/www.rapidsslonline.com\/blog\/android-apps-must-ssl-certificates\/\" class=\"btn btn-blue\">Read More <span class=\"screen-reader-text\">Why Android Apps Must Have SSL Certificates?<\/span><\/a><\/span><\/p>\n","protected":false},"author":10,"featured_media":493,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"inline_featured_image":false,"footnotes":""},"categories":[14],"tags":[],"yst_prominent_words":[2276,1638,1642,2263,584,116,176,2262,2265,1004,2266,2267,976,1645,2268,2264,2269,1157,46,1044],"class_list":["post-715","post","type-post","status-publish","format-standard","has-post-thumbnail","category-ssl-certificate"],"_links":{"self":[{"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/posts\/715","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/users\/10"}],"replies":[{"embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/comments?post=715"}],"version-history":[{"count":0,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/posts\/715\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/media\/493"}],"wp:attachment":[{"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/media?parent=715"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/categories?post=715"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/tags?post=715"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.rapidsslonline.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=715"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}