Bug 20868 - CFNetwork.GetDefaultProxy does not return proxy details
Summary: CFNetwork.GetDefaultProxy does not return proxy details
Status: RESOLVED DUPLICATE of bug 1081
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.4
Hardware: PC Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Bugzilla
Depends on:
Reported: 2014-06-25 04:51 UTC by Prashant Cholachagudda
Modified: 2015-04-17 11:27 UTC (History)
5 users (show)

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:

Description Prashant Cholachagudda 2014-06-25 04:51:26 UTC
The CFNetwork.GetDefaultProxy does not return correct proxy details and results in an exceptions

Sample code:

HttpWebRequest request = new HttpWebReqeust(new Uri(“https://developer.apple.com”));
request.Proxy = CFNetwork.GetDefaultProxy();
request.Method = “GET”;
WebResponse response = request.GetResponse();

The following exception is thrown at request.GetResponse()
Message Error:ConnectFailure
StackTrace at System.Net.HttpWebRequest.EndGetResponse(IAsyncReslult asyncReslut)[0x0000]in<filename unknown>:0 at System.Net.HttpWebRequest.GetResponse()[0x00000]in<filename unknown>:0 at… my solution caller.

This could be a duplicate of #19135
Comment 1 Ram Chandra 2014-06-25 07:08:18 UTC
I have checked this issue and I am getting the same behaviour.

Steps to reproduce:

1. Create an iOS "Single View Application" on XS
2. Write the following code in "ViewDidLoad() method"

            HttpWebRequest request = new HttpWebRequest(new Uri("https://developer.apple.com"));
            request.Proxy = CFNetwork.GetDefaultProxy();
            request.Method = "GET";
            WebResponse response = request.GetResponse();

3. Setup Charles Proxy (http://blog.cloudfour.com/using-charles-proxy-to-examine-ios-apps/)
4. Deploy the application on device. 

Case1: When charles proxy is not running.

I am getting the same exception when my charles proxy is not running.

Screencast: http://www.screencast.com/t/izxCDA2pKKNA
Exception Detail: https://gist.github.com/saurabh360/0551b60249345f7b2de8

Case2: When charles proxy is running.

When I setup charles proxy and deploy the application on device I observed that "request.GetResponse();" doesn't throw any exception any my app is working fine and deploy successfully on device.

Screencast: http://www.screencast.com/t/HmmYEHX9fB6l

Could you please check your charles proxy is running or not?

Environment Info:

Mac OS X 10.9.3
Xamarin Studio:5.0.1 (build 3)
Xamarin.iOS: (Enterprise Edition)

Build Information

Release ID: 500010003
Git revision: f94ee866936d25105704eb63728ad5a981eda0a4
Build date: 2014-06-04 12:19:12-04
Xamarin addins: 1a6044e8321ea07e03a56b5381951686c82fed8b
Comment 2 Vachel 2014-06-25 22:47:42 UTC
Yes, I have the same result as yours in your scenarios.
But if you read all my emails then you will find what the real defect is.
Below is the reproduce steps.
1. Setup a proxy which can configure the user access control. I didn't find this function in Charles Proxy. I used CCProxy and configure it in the Account tab. You can get the free CCProxy from http://www.youngzsoft.net/ccproxy/.
2. Configure the Wi-Fi proxy settings with the user and password configured in step 1 in your iOS device.
3. Run the test app you should get the same exception.
4. Access the “https://developer.apple.com” from Safari, you should get through and there should be logs in the CCProxy as well.
Comment 3 Rolf Bjarne Kvinge [MSFT] 2014-07-04 02:37:49 UTC
Jeff, this looks like your area. Could it be the issue where we don't get access to the user password for the proxy because iOS doesn't expose it?
Comment 4 Jeffrey Stedfast 2014-07-21 09:22:07 UTC
Rolf: It's possible, I don't know anything about iOS not exposing the proxy password though.

What I can tell you is that we can't support all proxy types, so it could be that the proxy type that he configured is one of the ones that is not supported (such as SOCKS).
Comment 5 Vachel 2014-07-23 21:28:19 UTC
Jeffrey, I am using Https proxy, and this issue occurs only while authentication is required in the proxy server.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2015-04-16 13:45:41 UTC

*** This bug has been marked as a duplicate of bug 1081 ***
Comment 7 Felix Deimel 2015-04-16 13:48:57 UTC
https://bugzilla.xamarin.com/show_bug.cgi?id=1081 is about MonoTouch, this however, is about CFNetwork which is available on both, iOS and OS X.
As far as I know it's possible to gather the required information on OS X so this shouldn't be dismissed.
Comment 8 Rolf Bjarne Kvinge [MSFT] 2015-04-16 14:10:44 UTC
@Felix, would you happen to know how to get the proxy password?

From what I can tell, CFProxySupport won't look in the keychain (or anywhere else) [1]:

"The keys for username and password are optional and are present only if the username or password could be extracted from the information passed in (either from the URL itself or from the proxy dictionary supplied). These APIs do not consult any external credential stores such as the Keychain."

and without the password we can't support proxies that require authentication.

[1] https://developer.apple.com/library/mac/documentation/CoreFoundation/Reference/CFProxySupport/index.html
Comment 9 Rolf Bjarne Kvinge [MSFT] 2015-04-16 14:14:45 UTC
It's of course possible to use the Keychain API to lookup the password, but IMHO that's a bit out of scope for CFNetwork, apps can do that themselves if they need it.
Comment 10 Felix Deimel 2015-04-16 16:01:56 UTC
@Rolf: That's right, the password isn't exposed by any of those classes but since you should have access to the username and proxy host, you should be able to look it up in Keychain yourself.

Here's some code I previously used for this task: https://gist.github.com/lemonmojo/e4d6f93075fe6d3a91a1

Disclaimer: I haven't used this in quite some time so it's untested.
Comment 11 Felix Deimel 2015-04-16 16:04:26 UTC
@Rolf: Sorry, only saw your comment after I posted mine. I guess I agree with what you said but the problem here is that in the end, one has to write quite a bit of code just to get "proper" proxy support using any of the Mono networking classes. Do you have another idea for making this easier for users?
Comment 12 Rolf Bjarne Kvinge [MSFT] 2015-04-17 11:27:07 UTC
SecKeychainFindInternetPassword is already bound: http://macapi.xamarin.com/?link=M%3aMonoMac.Security.SecKeyChain.FindInternetPassword, so it shouldn't be difficult to port your code to C#.