Add preliminary HTTPS handling support for Android.
authorJonathan Pryor <jonpryor@vt.edu>
Tue, 12 Oct 2010 21:43:45 +0000 (17:43 -0400)
committerJonathan Pryor <jonpryor@vt.edu>
Tue, 12 Oct 2010 21:47:53 +0000 (17:47 -0400)
The problem is that Android only exposes Java APIs for ~everything of
consequence, including/especially X509 Certificate validation.  Since
we want Mono-based HTTPS support to use the underlying platform
certificates, this requires some amount of Java-using glue.  However,
we don't want to pull in a ton of Java glue into System.dll (bleh!),
so we'll instead place the glue into Mono.Android.dll's
Android.Runtime.AndroidEnvironment.TrustEvaluateSsl(), and instead
create a delegate which will invoke TrustEvaluateSsl() when needed.

mcs/class/System/System.Net/ServicePointManager.cs

index 35f0aeea14e7d309fa478320614f80933b7c25e9..2b84c0c5e64a59cc414b11471bd1786753682c94 100644 (file)
@@ -402,8 +402,19 @@ namespace System.Net
                        static bool is_macosx = System.IO.File.Exists (MSX.OSX509Certificates.SecurityLibrary);
                        static X509RevocationMode revocation_mode;
 
+#if MONODROID
+                       static readonly Converter<Mono.Security.X509.X509CertificateCollection, bool> monodroidCallback;
+#endif
+
                        static ChainValidationHelper ()
                        {
+#if MONODROID
+                               monodroidCallback = (Converter<Mono.Security.X509.X509CertificateCollection, bool>)
+                                       Delegate.CreateDelegate (typeof(Converter<Mono.Security.X509.X509CertificateCollection, bool>), 
+                                                       Type.GetType ("Android.Runtime.AndroidEnvironment, Mono.Android", true)
+                                                       .GetMethod ("TrustEvaluateSsl", 
+                                                               System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic));
+#endif
                                revocation_mode = X509RevocationMode.NoCheck;
                                try {
                                        string str = Environment.GetEnvironmentVariable ("MONO_X509_REVOCATION_MODE");
@@ -498,6 +509,14 @@ namespace System.Net
                                }
 #endif
 
+#if MONODROID
+                               result = monodroidCallback (certs);
+                               if (result) {
+                                       status11 = 0;
+                                       errors = 0;
+                               }
+#endif
+
                                if (policy != null && (!(policy is DefaultCertificatePolicy) || cb == null)) {
                                        ServicePoint sp = null;
                                        HttpWebRequest req = sender as HttpWebRequest;