Skip to content
This repository has been archived by the owner on Sep 26, 2022. It is now read-only.

Request to https domain fails with SSLHandshakeException. #260

Open
Petru-design opened this issue May 29, 2022 · 5 comments
Open

Request to https domain fails with SSLHandshakeException. #260

Petru-design opened this issue May 29, 2022 · 5 comments

Comments

@Petru-design
Copy link

Petru-design commented May 29, 2022

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
@Rishabprasad
Copy link

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

@demoprojects123
Copy link

@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.

@Rishabprasad
Copy link

  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"**>

@demoprojects123
Copy link

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

@demoprojects123
Copy link

@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.!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants