Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added passphrase to app

  • Loading branch information...
commit 37d1d7e4c17e20c98f5ea876adb3088fb5f85e38 1 parent 5ba3ba6
Alexander Gräfenstein authored
View
16 app/models/apn/app.rb
@@ -12,6 +12,10 @@ def cert
Rails.env.production? ? apn_prod_cert : apn_dev_cert
end
+ def pass
+ Rails.env.production? ? apn_prod_pass : apn_dev_pass
+ end
+
# Opens a connection to the Apple APN server and attempts to batch deliver
# an Array of group notifications.
#
@@ -24,7 +28,7 @@ def send_notifications
raise APN::Errors::MissingCertificateError.new
return
end
- APN::App.send_notifications_for_cert(self.cert, self.id)
+ APN::App.send_notifications_for_cert(self.cert, self.pass, self.id)
end
def self.send_notifications
@@ -34,14 +38,14 @@ def self.send_notifications
end
if !APN.cert.blank?
global_cert = File.read(APN.cert)
- send_notifications_for_cert(global_cert, nil)
+ send_notifications_for_cert(global_cert, APN.passphrase, nil)
end
end
- def self.send_notifications_for_cert(the_cert, app_id)
+ def self.send_notifications_for_cert(the_cert, the_pass, app_id)
# unless self.unsent_notifications.nil? || self.unsent_notifications.empty?
begin
- APN::Connection.open_for_delivery({:cert => the_cert}) do |conn, sock|
+ APN::Connection.open_for_delivery({ :cert => the_cert, :passphrase => the_pass }) do |conn, sock|
APN::Device.find_each(:conditions => { :app_id => app_id }) do |dev|
dev.unsent_notifications.each do |noty|
conn.write(noty.message_for_sending)
@@ -62,7 +66,7 @@ def send_group_notifications
return
end
unless self.unsent_group_notifications.nil? || self.unsent_group_notifications.empty?
- APN::Connection.open_for_delivery({:cert => self.cert}) do |conn, sock|
+ APN::Connection.open_for_delivery({ :cert => self.cert, :passphrase => self.pass }) do |conn, sock|
unsent_group_notifications.each do |gnoty|
gnoty.devices.find_each do |device|
conn.write(gnoty.message_for_sending(device))
@@ -80,7 +84,7 @@ def send_group_notification(gnoty)
return
end
unless gnoty.nil?
- APN::Connection.open_for_delivery({:cert => self.cert}) do |conn, sock|
+ APN::Connection.open_for_delivery({ :cert => self.cert, :passphrase => self.pass }) do |conn, sock|
gnoty.devices.find_each do |device|
conn.write(gnoty.message_for_sending(device))
end
View
4 db/migrate/01_create_apn_on_rails_tables.rb
@@ -2,8 +2,10 @@ class CreateApnOnRailsTables < ActiveRecord::Migration
def self.up
create_table "apn_apps", :force => true do |t|
t.text "apn_dev_cert"
+ t.string "apn_dev_pass"
t.text "apn_prod_cert"
- t.string "name"
+ t.string "apn_prod_pass"
+ t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end
View
5 lib/apn/connection.rb
@@ -37,10 +37,9 @@ def open(options = {}, &block) # :nodoc:
:port => APN.port
}.merge(options)
- cert = options[:cert]
ctx = OpenSSL::SSL::SSLContext.new
- ctx.key = OpenSSL::PKey::RSA.new(cert, options[:passphrase])
- ctx.cert = OpenSSL::X509::Certificate.new(cert)
+ ctx.key = OpenSSL::PKey::RSA.new(options[:cert], options[:passphrase])
+ ctx.cert = OpenSSL::X509::Certificate.new(options[:cert])
sock = TCPSocket.new(options[:host], options[:port])
ssl = OpenSSL::SSL::SSLSocket.new(sock, ctx)
Please sign in to comment.
Something went wrong with that request. Please try again.