信任所有证书吗? X509证书

发布于 2024-12-06 12:01:25 字数 2541 浏览 1 评论 0 原文

我有以下通过 HTTPS 连接的代码,但在连接尝试期间出现以下错误。

警告/System.err(9456): javax.net.ssl.SSLHandshakeException: org.bouncycastle.jce.exception.ExtCertPathValidatorException:无法验证证书签名。

我该如何解决这个问题? 信任所有证书吗?我该怎么做? 这不会有问题,因为我只连接到同一台服务器。 财年我已经将 EasyX509TrustManager 作为我的应用程序中的一个类实现了。

先感谢您。

 try {
            HttpClient client = new DefaultHttpClient();
            // Setting up parameters 
            SchemeRegistry schemeRegistry = new SchemeRegistry(); 
            // http scheme 
            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
            // https scheme 
            schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); 

            HttpParams params = new BasicHttpParams(); 
            params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); 
            params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); 
            params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); 
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 

            ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); 

            DefaultHttpClient httpClient = new DefaultHttpClient(cm, client.getParams()); 


            // Example send HttpsPost request 
            final String url = "https://www.xxxx.com/web/restricted/form/formelement"; 

            // Do the HTTPS Post
            HttpPost httpPost = new HttpPost(url); 

                ArrayList<NameValuePair> postParameters; 
            postParameters = new ArrayList<NameValuePair>(2); 
            postParameters.add(new BasicNameValuePair("usr_name", username)); 
            postParameters.add(new BasicNameValuePair("usr_password", password));

            System.out.println(postParameters); 

            HttpResponse response = httpClient.execute(httpPost);
            Log.w("Response ","Status line : "+ response.toString());

嗨彼得,

谢谢你的回答,我听从了你的建议,无法验证的消息消失了。但是现在我收到以下消息:

09-26 23:47:20.381: WARN/ResponseProcessCookies(10704): Cookie 被拒绝:“BasicClientCookie[version=0,name=ObFormLoginCookie,domain=www.kpn.com,path=/ web/restricted/form?formelement=512663,expiry=null]”。非法路径属性“/web/restricted/form?formelement=512663”。来源路径:“/web/restricted/form/formelement=512663” 09-26 23:47:20.461:警告/响应(10704):状态行:org.apache.http.message.BasicHttpResponse@407afb98

那么标题中似乎有问题?

I have following code which connects through HTTPS but i am getting following error during connection attempt.

WARN/System.err(9456): javax.net.ssl.SSLHandshakeException:
org.bouncycastle.jce.exception.ExtCertPathValidatorException: Could not validate certificate signature.

How do i get this solved?
Trust all certificates? how do i do that?
It would be no issue as i only connect to the same server.
FY i already implemented EasyX509TrustManager as a class in my app.

Thank you in advance.

 try {
            HttpClient client = new DefaultHttpClient();
            // Setting up parameters 
            SchemeRegistry schemeRegistry = new SchemeRegistry(); 
            // http scheme 
            schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); 
            // https scheme 
            schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443)); 

            HttpParams params = new BasicHttpParams(); 
            params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 30); 
            params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(30)); 
            params.setParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, false); 
            HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); 

            ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry); 

            DefaultHttpClient httpClient = new DefaultHttpClient(cm, client.getParams()); 


            // Example send HttpsPost request 
            final String url = "https://www.xxxx.com/web/restricted/form/formelement"; 

            // Do the HTTPS Post
            HttpPost httpPost = new HttpPost(url); 

                ArrayList<NameValuePair> postParameters; 
            postParameters = new ArrayList<NameValuePair>(2); 
            postParameters.add(new BasicNameValuePair("usr_name", username)); 
            postParameters.add(new BasicNameValuePair("usr_password", password));

            System.out.println(postParameters); 

            HttpResponse response = httpClient.execute(httpPost);
            Log.w("Response ","Status line : "+ response.toString());

Hi Peter,

Thx for your answer, i followed your advise and the could not validate message is gone. However now i am getting the following message:

09-26 23:47:20.381: WARN/ResponseProcessCookies(10704): Cookie rejected: "BasicClientCookie[version=0,name=ObFormLoginCookie,domain=www.kpn.com,path=/web/restricted/form?formelement=512663,expiry=null]". Illegal path attribute "/web/restricted/form?formelement=512663". Path of origin: "/web/restricted/form/formelement=512663"
09-26 23:47:20.461: WARN/Response(10704): Status line : org.apache.http.message.BasicHttpResponse@407afb98

So something seems to be wrong in the headers?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

等风也等你 2024-12-13 12:01:25

不要相信所有证书,这是一个非常非常糟糕的主意。使用服务器的证书创建密钥库,放入应用程序的原始资产,然后将其加载到 HttpClient 的 SSLSocketFactory。然后在 SchemeRegistry 中为 https 注册该工厂。

Don't trust all certificates, that is a very, very bad idea. Create a keystore with your server's certificate, put in the app's raw assets, and load it into HttpClient's SSLSocketFactory. Then register this factory for https in the SchemeRegistry.

望笑 2024-12-13 12:01:25

您需要提供自己的信任所有证书的 TrustManager

请参阅此答案:HTTPS 和自签名证书问题

You need to provide your own TrustManager which trusts all certificates.

See this answer: HTTPS and self-signed certificate issue

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文