Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

certificaton error when send push notification #64

Open
gb0519 opened this issue May 30, 2024 · 1 comment
Open

certificaton error when send push notification #64

gb0519 opened this issue May 30, 2024 · 1 comment

Comments

@gb0519
Copy link

gb0519 commented May 30, 2024

I use the following codes to send push notification with certification.
These codes are from "base usage" of the readme file (removed the key part)

import asyncio
from uuid import uuid4
from aioapns import APNs, NotificationRequest, PushType

async def run():
    apns_cert_client = APNs(
        client_cert='mycert.cer',
        use_sandbox=False,
    )
    request = NotificationRequest(
        device_token='<DEVICE_TOKEN>',
        message = {
            "aps": {
                "alert": "Hello from APNs",
                "badge": "1",
            }
        },
        notification_id=str(uuid4()),  # optional
        time_to_live=3,                # optional
        push_type=PushType.ALERT,      # optional
    )
    await apns_cert_client.send_notification(request)
   
loop = asyncio.get_event_loop()
loop.run_until_complete(run())

The certification I generated and downloaded from developer.apple.com is cer format,
if I use it directly as
client_cert='mycert.cer',
Then I will get error: ssl.SSLError: [SSL] PEM lib (_ssl.c:3900)

If I convert it to pem with code:
openssl x509 -inform der -in mycert.cer -out mycert.pem
Then change code to
client_cert='mycert.pem',
Then I will get error: ssl.SSLError: [SSL] PEM lib (_ssl.c:3921)

The full traceback:

Traceback (most recent call last):
  File "/root/PythonDoc/study/testAPNs.py", line 25, in <module>
    loop.run_until_complete(run())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/root/PythonDoc/study/testAPNs.py", line 6, in run
    apns_cert_client = APNs(
  File "/usr/local/lib/python3.10/dist-packages/aioapns/client.py", line 37, in __init__
    self.pool = APNsCertConnectionPool(
  File "/usr/local/lib/python3.10/dist-packages/aioapns/connection.py", line 455, in __init__
    self.ssl_context.load_cert_chain(cert_file)
ssl.SSLError: [SSL] PEM lib (_ssl.c:3921)

What should I do to get the right certification to make it work?

@edvinasbartkus
Copy link

@gb0519 this guide should be helpful for you how to generate correct signing files:
https://github.com/node-apn/node-apn/wiki/Preparing-Certificates

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants