Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose the constructor so that a custom HttpClient can be passed in. #3

Closed
wants to merge 1 commit into from

Conversation

Yitzchok
Copy link

This is important for using this project with the .NET Framework instead of .NET Core, where a custom WinHttpHandler can to be passed in to use HTTP/2.

@alexalok
Copy link
Owner

Hello and thank you for your collaboration!

I went ahead and tried to port the library to multitarget .NET Framework as well. I have, however, faced with some difficulties.
As per your comment, I've made it so WinHttpHandler is used when library is consumed in .NET Framework project.
While sending pushes using JWT works, I didn't manage to make the certificate connection work. When making a request to APNs using HttpClient with WinHttpHandler (with certificate added using handler.ClientCertificates.Add(...), a HttpRequestException is thrown with the following inner exception: WinHttpException: Error 12152 calling WinHttpWriteData, 'The server returned an invalid or unrecognized response'.

The repro is as follows (using your fork):

var handler = new WinHttpHandler();
handler.ClientCertificateOption = ClientCertificateOption.Manual;
handler.ClientCertificates.Add(new X509Certificate2("cert.p12"));
var apns = new ApnsClient(new HttpClient(handler), new X509Certificate2("cert.p12"));
var push = ApplePush.CreateAlert("alert").AddToken("token");
var resp = await apns.Send(push);

Could you please clarify whether it is working for you? If it does, what .NET Framework version do you use?

For the reference, here is the WIP branch with the progress so far: https://github.com/alexalok/dotAPNS/commits/feature-netframework-support

@alexalok alexalok mentioned this pull request Dec 10, 2019
4 tasks
@Yitzchok
Copy link
Author

I didn't get errors because I was passing in a wrong certificate that didn't have the Client Authentication (1.3.6.1.5.5.7.3.2) extension.
The server returned a 403 causing the send method to return successful check

if (resp.StatusCode == HttpStatusCode.BadRequest)

I wasn't either able to get the certificate to be sent correctly with WinHttpHandler looks like it's related to this.
https://github.com/dotnet/corefx/issues/23518

@alexalok
Copy link
Owner

Thank you for taking your time to investigate the issue. From what I understand, dotnet/corefx#23518 mentions

internal tracking bug with WinHttp team
Ref: 13561564

Which seems to be a blocking bug for certificate connection support in dotAPNS. I will update the #4 accordingly.

@davidfowl, I'm sorry for disturbing, is it possible for you to clarify the current status of this internal bug? If it's marked as resolved, then I should probably create a new issue here. Thank you!

@alexalok alexalok mentioned this pull request Dec 16, 2019
4 tasks
@alexalok
Copy link
Owner

Library now supports .NET Framework 4.6 and above, see #4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants