3

I try to call a https webservice using fetch. The webservice uses a certificate to be able to connect. I follow this example to call it https://developer.android.com/training/articles/security-config. But I have this message:

08-28 10:57:14.191 6946-7509/com.mweb_dmc D/libc-netbsd: [getaddrinfo]: hostname=xxx.xxx.xx.xxx; servname=(null); netid=0; mark=0
    [getaddrinfo]: ai_addrlen=0; ai_canonname=(null); ai_flags=4; ai_family=0
08-28 10:57:14.192 6946-7509/com.mweb_dmc D/NativeCrypto: ssl=0xa9102280 NativeCrypto_SSL_do_handshake fd=0x97877d20 shc=0x97877d24 timeout_millis=0 client_mode=1 npn=0x0
    doing handshake ++
    ssl=0xa9102280 info_callback where=0x10 ret=1
    ssl=0xa9102280 handshake start in CINIT  before connect initialization
    ssl=0xa9102280 info_callback calling handshakeCompleted
    ssl=0xa9102280 info_callback completed
    ssl=0xa9102280 info_callback where=0x1001 ret=1
    ssl=0xa9102280 SSL_connect:CINIT  before connect initialization
    ssl=0xa9102280 info_callback ignored
    ssl=0xa9102280 info_callback where=0x1001 ret=1
    ssl=0xa9102280 SSL_connect:3WCH_A SSLv3 write client hello A
    ssl=0xa9102280 info_callback ignored
    ssl=0xa9102280 info_callback where=0x1002 ret=-1
    ssl=0xa9102280 SSL_connect:error exit in 3RSH_A SSLv3 read server hello A
    ssl=0xa9102280 info_callback ignored
    doing handshake -- ret=-1
    ssl=0xa9102280 NativeCrypto_SSL_do_handshake ret=-1 errno=11 sslError=2 timeout_millis=0
08-28 10:57:14.220 6946-7509/com.mweb_dmc D/NativeCrypto: doing handshake ++
    ssl=0xa9102280 info_callback where=0x1001 ret=1
    ssl=0xa9102280 SSL_connect:3RSH_A SSLv3 read server hello A
    ssl=0xa9102280 info_callback ignored
08-28 10:57:14.221 6946-7509/com.mweb_dmc E/NativeCrypto: ssl=0xa9102280 cert_verify_callback x509_store_ctx=0x97877b4c arg=0x0
    ssl=0xa9102280 cert_verify_callback calling verifyCertificateChain authMethod=ECDHE_RSA
08-28 10:57:14.225 6946-7509/com.mweb_dmc D/NativeCrypto: ssl=0xa9102280 cert_verify_callback => 0
08-28 10:57:14.226 6946-7509/com.mweb_dmc D/OpenSSLLib: OpensslErr:Module:16(190:126); file:external/boringssl/src/ssl/s3_clnt.c ;Line:984;Function:ssl3_get_server_certificate
08-28 10:57:14.226 6946-7509/com.mweb_dmc D/NativeCrypto: ssl=0xa9102280 info_callback where=0x4008 ret=558
    ssl=0xa9102280 SSL3 alert write:F:CU fatal certificate unknown
    ssl=0xa9102280 info_callback ignored
    ssl=0xa9102280 info_callback where=0x1002 ret=-1
    ssl=0xa9102280 SSL_connect:error exit in 3RSC_B SSLv3 read server certificate B
    ssl=0xa9102280 info_callback ignored
    doing handshake -- ret=-1
08-28 10:57:14.227 6946-7509/com.mweb_dmc D/NativeCrypto: ssl=0xa9102280 NativeCrypto_SSL_do_handshake exception => 0
08-28 10:57:14.227 6946-7509/com.mweb_dmc I/System.out: close [socket][/192.168.1.91:56795]
08-28 10:57:14.228 6946-7509/com.mweb_dmc I/System.out: close [socket][/:::56795]
08-28 10:57:14.302 883-992/? I/libPerfService: 5: set freq: 819000
    5: set: 3
08-28 10:57:14.345 6946-7288/com.mweb_dmc I/ReactNativeJS: { [Error: Erreur Connexion avec le serveur]
      line: 119532,
      column: 24,
      sourceURL: 'http://localhost:8081/index.delta?platform=android&dev=true&minify=false' }

This is my code:

fetch('https://xxx.xxx.xxx.xxx:1443/orawsv/ABL/WSS_MWEB_LOGIN/GETLOGIN', {
    method: 'POST',
    mode: 'cors',
    headers: headers,
    credentials: 'include',
    body:  sr
  }
        .then(function(response) {
          if(!response.ok)
          {
              cosole.error(response)
          throw new Error(response);
          }
          Alert.alert("OK")

        .catch((error) => {

          console.log(error);
        });

My AndroidManifest:

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mweb_dmc">

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW"/>

    <application
      android:name=".MainApplication"
      android:label="@string/app_name"
      android:icon="@mipmap/ic_launcher"
      android:allowBackup="false"
      android:networkSecurityConfig="@xml/network_security_config"
      android:theme="@style/AppTheme">
      <activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:configChanges="keyboard|keyboardHidden|orientation|screenSize"
        android:windowSoftInputMode="adjustResize">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
      </activity>
      <activity android:name="com.facebook.react.devsupport.DevSettingsActivity" />
    </application>

</manifest>

my network_security_config.xml :

 <?xml version="1.0" encoding="utf-8"?>
<network-security-config>
    <domain-config>
        <domain includeSubdomains="true">xxx.xxx.xxx.xxx:1443/</domain>
        <trust-anchors>
            <certificates src="@raw/dmc_ca"/>
        </trust-anchors>
    </domain-config>
    <domain-config cleartextTrafficPermitted="true">
        <domain includeSubdomains="true">xxx.xxx.xxx.xxx:1443/</domain>
    </domain-config>
</network-security-config>

To create my .pem I use the command :

openssl s_client -connect xxx.xxx.xxx.xxx:1443 -certform pem

This webservice functions on IOS. My problem is only on Android.

user3884677
  • 413
  • 5
  • 26
  • 1
    when you put something like `new URL("https://xxx.xxx.xxx.xxx:1443/orawsv/ABL/WSS_MWEB_LOGIN/GETLOGIN").openConnection().connect();` do you get the same ssl error? (Trying to determine if react does something funny with the ssl config) – zapl Aug 28 '18 at 12:27
  • I do not understand where I have to try this code? React do not know new URL(). I have this error : "creating url object is not supported yet" – user3884677 Aug 29 '18 at 13:09
  • 1
    This is Java and meant to be put in some Activity in an AsyncTask, Thread, or something other that runs off the ui thread. But I don't know if / how you can put java in a react-native project. I also think that `network-security-config` is only honored by devices that run API Level 24 or higher (i.e. Android 7.0 Nougat). Maybe you do have to load the truststore / certificate in code and build a customized http client. https://stackoverflow.com/questions/40240321/how-can-i-implement-ssl-certificate-pinning-while-using-react-native might be the way to do that. – zapl Aug 29 '18 at 18:22
  • Thank you for the link. But I can't use this code correctly. – user3884677 Sep 03 '18 at 12:39

0 Answers0