Why there is no need to change Certificate pinned in android app even after Renewing SSL Certifcate?

198 Views Asked by At

I am using SSL Certificate Pining in my android app, now when I renewed the SSL Certificate then I thought as I am only doing Certificate Pining not Public Key Pining in my Android App I will need to change Certificate in my android project and again update my app on the play store, but the thing is my app is working completely fine without the need to update Certificate file in my Android Project.

Can anyone please tell me is this the normal behaviour ??

Code

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();
    }
0

There are 0 best solutions below