【问题标题】:Self-signed certificate自签名证书
【发布时间】:2013-02-22 23:14:33
【问题描述】:

我使用带有自签名证书的主机。所以我从我的域https://www.marpel.cz/ 下载了证书,并使用http://portecle.sourceforge.net/ 创建了.bks 文件。

我需要建立 https 连接并从我的网络服务中检索数据。我使用 ksoap2 库。我已经复制并使用了 ksoap2 wiki 中所述的 ConnectionWithSelfSignedCertificate 类。

这就是我创建 keyStore 的方式

    MainActivity.java
    // Get an instance of the Bouncy Castle KeyStore format
    try {
        this.keyStore = KeyStore.getInstance("BKS");
    } catch (KeyStoreException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // Get the raw resource, which contains the keystore with
    // your trusted certificates (root and any intermediate certs)
    InputStream in = this.getApplicationContext().getResources().openRawResource(R.raw.myCer);
    try {
        // Initialize the keystore with the provided trusted certificates
        // Also provide the password of the keystore
        this.keyStore.load(in, "myPass".toCharArray());
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }finally {
        try {
            in.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    try {
        this.sslSocketFactory = new ConnectionWithSelfSignedCertificate(this.keyStore).getSSLSocketFactory();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

这是来自 AsyncTask 的代码

background task
final HttpsTransportSE transportSE = new HttpsTransportSE(URL, PORT, SERVICE, TIMEOUT);

    try {
        ((HttpsServiceConnectionSE) transportSE.getServiceConnection()).setSSLSocketFactory(this.sslSocketFactory);
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

如果我调用 transportSE.call(SOAP_ACTION, envelope);我收到 IOException,未验证主机名“www.marpel.cz”。我做错了什么?

我有一个 ICS 4.1.2 设备。

【问题讨论】:

    标签: java android ssl-certificate ksoap2


    【解决方案1】:

    首先,您使用自签名证书吗?

    如果是,请点击此链接:android-webservices-via-ksoap2-https

    您需要额外的类来创建 https 连接和接受证书。一切准备就绪后,您可以拨打您的transportSE

    【讨论】:

      【解决方案2】:

      我第一篇文章中的代码运行良好。我发现自签名证书是为不同的域颁发的。我修复了证书,一切正常。

      固定证书在这里运行https://www.marpel.cz:445/

      谢谢你,马丁。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-08-04
        • 1970-01-01
        • 2012-11-01
        • 2017-03-15
        • 2016-11-25
        • 1970-01-01
        相关资源
        最近更新 更多