PUP

PUP (Playstation Update Package) files are update archives for the PS3, PS Vita and PS4.

= PUP Structure =

A good resource on the PUP structure can be found here.

= Update .PKG files =

Most of the files in the update PUP are .pkg files, a sort of Certified File.

Each component of the update is broken up into multiple parts, then optionally compressed, and finally encrypted into the PKG.

Package Header
Right after the Certified File header (usually at offset 0x300 or 0x400) is the update package header that provides information for piecing the component back together. The contents of this header is as follows:

Flag
These bitflags indicate which products can install the package.

Type
The Type is used to identify the component of the update.

Subroutines
The SPKG Type determines which decryption routine to use in SceSblUpdateMgr. There is a truth table to determine which ID can be handled by which decryption function. To see how this table is used, check out the example code for decrypting update packages.

Tables for allowed for each operation.

No to return 0x800F0202.

= SCEWM =

SCEWM is a file embedded in the PUP to serve as a watermark.

PUP Watermark is present since at least FW 0.931.010. It was not present on FW 0.902.000. Nevertheless, on FW 0.931.010 the PUP watermark is never verified.

The SCEWM file is composed of 2 parts:
 * SCEWM header: size 0x20 bytes.
 * SCEWM body: size = file_size(usually 0x1000) - header_size(0x20). This part is encrypted.

Header
This is a watermark for PUPs. For development PUPs, the Issue ID is unique to the company/organization the PUP is issued to.

The message length for prototype/retail PUP is almost always 0x5A, see below why.

Body
The body is encrypted using AES128CBC with key and iv from update_service_sm.self.

After decryption, the body is composed of 3 parts:
 * 0x100 bytes: RSA2048 signature of SHA256 of the PUP Header Digest. It is verified with SCEWM RSA public key. The PUP Header is independant of the watermark and so is the RSA signature.
 * 0xDE0 bytes: plaintext ASCII message (unique message per DevNet issue ID or build time).
 * 0x100 bytes: RSA2048 signature of SHA256 of 0xF00 bytes (SCEWM header + decrypted PUP Header Digest signature + decrypted message). It is verified with SCEWM RSA public key.

PUP Header Digest RSA Signature
It is RSA2048 of SHA256 of the PUP Header Digest. It is verified with SCEWM RSA public key.

Default Watermark Message
For external PUPs not bound to any developer, nor downloaded from DevNet, the watermark has the default message.

Format for System Software versions 0.931.010-3.740.011: desc: default watermark id: build_team timestamp: YYYYMMDD_HHmmSS_JST host: build_machine

Dummy Watermark Message
For internal PUPs not bound to any developer, nor downloaded from DevNet, the watermark has the dummy message.

Here '??' represents a decimal number starting from '02'.

Format for watermark id 0x71: desc: dummy watermark id: hoshi timestamp: DDD MMM DD HH:mm:SS JST YYYY host: p2bld-l??.build.rd.scei.sony.co.jp

Format for watermark id 0x72: desc: dummy watermark id: hoshi timestamp: Fri Aug 16 07:36:14 JST 2019 host: p2bld-vl??.build.rd.scei.sony.co.jp

Format for watermark id 0xAC: desc: dummy watermark HH:mm:SS JST YYYY host: p2bld-l??.build.rd.scei.sony.co.jp id: hoshi timestamp: DDD MMM DD HH:mm:SS JST YYYY host: p2bld-l??.build.rd.scei.sony.co.jp

DevNet Watermark Message
For external PUPs bound to a company, downloaded from DevNet, the watermark has the DevNet message.

The watermark message is generated on developer's demand by DevNet server, written to the PUP, then the PUP download starts. The message syntax has changed with DevNet revisions. Old message was seen as early as 2011-07-29 and was replaced by a new message at some time between 2016-04-15 and 2018-04-23 after that SilicaAndPina leaked some DevKit/TestKit PS Vita PUP files.

The watermark message is independant of the PUP. The same PUP (for example PS Vita 0.945.050 PUP) downloaded from DevNet in 2011 and in 2018 has different watermark message syntax but apart from Watermark (and maybe Additional Signature) is identical.

Here 'x' represents an actual character, hidden here for confidentiality.

Old DevNet Watermark Message
User id:xxxxxx Org name:xxxxxxxxxxxxxx Company name:xxxxxxxxxxxxxxxxxxxxxxxxxxxx Date PUP downloaded:YYYY-MM-DD HH:mm Host IP address:xxx.xxx.xxx.xxx
 * 1) PUP watermark data that contain DevNet user id, org name, company name, date of PUP downloaded and host IP address

New DevNet Watermark Message
PUP serial number:xxxxxxxx
 * 1) PUP watermark data contain a serial_number that associates with the user who download this PUP
 * 2) Provide the serial number below to the DevNet development team to get user and org details.

SCEWM RSA Signature
It is RSA2048 of SHA256 of 0xF00 bytes: the SCEWM header + the decrypted SCEWM body. It is verified with SCEWM RSA public key.

Security
When comparing the same PUP signed for two different issue IDs, we can notice only 2 differences:
 * sometimes the message length in SCEWM header
 * the SCEWM encrypted unique data: the blocks of the message that differ and the RSA signature of the watermark

= SCEAS =

This file contains Additional Signature(s) (A.S.) necessary for validation of the PUP.

It was added on FW 0.996, probably for security reasons. This file is missing inside the Prototype DevKit PUP 0.945.040 (and all the pre-0.996 PUPs).

The SCEAS file is composed of 2 parts:
 * SCEAS header: size 0x20 bytes.
 * SCEAS body: size = file_size(usually 0x1000) - header_size(0x20). This part is encrypted.

Body
The body is encrypted using AES128CBC with key and iv from update_service_sm.self.

After decryption, the body is composed of 3 parts:
 * 0x100 bytes: RSA2048 signature of something unknown (to reverse). It is verified with SCEAS RSA public key.
 * 0x1E0 bytes: zeroes, maybe area for more than one signature, or just padding for decryption.
 * 0x100 bytes: RSA2048 signature of SHA256 of ?0x300 bytes (SCEAS header + decrypted unknown signature)?. It is verified with SCEAS RSA public key.