Certificate Pinning Issue with TLS1.2 Enabled Server

139 views Asked by At

While I am pinning the certificate in iOS and android using below code my callback is getting called and pinning is done, but while server is updated with TLS1.2 our callback is getting called for iOS, but its not getting called in Android.

void PinServerCertificate()
    {
        try
        {
            ServicePointManager.ServerCertificateValidationCallback += ServicePointManager_ServerCertificateValidationCallback;
            WebRequest wr = WebRequest.Create(GlobalVariables.BaseURL);
            wr.GetResponse();
        }
        catch (Exception ex)
        {
            RemoLogger.Log("Exception" + ex.Message);
        }
    }
bool ServicePointManager_ServerCertificateValidationCallback(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors)
    {
        if (null == certificate)
        {
            CertificateValidation.IsValid = false;
            return false;
        }
        string pk = certificate.GetPublicKeyString();
        if (pk.Equals(this.publicKey))
        {
            CertificateValidation.IsValid = true;
            return true;
        }
        CertificateValidation.IsValid = false;
        return false;
    }

Followed below link for TLS1.2 support

We checked with AndroidClientHandler and Managed[HttpClientHandler], but not getting any solution, please suggest what's going wrong in android.

Appreciate your help

0

There are 0 answers