Bug 4784 - Crash with HttpWebRequest request through an authenticated proxy
Summary: Crash with HttpWebRequest request through an authenticated proxy
Status: RESOLVED NOT_ON_ROADMAP
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: 7.2.0 (iOS 7.1)
Assignee: Sebastien Pouliot
URL:
Depends on:
Blocks:
 
Reported: 2012-04-30 20:37 UTC by Jackson Harper
Modified: 2014-02-25 15:26 UTC (History)
3 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 NOT_ON_ROADMAP

Description Jackson Harper 2012-04-30 20:37:56 UTC
This is a simple test, posting from a network that uses an authenticated proxy to any webserver. I get the following exception:

POST Request to http://ios.jackson.org:9000
  Error: System.Net.WebException: Operation is not supported. ---> System.NotSupportedException: Operation is not supported.
  at MonoTouch.CoreFoundation.CFNetwork+CFWebProxy.get_Credentials () [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.CheckAuthorization (System.Net.WebResponse response, HttpStatusCode code) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.CheckFinalStatus (System.Net.WebAsyncResult result) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.SetResponseData (System.Net.WebConnectionData data) [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at System.Net.HttpWebRequest.EndGetResponse (IAsyncResult asyncResult) [0x00000] in <filename unknown>:0
  at System.Net.HttpWebRequest.GetResponse () [0x00000] in <filename unknown>:0
  at ProxyConnectionTest.ProxyConnectionTestViewController.RunPostTest2 () [0x00000] in <filename 

It might be hard to replicate this issue, but if you look at the CFNetwork source and the HttpWebRequest source, its pretty obvious what is happening. HttpWebRequest tries to get the underlying credentials, but CFWebProxy throws a NotSupportedException.
Comment 1 Jackson Harper 2012-05-01 09:27:16 UTC
Just updating this a little. Its even easier to see the problem without needing to setup an authenticated proxy:

var wr = (HttpWebRequest) WebRequest.Create (url);
wr.Proxy.Credentials = new NetworkCredential ("i", "love", "bananas");

will throw a NotSupportedException
Comment 2 Sebastien Pouliot 2012-05-01 09:39:43 UTC
yup, removing the NotSupportedException is easy. Just need to test that it's enough to make the proxy authentication works as expected.
Comment 3 Sebastien Pouliot 2012-05-01 14:53:55 UTC
So we could use *provided* NetworkCredential (like comment #1) but we cannot use the one kept in the iOS device configuration - since the password is not available [1] (but we can retrieve the username).

<quote>
kCFProxyPasswordKey
The password to be used when contacting the proxy. This key is only present if the password can be determined from the information passed in. (External credential stores such as the keychain are not consulted.)
</quote>

Maybe it's marked as shared in the keychain ? but I can see how iOS itself could work without this being the case...

[1] http://developer.apple.com/library/ios/#DOCUMENTATION/CoreFoundation/Reference/CFProxySupport/Reference/reference.html
Comment 4 Sebastien Pouliot 2012-05-01 16:33:48 UTC
I have no luck with finding the password with keychain (it was a long shot) so, for the moment, I'll ensure developers can provide their own NetworkCredential and expose a few more things (like the NSDictionary that includes more than what's documented).
Comment 5 Sebastien Pouliot 2012-05-02 08:45:08 UTC
The (removal of) NotSupportedException and exposing the NSDictionary is now inside maccore

5.2-series: 53e13f17ff06801fa9c2cbfa2cf9b60c210ec476
master: 77264eb579463e5ce6e1ca538b14418c97609947

I still have a few crazy ideas to try... but the only one I'm sure would work if to ask (and cache) the proxy password in the application and provide it (with code) as the NetworkCredentials.
Comment 7 PJ 2013-11-19 16:44:44 UTC
This bug was targeted for a past milestone, moving to the next non-hotfix active milestone.
Comment 8 Sebastien Pouliot 2014-02-25 15:26:10 UTC
There's not good solution for HttpWebRequest. 

However System.Net.Http.HttpClient has a CFNetwork based backend that use Apple API (and would use the OS proxy, including any password).