9
이미 프로젝트에서 leaf 인증서를 구현 했으므로 잘 작동합니다. 아래 코드를 확인하십시오. 이제 잎 증명서가 1 년 후에 내 서버에서 만료되므로 잎 인증서의 유효성을 검사하여 유효 기간이 만료되었거나 유효하지 않을 때 중간 인증서를 사용할 수 있습니까?Android에서 리프/중간 인증서 고정을 구현하는 방법은 무엇입니까?
중간 인증서를 구현하는 예가 있습니까?
도와주세요!
코드 : -
SSLContext sslContext = null;
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
InputStream caInput = context.getResources().openRawResource(certRawRef);
Certificate ca;
try {
ca = cf.generateCertificate(caInput);
} finally {
caInput.close();
}
// Create a KeyStore containing our trusted CAs
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
// Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager
sslContext = SSLContext.getInstance("TLSv1.2");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext;
} catch (Exception e) {
Log.e("EXCEPTION",e.toString());
//Print here right certificate failure issue
}
이 문서가 당신을 도울 수 ... HTTPS : //medium.com/@appmattus/android-security- ssl-pinning-1db8acb6621e – PN10