I am trying to use PyAPNs2 on MacOS to send push notifications to iOS devices. The snippets for certificate-based authentication show that I evidently need a PEM file.
I followed some guides to download and install an APNs certificate with a .cer
extension. However, after using Keychain Access to export the certificate in P12 format, I get errors when trying to convert the file to PEM format:
>> openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes -clcerts
Enter Import Password:
Error outputting keys and certificates
8060FBF201000000:error:0308010C:digital envelope routines:inner_evp_generic_fetch:unsupported:crypto/evp/evp_fetch.c:341:Global default library context, Algorithm (RC2-40-CBC : 0), Properties ()
One thing I have noted is that in the tutorials the exported P12 certificate is called certificate.p12
while the file I have is called Certificates.p12
. Maybe something changed recently which invalidated the command used in the tutorials.
How can I correctly convert the downloaded APNs certificate correctly to PEM format and use it with pyAPNs2?
The solution was to add a -legacy
flag for openssl.
Here is the command that worked for me:
openssl pkcs12 -in Certificates.p12 -out Certificates.pem -nodes -clcerts -legacy