Merge pull request #5846 from leoetlino/fakesigned-tickets

Force ticket to have a correct key index for importing
This commit is contained in:
Anthony 2017-07-30 09:59:56 -07:00 committed by GitHub
commit 8da42fad73
3 changed files with 17 additions and 1 deletions

View File

@ -463,6 +463,13 @@ HLE::ReturnCode TicketReader::Unpersonalise(HLE::IOSC& iosc)
return ret;
}
void TicketReader::FixCommonKeyIndex()
{
u8& index = m_bytes[offsetof(Ticket, common_key_index)];
// Assume the ticket is using the normal common key if it's an invalid value.
index = index <= 1 ? index : 0;
}
struct SharedContentMap::Entry
{
// ID string

View File

@ -238,6 +238,10 @@ public:
// Decrypts the title key field for a "personalised" ticket -- one that is device-specific
// and has a title key that must be decrypted first.
HLE::ReturnCode Unpersonalise(HLE::IOSC& iosc);
// Reset the common key field back to 0 if it's an incorrect value.
// Intended for use before importing fakesigned tickets, which tend to have a high bogus index.
void FixCommonKeyIndex();
};
class SharedContentMap final

View File

@ -54,7 +54,12 @@ bool InstallWAD(const std::string& wad_path)
IOS::HLE::Device::ES::Context context;
IOS::HLE::ReturnCode ret;
const bool checks_enabled = SConfig::GetInstance().m_enable_signature_checks;
while ((ret = es->ImportTicket(wad.GetTicket().GetBytes(), wad.GetCertificateChain())) < 0 ||
IOS::ES::TicketReader ticket = wad.GetTicket();
// Ensure the common key index is correct, as it's checked by IOS.
ticket.FixCommonKeyIndex();
while ((ret = es->ImportTicket(ticket.GetBytes(), wad.GetCertificateChain())) < 0 ||
(ret = es->ImportTitleInit(context, tmd.GetBytes(), wad.GetCertificateChain())) < 0)
{
if (checks_enabled && ret == IOS::HLE::IOSC_FAIL_CHECKVALUE &&