enannne's avatar

Error 0480006C:PEM routines::no start line When Verifying Apple Signed Payload

I'm currently working on verifying the payload of an Apple App Store Server Notification (JWS) in a Laravel application. The signed payload includes a certificate chain in the x5c header, which I need to validate using OpenSSL. However, I'm getting the following error when trying to verify the signature:

0480006C:PEM routines::no start line

The issue seems to occur when I try to extract the public key from the leaf certificate and then verify the JWS signature.

Here's the flow I'm implementing: Extract the x5c header from the JWS payload to get the certificate chain (leaf, intermediate, root). Convert the base64-encoded certificates from x5c to PEM format using the following helper function:

private function buildPemFromX5c(string $x5c): string
{
    return "-----BEGIN CERTIFICATE-----\n" . wordwrap($x5c, 64, "\n", true) . "\n-----END CERTIFICATE-----";
} 

Load the public key from the leaf certificate using OpenSSL's openssl_pkey_get_public() function. Verify the JWS signature using openssl_verify():

$isValid = openssl_verify($dataToVerify, $signature, $publicKey, OPENSSL_ALGO_SHA256); Despite these steps, I’m getting the 0480006C:PEM routines::no start line error, which suggests that there's an issue with the format of the certificate or the public key. It seems like the PEM data is not being parsed correctly, or the format of the public key is invalid.

Heres the whole code:

0 likes
0 replies

Please or to participate in this conversation.