c# - AWS SNS 从 Apple APNS 的 .p12 文件中获取证书和私钥

标签 c# amazon-web-services ssl push-notification amazon-sns

我正在尝试在 SNS 上创建一个平台应用程序,并且可以轻松地为 GCM/Google 推送服务创建它,但我在使用 Apple 时遇到了问题。

当我调用 CreatePlatformApplication() 并传递请求时,我似乎需要 PlatformCredential 和 PlatformPrincipal,它们是证书和私钥。

应用程序 AWS 文档中的代码示例

var snsClient = new AmazonSimpleNotificationServiceClient();

var request = new CreatePlatformApplicationRequest
{
  Attributes = new Dictionary<string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } },
  Name = "TimeCardProcessingApplication",
  Platform = "GCM"
};

snsClient.CreatePlatformApplication(request);

我目前在系统上有一个 .p12 文件,它与我们的手动系统一起使用以发送推送通知,并且多次尝试从 p12 文件中获取证书和私钥,但我在发送请求时仍然收到错误消息说 PlatformPrincipal 无效。

有人知道如何从 .p12 文件中获取正确的 PlatformPrincipal 和 PlatformCredential 吗?

文档

http://aws-net-resources-preview-docs.s3-website-us-east-1.amazonaws.com/Index.html?page=NSNS_Resources_NET4_5.html&tocid=Amazon_SimpleNotificationService_Resources

最佳答案

在 C# 中没有简单的方法可以做到这一点,因为它需要导出为 ASN'1 格式,但您可以使用 OpenSSL:

私钥

openssl pkcs12 -in key.p12  -nodes -nocerts -passin pass: > private.txt

公钥

openssl pkcs12 -in key.p12 -nodes -nokeys -passin pass: > public.txt

然后发送到AWS SNS

string publicKey = File.ReadAllText("public.txt");
string privateKey = File.ReadAllText("private.txt");

using (var client = new AmazonSimpleNotificationServiceClient())
{
    var request = new CreatePlatformApplicationRequest()
    {
        Name = Client,
        Platform = TargetPlatform,
        Attributes =
                new Dictionary<string, string>()
                {
                {"PlatformCredential", privateKey },
                {"PlatformPrincipal", publicKey }
                }
    };
    var response = client.CreatePlatformApplication(request);
}

关于c# - AWS SNS 从 Apple APNS 的 .p12 文件中获取证书和私钥,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36343804/

相关文章:

Amazon S3 中的 Tomcat/Apache Solr?那可能吗?

java - 使用 curl 发布, postman 工作但 java 给出 SSL 错误

c# - 模板字段中的 ASP.NET c# 复选框列表

c# - 带有类库的 Nlog

c# - WPF 货币符号

c# - Websocket 服务器,客户端无法握手

amazon-web-services - 如果 AWS Lambda 函数具有来自多个 Kinesis 流的事件源,传入记录的批处理是来自单个 Kinesis 流还是混合?

amazon-web-services - 无法使两个账户之间的 Amazon S3 跨区域复制正常工作

java - 如何在 Java 中为 LDAP 服务器提供密码验证?

qt - Ubuntu 上 https 站点上的 QtWebkit 出现 SSL 错误