Re-implement FixCommonKeyIndex for WAD files

The old implementation of this was not able to distinguish between
a title that had the common key index set to 1 because it actually
was Korean and a title that had the common key index set to 1 due to
fakesigning. This new implementation solves the problem by
decrypting a content with each possible common key and checking
which result matches the provided SHA-1 hash.

The problem that the old implementation causes has only been reported
to affect a certain pirated WAD of Chronos Twins DX (WC6EUP), but it's
possible that the problem would start affecting more WADs if we add
support for the vWii common key (which uses index 2). Adding support
for the vWii common key would also prevent us from using the simpler
solution of always forcing the index to 0 if the title is not Korean.
This commit is contained in:
JosJuice committed 2019-07-21 09:58:16 +02:00
1 parent 4ee73dbad3
commit 4b73d18eaa
8 files changed
+137 -58

No files matched your search

+4 -6
View File
@@ -455,8 +455,8 @@ std::array<u8, 16> TicketReader::GetTitleKey(const HLE::IOSC& iosc) const
u8 index = m_bytes.at(offsetof(Ticket, common_key_index));
if (index >= HLE::IOSC::COMMON_KEY_HANDLES.size())
{
WARN_LOG(IOS_ES, "Bad common key index for title %016" PRIx64 ": %u -- using common key 0",
GetTitleId(), index);
PanicAlert("Bad common key index for title %016" PRIx64 ": %u -- using common key 0",
GetTitleId(), index);
index = 0;
}
auto common_key_handle = HLE::IOSC::COMMON_KEY_HANDLES[index];
@@ -533,11 +533,9 @@ HLE::ReturnCode TicketReader::Unpersonalise(HLE::IOSC& iosc)
return ret;
}
void TicketReader::FixCommonKeyIndex()
void TicketReader::OverwriteCommonKeyIndex(u8 index)
{
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 < HLE::IOSC::COMMON_KEY_HANDLES.size() ? index : 0;
m_bytes[offsetof(Ticket, common_key_index)] = index;
}
struct SharedContentMap::Entry
+1 -2
View File
@@ -257,9 +257,8 @@ public:
// 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();
void OverwriteCommonKeyIndex(u8 index);
};
class SharedContentMap final