alexalok / dotAPNS

dotAPNS is a library used to send push notifications to Apple devices using Apple Push Notification service via HTTP/2 API.
Apache License 2.0
110 stars 33 forks source link

Bouncy Castle - support for 3.1 #8

Closed Faisal0sal closed 4 years ago

Faisal0sal commented 4 years ago

Warning NU1701: Package 'BouncyCastle 1.8.5' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project. (NU1701)

alexalok commented 4 years ago

Hi!

.NET Core apps can consume .NET Framework library, albeit their functionality may be limited when used like that.

In our case, however, the required functionality works as expected, so you may safely ignore the warning. It shouldn't prevent you from building and running your application.

Faisal0sal commented 4 years ago

@alexalok Thank you for your response, I was going to use as you said anyway. But I'm trying to add services.AddApns();

And it says that there is no reference for it.

alexalok commented 4 years ago

It seems that you've referenced the main dotAPNS package. Instead, you should reference dotAPNS.AspNetCore package, which contains code that integrates dotAPNS with ASP.NET Core projects.

Also, if you reference dotAPNS.AspNetCore, you can safely remove the reference to dotAPNS as it is implicitly added to the project anyway.

Faisal0sal commented 4 years ago

Thank you so much. One more thing, when using the certificate we do need to specify the password. How would we do that after CreateUsingCert

Faisal0sal commented 4 years ago

I have created another certificate with no password, then faced this issue:

An error occurred while sending the request. ---> System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SslStream'.

alexalok commented 4 years ago

Please provide a code sample that you have issues with. Note that ApnsClient.CreateUsingCert has an overload allowing you to pass X509Certificate2 object, which you can construct from an arbitrary certificate, even the one that has a password (see this for reference).

Faisal0sal commented 4 years ago

Well, I have been able to work with the certificate issue. Only this issue is now I'm facing:

An error occurred while sending the request. ---> System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SslStream'.

`// POST // Send Notifications // KeyId {} [HttpPost("notify")] public async Task sendNotificationAsync() { string ErrorMessage = null; string private_key_path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), @"Cert/AppleCertificateWalaaDev.p12"); var cert = new X509Certificate2(private_key_path, ""); var push = ApplePush .CreateContentAvailable() .AddToken("12b5bb89699ca2a0068f4b01444d0cc49670c489b8e661c37e9029de3101141c");

        ApnsResponse response = await ApnsService.SendPush(push, cert);

        return Json(ApiResponse.GetResponse(HttpContext, 200));
    }`
alexalok commented 4 years ago

I see. Could you please provide a full stack trace of an exception? Right now I'm not entirely sure as to what can be the cause of the issue you're facing.

Faisal0sal commented 4 years ago

System.Net.Http.HttpRequestException: An error occurred while sending the request. ---> System.ObjectDisposedException: Cannot access a disposed object. Object name: 'SslStream'. at System.Net.Security.SslStream.ThrowIfExceptional() at System.Net.Security.SslStream.CheckThrow(Boolean authSuccessCheck, Boolean shutdownCheck) at System.Net.Security.SslStream.ReadAsync(Memory1 buffer, CancellationToken cancellationToken) at System.Net.Http.Http2Connection.ReadAtLeastAsync(Stream stream, Memory1 buffer, Int32 minReadBytes) at System.Net.Http.Http2Connection.EnsureIncomingBytesAsync(Int32 minReadBytes) at System.Net.Http.Http2Connection.ReadFrameAsync(Boolean initialFrame) at System.Net.Http.Http2Connection.ProcessIncomingFramesAsync() --- End of inner exception stack trace --- at System.Net.Http.Http2Connection.SendHeadersAsync(HttpRequestMessage request, CancellationToken cancellationToken, Boolean mustFlush) at System.Net.Http.Http2Connection.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpConnectionPool.SendWithRetryAsync(HttpRequestMessage request, Boolean doRequestAuth, CancellationToken cancellationToken) at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.DiagnosticsHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) at System.Net.Http.HttpClient.FinishSendAsyncBuffered(Task1 sendTask, HttpRequestMessage request, CancellationTokenSource cts, Boolean disposeCts) at dotAPNS.ApnsClient.Send(ApplePush push) at WalaaWalletPass.Controllers.PassHandler.sendNotificationAsync() in /Users/fmalsalamah/Projects/wallet-pass-db/CreativeTim.Argon.DotNetCore.Free/Controllers/PassHandler.cs:line 111 at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.TaskOfIActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.gAwaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gAwaited|24_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Rethrow(ResourceExecutedContextSealed context) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.g__Awaited|19_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted) at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.gLogged|17_1(ResourceInvoker invoker) at Microsoft.AspNetCore.Routing.EndpointMiddleware.g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger) at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Session.SessionMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Authentication.AuthenticationMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.StatusCodePagesMiddleware.Invoke(HttpContext context) at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)`

Faisal0sal commented 4 years ago

Issue is not happening anymore once I have set sandbox to true

alexalok commented 4 years ago

According to the stack trace, I can see that the actual exception happens somewhere inside the HttpClient that dotAPNS uses to make HTTP/2 requests. Unfortunately, there is no clear sign of what can be causing the issue.

If possible, create a separate project with the minimum code that reproduces the issue and send it to me at contact@alexalok.me If you do so, please be sure to include the certificate you are using as well, as I do not have any .p12 certificates to test with. I will make sure to delete it after we resolve the issue.

Another option would be to switch to a token-based connection. If you have the proper rights in the Apple Developer Account, I highly suggest to do so as the certificate-based HTTP/2 connection support overall seems to be quite quirky in .NET (see #3, #4).

alexalok commented 4 years ago

Hi, @Faisal0sal, just checking if you still need an assistance. If you're all up and running, perhaps the issue can be closed? Please note that if there is no answer from your side the issue will be closed in a few days.

alexalok commented 4 years ago

The issue is closed due to the lack of feedback.