1

我需要自己的 CA 来验证 SSL 连接中的自己的证书。我正在尝试这个,但不起作用:

            try {
                AssetManager assetManager = getApplicationContext().getAssets();
                InputStream inStrm = assetManager.open("cacert-devel.der");

                Intent intent = KeyChain.createInstallIntent();
                CertificateFactory cf = CertificateFactory.getInstance("X.509");
                X509Certificate x509 = (X509Certificate) cf.generateCertificate(inStrm);
                inStrm.close();
                intent.putExtra(KeyChain.EXTRA_CERTIFICATE, x509.getEncoded());
                intent.putExtra(KeyChain.EXTRA_NAME,"PCA");
                startActivity(intent);
            } catch (CertificateException e1) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

我如何测试是否安装了 CA?在这个 SSL 到这个 CA 的服务器之后,返回:

            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpGet httpget = new HttpGet();
            HttpResponse response = null;
            httpget.setURI(new URI("https://url...");
            response = httpclient.execute(httpget);
            StatusLine status = response.getStatusLine();
            int statuscode = status.getStatusCode();
            if (statuscode != 200){
                Log.e("GET", "Status"   + statuscode);
            }else{
                Log.e("GET","Status:"  + statuscode);
            }

IO 异常javax.net.ssl.SSLPeerUnverifiedException:没有对等证书

有什么建议吗?

4

0 回答 0