-
Notifications
You must be signed in to change notification settings - Fork 64
PKG Information
The PS4 Dev Wiki has some information on PKGs and PFS images. Also check out flatz's write-up on Fake PKGs.
Anyway, here's some information about PKGs I've discovered in making this library and toolset.
The contents of a PKG are encrypted with keys derived from a developer-specified passcode and the Content ID.
Let's call these derived keys dk0 to dk6 based on the index value used to create them.
- dk1 is what flatz/sony refer to as EKPFS. It is used to generate PFS encryption and signing keys.
- dk2 is used to generate the AES iv/key to encrypt the license.info in the PKG entry filesystem.
- dk3 is used to generate the AES iv/key to encrypt the IMAGE_KEY entry, the license.dat, and to encrypt the PKG header signature.
- It is not known if the other derived keys are used for anything. They can be used to encrypt entries in the PKG entry filesystem, but so far I've only seen dk2 and dk3 used for that.
To generate keys for PFS, the PFS key seed is combined with an index and then hashed with HMAC-SHA256 using the dk1 (EKPFS) as a key. Index 1 generates XTS tweak and data keys, while index 2 generates the HMAC-SHA256 signing key.
6 of the derived keys are encrypted using public-key RSA and stored in the ENTRY_KEYS entry. Their digests are also stored there. Each derived key gets encrypted with a unique RSA key. The passcode is stored in place of dk0 and it gets its own RSA key as well. We only have public moduli for these RSA keys; except RSA Key 3, for which we have the public and private keys. This entry is stored unencrypted in the PKG, so to access the passcode, for example, all you'd need is the private RSA key 0.
The EKPFS (dk1) is RSA encrypted with the "mount-image" public key and stored in IMAGE_KEY. We don't have the private "mount-image" RSA key, which is why for FAKE PKGs we actually replace it with flatz's generated mount-image key for Fake PKGs. This allows us to decrypt FAKE PKGs without a passcode or license, the same way flatz illustrated in his Fake PKG kernel patches in the write-up.
So, if you want to decrypt the PFS image of any PKG, only one of the following items is required:
- RSA key 0 (public modulus starts
d6 aa 0c 5c
) - RSA key 1 (public modulus starts
b9 69 53 ee
) - The mount-image RSA key
- The passcode
- The EKPFS
- The XTS data and tweak keys
Having any of the items 1-3 would allow you to decrypt the PFS of any PKG. Having any of 4-6 would allow you to decrypt a specific PKG.
For Fake PKGs, we have replaced item 3 with our own key so we can already decrypt any Fake PKG using PkgEditor or PkgTool.
PKG files utilize SHA-256, HMAC-SHA256, and RSA to authenticate and prevent tampering.