diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/file_sys/submission_package.cpp | 49 |
1 files changed, 28 insertions, 21 deletions
diff --git a/src/core/file_sys/submission_package.cpp b/src/core/file_sys/submission_package.cpp index 6ff43fa77..b1ebab17f 100644 --- a/src/core/file_sys/submission_package.cpp +++ b/src/core/file_sys/submission_package.cpp | |||
| @@ -18,6 +18,33 @@ | |||
| 18 | #include "core/loader/loader.h" | 18 | #include "core/loader/loader.h" |
| 19 | 19 | ||
| 20 | namespace FileSys { | 20 | namespace FileSys { |
| 21 | namespace { | ||
| 22 | void SetTicketKeys(const std::vector<VirtualFile>& files) { | ||
| 23 | Core::Crypto::KeyManager keys; | ||
| 24 | |||
| 25 | for (const auto& ticket_file : files) { | ||
| 26 | if (ticket_file->GetExtension() != "tik") { | ||
| 27 | continue; | ||
| 28 | } | ||
| 29 | |||
| 30 | if (ticket_file == nullptr || | ||
| 31 | ticket_file->GetSize() < | ||
| 32 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 33 | continue; | ||
| 34 | } | ||
| 35 | |||
| 36 | Core::Crypto::Key128 key{}; | ||
| 37 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 38 | std::string_view name_only(ticket_file->GetName()); | ||
| 39 | name_only.remove_suffix(4); | ||
| 40 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 41 | u128 rights_id; | ||
| 42 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 43 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 44 | } | ||
| 45 | } | ||
| 46 | } // Anonymous namespace | ||
| 47 | |||
| 21 | NSP::NSP(VirtualFile file_) | 48 | NSP::NSP(VirtualFile file_) |
| 22 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, | 49 | : file(std::move(file_)), status{Loader::ResultStatus::Success}, |
| 23 | pfs(std::make_shared<PartitionFilesystem>(file)) { | 50 | pfs(std::make_shared<PartitionFilesystem>(file)) { |
| @@ -43,27 +70,7 @@ NSP::NSP(VirtualFile file_) | |||
| 43 | extracted = false; | 70 | extracted = false; |
| 44 | const auto files = pfs->GetFiles(); | 71 | const auto files = pfs->GetFiles(); |
| 45 | 72 | ||
| 46 | Core::Crypto::KeyManager keys; | 73 | SetTicketKeys(files); |
| 47 | for (const auto& ticket_file : files) { | ||
| 48 | if (ticket_file->GetExtension() != "tik") { | ||
| 49 | continue; | ||
| 50 | } | ||
| 51 | |||
| 52 | if (ticket_file == nullptr || | ||
| 53 | ticket_file->GetSize() < | ||
| 54 | Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { | ||
| 55 | continue; | ||
| 56 | } | ||
| 57 | |||
| 58 | Core::Crypto::Key128 key{}; | ||
| 59 | ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); | ||
| 60 | std::string_view name_only(ticket_file->GetName()); | ||
| 61 | name_only.remove_suffix(4); | ||
| 62 | const auto rights_id_raw = Common::HexStringToArray<16>(name_only); | ||
| 63 | u128 rights_id; | ||
| 64 | std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128)); | ||
| 65 | keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); | ||
| 66 | } | ||
| 67 | 74 | ||
| 68 | for (const auto& outer_file : files) { | 75 | for (const auto& outer_file : files) { |
| 69 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { | 76 | if (outer_file->GetName().substr(outer_file->GetName().size() - 9) != ".cnmt.nca") { |