Added support to read rsa key provided by the user

This commit is contained in:
ergo720 2018-04-12 22:19:45 +02:00
parent 6b6f6265f5
commit 0b972c7989
3 changed files with 41 additions and 7 deletions

View File

@ -438,7 +438,7 @@ XBSYSAPI EXPORTNUM(354) XBOX_KEY_DATA XboxAlternateSignatureKeys[ALTERNATE_SIGNA
// ******************************************************************
// * 0x0163 - XePublicKeyData
// ******************************************************************
XBSYSAPI EXPORTNUM(355) DWORD XePublicKeyData;
XBSYSAPI EXPORTNUM(355) UCHAR XePublicKeyData[284];
// ******************************************************************
// * 0x0165 - IdexChannelObject

View File

@ -912,12 +912,13 @@ void CxbxKrnlMain(int argc, char* argv[])
void LoadXboxKeys(std::string path)
{
std::string keys_path = path + "\\keys.bin";
std::string RSA_key_path = path + "\\RSAkey.bin";
// Attempt to open Keys.bin
FILE* fp = fopen(keys_path.c_str(), "rb");
if (fp != nullptr) {
// Determine size of Keys.bin
// Determine the size of Keys.bin
xboxkrnl::XBOX_KEY_DATA keys[2];
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
@ -934,11 +935,44 @@ void LoadXboxKeys(std::string path)
}
fclose(fp);
return;
}
else
{
// keys.bin could not be loaded
EmuWarning("Failed to load Keys.bin. Cxbx-Reloaded will be unable to read Save Data from a real Xbox");
}
// If we didn't already exit the function, keys.bin could not be loaded
EmuWarning("Failed to load Keys.bin. Cxbx-Reloaded will be unable to read Save Data from a real Xbox");
// Now load the RSA key data if available
fp = fopen(RSA_key_path.c_str(), "rb");
if (fp != nullptr) {
// Determine the size of RSAkey.bin
fseek(fp, 0, SEEK_END);
long size = ftell(fp);
rewind(fp);
// Ensure that RSAkey.bin is 284 bytes and has a valid magic signature
if (size == 284) {
UCHAR temp[284] = { 0 };
fread(temp, 284, 1, fp);
if (!memcmp(temp, "RSA1", 4)) {
memcpy(xboxkrnl::XePublicKeyData, temp, 284);
}
else {
EmuWarning("RSAkey.bin has an invalid magic signature. Should be \"RSA1\"");
}
}
else {
EmuWarning("RSAkey.bin has an incorrect filesize. Should be 284 bytes");
}
fclose(fp);
}
else
{
// RSAkey.bin could not be loaded
EmuWarning("Failed to load RSAkey.bin. Cxbx-Reloaded will be unable to verify the integrity of the loaded xbe");
}
}
__declspec(noreturn) void CxbxKrnlInit

View File

@ -175,6 +175,6 @@ XBSYSAPI EXPORTNUM(328) xboxkrnl::NTSTATUS NTAPI xboxkrnl::XeUnloadSection
// ******************************************************************
// * 0x0163 - XePublicKeyData
// ******************************************************************
// TODO : What should we initialize this to?
XBSYSAPI EXPORTNUM(355) xboxkrnl::DWORD xboxkrnl::XePublicKeyData = 0;
// Read from RSAkey.bin if found, otherwise all-zeros
XBSYSAPI EXPORTNUM(355) xboxkrnl::UCHAR xboxkrnl::XePublicKeyData[284] = { 0 };