小编Edu*_*ero的帖子

SSLHandshakeException:找不到证书路径的信任锚.仅适用于Android API <19

我遇到了与设备<api 19上带有自签名证书的服务器的https连接问题.我按照android发布的这个指南来信任自签名证书Android SSL,它似乎可以正常使用所有api> 19我测试的设备.我如何继续在19号前获得"未找到证书路径的信任锚"错误.

我使用keytool创建了密钥库,但似乎不是问题因为正在使用某些设备.

这是我的代码:

        URL url_uri = new URL(url);
        AssetManager am = context.getAssets();
        InputStream caInput = am.open("certs/myCert.bks");
        KeyStore keyStore;
        try {
            keyStore = KeyStore.getInstance("BKS");
            char[] pass = "MyPassword".toCharArray();
            keyStore.load(caInput, pass);
        } finally {
            caInput.close();
        }

        // Create a TrustManager that trusts the CAs in our KeyStore
        String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
        TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
        tmf.init(keyStore);

        // Create an SSLContext that uses our TrustManager
        SSLContext context = SSLContext.getInstance("TLS");
        context.init(null, tmf.getTrustManagers(), null);

        HttpsURLConnection urlConnection =
                (HttpsURLConnection)url_uri.openConnection();
        urlConnection.setSSLSocketFactory(context.getSocketFactory());

        InputStream …
Run Code Online (Sandbox Code Playgroud)

ssl android keystore ssl-certificate truststore

6
推荐指数
0
解决办法
503
查看次数

标签 统计

android ×1

keystore ×1

ssl ×1

ssl-certificate ×1

truststore ×1