Comments (19)
Hello, sorry for late response, yes, .net core test seems to be working better, got an error - Bad device id, but that's something more related.
from net-core-push-notifications.
@igobl @andrei-m-code - This looks like a .NET 4.6.x issue -- ECParameters is only supported for .NET Framework 4.7+
https://docs.microsoft.com/en-us/dotnet/api/system.security.cryptography.ecparameters?view=net-5.0
from net-core-push-notifications.
I had to change my approach from using this library due to this dependency. However, to get around using ECParameters in 4.6.x you can use:
var key = CngKey.Import(Convert.FromBase64String(certContent), CngKeyBlobFormat.Pkcs8PrivateBlob);
However, that being said there are challenges using this here with IIS as you need to change AppPool settings. This is not recommended for all .NET Framework projects, just 4.6.x as a workaround.
from net-core-push-notifications.
@Novotnde what environment are you running on? Is it your local or cloud? Windows, Linux or Mac?
from net-core-push-notifications.
@andrei-m-code Thank you for fast reply, local and Mac
from net-core-push-notifications.
@Novotnde yw! Everything seems to work well on my mac. Also It's weird that you're saying you can run .net 4.6.2 on your mac. It's not a cross-platform version of .net. I think you need to check the certificate that you're using. The library code may throw all sorts of different crypto related errors when the settings are incorrect.
from net-core-push-notifications.
Yes, we are targeting .net framework but running on mono version Mono version 6.12.0.113. Ok, I will check that :) thank you for support.
from net-core-push-notifications.
oh wow. @Novotnde I wouldn't be surprised if mono is a problem. Try building a small "tester" project and target .net core 2.0+. See what happens. Let me know!
from net-core-push-notifications.
@andrei-m-code Hey, I got a question related to .net framework. Since you have mentioned it worked in this I will just ask here rather then starting new issue. I have tried my .net framework app on windows but actually got and HHTP exception so I just been wondering if you have working .net framework app maybe you know the solution to this ?
v System.Net.HttpWebRequest.set_ProtocolVersion(Version value)
v System.Net.Http.HttpClientHandler.CreateAndPrepareWebRequest(HttpRequestMessage request)
v System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
v System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
v System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
v CorePush.Apple.ApnSender.d__7.MoveNext()
v System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
v System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
v System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
v workConsole.ApTest.d__4.MoveNext() v souboru
from net-core-push-notifications.
what kind of http error?
from net-core-push-notifications.
it could be a lot of things. Would be interesting to know the status and the response body. Check exception message. Maybe it has something. In some cases you need to disable certificate validation and/or other things. This is why we allow to inject HttpClient rather than creating it within the sender class.
from net-core-push-notifications.
HTTP 1 or hhtp1.1 is allowed only
from net-core-push-notifications.
@andrei-m-code - I'm running into the same exception here I was wondering if you might have anymore insight into this issue.
My solution uses a .NET Standard 2.0 NuGet package that is consumed by a .NET Framework 4.6.1 WebAPI project.
I'm using WinHttpHandler v5.0.0 to create my HttpClient as follows:
using (var http = new HttpClient(new Http2CustomHandler())) { var apn = new ApnSender(settings, http); Task.Run(() => apn.SendAsync(fullApnsPayload, notification.Device.DevicePushId)).Wait(); }
My Http2CustomHandler is a simple override of WinHttpHandler:
public class Http2CustomHandler : WinHttpHandler { protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { request.Version = new Version("2.0"); return base.SendAsync(request, cancellationToken); } }
Exception:
{"Could not load type 'System.Security.Cryptography.ECParameters' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.":"System.Security.Cryptography.ECParameters"}
Stack-Trace:
at CorePush.Utils.AppleCryptoHelper.GetEllipticCurveAlgorithm(String privateKey)\r\n at CorePush.Apple.ApnSender.CreateJwtToken()\r\n at CorePush.Apple.ApnSender.<GetJwtToken>b__8_0(String _)\r\n at System.Collections.Concurrent.ConcurrentDictionary
2.GetOrAdd(TKey key, Func2 valueFactory) in f:\\dd\\ndp\\clr\\src\\BCL\\system\\Collections\\Concurrent\\ConcurrentDictionary.cs:line 1070\r\n at CorePush.Apple.ApnSender.GetJwtToken()\r\n at CorePush.Apple.ApnSender.<SendAsync>d__7.MoveNext()
from net-core-push-notifications.
Same issue here using System.Net.HttpClient. If anyone managed to find a fix it would be very welcome given that binary protocol is being retired by Apple at the end of the month :|
WebApp targeting .NET framework 4.6.2
CorePush v 3.0.4
var apnSettings = new ApnSettings() { // My settings here }; var sender = new ApnSender(apnSettings, _httpClient); var response = await sender.SendAsync(apnPayload, deviceToken: apnToken);
Stack-Trace:
Uncaught (non-HTTP) exception System.TypeLoadException: Could not load type 'System.Security.Cryptography.ECParameters' from assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.
at CorePush.Utils.AppleCryptoHelper.GetEllipticCurveAlgorithm(String privateKey)
at CorePush.Apple.ApnSender.CreateJwtToken()
at CorePush.Apple.ApnSender.b__8_0(String _)
at System.Collections.Concurrent.ConcurrentDictionary2.GetOrAdd(TKey key, Func
2 valueFactory)
at CorePush.Apple.ApnSender.GetJwtToken()
at CorePush.Apple.ApnSender.d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
from net-core-push-notifications.
Thank you for all your feedback! It is working well with .NET 3.1+ (.NET Standard 2.1). But I'll try with .NET Standard 2.0 and see what happens.
from net-core-push-notifications.
I'll be trying some things as well, I'll update if I find anything.
from net-core-push-notifications.
@reeceengle I have no windows to testing on 4.6.x. If anyone else can - I'd appreciate it. Other than that all the .net core versions seem to work fine..
from net-core-push-notifications.
(possible reason noted below)
I did a fair amount of search on the net, but could not figure out a solution.
I use .Net Framework 4.7.2.
I don't get this error when I run the code on my local machine, but I encounter the issue on the test server. Is there a possibility this may be due to expired SSL certificate? Or is this something specific to this nuget package?
I get the following exception right after executing following statements:
var apn = new ApnSender(settings, http);
var payload = new AppleNotificationHttp2(Guid.NewGuid(), message, title);
Exception details:
InnerException: System.Net.Http.WinHttpException (0x80072F8F): Error 12175 calling WINHTTP_CALLBACK_STATUS_REQUEST_ERROR, 'A security error occurred'. at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Threading.Tasks.RendezvousAwaitable`1.GetResult() at System.Net.Http.WinHttpHandler.d__109.MoveNext()
StackTrace: at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at CorePush.Apple.ApnSender.d__7.MoveNext() --- End of stack trace from previous location where exception was thrown --- at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at PushApple.d__7.MoveNext()
Possible reason: HTTP/2 requires IIS10 and Windows Server 2016. I'm using Windows Server 2012 R2 and IIS8.5. For further info: https://stackoverflow.com/questions/48047398/send-http-2-request-on-windows-server-2012-r2
from net-core-push-notifications.
One thing to try:
services.AddHttpClient<IApnSenderFactory, ApnSenderFactory>().ConfigurePrimaryHttpMessageHandler(() =>
{
var handler = new HttpClientHandler();
handler.ServerCertificateCustomValidationCallback = HttpClientHandler.DangerousAcceptAnyServerCertificateValidator;
return handler;
});
from net-core-push-notifications.
Related Issues (20)
- Push icon HOT 3
- Additional functionality HOT 1
- Non-hardcoded FCM Url HOT 3
- How can distinguish between fem tokens
- Distinguish between fcm tokens HOT 1
- Only HTTP/1.0 and HTTP/1.1 version requests are currently supported HOT 1
- Version 3.1.1 & 3.1.0 - ApnSender Fails With Serialization Error (.Net Core 6.0.7) HOT 3
- ApnsResponse from ApnSender.Send has IsSuccess = true, but I never receive notification? HOT 1
- Cancel a notification HOT 1
- Support for System.Text.JSON HOT 5
- Migrate from legacy HTTP to HTTP v1 HOT 1
- ApnSender.Send throws an Exception when Bad DeviceId is provided. HOT 4
- Firebase Error Throws Exception HOT 2
- Usage clarification HOT 2
- For Anyone Who Has Issues with Azure Service & Firebase (Cryptography) - See this... HOT 1
- message.data serialization convention HOT 3
- Exception when sending notifications to iOS devices HOT 1
- work with apple wallet passbook HOT 1
- FirebaseSettings are a record thus not allowing binding to appsettings.json HOT 1
- Firebase CryptographicException when deployed to production server (NOT Azure)
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from net-core-push-notifications.