AWS SNS Get Certificate and Private key from .p12 file for Apple APNS
I'm trying to create a platform application on SNS and can easily do it for GCM/Google Push service but I am having problems with Apple.
It seems when I when i call CreatePlatformApplication() and pass the request I need to have PlatformCredential and PlatformPrincipal which is the Certificate and Private key.
Example of code from AWS Documentation for a application
var snsClient = new AmazonSimpleNotificationServiceClient();
var request = new CreatePlatformApplicationRequest
{
Attributes = new Dictionary<string, string>() { { "PlatformCredential", "AIzaSyDM1GHqKEdVg1pVFTXPReFT7UdGEXAMPLE" } },
Name = "TimeCardProcessingApplication",
Platform = "GCM"
};
snsClient.CreatePlatformApplication(request);
I have a .p12 file currently on system which is used with our manual system to send push notifications and have tried may times to get the certificate and private key out of the p12 file but i still receieve a error when sending the request saying that PlatformPrincipal is invalid.
Any one have ideas how to get the correct PlatformPrincipal and PlatformCredential from the .p12 files?
Documentation
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
Solution 1:
There is no easy way to do this in C# as it needs to be exported to ASN'1 format, but you can use OpenSSL:
Private key
openssl pkcs12 -in key.p12 -nodes -nocerts -passin pass: > private.txt
Public key
openssl pkcs12 -in key.p12 -nodes -nokeys -passin pass: > public.txt
Then send to 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);
}