Merge pull request #472 from MelanieT/spmanager_fix
[mono.git] / mcs / class / System / System.Net / ServicePointManager.cs
index 85ab3a30bfad2dff73113c260559861294898fc8..21de4e04e02fbe8f6e7bb1d3726c3c957e180929 100644 (file)
@@ -305,6 +305,8 @@ namespace System.Net
                                throw new ArgumentNullException ("address");
 
                        RecycleServicePoints ();
+
+                       var origAddress = new Uri (address.Scheme + "://" + address.Authority);
                        
                        bool usesProxy = false;
                        bool useConnect = false;
@@ -323,7 +325,7 @@ namespace System.Net
                        
                        ServicePoint sp = null;
                        lock (servicePoints) {
-                               SPKey key = new SPKey (address, useConnect);
+                               SPKey key = new SPKey (origAddress, useConnect);
                                sp = servicePoints [key] as ServicePoint;
                                if (sp != null)
                                        return sp;
@@ -456,7 +458,14 @@ namespace System.Net
                                SslPolicyErrors errors = 0;
                                X509Chain chain = null;
                                bool result = false;
-#if !MONOTOUCH
+#if MONOTOUCH
+                               // The X509Chain is not really usable with MonoTouch (since the decision is not based on this data)
+                               // However if someone wants to override the results (good or bad) from iOS then they will want all
+                               // the certificates that the server provided (which generally does not include the root) so, only  
+                               // if there's a user callback, we'll create the X509Chain but won't build it
+                               // ref: https://bugzilla.xamarin.com/show_bug.cgi?id=7245
+                               if (cb != null) {
+#endif
                                chain = new X509Chain ();
                                chain.ChainPolicy = new X509ChainPolicy ();
                                chain.ChainPolicy.RevocationMode = revocation_mode;
@@ -464,7 +473,9 @@ namespace System.Net
                                        X509Certificate2 c2 = new X509Certificate2 (certs [i].RawData);
                                        chain.ChainPolicy.ExtraStore.Add (c2);
                                }
-
+#if MONOTOUCH
+                               }
+#else
                                try {
                                        if (!chain.Build (leaf))
                                                errors |= GetErrorsFromChain (chain);