karlwancl / GoogleCloudPrintApi

A .NET wrapper for Google Cloud Print API, based on .NET standard 1.4
MIT License
12 stars 14 forks source link

Issues surrounding dependencies #4

Closed Jezternz closed 7 years ago

Jezternz commented 7 years ago

The library has been working perfectly and is running all the calls as expected, however ever since attempting to make unrelated-to-googlecloudprint https calls in the program, I have had a long string of issues.

The issues I believe primarily stem from the fact that a connection to the google cloud print endpoints probably require an established and valid connection via HTTPS, and globally has some control over all other http connections running in the same program. However for my use I need to be able to connect to my local machine (Where I want to use a self-signed / not valid HTTPS connection).

So aside from my connection to google, I also need to talk to a local client via HTTPS calls and also to the local client via websockets.

The first issue I hit was when I tried to make a connection to my own self-signed server via https using the following call:

static void Main(string[] args)
{
        var client = new HttpClient();
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        HttpResponseMessage response = client.GetAsync("https://server/myapi").Result;
}

Unfortuantely this was throwing the following ambiguous error:

A security error occured

I tried to track down this very ambiguous problem, and didn't really find any answers. From here I decided to modify my own code to:

static void Main(string[] args)
{
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        var myReq = (HttpWebResponse)((HttpWebRequest)WebRequest.Create("https://server/myapi")).GetResponse();
}

This seemed to fix it; for whatever strange reason using WebRequest was fine, but using HttpClient was not ok.

This was an acceptable fix for me, however from there I went to connect my SignalR client (Microsoft.AspNet.SignalR.Client), and now signalR is throwing this error:

Inheritance security rules violated by type: 'System.Net.Http.WebRequestHandler'. Derived types must either match the security accessibility of the base type or be less accessible.

static void Main(string[] args)
{
        var _hubConnection = new HubConnection("https://server/myapi");
        var _hubProxy = _hubConnection.CreateHubProxy("NotificationHub");
        ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };
        _hubConnection.Start().Wait();
}

From here I am utterly confused, how is it that the GoogleCloudPrintAPI nuget package, seems to break any non-secure SSL connections where before I installed GoogleCloudPrintAPI nuget package previously it worked?

karlwancl commented 7 years ago

Hi J,

After some digging, I find that it may be an issue from Microsoft itself. You can find the related issue here. In short, the problem is due to missing security components from the System.Net.Http 4.1.0 nuget package that targets .NET Standard Platform, which may fail HTTPS call if security rule is not set properly.

Unfortunately, the issue is not fixed for the time being, the temporary solution for this problem is to fallback to the older System.Net.Http 4.0.0 nuget package.

I have also uploaded a package that targets .NET Framework 4.5.2 or above instead of .NET Standard, and it should be compatible with the older 4.0.0 Http package. Please help to check if it works. Thanks.

Best, Karl

Jezternz commented 7 years ago

I checked out the project and built with the .net452 project and all my problems are gone! Thankyou @salmonthinlion you have gone above & beyond and have helped out very quickly, much appreciated!