ostinelli / apnotic

A Ruby APNs HTTP/2 gem able to provide instant feedback.
MIT License
477 stars 95 forks source link

Token-based authentication fails with "invalid curve name" #89

Closed kcfancher closed 3 years ago

kcfancher commented 4 years ago

I've successfully used the certificate based auth, but now I'm looking to transition to token-based and I'm getting the below crash.

Traceback (most recent call last):
        7: from apn.rb:37:in `<main>'
        6: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/connection.rb:44:in `push'
        5: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/connection.rb:86:in `prepare_request'
        4: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/connection.rb:143:in `provider_token'
        3: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/connection.rb:143:in `new'
        2: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/provider_token.rb:8:in `initialize'
        1: from /Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/provider_token.rb:8:in `new'
/Library/Ruby/Gems/2.6.0/gems/apnotic-1.6.0/lib/apnotic/provider_token.rb:8:in `initialize': invalid curve name (OpenSSL::PKey::ECError)

Below is a bare-bones test file that I've used for both cert & token based auth.

#!/usr/bin/env ruby
# encoding: utf-8

require 'apnotic'

# create a persistent connection
# connection = Apnotic::Connection.development(cert_path: "cert_file.pem", cert_pass: "cert_pass")
connection = Apnotic::Connection.development(
    auth_method: :token,
    cert_path: "AuthKey_file.p8",
    key_id: "our_key_id",
    team_id: "our_team_id",
  )

# create a notification for a specific device token
token = "5b...b3f" # valid token

## Standard Push Notification
notification       = Apnotic::Notification.new(token)
notification.alert = "Hey!"
notification.topic = "our_app_identifier"

# send (this is a blocking call)
response = connection.push(notification)

# read the response
puts response.ok?
puts response.status
puts response.headers
puts response.body

# close the connection
connection.close

I'm sure it's not a malformed p8 file as I've tested push notifications using a standalone app for debugging APNs and it worked fine there. Any ideas or guidance?

brianinator commented 4 years ago

I'm sure it's not a malformed p8 file

Double check it I ran into this issue and it was extra white space in the file.

kcfancher commented 4 years ago

I just checked, there's no whitespace except for newlines. And as I said it works in 'Push Notifications.app'.

kcfancher commented 4 years ago

Here's the project I'm using to test my Push Notifications outside of apnotic: https://github.com/onmyway133/PushNotifications

benubois commented 3 years ago

Double check that the connection is able to read the file and gets the correct contents.

connection.send(:certificate)

You should see something like this:

-----BEGIN PRIVATE KEY-----
YOUR_PRIVATE_KEY
-----END PRIVATE KEY-----