From 0634f8f156e7f196fa126279fe337395c6fc6f27 Mon Sep 17 00:00:00 2001 From: "seonkyu.kim" Date: Sat, 30 Nov 2024 02:55:12 +0900 Subject: [PATCH] =?UTF-8?q?[=F0=9F=90=9B]=205=EC=B0=A8=20=ED=91=B8?= =?UTF-8?q?=EC=8B=9C=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: seonkyu.kim --- Program/V1/Controllers/PushController.cs | 8 ++++---- Program/V1/Services/PushService.cs | 23 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/Program/V1/Controllers/PushController.cs b/Program/V1/Controllers/PushController.cs index c487772..064f8c1 100644 --- a/Program/V1/Controllers/PushController.cs +++ b/Program/V1/Controllers/PushController.cs @@ -38,14 +38,14 @@ public class PushController : ControllerBase if (_env.IsDevelopment()) { uri = "https://api.sandbox.push.apple.com"; - p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push_Sandbox.p12"; - // "private/AM_Push_Sandbox.p12"; + p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push_Sandbox.pfx"; + // p12FilePath = "private/AM_Push_Sandbox.p12"; } else { uri = "https://api.push.apple.com"; - p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push.p12"; - // "private/AM_Push.p12"; + p12FilePath = "/volume1/AcaMate/PROJECT/Application/Back/private/AM_Push.pfx"; + // p12FilePath = "private/AM_Push.p12"; } var apnsTopic = "me.myds.ipstien.acamate.AcaMate"; diff --git a/Program/V1/Services/PushService.cs b/Program/V1/Services/PushService.cs index 1766aa4..be459da 100644 --- a/Program/V1/Services/PushService.cs +++ b/Program/V1/Services/PushService.cs @@ -1,5 +1,6 @@ using System.Net.Http; using System.Net.Http.Headers; +using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; using System.Text.Json; @@ -37,12 +38,26 @@ public class PushServiceWithP12 }; var jsonPayload = JsonSerializer.Serialize(payload); - var certificate = new X509Certificate2(p12Path, p12Password, - X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable - ); var handler = new HttpClientHandler(); - handler.ClientCertificates.Add(certificate); + + try + { + var certificate = new X509Certificate2(p12Path, p12Password, + X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.PersistKeySet | X509KeyStorageFlags.Exportable); + + handler.ClientCertificates.Add(certificate); + } + catch (CryptographicException ex) + { + Console.WriteLine($"CryptographicException: {ex.Message}"); + } + catch (Exception ex) + { + Console.WriteLine($"Unexpected error: {ex.Message}"); + } + + using var client = new HttpClient(handler) {