From 81a429bd59ac13154ec2a91d76b8fe32aa0eb631 Mon Sep 17 00:00:00 2001 From: hhuai <8863824@gmail.com> Date: Fri, 12 Jul 2013 12:01:18 +0800 Subject: [PATCH] p12 support --- README.textile | 5 ++++- lib/apns/core.rb | 11 +++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/README.textile b/README.textile index a411839..53b9581 100644 --- a/README.textile +++ b/README.textile @@ -53,7 +53,10 @@ APNS.feedback_host = 'feedback.push.apple.com' # Path to the .pem file created earlier APNS.pem = '/path/to/pem/file' -# Password for decrypting the .pem file, if one was used +# or you can use origin p12 file +APNS.pem = '/path/to/pem/file.p12' + +# Password for decrypting the .pem or p12 file, if one was used APNS.pass = 'xxxx' #################### diff --git a/lib/apns/core.rb b/lib/apns/core.rb index 4ae9109..47c5f33 100644 --- a/lib/apns/core.rb +++ b/lib/apns/core.rb @@ -151,8 +151,15 @@ def self.open_connection(host, port) raise "The path to your pem file does not exist!" unless File.exist?(self.pem) context = OpenSSL::SSL::SSLContext.new - context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem)) - context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.pass) + + if self.pem.end_with?(".p12") + pkcs = OpenSSL::PKCS12.new(File.read(self.pem), self.pass) + context.cert = pkcs.certificate + context.key = pkcs.key + else + context.cert = OpenSSL::X509::Certificate.new(File.read(self.pem)) + context.key = OpenSSL::PKey::RSA.new(File.read(self.pem), self.pass) + end retries = 0 begin