http icon indicating copy to clipboard operation
http copied to clipboard

Request to https domain fails with SSLHandshakeException.

Open Petru-design opened this issue 2 years ago • 5 comments

Request to https domain fails with SSLHandshakeException.

I am trying to perform http requests to my backend api server, which has a valid certificate and is running https. Unfortunately, the request to my particular domain fails, as can be seen in the screenshot attached. Is this an issue with the certificate? I have been reading something about SSL pinning, but not sure that means and how to do it

Expected behavior A clear and concise description of what you expected to happen.

Screenshots image

Smartphone (please complete the following information):

  • Device: Samsung
  • OS: Android
  • Browser Ionic webview

Petru-design avatar May 29 '22 14:05 Petru-design

You need to add networkconfig.xml file in android folder. Networkconfig.xml look like this:

youneedtoadddomain/hostnameappwantstoreach youneedtoadddomain/hostnameappwantstoreach Path to add that file: C:\Users\\Documents\Project\\android\app\src\main\res\xml\network_security_config.xml Do not forgot to add below line in manifest.xml file; C:\Users\\Documents\Project\\android\app\src\main\AndroidManifest.xml

Rishabprasad avatar Jun 12 '22 17:06 Rishabprasad

@Rishabprasad Can you please write /paste here picture or code related to SSL pinning in code and Android Studio code. Stepwise procedure. [For valid and self-signed SSL certificate] .Using IONIC Framework+React+api calling library:capacitor-community/http. please write headers also if necessary for https api calling. I am stuck. Kindly HELP.

demoprojects123 avatar Aug 02 '22 10:08 demoprojects123

  1. Create network_security_config.xml on this location: C:\Users\\Documents\Project\xyz\android\app\src\main\res\xml\network_security_config.xml
  2. Add following code into it;
<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">connecttohostserver.com</domain>
        <domain includeSubdomains="true">connecttohostserver.net</domain>
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </domain-config>
</network-security-config>
  1. Add this xml file reference into C:\Users\xyz\Documents\Project\projectname\android\app\src\main\AndroidManifest.xml
<?xml version='1.0' encoding='utf-8'?>
<manifest package="com.project.demo" xmlns:android="http://schemas.android.com/apk/res/android">
    <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" **android:networkSecurityConfig="@xml/network_security_config"**  android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme" **android:usesCleartextTraffic="true"**>

Rishabprasad avatar Aug 02 '22 12:08 Rishabprasad

@Rishabprasad Thanks for Android studio code. Please share SSL Pinning code in React. How to call apis with ssl pinning. Please share code.

demoprojects123 avatar Aug 03 '22 07:08 demoprojects123

@Rishabprasad Can you paste the pinning code here for reference. as It is not working for self-signed certificate [Internal company] for https url. It is throwing SSLHANDSHAKEEXCEPTION ERROR after including your android studio code. I am using IONIC Framework+ React+ capacitor-community/http for api calling. HELP.!

demoprojects123 avatar Aug 03 '22 07:08 demoprojects123