If you have an own server and want to comunicate with it by use of HTTPS (SSL - encrypted), you need a certificate. You can get one from an offcial certification authority (CA) or you create a self signed certificate. The use of a self signed certificate normally generates a warning (certificate validation failed - issuer certificate is unknown) as shown at the following browser example, which you can accept manually if you trust it.
But, such a similiar interaction is not longer possible for an official Google Playstore app since Google has changed the sercurity guidlines that does not allow to simply pass-through the connection in case of such an issue. It is OK, because that increases the security, and we have to use another approach to get a secure encrypted communication channel from the app to the server. Following guide describes the two main steps which are neded for using a self signed certificate to establish an ssl connection between a server and apps on a android devices.
Following steps (commandline at i.e. Linux) are necesarry to generate a self signed certificate by use of openssl:
mkdir /my_server_certs
cd /my_server_certs
openssl genrsa -out my_server.key 1024
openssl req -x509 -new -nodes -key my_server.key -days 3650 -out my_server.pem
openssl x509 -in my_server.pem -outform der -out my_server.der.crt
After privat key and certification generation the server has to be configured for ssl. Following steps show the required Apache server configuration for ssl.
SSLEngine on
SSLCertificateKeyFile /my_server_certs/my_server.key
SSLCertificateFile /my_server_certs/my_server.pem
Example of Apache Virtual Host File
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
ServerName my_server
<Directory /var/www/public>
Options FollowSymLinks MultiViews
AllowOverride all
Order deny,allow
SSLRequireSSL
</Directory>
SSLEngine on
SSLCertificateFile /my_server_certs/my_server.pem
SSLCertificateKeyFile /my_server_certs/my_server.key
</VirtualHost>
The *:443 enables the server to listen for all https requests at standard TCP port 443. It's important to define a server name which is done here by the line ServerName my_server
.
After we've configuered our server for ssl, lets enable our Android device to trust the connection to our server by importing the server certificate. This can be done by following steps on Android 6.x :
my_server.der.crt
to the device (SD card).To view or uninstall the certificate go to "Settings" -> "Lock screen and security" -> "Other security settings"-> "View security certificates" and select the "USER" tab.
Removal of all user certificates can also be achieved by option "Clear Credentials".
Hint: