Skip to content
Permalink
Browse files

WiiSave: Fix save signing

The system menu is passing the SHA1 hash of the save data to ES
to sign, not the save data itself.

Fixes save import in the System Menu for saves that were exported
by Dolphin.
  • Loading branch information...
leoetlino committed May 6, 2019
1 parent 6f6c7e5 commit 2740ff9a9d1207ec6d4ea34ff7bc1db2ede619a0
Showing with 12 additions and 7 deletions.
  1. +12 −7 Source/Core/Core/HW/WiiSave.cpp
@@ -15,6 +15,7 @@
#include <cstdio>
#include <cstring>
#include <mbedtls/md5.h>
#include <mbedtls/sha1.h>
#include <memory>
#include <optional>
#include <string>
@@ -403,17 +404,21 @@ class DataBinStorage final : public Storage
return false;

// Read data to sign.
const u32 data_size = bk_header->size_of_files + sizeof(BkHeader);
auto data = std::make_unique<u8[]>(data_size);
m_file.Seek(sizeof(Header), SEEK_SET);
if (!m_file.ReadBytes(data.get(), data_size))
return false;
std::array<u8, 20> data_sha1;
{
const u32 data_size = bk_header->size_of_files + sizeof(BkHeader);
auto data = std::make_unique<u8[]>(data_size);
m_file.Seek(sizeof(Header), SEEK_SET);
if (!m_file.ReadBytes(data.get(), data_size))
return false;
mbedtls_sha1(data.get(), data_size, data_sha1.data());
}

// Sign the data.
IOS::CertECC ap_cert;
Common::ec::Signature ap_sig;
m_iosc.Sign(ap_sig.data(), reinterpret_cast<u8*>(&ap_cert), Titles::SYSTEM_MENU, data.get(),
data_size);
m_iosc.Sign(ap_sig.data(), reinterpret_cast<u8*>(&ap_cert), Titles::SYSTEM_MENU,
data_sha1.data(), static_cast<u32>(data_sha1.size()));

// Write signatures.
if (!m_file.Seek(0, SEEK_END))

0 comments on commit 2740ff9

Please sign in to comment.
You can’t perform that action at this time.