I have .p12 file from Apple and tried to convert it to .pem file with following command:
openssl pkcs12 -in cert.p12 -out apple_push_notification_development
This also may happen when you forget to sign newly generated certificate. I wanted to use self-signed certificate but forgot signing part.
# Create key
key = OpenSSL::PKey::RSA.new(2048)
open("key.pem", "w") do |io| io.write(key.to_pem) end
# Generate certificate
name = OpenSSL::X509::Name.parse("CN=example.com/C=EE")
cert = OpenSSL::X509::Certificate.new
cert.version = 2
cert.serial = 0
cert.not_before = Time.now
cert.not_after = cert.not_before + 1 * 365 * 24 * 60 * 60 # 1 year validity
cert.public_key = key.public_key
cert.subject = name
and this part of code is what I missed:
cert.issuer = name
cert.sign key, OpenSSL::Digest::SHA1.new
open "cert.pem", 'w' do |io| io.write cert.to_pem end