1、pem文件概述
pem文件是服务器向苹果服务器做推送时候需要的文件,主要是给php向苹果服务器验证时使用,下面介绍一下pem文件的生成。
2、生成pem文件步骤
1、打开钥匙串,选择需要生成的推送证书

2、将certificate和private key导出得到.p12文件
2.1、生成证书apns-dev-cert.p12的p12文件,按照下面操作导出p12,桌面对应生成apns-dev-cer.p12文件



2.2、生成证书对应的秘钥apns-dev-key.p12的p12文件,按照下面操作导出p12,桌面对应生成apns-dev-ker.p12文件。



3、将apns-dev-cert.p12和apns-dev-key.p12文件对应转化为apns-dev-cer.pem和apns-dev-key.pem文件
3.1、打开终端,输入cd Desktop
cd Desktop
3.2、将apns-dev-cert.p12文件转换为pen格式,输入openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12
openssl pkcs12 -clcerts -nokeys -out apns-dev-cert.pem -in apns-dev-cert.p12

此处要求输入一个密码,输入123456.(此处为导出p12的保护密码),此时桌面会生成一个apns-dev-cert.pem文件
3.3、将apns-dev-key.p12文件转换为pen格式,输入openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12
openssl pkcs12 -nocerts -out apns-dev-key.pem -in apns-dev-key.p12

此处要求输入一个密码,输入123456.(此处为导出p12的保护密码)

此处要求设置一个保护密码,输入123456.

此处要求验证保护密码,再一次输入123456,此时桌面会生成一个apns-dev-key.pem文件
4、将apns-dev-cert.pem和apns-dev-key.pem文件合成为apns-dev.pem文件,此文件将给php后台用于连接苹果服务器时需要使用,在终端继续输入:cat apns-dev-cert.pem apns-dev-key.pem > apns-dev.pem,此时桌面生成一个apns-dev.pem
cat apns-dev-cert.pem apns-dev-key.pem > apns-dev.pem

在终端测试:openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert apns-dev-cert.pem -key apns-dev-key.pem
终端最后显示以下内容,表示配置pem文件成功,
.............................
Key-Arg : None
Start Time: 1467854873
Timeout : 300 (sec)
Verify return code: 0 (ok)
网友评论
实在不行的话,你就叫他用我写的第二种方法,分开生成pem,然后生成的私钥的pem为无加密的,再合成一个。后台就只需要输入验证密码和包名要对应上,发给苹果APNS时的网址要正确就可以了。
在钥匙串中找到相应的证书,直接整体导出p12,不用分别导出两个 p12 文件,然后终端执行下面代码:
openssl pkcs12 -in XXX.p12 -out XXX.pem -nodes
前面有同行给出了一个链接:http://push.baidu.com/doc/ios/api ,你没有看吗???
unknown option -connectgateway.sandbox.push.apple.com:2195-cert
usage: s_client args
-host host - use -connect instead
-port port - use -connect instead
-connect host:port - who to connect to (default is localhost:4433)
-verify depth - turn on peer certificate verification
-cert arg - certificate file to use, PEM format assumed
-certform arg - certificate format (PEM or DER) PEM default
-key arg - Private key file to use, in cert file if
not specified but cert file is.
-keyform arg - key format (PEM or DER) PEM default
-pass arg - private key file pass phrase source
-CApath arg - PEM format directory of CA's
-CAfile arg - PEM format file of CA's
-reconnect - Drop and re-make the connection with the same Session-ID
-pause - sleep(1) after each read(2) and write(2) system call
-showcerts - show all certificates in the chain
-debug - extra output
-msg - Show protocol messages
-nbio_test - more ssl protocol testing
-state - print the 'ssl' states
-nbio - Run with non-blocking IO
-crlf - convert LF from terminal into CRLF
-quiet - no s_client output
-ign_eof - ignore input eof (default when -quiet)
-no_ign_eof - don't ignore input eof
-ssl2 - just use SSLv2
-ssl3 - just use SSLv3
-tls1 - just use TLSv1
-dtls1 - just use DTLSv1
-fallback_scsv - send TLS_FALLBACK_SCSV
-mtu - set the link layer MTU
-no_tls1/-no_ssl3/-no_ssl2 - turn off that protocol
-bugs - Switch on all SSL implementation bug workarounds
-serverpref - Use server's cipher preferences (only SSLv2)
-cipher - preferred cipher to use, use the 'openssl ciphers'
command to see what
2.2里还出了个apps-dev-ker.p12????