自签名证书 [英] Self-signed certificate

查看:264
本文介绍了自签名证书的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I use a hosting with a self-signed certificate. So I downloaded the certificate from my domain https://www.marpel.cz/ and created .bks file using http://portecle.sourceforge.net/.

我需要从我的web服务建立HTTPS连接和检索数据。我用ksoap2库。我已经复制并使用的类<一href=\"http://$c$c.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#How_to_set_the_SSLSocketFactory_on_a_https_connection__in_order\"相对=nofollow> ConnectionWithSelfSignedCertificate 在ksoap2维基说。

I need to establish the https connection and retrieve data from my webservice. I use ksoap2 library. I have copied and used a class ConnectionWithSelfSignedCertificate stated in ksoap2 wiki.

这是我创建密钥库的方式

This is the way I create a 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的code

And this is a code from 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,信封);我得到IOException异常,主机名www.marpel.cz没有核实。我该怎么办错了?

If I call transportSE.call(SOAP_ACTION, envelope); I get IOException, Hostname 'www.marpel.cz' was not verified. What do I do wrong?

我有一个ICS 4.1.2设备。

I have an ICS 4.1.2 device.

推荐答案

在我的第一篇的code正常工作。我发现,自签名证书是为不同的域发出。我固定证书和一切工作正常。

The code in my first post works fine. I have found out that the self-signed certificate was issued for different domain. I fixed the certificate and everything works fine.

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

感谢您,马丁。

这篇关于自签名证书的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆