ruby-on-railsopenssl

Apnotic gem OpenSSL issue when creating new session


I have a Rails 8 app that I am trying to send Apple push notification with using the Apnotic gem.

  def connection
    @connection ||= Apnotic::Connection.new(
      cert_path: StringIO.new(credentials.apns_key),
      team_id: credentials.team_id,
      key_id: credentials.key_id
    )
  end

  def credentials
    @credentials ||= Rails.application.credentials.ios
  end

When it hits this code, it fails on Apnotic::Connection.new. I get:

OpenSSL::PKey::RSAError (incorrect pkey type: id-ecPublicKey) Caused by: OpenSSL::PKCS12::PKCS12Error (PKCS12_parse: invalid null pkcs12 pointer)

I've tried inspecting my credentials which begin with -----BEGIN PRIVATE KEY----- and includes new line characters. I tried using a hard coded string, and bringing the Apple certificate into the Rails project directly, and always get the same error. My cert was just generated today, and is a .p8 file

One thing I'm wondering about is if this is looking for a public, not private key, but I only got the one cert from Apple with the private key only.


Solution

  • It needed auth method :token
    `

      def connection
        @connection ||= Apnotic::Connection.new(
          cert_path: StringIO.new(credentials.apns_key),
          auth_method: :token,
          team_id: credentials.team_id,
          key_id: credentials.key_id,
          bundle_identifier: credentials.bundle_identifier
        )
      end