【问题标题】:Mutual authentication Android and TomcatAndroid和Tomcat相互认证
【发布时间】:2015-02-03 08:21:54
【问题描述】:

我想为我的应用程序和服务器进行相互身份验证。 我按照这个步骤:

1) 创建一个证书。和服务器 tomcat 的密钥库 (tomcat.keystore)

2) 创建一个证书。给客户

3) 导入客户端证书。进入服务器密钥库

4) 为 Android 创建一个 bks 密钥库 (smartssl.bks)

5) 导入证书。服务器和客户端进入 Android 密钥库

现在我配置 Tomcat:

<Connector SSLEnabled="true" clientAuth="true"
            keystoreFile="/home/antonio/Documenti/keystore/tomcat.keystore"
            keystorePass="pass" maxThreads="150" port="8443" scheme="https"
            secure="true" sslProtocol="TLS"
            truststoreFile="/home/antonio/Documenti/keystore/tomcat.keystore"
            truststorePass="pass" />

在 Android 应用中,我使用这样的 Volley 框架:

 InputStream keyStore = getResources().openRawResource(R.raw.smartssl);

                // Usually getting the request queue shall be in singleton like in {@see Act_SimpleRequest}
                // Current approach is used just for brevity
                RequestQueue queue = Volley
                        .newRequestQueue(Act_SsSslHttpClient.this,
                                         new ExtHttpClientStack(new SslHttpClient(keyStore, "pass", 443)));

                StringRequest myReq = new StringRequest(Method.GET,
                                                        "https://192.168.1.4:8443/REST/app/generali/getA",
                                                        createMyReqSuccessListener(),
                                                        createMyReqErrorListener()){
                @Override
                public Map<String, String> getHeaders() throws AuthFailureError {
                    return createBasicAuthHeader("user", "strongpassword");
                }};

                queue.add(myReq);
            }
        });

有了这个配置。我有这个错误:

no peer certificate 

如果我尝试使用此更改 Tomcat 配置:

clientAuth="false"

有效,所以问题出在 bks 文件中?还是在哪里?

【问题讨论】:

    标签: java android tomcat ssl


    【解决方案1】:

    我通过在应用程序中放入 BKS 中的 Keystore 和 Truststore 来解决。

    这里有一个创建自我证书的指南:

    Create a self certificate for client and server

    这里有一个使用 Volley 进行相互身份验证的类示例:

    Example class for Mutual auth TLS/SSL

    Class SSLSocket

    【讨论】:

    • 嗨@antonio,我试过上面的教程但没能成功。能否请您提供我的示例 android 项目。我的 android 应用程序抛出以下异常:java.security.GeneralSecurityException: Problem reading keystore stream
    • @IB 可能你的密钥库是 BKS2.. 尝试使用 keyexplorer 创建密钥库并选择 bks
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-01-11
    • 1970-01-01
    • 2018-09-02
    • 2012-11-19
    • 2012-09-12
    • 2014-03-03
    • 1970-01-01
    相关资源
    最近更新 更多