为什么即使在更新SSL Certificate之后也不需要更改android应用程序中固定的证书?
我在android应用程序中使用SSL为什么即使在更新SSL Certificate之后也不需要更改android应用程序中固定的证书?,android,ssl,ssl-certificate,certificate-pinning,Android,Ssl,Ssl Certificate,Certificate Pinning,我在android应用程序中使用SSLCertificate Pining,现在当我更新SSL证书时,我认为我只是在android应用程序中使用Certificate Pining而不是公钥Pining,我需要在android项目中更改证书,然后在play store上再次更新我的应用程序,但问题是我的应用程序运行完全正常,无需在我的Android项目中更新证书文件 谁能告诉我这是正常的行为吗 代码 public Certificate findCertificate() throws Cert
Certificate Pining
,现在当我更新SSL证书时,我认为我只是在android应用程序中使用Certificate Pining
而不是公钥Pining
,我需要在android项目中更改证书,然后在play store上再次更新我的应用程序,但问题是我的应用程序运行完全正常,无需在我的Android项目中更新证书文件
谁能告诉我这是正常的行为吗
代码
public Certificate findCertificate() throws CertificateException {
CertificateFactory instance = CertificateFactory.getInstance("X.509");
InputStream resourceAsStream = getResources().openRawResource(R.folder.certificate_name);
InputStream bufferedInputStream = new BufferedInputStream(resourceAsStream);
try {
Certificate generateCertificate = instance.generateCertificate(bufferedInputStream);
try {
resourceAsStream.close();
} catch (IOException e) {
}
return generateCertificate;
} finally {
try {
bufferedInputStream.close();
} catch (IOException e2) {
}
try {
resourceAsStream.close();
} catch (IOException e3) {
}
}
}
public SSLContext findSSLConfiguration(Context context) throws CertificateException, IOException,
KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
CertificateFactory cf = null;
cf = CertificateFactory.getInstance("X.509");
Certificate ca = findCertificate();
String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null);
keyStore.setCertificateEntry("ca", ca);
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null);
return sslContext;
}
public void server_call() throws CertificateException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, IOException {
OkHttpClient okHttp = new OkHttpClient.Builder()
.sslSocketFactory(findSSLConfiguration(getBaseContext()).getSocketFactory())
.build();
}
显示您的代码。@SLaks请查看我的更新代码。您确定此代码不会将证书固定到服务器证书上吗?鉴于您使用的名称,我宁愿假设“ca”是证书颁发机构(证书的颁发者,在续订时不会更改),而不是服务器证书。您在代码中实际加载的证书是什么?@SteffenUllrich certificate位于
文件夹中。certificate\u name
属于myorganization
,而不是颁发者的证书。@sudhanshugar:“属于myorganization”听起来不像服务器证书。那么,这是服务器将发送的叶证书还是不发送的叶证书,或者是某个CA证书还是什么?