diff options
| author | Matthew Parlane <parlane@gmail.com> | 2017-03-09 10:58:06 +1300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-03-09 10:58:06 +1300 |
| commit | cd826cee3480483de7fd346eb0f92685d0ae014e (patch) | |
| tree | 6b1cc8b320cde1cb07fc1855db73249ae709a6c3 /Source/Core | |
| parent | be8de62b8867d875ff2dbeeb6a3ba5c41db7d172 (diff) | |
| parent | daa5ff9a81447e2fad1746a17d69c1f07b362de7 (diff) | |
Merge pull request #5039 from leoetlino/es-import-hash-check
IOS/ES: Check the content hash during imports
Diffstat (limited to 'Source/Core')
| -rw-r--r-- | Source/Core/Core/IOS/ES/ES.cpp | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/Source/Core/Core/IOS/ES/ES.cpp b/Source/Core/Core/IOS/ES/ES.cpp index 9a3bd84a73..91a7fdbb9b 100644 --- a/Source/Core/Core/IOS/ES/ES.cpp +++ b/Source/Core/Core/IOS/ES/ES.cpp @@ -14,6 +14,7 @@ #include <vector> #include <mbedtls/aes.h> +#include <mbedtls/sha1.h> #include "Common/Align.h" #include "Common/Assert.h" @@ -581,6 +582,13 @@ IPCCommandResult ES::AddContentData(const IOCtlVRequest& request) return GetDefaultReply(IPC_SUCCESS); } +static bool CheckIfContentHashMatches(const std::vector<u8>& content, const IOS::ES::Content& info) +{ + std::array<u8, 20> sha1; + mbedtls_sha1(content.data(), info.size, sha1.data()); + return sha1 == info.sha1; +} + IPCCommandResult ES::AddContentFinish(const IOCtlVRequest& request) { if (!request.HasNumberOfValidVectors(1, 0)) @@ -615,6 +623,11 @@ IPCCommandResult ES::AddContentFinish(const IOCtlVRequest& request) std::vector<u8> decrypted_data(m_addtitle_content_buffer.size()); mbedtls_aes_crypt_cbc(&aes_ctx, MBEDTLS_AES_DECRYPT, m_addtitle_content_buffer.size(), iv, m_addtitle_content_buffer.data(), decrypted_data.data()); + if (!CheckIfContentHashMatches(decrypted_data, content_info)) + { + ERROR_LOG(IOS_ES, "AddContentFinish: Hash for content %08x doesn't match", content_info.id); + return GetDefaultReply(ES_HASH_DOESNT_MATCH); + } std::string content_path; if (content_info.IsShared()) |
