SSL 证书用于从您的服务器端代码建立到 gateway.push.apple.com 的套接字连接。以下是一些 Ruby 代码作为示例:
APN_SSL_KEY_FILE = 'lib/SSLCert_Private_Key.pem'
APN_SSL_HOST = 'gateway.push.apple.com'
APN_SSL_PORT = 2195
APN_SSL_PASSWORD = '<password>'
def configure_apn_cert
@@apn_cert = File.read(File.join(RAILS_ROOT, APN_SSL_KEY_FILE))
@@apn_context = OpenSSL::SSL::SSLContext.new
@@apn_context.key = OpenSSL::PKey::RSA.new(@@apn_cert, APN_SSL_PASSWORD)
@@apn_context.cert = OpenSSL::X509::Certificate.new(@@apn_cert)
end
def create_and_configure_apn_server
configure_apn_cert if not @@apn_cert
puts "APN Service: Configuring APN SOCKET and SSL connection"
@apn_socket = TCPSocket.new(APN_SSL_HOST, APN_SSL_PORT)
@apn_ssl = OpenSSL::SSL::SSLSocket.new(@apn_socket, @@apn_context)
@apn_ssl.sync = true
@apn_ssl.connect
@apn_is_active = false; # reopen the TCP/SSL sockets for now
end
你会得到一个 .pem 文件:
$ openssl pkcs12 -in myfile.p12 -out myfile.pem