Android apps that use SSL/TLS protocols for secure communication should properly verify server certificates. The basic verification includes:
- verify that the subject (CN) of X.509 certificate and the URL matches
- verify that the certificate is signed by the trusted CA
- verify that the signature is correct
- verify that the certificate is not expired
Android SDK 4.0 and later offers packages to implement capabilities to establish network connections. For example, by using
org.apache.http, a developer can create server sockets or HTTP connection.
org.webkit offers functions necessary to implement web browsing capabilities.
A developer has the freedom to customize their SSL implementation, and thus has a responsibility to properly use SSL depending on the intent of the app as well as the environment the apps are used in. If the SSL is not correctly used, a user's sensitive data may leak via the vulnerable SSL communication channel.
Fahl et al [Fahl 2012] summarises the following patterns of the insecure use of SSL:
Trusting All Certificates
- The developer implements the TrustManager interface so that it will trust all the server certificate (regardless of who signed it, what is the CN etc.)
Allowing All Hostnames
- The app does not verify if the certificate is issued for the URL the client is connecting to.
- When a client connects to example.com, it will accept a server certificate issued for some-other-domain.com.
Mixed-Mode / No SSL
- A developer mixes secure and insecure connections in the same app or does not use SSL at all.
On Android, using
HttpURLConnection is recommended for HTTP client implementation.
Noncompliant Code Example
The following code implements a custom
MySSLSocketFactory class that inherits
In the example above,
checkServerTrusted() are overriden to make a blank implementation so that
SSLSocketFactory does not verify the SSL certificate. The
MySSLSocketFactory class is used to create an instance of
HttpClient in another part of the application.
Proof of Concept
Typically, an application stores files in the directory as follows:
Compliant Solution (Save a File on Internal Storage)
The following code uses the
openFileOutput() method to create
"myfile" in an application data directory with permission set to
MODE_PRIVATE so that other apps cannot access the file:
Storing sensitive information on external storage can leak sensitive information to malicious apps.
It is possible to automatically detect whether an application writes to external storage. It is not feasible to automatically determine whether such output could be stored internally.
- JVN#92038939 mixi for Android information management vulnerability
- JVN#05102851 Yome Collection for Android issue in management of IMEI
Android Secure Coding Guidebook by JSSEC
4.6 Secure File Handling