webView证书校验:
通过chrome浏览器拿到证书cer文件
获取证书公钥
public void readX509CerFile() {
try {
InputStream inStream = getAssets().open("ccc.cer");
// 创建X509工厂类
CertificateFactory cf = CertificateFactory.getInstance("X.509");
// 创建证书对象
X509Certificate oCert = (X509Certificate) cf
.generateCertificate(inStream);
inStream.close();
String info = null;
// 获得证书版本
Log.d(TAG, "publicKey: " + oCert.getPublicKey());
} catch (Exception e) {
e.printStackTrace();
}
}
证书公钥类
public class SslCert {
public static final String[] keys = new String[]{
"30820122300d06092a864886f70d01010105000382010f003082010a0282010100证书公钥0203010001"
};
}
判断证书接口类
public class SslInterfance {
public interface SslInterfase {
void signSslResult(boolean result);
}
private static SslInterfase mSslInterfase;
public static void setSslInterfase(SslInterfase sslInterfase) {
mSslInterfase = sslInterfase;
}
public static void getUnsafeFromService(String url) {
String[] publicKeys = SslCert.keys;
try {
X509TrustManager[] trustManagers = new X509TrustManager[]{
new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
if (x509Certificates == null) {
throw new IllegalArgumentException("check Service x509Certificates is null