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