(转)pem, cer, p12 and the pains of iOS Push Notifications encryption
转自:http://cloudfields.net/blog/ios-push-notifications-encryption/
The serious pains of setting up a Remote Push Notification in an iOS app come not from coding the app itself. They mostly relate in making the intermediate environment to connect with the Apple Push Notification Servers (APNS) and the security behind it…
I will not refer to anything specific to the xCode or Obj-C coding of Push Notifications here. A very nice and simple implementation for Apple Push Notifications management is the PHP-Mysql—Apple-Push-Notification-Server developed by Benjamin Ortuzar. What I’m covering in this post refers on how to create the encryption .pem files needed for the management system to communicate with the APNS.
If you decide not to use Benjamin Ortuzar’s system and go on making your own instead, you’ll probably need all the same the encryption files covered here. If on the other hand you choose to use a service providing Push Notifications like Urban Airship, you won’t need anything from below.
Things taken for granted in this post:
- You already have a Apple Developer ID,
- You have already setup the App ID and enabled it for Push Notifications,
- You have created the development and production certificate for Push Notifications for your app,
- You have the private key in your keychain (it must be there since its needed for the certificate creation above).
All we need is 2 files:
- the private key .p12 file (let’s call it pkey.p12). This can be found in the Keys section of the OSX keychain. Right click on it, select export, enter the filename in .p12 file format and enter its password.
- the SSL certificate (let’s call this sslcert.cer). For this post, I’m using the development certificate and this can be either downloaded from the Developer Connection website (same page where you created it) or you can simply drag and drop it to Finder/Desktop from the My Certificates section in the keychain.
Having done the above, open Ternimal in a Mac OSX. A Linux distribution with openssl installed will do the job as well (100% compatible and tested on Fedora Core 18). If your Linux doesn’t have openssl, type
sudo yum install openssl |
for RedHat-type distributions or
sudo apt-get install openssl |
for Debian.
Step 1: The Certificate
At first we need to convert the sslcert.cer to a .pem format the APNS will understand. Just type in Terminal:
$ openssl x509 -inform der -in sslcert.cer -out certificate.pem |
and let’s call the output file certificate.pem.
Step 2: The Private Key
Same must be done for the private key. This is a bit more complex as it involves a security pass phrase. Again on Terminal:
$ openssl pkcs12 -nocerts -in pkey.p12 -out pkey.pem |
You will be asked to enter the password protecting the pkey.p12 file and then enter a pass phrase that will protect the output pem file. We call the output pkey.pem and we’ll use it later on. Type the password, type the pass phrase, remember the pass phrase and let’s proceed…
Step 3: Merging the pem
Where we need to merge the two files into a single pem file. Extremely simple:
$ cat certificate.pem pkey.pem > apn_cert.pem |
The created apns_cert.pem file will have the same pass phrase entered in step 2 and is the file needed for communication with the APNS servers.
At this point, the only thing left is to test if the file is correct.
Step 4: Testing
So far, the required pem file for the APNS communication is ready but we need to test it. The openssl command provides this as well. Since we used the development certificate on this post, we are going to test the sandbox APNS using this command:
$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns_cert.pem -key apns_cert.pem |
And type the pass phrase again. After that, if all is done correctly, the connection will open with a wall of text letting you know what is going on. Typing a couple of characters, it will disconnect which is normal. If there is an error in the file, openssl will give an error message and you’ll have to read the whole wall of text to find what went wrong.
An indication of a successful connection will look something like this:
CONNECTED(00000003) |
where the certificate data are printed and then:
-----END CERTIFICATE----- |
followed by the ticket data.
Finally, with the pem file created, you can use it in any application or system you have developed or used to manage Push Notifications. Copy it where it needs to be and start sending…
(转)pem, cer, p12 and the pains of iOS Push Notifications encryption的更多相关文章
- Send Push Notifications to iOS Devices using Xcode 8 and Swift 3, APNs Auth Key
Send Push Notifications to iOS Devices using Xcode 8 and Swift 3 OCT 6, 2016 Push notifications are ...
- 实战p12文件转pem文件
1.首先生成一个ssl的证书 选择app IDS 后实现下面这个(这里不详细说明怎么生成了) 点击Download按钮,我就下载Development的ssl证书,下载成功后,双击运行,会打开钥匙串程 ...
- (转)实战p12文件转pem文件
需要实现这个功能的一般都是app开发证书不支持通配符(即com.xxx.xxx.xxx格式),在业务需求上类似消息推送这样的业务. 1.首先生成一个ssl的证书 选择app IDS 后实现下面这个(这 ...
- pem文件转p12
p12->pem cer.p12: openssl pkcs12 -clcerts -nokeys -out cer.pem -in cer.p12 key.p12: openssl pkcs1 ...
- iOS推送证书转pem文件
iOS推送证书转 .pem文件. 推送证书转pem文件openssl x509 -in apns_miaobozhibo.cer -inform der -out apns_miaobozhibo.p ...
- Atitti.数字证书体系cer pfx attilax总结
Atitti.数字证书体系cer pfx attilax总结 一.数字证书常见标准 1 数字证书文件格式(cer和pfx)的区别: 1 二.数字证书存储内容 2 X.509是一种非常通用的证书格式. ...
- c#上iOS apns p12文件制作记录 iOS推送证书制件
前期一些准备工作可参考:http://jingyan.baidu.com/article/7082dc1c6bb86de40a89bd1a.html 1.在桌面上建一个"apns_p12&q ...
- c#上iOS apns p12文件制作记录
1.在桌面上建一个"apns_p12"文件夹,所有的保存和生成文件都放在这里 2.从钥匙串中生成CertificateSigningRequest.certSigningReque ...
- iOS 推送证书生成pem
cert: openssl x509 -in aps_development\ \(8\).cer -inform der -out pushDeveCerTopem.pem key: openssl ...
随机推荐
- HDU -2546饭卡(01背包+贪心)
这道题有个小小的坎,就是低于5块不能选,大于5块,可以任意选,所以就在初始条件判断一下剩余钱数,然后如果大于5的话,这时候就要用到贪心的思想,只要大于等于5,先找最大的那个,然后剩下的再去用背包去选择 ...
- Java类与类之间关系总结
继承,依赖,关联,聚合,组合 一般来说依赖和关联是类似的,关联是强依赖,聚合和组合是一类,组合属于强聚合. 继承:一般是子类和父类之间的关系,关键字extends 依赖:可以这样记忆,做某件事必须要依 ...
- phpmyadmin导出数据库为什么是php文件
你的迅雷在作怪,把它卸载了,或者在迅雷的高级设置中,关闭监听浏览器,就不会触发迅雷下载,就没问题了.或者360浏览器的话,把急速模式改为兼容模式
- 粗俗易懂的SQL存储过程在.NET中的实例运用
整理了一下存储过程在项目中的运用,防止遗忘,便记录于此!存储过程(Stored Procedure)是一组为了完成特定功能的SQL语句集,经编译后存储在数据库中.用户通过指定存储过程的名字并给出参数( ...
- 几种常用的Java数据源解决方案
http://blog.163.com/qqabc20082006@126/blog/static/22928525201041944847653/
- Centos 5.2安装配置DNS服务器
BIND安装配置(主从)我的系统环境:centos 5.2 作者:哈密瓜 主:我采用的是yum安装[root@linux src]#yum -y install bind* 生成rndc控制命令的ke ...
- iOS 网络与多线程--4.同步Post方式的网络请求
通过Post请求方式,同步获取网络数据,一旦发送同步请求,程序将停止用户交互,直至服务器返回数据 在ViewController.m文件内的viewDidLoad函数添加一下测试代码 - (void) ...
- golang byte转string 字节数组转字符串的问题
golang语言本身就是c的工具集,开发c的程序用到的大部分结构体,内存管理,携程等,golang基本都有,他只是在这个基础上又加了一些概念这里说一个很小的问题,就是字节数组转string的问题,网上 ...
- 浏览器d判断
1.判断浏览器类型 if navigator.userAgent.indexOf(”MSIE”)>0) {} //判断是否IE浏览器 if(isFirefox=navigator.userAge ...
- 新安装ubuntu后几项配置
新安的ubuntu13.04 为了编程方便 进行如下设置 安装右键terminal sudo apt-get install nautilus-open-terminal 安装远程连接ssh ...