diff --git a/programs/nstool/source/UserSettings.cpp b/programs/nstool/source/UserSettings.cpp index f50b9b1..58261fc 100644 --- a/programs/nstool/source/UserSettings.cpp +++ b/programs/nstool/source/UserSettings.cpp @@ -22,7 +22,8 @@ #include #include #include -#include +#include +#include UserSettings::UserSettings() {} @@ -66,6 +67,7 @@ void UserSettings::showHelp() printf(" --listfs Print file system in embedded partitions.\n"); printf(" --titlekey Specify title key extracted from ticket.\n"); printf(" --bodykey Specify body encryption key.\n"); + printf(" --tik Specify ticket to source title key.\n"); printf(" --part0 Extract \"partition 0\" to directory.\n"); printf(" --part1 Extract \"partition 1\" to directory.\n"); printf(" --part2 Extract \"partition 2\" to directory.\n"); @@ -297,6 +299,12 @@ void UserSettings::populateCmdArgs(const std::vector& arg_list, sCm cmd_args.nca_bodykey = arg_list[i+1]; } + else if (arg_list[i] == "--tik") + { + if (!hasParamter) throw fnd::Exception(kModuleName, arg_list[i] + " requries a parameter."); + cmd_args.ticket_path = arg_list[i+1]; + } + else if (arg_list[i] == "--part0") { if (!hasParamter) throw fnd::Exception(kModuleName, arg_list[i] + " requries a parameter."); @@ -527,6 +535,28 @@ void UserSettings::populateKeyset(sCmdArgs& args) } } + // get titlekey from ticket + if (args.ticket_path.isSet) + { + fnd::SimpleFile tik_file; + fnd::Vec tik_raw; + pki::SignedData tik; + + tik_file.open(args.ticket_path.var, fnd::SimpleFile::Read); + tik_raw.alloc(tik_file.size()); + tik_file.read(tik_raw.data(), tik_raw.size()); + tik.fromBytes(tik_raw.data(), tik_raw.size()); + + if (tik.getBody().getTitleKeyEncType() == es::ticket::AES128_CBC) + { + memcpy(mKeyset.nca.manual_title_key_aesctr.key, tik.getBody().getEncTitleKey(), crypto::aes::kAes128KeySize); + } + else + { + std::cout << "[WARNING] Titlekey not imported from ticket because it is personalised" << std::endl; + } + } + #undef _SAVE_KEYDATA #undef _CONCAT_3_STRINGS #undef _CONCAT_2_STRINGS diff --git a/programs/nstool/source/UserSettings.h b/programs/nstool/source/UserSettings.h index 505b586..43d773c 100644 --- a/programs/nstool/source/UserSettings.h +++ b/programs/nstool/source/UserSettings.h @@ -62,6 +62,7 @@ private: sOptional fs_path; sOptional nca_titlekey; sOptional nca_bodykey; + sOptional ticket_path; sOptional part0_path; sOptional part1_path; sOptional part2_path;