[英]how to verify the validity of SSL certificate in an Android application
I need to verify SSL certificate validity before making a service call. 在进行服务呼叫之前,我需要验证SSL证书的有效性。 If certificate is not valid I need to show an alert. 如果证书无效,则需要显示警报。 Please give me some idea on this. 请给我一些想法。
Host name validation can be customizez by setting a custom X509HostnameVerifier
on the SSLSocketFactory
. 可以通过在SSLSocketFactory
上设置自定义X509HostnameVerifier
来自定义主机名验证。 Some implementations are already available in android: AllowAllHostnameVerifier
, BrowserCompatHostnameVerifier
, StrictHostnameVerifier
/* ... */ 某些实现已在android中提供: AllowAllHostnameVerifier
, BrowserCompatHostnameVerifier
, StrictHostnameVerifier
/ * ... * /
public class MyHostnameVerifier extends AbstractVerifier {
boolean verify(String hostname, SSLSession session) {
X509Certificate[] chain = session.getPeerCertificateChain();
/* made some checks... */
return checked;
}
}
sslSocketFactory.setHostnameVerifier(new MyHostnameVerifier());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.