{"id":687,"date":"2013-04-06T17:50:58","date_gmt":"2013-04-06T17:50:58","guid":{"rendered":"http:\/\/mooredynasty.net\/?p=687"},"modified":"2013-04-06T17:57:16","modified_gmt":"2013-04-06T17:57:16","slug":"ios-push-notifications-certificate","status":"publish","type":"post","link":"https:\/\/mooredynasty.net\/index.php\/2013\/04\/ios-push-notifications-certificate\/","title":{"rendered":"iOS Push Notifications Certificate"},"content":{"rendered":"<p>To successfully send a push notification to an iOS device using Apple Push Notification Services (APNS), the pushing application must have a certificate and key registered with Apple.<\/p>\n<p>This is done while setting up an iOS application in the Apple Provisioning Portal, <a href=\"http:\/\/www.raywenderlich.com\/3443\/apple-push-notification-services-tutorial-part-12\">as described in detail by Matthijs Hollemans<\/a> (<a href=\"http:\/\/www.raywenderlich.com\/3525\/apple-push-notification-services-tutorial-part-2\">and continued in Part 2<\/a>).<\/p>\n<p>To create the certificate for the application serving the APNS messages, the following are needed:<\/p>\n<ul>\n<li>YourAppCertificate.pem <\/li>\n<li>YourAppKey.pem <\/li>\n<\/ul>\n<p>(See Matthijs\u00e2\u20ac\u2122 articles if these are a mystery)<\/p>\n<p>If you\u00e2\u20ac\u2122re a Windows user like me, you\u00e2\u20ac\u2122ll also need to have the following software installed:<\/p>\n<ul>\n<li>OpenSSL, see <a href=\"http:\/\/slproweb.com\/products\/Win32OpenSSL.html\">http:\/\/slproweb.com\/products\/Win32OpenSSL.html<\/a> <\/li>\n<li>Visual C++ 2008 Redistributables, also available from the link above <\/li>\n<\/ul>\n<p>To get OpenSSL to cooperate, I found that <a href=\"http:\/\/jaspreetchahal.org\/warning-cant-open-config-file-usrlocalsslopenssl-cnf\/\">setting an environmental variable<\/a> was necessary:<\/p>\n<blockquote>\n<p>set OPENSSL_CONF=c:\\openssl\\bin\\openssl.cfg<\/p>\n<\/blockquote>\n<p>I also found it easiest to copy my PEM files to the OpenSSL bin folder; presumedly you could set the Windows Path and avoid this nuisance step.<\/p>\n<p>With all the pieces in place, generating the certificate itself is quite easily, if you know the magic command (<a href=\"http:\/\/help.adobe.com\/en_US\/as3\/iphone\/WS144092a96ffef7cc-371badff126abc17b1f-7fff.html\">nicely documented by Adobe<\/a>):<\/p>\n<blockquote>\n<p>openssl pkcs12 -export -inkey YourAppKey.pem -in YourAppCert.pem -out YourAppCertificate.p12<\/p>\n<\/blockquote>\n<p>You\u00e2\u20ac\u2122ll be prompted for the pass phrase for the key PEM, which you must supply.<\/p>\n<p>Then you\u00e2\u20ac\u2122ll be prompted to set a password on the certificate, which your application will sent with the certificate when it queues an APNS message with Apple.<\/p>\n<p>Sending an APNS message is not overly difficult, but that\u00e2\u20ac\u2122s a subject for another day\u00e2\u20ac\u00a6<\/p>\n<hr \/>\n<\/p>\n<p><em>Below are some helpful OpenSSL commands I copied from <\/em><a href=\"http:\/\/help.adobe.com\/en_US\/as3\/iphone\/WS144092a96ffef7cc-371badff126abc17b1f-7fff.html\"><em>the Adobe article<\/em><\/a><em> so as to have them close at hand<\/em><\/p>\n<p><em>Marc<\/em><\/p>\n<p><em><\/em><\/p>\n<h6>Convert an Apple developer certificate to a P12 file on Windows<\/h6>\n<p>To develop iPhone applications using Flash CS5, you must use a P12 certificate file. You generate this certificate based on the Apple iPhone developer certificate file you receive from Apple.<\/p>\n<ol>\n<li>\n<p>Convert the developer certificate file you receive from Apple into a PEM certificate file. Run the following command-line statement from the OpenSSL bin directory:<\/p>\n<pre>openssl x509 -in developer_identity.cer -inform DER -out developer_identity.pem -outform PEM<\/pre>\n<\/li>\n<li>\n<p>If you are using the private key from the keychain on a Mac computer, convert it into a PEM key:<\/p>\n<pre>openssl pkcs12 -nocerts -in mykey.p12 -out mykey.pem<\/pre>\n<\/li>\n<li>\n<p>You can now generate a valid P12 file, based on the key and the PEM version of the iPhone developer certificate:<\/p>\n<pre>openssl pkcs12 -export -inkey mykey.key -in developer_identity.pem -out iphone_dev.p12<\/pre>\n<p>If you are using a key from the Mac OS keychain, use the PEM version you generated in the previous step. Otherwise, use the OpenSSL key you generated earlier (on Windows).<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>To successfully send a push notification to an iOS device using Apple Push Notification Services (APNS), the pushing application must have a certificate and key registered with Apple. This is done while setting up an iOS application in the Apple Provisioning Portal, as described in detail by Matthijs Hollemans (and &hellip; <\/p>\n","protected":false},"author":6,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15],"tags":[],"class_list":["post-687","post","type-post","status-publish","format-standard","hentry","category-development"],"_links":{"self":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/687","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/users\/6"}],"replies":[{"embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/comments?post=687"}],"version-history":[{"count":3,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/687\/revisions"}],"predecessor-version":[{"id":690,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/posts\/687\/revisions\/690"}],"wp:attachment":[{"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/media?parent=687"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/categories?post=687"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mooredynasty.net\/index.php\/wp-json\/wp\/v2\/tags?post=687"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}