diff --git a/include/core/nacp.h b/include/core/nacp.h index 34ac952..63d6ed4 100644 --- a/include/core/nacp.h +++ b/include/core/nacp.h @@ -335,8 +335,8 @@ typedef struct { u8 logo_handling; ///< NacpLogoHandling. u8 runtime_add_on_content_install; ///< NacpRuntimeAddOnContentInstall. u8 runtime_parameter_delivery; ///< NacpRuntimeParameterDelivery. - u8 undecided_parameter_75b8b; ///< NacpUndecidedParameter75b8b. u8 reserved_1; + u8 undecided_parameter_75b8b; ///< NacpUndecidedParameter75b8b. u8 crash_report; ///< NacpCrashReport. u8 hdcp; ///< NacpHdcp. u64 seed_for_pseudo_device_id; diff --git a/include/core/nca.h b/include/core/nca.h index 29baae5..f01bf2b 100644 --- a/include/core/nca.h +++ b/include/core/nca.h @@ -83,7 +83,7 @@ typedef enum { NcaKeyGeneration_Since900NUP = 10, ///< 9.0.0 - 9.0.1. NcaKeyGeneration_Since910NUP = 11, ///< 9.1.0 - 12.0.3. NcaKeyGeneration_Since1210NUP = 12, ///< 12.1.0. - NcaKeyGeneration_Since1300NUP = 13, ///< 13.0.0. + NcaKeyGeneration_Since1300NUP = 13, ///< 13.0.0 - 13.2.0. NcaKeyGeneration_Current = NcaKeyGeneration_Since1300NUP, NcaKeyGeneration_Max = 32 } NcaKeyGeneration; diff --git a/source/core/tik.c b/source/core/tik.c index c0befa7..7a90ffb 100644 --- a/source/core/tik.c +++ b/source/core/tik.c @@ -108,6 +108,7 @@ bool tikRetrieveTicketByRightsId(Ticket *dst, const FsRightsId *id, bool use_gam return false; } + u8 key_generation = id->c[0xF]; TikCommonBlock *tik_common_block = NULL; /* Check if this ticket has already been retrieved. */ @@ -135,16 +136,23 @@ bool tikRetrieveTicketByRightsId(Ticket *dst, const FsRightsId *id, bool use_gam return false; } - /* Even though tickets do have a proper key_generation field, we'll just retrieve it from the rights_id field. */ - /* Old custom tools used to wipe the key_generation field or save its value to a different offset. */ - if (!tikGetDecryptedTitleKey(dst->dec_titlekey, dst->enc_titlekey, id->c[0xF])) + /* Get common ticket block. */ + tik_common_block = tikGetCommonBlock(dst->data); + + /* Get proper key generation value. */ + /* Nintendo didn't start putting the key generation value into the rights ID until HOS 3.0.1. */ + /* If this is the case, we'll just use the key generation value from the common ticket block. */ + /* However, old custom tools used to wipe the key generation field or save its value to a different offset, so this may fail with titles with custom/modified tickets. */ + if (key_generation < NcaKeyGeneration_Since301NUP || key_generation > NcaKeyGeneration_Max) key_generation = tik_common_block->key_generation; + + /* Get decrypted titlekey. */ + if (!tikGetDecryptedTitleKey(dst->dec_titlekey, dst->enc_titlekey, key_generation)) { LOG_MSG("Unable to decrypt titlekey!"); return false; } /* Generate rights ID string. */ - tik_common_block = tikGetCommonBlock(dst->data); utilsGenerateHexStringFromData(dst->rights_id_str, sizeof(dst->rights_id_str), tik_common_block->rights_id.c, sizeof(tik_common_block->rights_id.c), false); return true;