Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -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'

####################
Expand Down
11 changes: 9 additions & 2 deletions lib/apns/core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down