Quantcast
Channel: Ionic Forum - Latest topics
Viewing all articles
Browse latest Browse all 70920

Fail to fetch to CouchDB server using self-signed certificate from physical Android - Ionic

$
0
0

I’m developing an app that requests documents from a CouchDB server, when running the same code using ionic serve from a computer, it works, when using inside Android (On my physical cellphone), I get a fail to fetch.

My CouchDB server is running using self-signed certificate.
My server has CORS enabled:

pnpm install -g add-cors-to-couchdb
add-cors-to-couchdb http://192.168.1.27:5984 -u admin -p xxxx

My code uses PouchDB

    this.rdb = new PouchDB('https://192.168.1.2:6984/employees',
    {
      auth: {
        username: "xxxx",
        password: "xxxx",
      },
    });

Inspecting the calls from the Android app I get this error message:

When I open the same url (https://192.168.1.2:6984) inside a browser using my cellphone, it works.

My App has many settings:
AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:networkSecurityConfig="@xml/network_security_config" >

    <application
        android:usesCleartextTraffic="true"
        tools:ignore="GoogleAppIndexingWarning">
        <uses-library
            android:name="org.apache.http.legacy"
            android:required="false" />
    ...
    </application>
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
</manifest>

network_security_config.xml

<?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">localhost</domain>
        <domain includeSubdomains="true">192.168.1.27</domain>
    </domain-config>
    <base-config cleartextTrafficPermitted="true">
        <trust-anchors>
            <certificates src="system" />
            <certificates src="user" />
        </trust-anchors>
    </base-config>
    <debug-overrides>
      <trust-anchors>
          <certificates src="@raw/couchdb"/>
      </trust-anchors>
  </debug-overrides>
</network-security-config>

I renamed and copied my certificate from couchdb.pem to:
android/app/src/main/res/raw/couchdb.crt
and to:
android/app/src/main/assets/couchdb.crt

capacitor.config.ts

...
  server: {
    androidScheme: 'https',
    allowNavigation: ['https://192.168.1.27:6984/employees']
  }
...

CouchDB Server settings

local.ini

[ssl]
enable = true
cert_file = /etc/couchdb/cert/couchdb.pem
key_file = /etc/couchdb/cert/privkey.pem

I generated my certificate using:

openssl req -newkey rsa:2048 -nodes -x509 -keyout privkey.pem -out couchdb.pem -days 1095 -addext "subjectAltName = IP.1:192.168.1.27"

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 70920

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>