在Android

时间:2018-08-28 11:24:58

标签: android react-native ssl-certificate

我尝试使用访存调用https网络服务。 Web服务使用证书可以连接。我按照以下示例将其称为https://developer.android.com/training/articles/security-config。 但我有此消息:

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' }

这是我的代码:

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);
        });

我的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>

我的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>

要创建我的.pem,请使用以下命令:

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

此Web服务在IOS上起作用。我的问题仅限于Android。

0 个答案:

没有答案