Editing Sealedkey / pfsSKKey

Jump to navigation Jump to search
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
The Sealed Key is a an encrypted key used on PS Vita, PS4 and PS5 to prevent files modification and extraction. It can be found on different places in the filesystem and is used for Save Data and Trophy Data decryption and encryption.
This key can be found on different places and will be used for eg. SaveGame or Trophy Data decryption and encryption.
 
==== Paths ====
See also [https://wiki.henkaku.xyz/vita/Sealedkey PS Vita Sealedkey].
 
= PS4 =
 
== Location ==
 
The sealedkey file is located in the folder of every savedata/trophies. It is not PFS encrypted.
 
{| class="wikitable"
{| class="wikitable"
|-
|-
! Kind !! Path
! Kind !! Path
|-
|-
| Trophy || /user/home/[[User ID|User Id]]/trophy/data/[[sce_trop]]/sealedkey
| Trophys || /user/home/[[User ID|user Id]]/trophy/data/[[sce_trop]]/sealedkey
|-
|-
| Save Data (internal HDD) || /user/home/[[User ID|User Id]]/[[NP Title ID|Title ID]]/[[save data directory]]/[[sce_sys]]/
| SaveGames || /user/home/[[User ID|user Id]]/[[NP Title ID|title Id]]/[[save data directory]]/[[sce_sys]]/
|-
| Save Data (USB Storage) || /PS4/SAVEDATA/[[User ID|User Id]]/[[NP Title ID|Title ID]]/<sealed_filename>.bin
|}
|}


= Structure =
== Structure ==
 
- size always 96 bytes
* Size is always 96 bytes.


{| class="wikitable"
{| class="wikitable"
|-
|-
! Offset !! Size !! Description !! Notes
! From !! To !! Description
|-
| 0 || 8 || Magic || "pfsSKKey" standing for PFS SealedKey Key
|-
|-
| 0x8 || 2 || [[#Keyset]] ||
| 00 || 07 || MAGIC ("pfsSKKey") (?playstation file system sealed key key?)
|-
|-
| 0xA || 6 || Padding || Zeroed
| 08 || 0F || Category (game=1 or version ?)
|-
|-
| 0x10 || 16 || IV || AES-128-CBC IV for use with the pfsSKKey__EncKey Key
| 10 || 1F || IV (16 bytes)
|-
|-
| 0x20 || 32 || Encrypted Sealed Key ||
| 20 || 3F || Encrypted key (32 bytes)
|-
|-
| 0x40 || 32 || Digest || HMAC-SHA256 digest for use with the pfsSKKey__Secret Key
| 40 || 5F || SHA-256 (32 bytes)
|}
|}


'''C'''
<source lang="c">
<source lang="c">
  typedef struct {
typedef struct sealedkey {
      const char magic[8];
    const unsigned char MAGIC[8];
      unsigned short keyset;
    const unsigned char CAT[8];
      unsigned char reserved[6];
    const unsigned char IV[16];
      unsigned char iv[16];
    const unsigned char KEY[32];
      unsigned char encrypted_sealedkey[32];
    const unsigned char SHA256[32];
      unsigned char digest[32];
} selaedkey;
  } sealed_key;
</source>
</source>


== Keyset ==
'''CSharp'''
 
<source lang="csharp">
{| class="wikitable"
protected internal struct sealedkey {
|-
    internal static byte[] MAGIC = new byte[8];
! Keyset !! System Software version !! Notes
    internal static byte[] CAT = new byte[8];
|-
    internal static byte[] IV = new byte[16];
| 1 || 1.01-1.73 ||
    internal static byte[] KEY = new byte[32];
|-
    internal static byte[] SHA256 = new byte[32];
| 2 || 4.55 ||
}
|-
</source>
| 3 || ?4.70? ||
|-
| 4 || 5.05 ||
|-
| 5 || ? ||
|-
| 6 || ? ||
|-
| 7 || ? ||
|-
| 8 || ? ||
|-
| 9 || ? ||
|-
| 10 || ?8.00?-12.00 ||
|}


For example, in PS4 4.55 kernel, the function '''sceSblSsDecryptSealedKey''' checks that the keyset is less or equal 2 before calling '''sceSblSsDecryptWithPortability'''.
Note: You can't use a const byte[] defination in C#. It need to be a static byte[].


== Usage ==
== De/En -Crypting ==
 
Can be decrypted by frindly asking the OS to do it for you. You will need kernel rights to be able to ask the PS4 for it.
With code execution in PS4 kernel, the sealed key can be decrypted by asking the PS4 kernel:
<source lang="c">
* with '''sceSblSsDecryptSealedKey''' (see Talk page),
/* Decryption */
* or with '''sceSblSsDecryptWithPortability''' (reimplement '''sceSblSsDecryptSealedKey''' by reversing Kernel),
#define foreach(item, array) \
* or with portability master keys (see [[Vulnerabilities#%3C=_?7.55?_-_Missing_HMAC_key_length_check_in_Secure_Kernel_leading_to_Partial_SAMU_KeyRings_bruteforce]]).
    for (int keep = 1, \
 
              count = 0, \
 
              size = sizeof(array) / sizeof(*array); \
{{File Formats}}
          keep && count != size; \
<noinclude>[[Category:Main]]</noinclude>
          keep = !keep, count++) \
        for (item = (array) + count; keep; keep = !keep)
typedef unsigned char byte;              /* byte defination for c/c++ */
const char USER1 = "10000000";
const cahr usb0 = "/mnt/usb0/";
const char usb1 = "/mnt/usb1/";
const char pfs = "dec_pfsSK.Key";
const char home = "/user/home/";
const char tropkey = "/trophy/data/sce_trop/sealedkey";
char usb_error = "[-] ERROR: Can't access usb0 nor usb1!\n[-] Will return now to caller.\n"
char usb0path[(sizeof(usb0) + sizeof(pfs))];
char usb1path[sizeof(usb0path)];
byte pfsSKKey[96];
/* Get's the encrypted sealed key based on user id */
byte get_pfsSKKey(const char *userID, const char path) {
    char toOpen[(sizeof(home) + sizeof(userID) + sizeof(path))];
    FILE *pfskey = fopen(snprintf(toOpen, sizeof(toOpen), %s%s%s, home, userID, path), "rb");
    if (!pfskey) return NULL;
 
    byte pfsSKKey[96];
    fread(pfsSKKey, 96, 1, pfskey);
    fclose(pfskey);
    return pfsSKKey;
}
/* Dump the sealedkey. Send over tcp and save to file */
int dumpDecryptedSealedKey(int to) {
    if (to != 0 || to != 1) return -2;
    byte enc_pfsSKKey;
    if (sizeof((enc_pfsSKKey = get_pfsSKKey(USER1, tropkey))) != 96) {
        printf("[-] Can not load the sealed key!\n");
        return -1;
    }
    /* Now decrpyt the key */
    byte dec_pfsSKKey[16];
    int i = kernel.sceSblSsDecryptSealedKey(enc_pfsSKKey, dec_pfsSKKey);
    printf("[+] sceSblSsDecryptSealedKey returned %d\n", i);
    /* Sending over tcp */
    if (i) {
        if (!to) {
            printf("[+] Your decrypted sealedkey = ");
            foreach(byte *val, dec_pfsSKKey) {
                printf("%02X", *val);
            }
            printf("\n");
            return 1;
        }
        else { /* Saving to file */
            printf("[+] Will try to save to file...");
   
            snprintf(usb0path, sizeof(usb0path), %s%s, usb0, pfs);
            snprintf(usb1path, sizeof(usb1path), %s%s, usb1, pfs);
            FILE *dump = fopen(usb0path, "wb");
 
            if (!dump) {
                dump = fopen(usb1path, "wb");
                if (!dump) {
                    printf("fail!\n" + usb_error);
                    return -3;
                }
            }
            fwrite(dec_pfsSKKey, 16, 1, dump);
            printf("done!\n");
            fclose(dump);
            return 1;
        }
    }
    else printf("[+] Error!\n");
    return -1;
}
</source>
Please note that all contributions to PS4 Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PS4 Developer wiki:Copyrights for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource. Do not submit copyrighted work without permission!

To protect the wiki against automated edit spam, we kindly ask you to solve the following hCaptcha:

Cancel Editing help (opens in new window)