如何在react-native中集成自定义证书和trustmanager?

时间:2017-10-18 06:13:00

标签: android ios react-native

这是android java中的代码。什么是反应原生的等价物? stack over flow不允许我发布大部分代码。所以这只是无用的细节。我的问题已经结束了。

        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);tmf.init(keystore);

        KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");

        kmf.init(keystore, "PASSWORD".toCharArray());

        TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
            public java.security.cert.X509Certificate[] getAcceptedIssuers() {
                return new java.security.cert.X509Certificate[] {};
            }

            public void checkClientTrusted(X509Certificate[] chain,
                                           String authType) throws CertificateException {
            }

            public void checkServerTrusted(X509Certificate[] chain,
                                           String authType) throws CertificateException {
            }
        } };
        final SSLContext sc = SSLContext.getInstance("TLSv1.2");
        sc.init(kmf.getKeyManagers(), trustAllCerts, new java.security.SecureRandom());
        final SSLSocketFactory socketFactory = sc.getSocketFactory();
        HttpsURLConnection.setDefaultSSLSocketFactory(socketFactory);
        urlConnection.setSSLSocketFactory(sc.getSocketFactory());

0 个答案:

没有答案