Skip to content

Commit

Permalink
Force ticket to have a correct key index for importing
Browse files Browse the repository at this point in the history
This commit changes the import code to ensure the common key index
in the ticket is correct, as it's checked by IOS.
  • Loading branch information
leoetlino committed Jul 30, 2017
1 parent 7c1aa9f commit 072991f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
7 changes: 7 additions & 0 deletions Source/Core/Core/IOS/ES/Formats.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions Source/Core/Core/IOS/ES/Formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,10 @@ class TicketReader final : public SignedBlobReader
// 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
Expand Down
7 changes: 6 additions & 1 deletion Source/Core/Core/WiiUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 072991f

Please sign in to comment.