From 6d9510cde455915e914075132228aae9f025080a Mon Sep 17 00:00:00 2001 From: jakcron Date: Fri, 8 Oct 2021 17:59:27 +0800 Subject: [PATCH] Add the ability to import initial_data_kek --- src/KeyBag.cpp | 13 +++++++++++++ src/KeyBag.h | 1 + 2 files changed, 14 insertions(+) diff --git a/src/KeyBag.cpp b/src/KeyBag.cpp index 15af9f3..684ddf1 100644 --- a/src/KeyBag.cpp +++ b/src/KeyBag.cpp @@ -132,6 +132,7 @@ void nstool::KeyBagInitializer::importBaseKeyFile(const tc::io::Path& keyfile_pa std::vector kPkg1Base = { "package1" }; std::vector kPkg2Base = { "package2" }; std::vector kXciHeaderBase = { "xci_header" }; + std::vector kXciInitialDataBase = { "xci_initial_data" }; std::vector kXciCertBase = { "xci_cert" }; std::vector kContentArchiveHeaderBase = { "nca_header", "header" }; std::vector kAcidBase = { "acid" }; @@ -358,6 +359,18 @@ void nstool::KeyBagInitializer::importBaseKeyFile(const tc::io::Path& keyfile_pa //fmt::print("{:s}_{:s}_{:s}\n", kXciHeaderBase[name_idx], kSignKey, kModulusStr); _SAVE_RSAKEY(fmt::format("{:s}_{:s}", kXciHeaderBase[name_idx], kSignKey), xci_header_sign_key, 2048); } + + /* XCI InitialData */ + if (name_idx < kXciInitialDataBase.size()) + { + // xci initial data key (based on index) + for (size_t kek_index = 0; kek_index < 8; kek_index++) + { + //fmt::print("{:s}_{:s}_{:02x}\n", kXciInitialDataBase[name_idx], kKekStr, kek_index); + _SAVE_AES128KEY(fmt::format("{:s}_{:s}_{:02x}", kXciInitialDataBase[name_idx], kKekStr, kek_index), xci_initial_data_kek[kek_index]); + } + } + /* XCI cert */ if (name_idx < kXciCertBase.size()) { diff --git a/src/KeyBag.h b/src/KeyBag.h index a7cb369..e198932 100644 --- a/src/KeyBag.h +++ b/src/KeyBag.h @@ -48,6 +48,7 @@ struct KeyBag // xci tc::Optional xci_header_sign_key; std::map xci_header_key; + std::map xci_initial_data_kek; tc::Optional xci_cert_sign_key; // ticket