gpt4 book ai didi

android - 信任所有证书? X509证书

转载 作者:行者123 更新时间:2023-11-30 04:31:54 25 4
gpt4 key购买 nike

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

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

我该如何解决这个问题?信任所有证书?我怎么做?这没问题,因为我只连接到同一台服务器。仅供引用,我已经在我的应用程序中将 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,过期=空]”。非法路径属性“/web/restricted/form?formelement=512663”。来源路径:“/web/restricted/form/formelement=512663”09-26 23:47:20.461:警告/响应(10704):状态行:org.apache.http.message.BasicHttpResponse@407afb98

所以标题中似乎有问题?

最佳答案

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

关于android - 信任所有证书? X509证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7561142/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com