diff --git a/Source/Core/Core/IOS/IOSC.cpp b/Source/Core/Core/IOS/IOSC.cpp index 16d1734a29..a83a84f50f 100644 --- a/Source/Core/Core/IOS/IOSC.cpp +++ b/Source/Core/Core/IOS/IOSC.cpp @@ -85,11 +85,19 @@ constexpr size_t AES128_KEY_SIZE = 0x10; ReturnCode IOSC::ImportSecretKey(Handle dest_handle, Handle decrypt_handle, u8* iv, const u8* encrypted_key, u32 pid) { - if (!HasOwnership(dest_handle, pid) || !HasOwnership(decrypt_handle, pid) || - IsDefaultHandle(dest_handle)) - { + std::array decrypted_key; + const ReturnCode ret = + Decrypt(decrypt_handle, iv, encrypted_key, AES128_KEY_SIZE, decrypted_key.data(), pid); + if (ret != IPC_SUCCESS) + return ret; + + return ImportSecretKey(dest_handle, decrypted_key.data(), pid); +} + +ReturnCode IOSC::ImportSecretKey(Handle dest_handle, const u8* decrypted_key, u32 pid) +{ + if (!HasOwnership(dest_handle, pid) || IsDefaultHandle(dest_handle)) return IOSC_EACCES; - } KeyEntry* dest_entry = FindEntry(dest_handle); if (!dest_entry) @@ -99,8 +107,8 @@ ReturnCode IOSC::ImportSecretKey(Handle dest_handle, Handle decrypt_handle, u8* if (dest_entry->type != TYPE_SECRET_KEY || dest_entry->subtype != SUBTYPE_AES128) return IOSC_INVALID_OBJTYPE; - dest_entry->data.resize(AES128_KEY_SIZE); - return Decrypt(decrypt_handle, iv, encrypted_key, AES128_KEY_SIZE, dest_entry->data.data(), pid); + dest_entry->data = std::vector(decrypted_key, decrypted_key + AES128_KEY_SIZE); + return IPC_SUCCESS; } ReturnCode IOSC::ImportPublicKey(Handle dest_handle, const u8* public_key, diff --git a/Source/Core/Core/IOS/IOSC.h b/Source/Core/Core/IOS/IOSC.h index 653b7a3a01..33ddc3ded2 100644 --- a/Source/Core/Core/IOS/IOSC.h +++ b/Source/Core/Core/IOS/IOSC.h @@ -172,6 +172,8 @@ public: // Import a secret, encrypted key into dest_handle, which will be decrypted using decrypt_handle. ReturnCode ImportSecretKey(Handle dest_handle, Handle decrypt_handle, u8* iv, const u8* encrypted_key, u32 pid); + // Import a secret key that is already decrypted. + ReturnCode ImportSecretKey(Handle dest_handle, const u8* decrypted_key, u32 pid); // Import a public key. public_key_exponent must be passed for RSA keys. ReturnCode ImportPublicKey(Handle dest_handle, const u8* public_key, const u8* public_key_exponent, u32 pid);