// This is invoked by
        // System.dll!System.AndroidPlatform.TrustEvaluateSsl()
        // DO NOT REMOVE
        //
        // Exception audit:
        //
        //  Verdict
        //     No need to wrap thrown exceptions in a BCL class
        //
        //  Rationale
        //     This method is called by System.AndroidPlatform.TrustEvaluateSsl which is, eventually, called by
        //     System/Mono.Net.Security/SystemCertificateValidator(). All exceptions are caught and handled
        //     by the caller.
        //
        static bool TrustEvaluateSsl(List <byte[]> certsRawData)
        {
            SetupTrustManager();

            if (sslTrustManager == null)
            {
                return(false);
            }

            var factory     = GetX509CertificateFactory();
            var nativeCerts = new Java.Security.Cert.X509Certificate [certsRawData.Count];

            for (int i = 0; i < nativeCerts.Length; ++i)
            {
                // wha? api.xml doesn't contain:  http://developer.android.com/reference/javax/security/cert/X509Certificate.html#getInstance(byte[])
                // nativeCerts [i] = Java.Security.Cert.X509Certificate.GetInstance (certs [i].RawData);
                nativeCerts [i] = ConvertCertificate(factory, certsRawData [i]);
            }
            try {
                sslTrustManager.CheckServerTrusted(nativeCerts, TrustManagerFactory.DefaultAlgorithm);
                return(true);
            }
            catch (Exception) {
                // ignore
            }
            try {
                // Trying to use the collection as a chain failed; see https://bugzilla.xamarin.com/show_bug.cgi?id=6501
                // Try just using the leaf certificate
                sslTrustManager.CheckServerTrusted(new[] { nativeCerts [0] }, TrustManagerFactory.DefaultAlgorithm);
                return(true);
            }
            catch (Exception) {
                return(false);
            }
        }
Beispiel #2
0
        internal static bool IsSignedBy(this JavaX509Certificate cert, JavaX509Certificate signingCert)
        {
            if (cert?.IssuerDN is X500Principal p1 &&
                signingCert?.SubjectDN is X500Principal p2 &&
                p1.Equals(p2))
            {
                try
                {
                    cert.Verify(signingCert.PublicKey);
                    return(true);
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Debug.WriteLine(ex);
                }
            }

            return(false);
        }
        // This is invoked by
        // System.dll!System.AndroidPlatform.TrustEvaluateSsl()
        // DO NOT REMOVE
        static bool TrustEvaluateSsl(List <byte[]> certsRawData)
        {
            SetupTrustManager ();

            if (sslTrustManager == null) {
                return false;
            }

            var factory     = GetX509CertificateFactory ();
            var nativeCerts = new Java.Security.Cert.X509Certificate [certsRawData.Count];
            for (int i = 0; i < nativeCerts.Length; ++i) {
                // wha? api.xml doesn't contain:  http://developer.android.com/reference/javax/security/cert/X509Certificate.html#getInstance(byte[])
                // nativeCerts [i] = Java.Security.Cert.X509Certificate.GetInstance (certs [i].RawData);
                nativeCerts [i] = ConvertCertificate (factory, certsRawData [i]);
            }
            try {
                sslTrustManager.CheckServerTrusted (nativeCerts, TrustManagerFactory.DefaultAlgorithm);
                return true;
            }
            catch (Exception e) {
                // ignore
            }
            try {
                // Trying to use the collection as a chain failed; see https://bugzilla.xamarin.com/show_bug.cgi?id=6501
                // Try just using the leaf certificate
                sslTrustManager.CheckServerTrusted (new[]{ nativeCerts [0] }, TrustManagerFactory.DefaultAlgorithm);
                return true;
            }
            catch (Exception e) {
                return false;
            }
        }
Beispiel #4
0
 internal static DotNetX509Certificate ToDotNetX509Certificate(this JavaX509Certificate cert)
 => new DotNetX509Certificate(cert.GetEncoded());