【问题标题】:AWS SNS Get Certificate and Private key from .p12 file for Apple APNSAWS SNS 从 Apple APNS 的 .p12 文件中获取证书和私钥
【发布时间】:2016-03-31 21:08:11
【问题描述】:

我正在尝试在 SNS 上创建一个平台应用程序,并且可以轻松地为 GCM/Google Push 服务完成它,但我遇到了 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# amazon-web-services ssl push-notification amazon-sns


    【解决方案1】:

    在 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);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-07-05
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多