early-access version 3508

This commit is contained in:
pineappleEA 2023-04-14 19:07:21 +02:00
parent 60ca72ab85
commit 83a9607e8a
6 changed files with 68 additions and 55 deletions

View File

@ -1,7 +1,7 @@
yuzu emulator early access yuzu emulator early access
============= =============
This is the source code for early-access 3507. This is the source code for early-access 3508.
## Legal Notice ## Legal Notice

View File

@ -210,6 +210,36 @@ Ticket Ticket::SynthesizeCommon(Key128 title_key, const std::array<u8, 16>& righ
return Ticket{out}; return Ticket{out};
} }
bool Ticket::Read(Ticket& ticket_out, const FileSys::VirtualFile& file) {
SignatureType sig_type;
if (file->Read(reinterpret_cast<u8*>(&sig_type), sizeof(sig_type), 0) < sizeof(sig_type)) {
return false;
}
switch (sig_type) {
case SignatureType::RSA_4096_SHA1:
case SignatureType::RSA_4096_SHA256: {
ticket_out.data.emplace<RSA4096Ticket>();
file->Read(reinterpret_cast<u8*>(&ticket_out.data), sizeof(RSA4096Ticket), 0);
return true;
}
case SignatureType::RSA_2048_SHA1:
case SignatureType::RSA_2048_SHA256: {
ticket_out.data.emplace<RSA2048Ticket>();
file->Read(reinterpret_cast<u8*>(&ticket_out.data), sizeof(RSA2048Ticket), 0);
return true;
}
case SignatureType::ECDSA_SHA1:
case SignatureType::ECDSA_SHA256: {
ticket_out.data.emplace<ECDSATicket>();
file->Read(reinterpret_cast<u8*>(&ticket_out.data), sizeof(ECDSATicket), 0);
return true;
}
default:
return false;
}
}
Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, Key128 key_seed) { Key128 GenerateKeyEncryptionKey(Key128 source, Key128 master, Key128 kek_seed, Key128 key_seed) {
Key128 out{}; Key128 out{};
@ -290,9 +320,9 @@ void KeyManager::DeriveGeneralPurposeKeys(std::size_t crypto_revision) {
} }
} }
RSAKeyPair<2048> KeyManager::GetETicketRSAKey() const { void KeyManager::DeriveETicketRSAKey() {
if (IsAllZeroArray(eticket_extended_kek) || !HasKey(S128KeyType::ETicketRSAKek)) { if (IsAllZeroArray(eticket_extended_kek) || !HasKey(S128KeyType::ETicketRSAKek)) {
return {}; return;
} }
const auto eticket_final = GetKey(S128KeyType::ETicketRSAKek); const auto eticket_final = GetKey(S128KeyType::ETicketRSAKek);
@ -304,12 +334,12 @@ RSAKeyPair<2048> KeyManager::GetETicketRSAKey() const {
rsa_1.Transcode(eticket_extended_kek.data() + 0x10, eticket_extended_kek.size() - 0x10, rsa_1.Transcode(eticket_extended_kek.data() + 0x10, eticket_extended_kek.size() - 0x10,
extended_dec.data(), Op::Decrypt); extended_dec.data(), Op::Decrypt);
RSAKeyPair<2048> rsa_key{}; std::memcpy(eticket_rsa_keypair.decryption_key.data(), extended_dec.data(),
std::memcpy(rsa_key.decryption_key.data(), extended_dec.data(), rsa_key.decryption_key.size()); eticket_rsa_keypair.decryption_key.size());
std::memcpy(rsa_key.modulus.data(), extended_dec.data() + 0x100, rsa_key.modulus.size()); std::memcpy(eticket_rsa_keypair.modulus.data(), extended_dec.data() + 0x100,
std::memcpy(rsa_key.exponent.data(), extended_dec.data() + 0x200, rsa_key.exponent.size()); eticket_rsa_keypair.modulus.size());
std::memcpy(eticket_rsa_keypair.exponent.data(), extended_dec.data() + 0x200,
return rsa_key; eticket_rsa_keypair.exponent.size());
} }
Key128 DeriveKeyblobMACKey(const Key128& keyblob_key, const Key128& mac_source) { Key128 DeriveKeyblobMACKey(const Key128& keyblob_key, const Key128& mac_source) {
@ -665,6 +695,14 @@ void KeyManager::LoadFromFile(const std::filesystem::path& file_path, bool is_ti
encrypted_keyblobs[index] = Common::HexStringToArray<0xB0>(out[1]); encrypted_keyblobs[index] = Common::HexStringToArray<0xB0>(out[1]);
} else if (out[0].compare(0, 20, "eticket_extended_kek") == 0) { } else if (out[0].compare(0, 20, "eticket_extended_kek") == 0) {
eticket_extended_kek = Common::HexStringToArray<576>(out[1]); eticket_extended_kek = Common::HexStringToArray<576>(out[1]);
} else if (out[0].compare(0, 19, "eticket_rsa_keypair") == 0) {
const auto key_data = Common::HexStringToArray<528>(out[1]);
std::memcpy(eticket_rsa_keypair.decryption_key.data(), key_data.data(),
eticket_rsa_keypair.decryption_key.size());
std::memcpy(eticket_rsa_keypair.modulus.data(), key_data.data() + 0x100,
eticket_rsa_keypair.modulus.size());
std::memcpy(eticket_rsa_keypair.exponent.data(), key_data.data() + 0x200,
eticket_rsa_keypair.exponent.size());
} else { } else {
for (const auto& kv : KEYS_VARIABLE_LENGTH) { for (const auto& kv : KEYS_VARIABLE_LENGTH) {
if (!ValidCryptoRevisionString(out[0], kv.second.size(), 2)) { if (!ValidCryptoRevisionString(out[0], kv.second.size(), 2)) {
@ -1102,13 +1140,12 @@ void KeyManager::DeriveETicket(PartitionDataManager& data,
eticket_extended_kek = data.GetETicketExtendedKek(); eticket_extended_kek = data.GetETicketExtendedKek();
WriteKeyToFile(KeyCategory::Console, "eticket_extended_kek", eticket_extended_kek); WriteKeyToFile(KeyCategory::Console, "eticket_extended_kek", eticket_extended_kek);
DeriveETicketRSAKey();
PopulateTickets(); PopulateTickets();
} }
void KeyManager::PopulateTickets() { void KeyManager::PopulateTickets() {
const auto rsa_key = GetETicketRSAKey(); if (eticket_rsa_keypair == RSAKeyPair<2048>{}) {
if (rsa_key == RSAKeyPair<2048>{}) {
return; return;
} }
@ -1136,7 +1173,7 @@ void KeyManager::PopulateTickets() {
for (std::size_t i = 0; i < res.size(); ++i) { for (std::size_t i = 0; i < res.size(); ++i) {
const auto common = i < idx; const auto common = i < idx;
const auto pair = ParseTicket(res[i], rsa_key); const auto pair = ParseTicket(res[i], eticket_rsa_keypair);
if (!pair) { if (!pair) {
continue; continue;
} }
@ -1284,12 +1321,11 @@ const std::map<u128, Ticket>& KeyManager::GetPersonalizedTickets() const {
} }
bool KeyManager::AddTicketCommon(Ticket raw) { bool KeyManager::AddTicketCommon(Ticket raw) {
const auto rsa_key = GetETicketRSAKey(); if (eticket_rsa_keypair == RSAKeyPair<2048>{}) {
if (rsa_key == RSAKeyPair<2048>{}) {
return false; return false;
} }
const auto pair = ParseTicket(raw, rsa_key); const auto pair = ParseTicket(raw, eticket_rsa_keypair);
if (!pair) { if (!pair) {
return false; return false;
} }
@ -1303,12 +1339,11 @@ bool KeyManager::AddTicketCommon(Ticket raw) {
} }
bool KeyManager::AddTicketPersonalized(Ticket raw) { bool KeyManager::AddTicketPersonalized(Ticket raw) {
const auto rsa_key = GetETicketRSAKey(); if (eticket_rsa_keypair == RSAKeyPair<2048>{}) {
if (rsa_key == RSAKeyPair<2048>{}) {
return false; return false;
} }
const auto pair = ParseTicket(raw, rsa_key); const auto pair = ParseTicket(raw, eticket_rsa_keypair);
if (!pair) { if (!pair) {
return false; return false;
} }
@ -1316,7 +1351,7 @@ bool KeyManager::AddTicketPersonalized(Ticket raw) {
const auto& [rid, key] = *pair; const auto& [rid, key] = *pair;
u128 rights_id; u128 rights_id;
std::memcpy(rights_id.data(), rid.data(), rid.size()); std::memcpy(rights_id.data(), rid.data(), rid.size());
common_tickets[rights_id] = raw; personal_tickets[rights_id] = raw;
SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]); SetKey(S128KeyType::Titlekey, key, rights_id[1], rights_id[0]);
return true; return true;
} }

View File

@ -29,8 +29,6 @@ enum class ResultStatus : u16;
namespace Core::Crypto { namespace Core::Crypto {
constexpr u64 TICKET_FILE_TITLEKEY_OFFSET = 0x180;
using Key128 = std::array<u8, 0x10>; using Key128 = std::array<u8, 0x10>;
using Key256 = std::array<u8, 0x20>; using Key256 = std::array<u8, 0x20>;
using SHA256Hash = std::array<u8, 0x20>; using SHA256Hash = std::array<u8, 0x20>;
@ -106,6 +104,7 @@ struct Ticket {
u64 GetSize() const; u64 GetSize() const;
static Ticket SynthesizeCommon(Key128 title_key, const std::array<u8, 0x10>& rights_id); static Ticket SynthesizeCommon(Key128 title_key, const std::array<u8, 0x10>& rights_id);
static bool Read(Ticket& ticket_out, const FileSys::VirtualFile& file);
}; };
static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big."); static_assert(sizeof(Key128) == 16, "Key128 must be 128 bytes big.");
@ -280,6 +279,7 @@ private:
std::array<std::array<u8, 0xB0>, 0x20> encrypted_keyblobs{}; std::array<std::array<u8, 0xB0>, 0x20> encrypted_keyblobs{};
std::array<std::array<u8, 0x90>, 0x20> keyblobs{}; std::array<std::array<u8, 0x90>, 0x20> keyblobs{};
std::array<u8, 576> eticket_extended_kek{}; std::array<u8, 576> eticket_extended_kek{};
RSAKeyPair<2048> eticket_rsa_keypair{};
bool dev_mode; bool dev_mode;
void LoadFromFile(const std::filesystem::path& file_path, bool is_title_keys); void LoadFromFile(const std::filesystem::path& file_path, bool is_title_keys);
@ -290,7 +290,7 @@ private:
void DeriveGeneralPurposeKeys(std::size_t crypto_revision); void DeriveGeneralPurposeKeys(std::size_t crypto_revision);
RSAKeyPair<2048> GetETicketRSAKey() const; void DeriveETicketRSAKey();
void SetKeyWrapped(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0); void SetKeyWrapped(S128KeyType id, Key128 key, u64 field1 = 0, u64 field2 = 0);
void SetKeyWrapped(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0); void SetKeyWrapped(S256KeyType id, Key256 key, u64 field1 = 0, u64 field2 = 0);

View File

@ -164,24 +164,6 @@ VirtualFile NSP::GetNCAFile(u64 title_id, ContentRecordType type, TitleType titl
return nullptr; return nullptr;
} }
std::vector<Core::Crypto::Key128> NSP::GetTitlekey() const {
if (extracted)
LOG_WARNING(Service_FS, "called on an NSP that is of type extracted.");
std::vector<Core::Crypto::Key128> out;
for (const auto& ticket_file : ticket_files) {
if (ticket_file == nullptr ||
ticket_file->GetSize() <
Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) {
continue;
}
out.emplace_back();
ticket_file->Read(out.back().data(), out.back().size(),
Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET);
}
return out;
}
std::vector<VirtualFile> NSP::GetFiles() const { std::vector<VirtualFile> NSP::GetFiles() const {
return pfs->GetFiles(); return pfs->GetFiles();
} }
@ -208,22 +190,17 @@ void NSP::SetTicketKeys(const std::vector<VirtualFile>& files) {
continue; continue;
} }
if (ticket_file->GetSize() < Core::Crypto::Ticket ticket{};
Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET + sizeof(Core::Crypto::Key128)) { if (!Core::Crypto::Ticket::Read(ticket, ticket_file)) {
LOG_WARNING(Common_Filesystem, "Could not read NSP ticket {}", ticket_file->GetName());
continue; continue;
} }
Core::Crypto::Key128 key{}; if (ticket.GetData().type == Core::Crypto::TitleKeyType::Common) {
ticket_file->Read(key.data(), key.size(), Core::Crypto::TICKET_FILE_TITLEKEY_OFFSET); keys.AddTicketCommon(ticket);
} else {
// We get the name without the extension in order to create the rights ID. keys.AddTicketPersonalized(ticket);
std::string name_only(ticket_file->GetName()); }
name_only.erase(name_only.size() - 4);
const auto rights_id_raw = Common::HexStringToArray<16>(name_only);
u128 rights_id;
std::memcpy(rights_id.data(), rights_id_raw.data(), sizeof(u128));
keys.SetKey(Core::Crypto::S128KeyType::Titlekey, key, rights_id[1], rights_id[0]);
} }
} }

View File

@ -52,7 +52,6 @@ public:
TitleType title_type = TitleType::Application) const; TitleType title_type = TitleType::Application) const;
VirtualFile GetNCAFile(u64 title_id, ContentRecordType type, VirtualFile GetNCAFile(u64 title_id, ContentRecordType type,
TitleType title_type = TitleType::Application) const; TitleType title_type = TitleType::Application) const;
std::vector<Core::Crypto::Key128> GetTitlekey() const;
std::vector<VirtualFile> GetFiles() const override; std::vector<VirtualFile> GetFiles() const override;

View File

@ -330,6 +330,8 @@ PipelineCache::PipelineCache(RasterizerVulkan& rasterizer_, const Device& device
.lower_left_origin_mode = false, .lower_left_origin_mode = false,
.need_declared_frag_colors = false, .need_declared_frag_colors = false,
.need_gather_subpixel_offset = driver_id == VK_DRIVER_ID_AMD_PROPRIETARY || .need_gather_subpixel_offset = driver_id == VK_DRIVER_ID_AMD_PROPRIETARY ||
driver_id == VK_DRIVER_ID_AMD_OPEN_SOURCE ||
driver_id == VK_DRIVER_ID_MESA_RADV ||
driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS || driver_id == VK_DRIVER_ID_INTEL_PROPRIETARY_WINDOWS ||
driver_id == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA, driver_id == VK_DRIVER_ID_INTEL_OPEN_SOURCE_MESA,