ruby on rails - Apnotic gem OpenSSL issue when creating new session - Stack Overflow

admin2025-04-08  0

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.

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.

Share Improve this question edited Mar 26 at 22:04 Steve Schwedt asked Mar 26 at 21:53 Steve SchwedtSteve Schwedt 4403 silver badges14 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 1

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
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744124193a232386.html

最新回复(0)