Bug 4488 - MonoTouch.CoreFoundation.CFNetwork+CFWebProxy does not work for https urls
Summary: MonoTouch.CoreFoundation.CFNetwork+CFWebProxy does not work for https urls
Status: RESOLVED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: Other Other
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-04-18 00:21 UTC by David Leaver
Modified: 2012-04-18 16:51 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description David Leaver 2012-04-18 00:21:33 UTC
I've been trying to call a web service that is on HTTPS from a device with a HTTP proxy configured. It just doesn't work.
From my packet capture the device looks like it is trying to speak HTTPS to the proxy.
This issue also happens with System.Net.WebClient

To test:
Configure your device to use a HTTP proxy (I've used tinyproxy https://banu.com/tinyproxy/ as my server)
Mine is IP: 10.0.210.22, Port: 8888 in the details below

I get the proxy with any of these:
var a = System.Net.WebRequest.DefaultWebProxy;
var b = System.Net.WebRequest.GetSystemWebProxy();
var c = CFNetwork.GetDefaultProxy();

Then set the proxy on my WebClient and try get something by https:
var client = new System.Net.WebClient();
client.Proxy = a;
client.DownloadString("https://developers.google.com");

DownloadString doesn't return until a timeout occurs. A packet capture on the proxy shows some bad data and the proxy does nothing.


I believe the issue is because of this:
Console.WriteLine(a + " " + a.GetProxy(new Uri("https://developers.google.com")));
Which returns: "https://10.0.210.22:8888/"


If I instead do:
string newProxy = a.GetProxy(new Uri(ws.Url)).ToString().Replace("https:", "http:");
Console.WriteLine("Creating proxy for: " + newProxy);
client.Proxy = new System.Net.WebProxy(newProxy);

Console.WriteLine(client.Proxy.GetProxy(new Uri("https://developers.google.com")));
Now returns: "http://10.0.210.22:8888/"
And the communication all works.


This bug may also appear in MonoMac at a guess.
Comment 1 Sebastien Pouliot 2012-04-18 09:59:42 UTC
The CFNetwork API returns (at least using my own configuration) a proxy of type HTTPS - while only a hostname and port are provided to iOS (OSX has far more options, including a separate "Secure Web Proxy").

e.g. CFNetwork.GetProxiesForUri (new Uri ("https://developers.google.com"), settings) [0].ProxyType;

Of course if the proxy does not support HTTPS connections it will fail (while it works for NSUrl* types). This needs a bit more testing (on OSX) to ensure we get the right behavior in both cases.
Comment 2 Sebastien Pouliot 2012-04-18 11:48:50 UTC
https uses http + connect. I could have sworn that was tested for a previous bug report :|

Anyway it's fixed and will be in 5.2.12 (not the upcoming 5.2.11). In the meantime your workaround is fine (and it won't break once the fix is available).

5.2-series: a191ee8796fce5de6d04537156b7b3a359142e90
master: c3bdfeb959cfe84396299191f7a0525fb6cc98f9

QA: if you can set up a permanent proxy in your testing environment we could add unit tests for this.
Comment 3 David Leaver 2012-04-18 16:51:32 UTC
Awesome thanks guys! <3