Ameya Vichare
Ameya Vichare

Reputation: 1289

OpenSSL::PKey::RSAError (Neither PUB key nor PRIV key: nested asn1 error) while using Grocer gem on RoR app

I know there are a lot of questions on this scenario but I've tried every solution and I am still stuck. I am using the grocer gem to send push notifications to the APN service. I am stuck on the certificate issue.

Here's the code

pusher = Grocer.pusher(
  certificate: "#{Rails.root}/public/certificate1.pem",      # required
  passphrase:  "",                       # optional
  gateway:     "gateway.push.apple.com", # optional; See note below.
  port:        2195,                     # optional
  retries:     3                         # optional
) 


notification = Grocer::Notification.new(
  device_token: token,
  alert: "#{uname} liked your post",
  sound: 'default',
  badge:  0
)

pusher.push(notification)

I am in a production environment where I am hosting the app on Heroku. Heroku logs show me this

OpenSSL::PKey::RSAError (Neither PUB key nor PRIV key: nested asn1 error):
app/controllers/api/v1/feeds_controller.rb:49:in `likeit'

Line 49 is the line where the notification is pushed.

I'm certain that the certificate I'm using is proper as I have tested push notifications using it. Also when generating the pem file I have exported both the certificate as well as the private key.

Reference: grocer gem

Any suggestions are welcome!

Upvotes: 1

Views: 1379

Answers (1)

Ameya Vichare
Ameya Vichare

Reputation: 1289

I had to change these two things:

1) Get the production SSL certificate under the push notifications tab on apple developer accounts

2) Change gateway.push.apple.com to gateway.sandbox.push.apple.com as I was still in development mode.

Upvotes: 1

Related Questions