What is the file with .p8 extension? (APNs Auth Key / JWT)
Asked Answered
B

4

22

I think it is a little ridiculous but it's hard to find information about what is this file. I've found a lot info how to get this Apple Push Notification Authentication Key, but i also want to know exactly what is it.
Here is some info i have found:

Benefits:

  • No need to re-generate the push certificate every year;
  • One auth key can be used for all your apps;
  • Same for sandbox and Production.

From Apple Docs:

Token-based provider connection trust: A provider using the HTTP/2-based API can use JSON web tokens (JWT) to provide validation credentials for connection with APNs. In this scheme, you provision a public key to be retained by Apple, and a private key which you retain and protect. Your providers then use your private key to generate and sign JWT provider authentication tokens. Each of your push notification requests must include a provider authentication token.

You can use a single, token-based connection between a provider and APNs can to send push notification requests to all the apps whose bundle IDs are listed in your online developer account.

Every push notification request results in an HTTP/2 response from APNs, returning details on success or failure to your provider. Further check Token-Based Provider-to-APNs Trust section.

Questions:

  • What is actually the .p8 file?
  • What programm can open it? (Keychain didn't work for me)
  • Is there a way to convert it to .pem or .p12?
  • A little flow-out question in order to not create a new topic: Does the server side operate with .p8 the same way as .p12 or it should be additional tools added?
Barolet answered 16/3, 2018 at 17:7 Comment(0)
R
45

The following is the state of my research:

The APNS .p8 file contains the PRIVATE KEY that is used to SIGN the JWT content for APNS messages. The file itself is a pure text file, the KEY inside is formatted in PEM format.

The part between the -----BEGIN PRIVATE KEY----- and -----END PRIVATE KEY----- is a base64 formatted ASN.1 PKCS#8 representation of the key itself. Some can use the following web service to extract its contents (ASN1JS).

The KEY itself is 32 bytes long and is used to create the required ECDSA P-256 SHA-256 signature for the JWT. The resulting JWT looks like this '{JWT header base64 encoded}.{JWT payload base64 encoded}.Signature (64 bytes) base64 encoded'.

There are a lot of web services to decode such tokens, but some couldn't check the signature, as the corresponding PUBLIC KEY isn't known (Apple keeps it secret when providing the PRIVATE KEY).

EDIT: It seems, that the PUBLIC KEY is also included in the .p8 file, it can be extracted via OpenSSL (and is visible when decoding the ASN.1 content: the 520 bit stream).

openssl ec -in AuthKey_123ABC4567.p8 -pubout -out AuthKey_123ABC4567_Public.p8

Raymundorayna answered 4/3, 2019 at 10:35 Comment(1)
Technically, PUBLIC KEY is not included in the .p8 file, but instead it can be inferred from the private key.Finegrained
C
5

File extensions are just a convention, but most likely the .p8 extension is used to indicate that it is a PKCS#8 PrivateKeyInfo (or EncryptedPrivateKeyInfo).

I'd expect the Keychain program to be able to open it as "a key", but not having a mac at hand I can't say. It should open with SecItemImport (kSecFormatOpenSSL, kSecItemTypePrivateKey).

Is there a way to convert it to .pem or .p12?

Assuming you mean "certificate" by .pem, no. If you mean PEM encoded, sure. It's either "BEGIN PRIVATE KEY" or "BEGIN ENCRYPTED PRIVATE KEY", depending.

It can also, technically, be converted into a PKCS#12. But Apple's PKCS#12 importer won't import (last I saw) private keys that it can't figure out what certificate they belong with (from the same PKCS#12).

This is just a private key, there's no certificate (thus no expiration). So certificate-based approaches don't make sense.

Does the server side can operate with .p8 the same way as .p12 or it should be additional tools added?

This depends entirely on the details of the protocol, which I don't know. If the protocol transported the certificate then different machinery is involved with the conversion. If it just transported a signature and the server looked up the public key for verification then nothing changed server side.

Cline answered 16/3, 2018 at 17:27 Comment(0)
S
5

It's a text file! The .p8 extension signifies a simple text file containing public/private key. You can open it with any text editor (TextEdit, vim, Sublime Text) to see your key.

Spires answered 9/6, 2018 at 0:35 Comment(0)
R
1

This is a private key most likely in PEM format. The file type extension is described in IANA application/pkcs8.

The extension is defined in RFC 5958:

.p8 files are sometimes PEM-encoded. When .p8 files are PEM encoded
they use the .pem file extension. PEM encoding is either the Base64
encoding, from Section 4 of [RFC4648], of the DER-encoded
EncryptedPrivateKeyInfo sandwiched between:

-----BEGIN ENCRYPTED PRIVATE KEY----- -----END ENCRYPTED PRIVATE KEY-----

or the Base64 encoding, see Section 4 of [RFC4648], of the DER-
encoded PrivateKeyInfo sandwiched between:

-----BEGIN PRIVATE KEY----- -----END PRIVATE KEY-----

You can use Keystore Explorer to open it.

Rede answered 14/10, 2023 at 14:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.