I'm currently working on a university project where I'm setting up an Ubuntu Server to correspond with an existing app. The app should be able to send data and pictures to my server via a post-request. The server is supposed to process the data and save it.
Everything works fine when I'm running it in Ionic on my computer. However, as soon as I start testing it on a smartphone, I encounter this error:I'm unsing a Google Pixel with Andoid Version 14
https://localhost/polyfills.826f909f93350bf7.js - Line 1 - Message: Mixed Content: The page at 'https://localhost/form' was loaded over HTTPS, but requested an insecure resource 'http://###IP-Address###:8080/Server.php'. This request has been blocked; the content must be served over HTTPS.
When I change the address of my server to https://...
, I get the following error:
[ERROR:ssl_client_socket_impl.cc(970)] handshake failed; returned -1, SSL error code 1, net_error -200
So I tried to use a self-generated SSL certificate. Since all of this is just for demonstration purposes and the server is never going to be accessible outside the university network.
Here's what I've done so far:
Configured my server like this:
/etc/apache2/sites-enabled/000-default.conf
:<VirtualHost *:8080> ServerAdmin webmaster@localhost DocumentRoot /var/www/html ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined # SSL Configuration SSLEngine on SSLCertificateFile /etc/ssl/certs/certificate_ssl.pem SSLCertificateKeyFile /etc/ssl/private/key.pem<Directory /var/www/html> Options Indexes FollowSymLinks AllowOverride None Require all granted</Directory></VirtualHost>
/etc/apache2/sites-available/default-ssl.conf
:SSLCertificateFile /etc/ssl/certs/certificate_ssl.pemSSLCertificateKeyFile /etc/ssl/private/key.pem
In the app, I made the following changes:
Created this file
android\app\src\main\res\xml\network_security_config.xml
, containing this:<?xml version="1.0" encoding="utf-8"?><network-security-config><debug-overrides><trust-anchors><certificates src="@raw/debug_cas"/></trust-anchors></debug-overrides></network-security-config>
I put my certificate here:
android\app\src\main\res\raw\debug_cas.pem
My
AndroidManifest.xml
looks like this:<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"><application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:networkSecurityConfig="@xml/network_security_config" android:theme="@style/AppTheme"><activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale|smallestScreenSize|screenLayout|uiMode" android:name=".MainActivity" android:label="@string/title_activity_main" android:theme="@style/AppTheme.NoActionBarLaunch" android:launchMode="singleTask" android:exported="true"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity><provider android:name="androidx.core.content.FileProvider" android:authorities="${applicationId}.fileprovider" android:exported="false" android:grantUriPermissions="true"><meta-data android:name="android.support.FILE_PROVIDER_PATHS" android:resource="@xml/file_paths"></meta-data></provider></application><!-- Permissions --><uses-permission android:name="android.permission.INTERNET" /></manifest>