Editing NPDRM

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:
{{Wikify}}
[[Category:Software]]{{Wikify}}


'''The info on this page is an extract (and simplify) of talk page, conversations and forum posts, please digest the info and move it to this page.'''
'''The info on this page is an extract (and simplify) of talk page, conversations and forum posts, please digest the info and move it this page'''


To merge on wiki:
* [http://www.emunewz.net/forum/showthread.php?tid=8134 PSP NPDRM explanation by Hykem]
* [http://wololo.net/talk/viewtopic.php?f=67&t=40656 How to find dev klicensee in NPDRM SELF - SPRX by '''Mysis''']


See also [https://wiki.henkaku.xyz/vita/SceNpDrm PS Vita NPDRM] and PSP NPDRM.
Once the user is trying to start a [[SELF File Format and Decryption|SELF]], the [[VSH|vsh]] looks for the [[SELF_File_Format_and_Decryption#App_Info|appinfo header type]]. If the [[SELF_Types|type is 8]], then the [[SELF_File_Format_and_Decryption#Control_Information|control digest element type 3]] (NPD element) is located. From this NPD header the vsh gets the [[License Types]] (network license, local or free).


= PS3 NPDRM SELF - SPRX decryption steps =
*'''Network License''' (type 1): if a remote paid content is to be loaded, the vsh loads the act.dat and the rif associated to the content (will download to vsh process memory).


Once that the user is trying to start a [[SELF - SPRX]], the [[VSH]] looks for the [[SELF_-_SPRX#Program_Identification_Header|Program Identification Header]]. If the [[Program Type]] is NPDRM, then the [[SELF_-_SPRX#Supplemental_Header_Table|Supplemental Header Table NPDRM header]] is located. From this [[NPD]] header the [[VSH]] gets the [[#DRM Type]].
*'''Local''' (type 2): For this paid content too, the vsh locate a file with the same title id on NPD element (CONTENT_ID), then the signature is checked (last 0x28 bytes of both RIF and act.dat).


If a Network DRM content is to be loaded, the [[VSH]] loads the act.dat and the .rif associated to the content (it will download .rif to VSH process memory).
*'''Free''' (type 3): if a free content (no license check) is detected then a [[Keys#klic_free_key|generic klicense]] will be use for further steps (go to LV2).  


For Local DRM content too, the [[VSH]] locates a file with the same CONTENT ID as in NPDRM header, then the signatures are checked (RIF offset 0x70 and act.dat offset 0x1010). Using the [[Keys#NPDRM_Keys|np_act_data_index_dec_key]], it will decrypt the actdatIndex stored in RIF.
Using the RIF_KEY it will obtain the actdatIndex, and finally having the actDat key index the execution pass to [[LV2_Functions_and_Syscalls#LV2_Syscalls|LV2 Syscalls 471.]]


If a Free DRM (DRM type 3) content is detected then there is no license check, so no need for .rif/act.dat, and a generic klicensee [[Keys#NPDRM_Keys|klic_ps3_free]] will be used for further steps.


Then the execution passes to [[LV2_Functions_and_Syscalls#LV2_Syscalls|LV2 Syscall no 471 sys_npdrm_regist_ekc]].
This function has different parameters depending if the content is debug, paid (type 1 & 2) or free (type 3):
<source lang="C">
// is it titleID or content_id?
int sys_npdrm_regist_ekc(uint32_t type, char* titleID, void* klicensee, uint8_t* actdat, uint8_t* rif, int32_t licenseType, uint8_t* magicVersion);</source>
This function has different parameters depending on the [[#DRM Type]]:
* Local/Network DRM content: <source lang="C">sys_npdrm_regist_ekc(npd.type, &npd.titleID, NULL, &actdat.keyTable[rif.actDatIndex], &rif.key, npd.license, &npd);</source>
* Free DRM content: <source lang="C">sys_npdrm_regist_ekc(npd.type, &npd.titleID, klic_ps3_free, NULL, NULL, npd.license, &npd);</source>


The lv2 keeps a memory table with contentID and the associated klicensee:
PAID: syscall471(npd.type, &npd.titleID, NULL, &actdat.keyTable[rif.actDatIndex], &rif.key, npd.license, &npd);
* Local/Network DRM content: lv2 AES128 decrypts the encrypted klicensee from RIF by using [[Keys#NPDRM_Keys|NPDRM IDPS Seed]], [[IDPS]], act.dat and some other keys. Once transformed, klicensee is stored in a memory table.
FREE: syscall471(npd.type, &npd.titleID, freeklicensee, NULL, NULL, npd.license, &npd);
* Free DRM content: lv2 copies the titleID and the generic klicensee (klic_ps3_free) to a memory table.
:<small>*PAID can also include free games/apps too but require this licensing check</small>


From there, the lv1 hypervisor, by loading [[Hypervisor_Reverse_Engineering#appldr|appldr]], will transform the key by using the [[Keys#ps3_klic_dec_key|ps3_klic_dec_key]] and finally remove the NPDRM layer of the SELF/SPRX to start the [[SELF - SPRX]] decryption.
The lv2 keeps a memory table with contentID and the associated key:
*Paid content: the rif.key is converted to the klicensee (by using a constant value on lv2, [[IDPS|IDPS]] and the act.dat) and once transformed it is stored on memory table.
*free content: copies the titleID and the klicensee to the table.


= PS3 NPDRM EDAT decryption steps =


See [[EDAT files]].
From there, the lv1 hypervisor by loading [[Hypervisor_Reverse_Engineering#appldr|Appldr]], will transform (again) this key by using the [[Keys#klic_dec_key|klic_dec_key]] and finally remove the NPDRM layer for start the [[SELF File Format and Decryption|SELF]] decryption.


= DRM Type =
==act.dat header(encrypted) structure==


A temporary name was "License type".
{| class="wikitable sortable"
|-
| style="background-color:#123EDA; color:#FFFFFF;" |'''Name'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Offset'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Size'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Example'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Remark'''
|-
| Version Number || 0x0 || 0x4 || 00000001 ||
|-
| License Type || 0x4 || 0x4 || 00000001 ||
|-
| User Number || 0x8 || 0x8 || N.A ||
|-
| KeyTable Retail || 0x10 || 0x800 || N.A ||
|-
| KeyTable Debug? || 0x810 || 0x800 || N.A ||
|-
| Signature || 0x1010 || 0x28 || N.A ||
|-
|}
 
 
==rif file(encrypted) structure==
 
The rif holds the klicensee for both SELF and paid [[EDAT_files|EDAT]].


{| class="wikitable sortable"
{| class="wikitable sortable"
|-
|-
! Value !! Type !! Remarks
| style="background-color:#123EDA; color:#FFFFFF;" |'''Name'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Offset'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Size'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Example'''
| style="background-color:#123EDA; color:#FFFFFF;" |'''Remark'''
|-
|-
| 0 || Unknown (official name) || It does not require any license. Set in [[EDAT_files|SDATA files]].
| Version Number || 0x0 || 0x4 || 00 00 00 01 ||  
|-
|-
| 1 || Network || It requires network authentication every time the content is launched. See [http://en.wikipedia.org/wiki/PlayStation_Network_outage#Inability_to_use_PlayStation_3_content inability example].
| License Type || 0x4 || 0x4 || 00 01 00 02 ||
|-
|-
| 2 || Local || It requires first time activation online (paid content but also demo and free of charge content).
| User Number || 0x8 || 0x8 || 00 00 00 00 00 00 00 02 || Used on Rap2Rif header
|-
|-
| 3 || Free || On PS3, it does not require any license file nor console activation (act.dat). PS3 disc bind contents use this DRM Type. On PSP, when a .rif is present for Free DRM Type, the RIF NP Account ID is replaced by a Magic Gate Memory Stick command result and the RIF encrypted account keyring index is replaced by the sha1 digest of this Magic Gate Memory Stick command result.
| [[PARAM.SFO#CONTENT_ID|CONTENT ID]] || 0x10 || 0x30 || N.A || Content ID
|-
|-
| 4 || PSP || This type exists according to PS3 make_package_npdrm.exe revision 1972. However, no .rif holding this DRM Type was ever seen.
| Random Padding || 0x40 || 0xC || N.A ||
|-
|-
| 0xD || Free (PSP2/PSM) || Used for Free contents but with license (.rif) requirement, unlike DRM Type 3. Requires either pd0:license/rifname.rif (for Welcome Park) or /app/TITLEID/sce_sys/package/temp.bin (for .pkg installed from PS Store).
| act.dat index key || 0x4C || 0x4 || N.A ||
|-
|-
| 0x100 || Network (PSP/PSP2) || Seen in PSP and PS Vita OS. On PSP, extends the RIF ECDSA signed data with IDPS and Fuse ID. On PS Vita, forces OpenPSID comparison in RIF and thus RIF RSA signature verification.
| encrypted klic || 0x50 || 0x10 || N.A  ||
|-
|-
| 0x400 || GameCard (PSP2) || Requires a .rif stored in the gamecard filesystem and the gamecard  to be inserted for authentication.
| bought on/ start || 0x60 || 0x8 || 00 00 01 2F 41 5C 00 00 || For human readable, convert to decimal and use one [http://www.epochconverter.com/ Epoch-Unix converter] time format online.
|-
|-
| 0x2000 || Unknown (PS3) || Seen in EP0001-NPEB00560_00-GRAW2PS3REMPKG01.rif.
| expires in || 0x68 || 0x8 || 00 00 00 00 00 00 00 00 || If zeroed,-, there is no time limit. Used on PS+ for example.
|-
| Signature || 0x70 || 0x28 || 11 || Patched on some cfw. See Rif_Junk on Rap2Rif by '''Flatz'''
|-
|}
|}


NPDRM contents decryption requires a key, the key licensee or klicensee. Depending on the content's DRM Type, klicensee is got in different ways:
*[http://pastie.org/private/yltlfwubsz8w5pyhmojyfg '''Rap2Rif''' source code by '''Flatz''' ]
* DRM type Network: klicensee is generated using associated RIF downloaded on-load from PS Store + ?to detail?
* DRM type Local: klicensee is generated using associated RIF downloaded on-installation from PS Store + act.dat + console's IDPS
* DRM type Free: klicensee is the constant PS3 Free klicensee (see [[Keys#NPDRM_Keys|NPDRM keys]] and [[Keys#Appldr|appldr keys]])
* DRM type Free (PSP2/PSM): klicensee is derived from associated RIF stored in the NPDRM PKG file
* DRM type GameCard: klicensee is derived from associated RIF stored in the gamecard and gamecard authentication command
 
Free games/applications, e.g. demos and free additional contents can either use Free, Free (PSP2/PSM) or Local DRM Types.
 
= License Flags =
 
License Flags are guessed to be either 4 or 6 bytes long (leaving DRM Type either 2 or 4 bytes long).
 
See [[RIF]].
 
* 1 by default
* 0x200 for preordered content that is not usable yet. Seen in EP1004-BLES01807_00-GTAVDLCATOMICBLI.rif, EP1004-NPEB01283_00-GTAVDIGITALDOWNL.rif and EP1004-NPEP00231_00-TGRANDTHEF000001.rif.
 
= Tools =
 
* Tools to convert RAP to klicensee: [[Dev_Tools#ReactPSN_.rap_to_.rif_converter|download links and usage]]


*[http://pastie.org/private/pmnmsnqg6zbfnk9xactbw#1 '''Rap2Rif Key''' souce code by '''Flatz''']


{{File Formats}}<noinclude>[[Category:Main]]</noinclude>
*[[Dev_Tools#ReactPSN_.rap_-.3E_.rif_converter|Link download & usage]]
Please note that all contributions to PS3 Developer wiki are considered to be released under the GNU Free Documentation License 1.2 (see PS3 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)