mirror of
https://github.com/ryujinx-mirror/ryujinx.git
synced 2024-12-23 03:05:45 +00:00
Always use an all-zeros key for AES-XTS file systems (#2561)
This commit is contained in:
parent
680d3ed198
commit
cd4530f29c
2 changed files with 65 additions and 0 deletions
62
Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs
Normal file
62
Ryujinx.HLE/FileSystem/EncryptedFileSystemCreator.cs
Normal file
|
@ -0,0 +1,62 @@
|
|||
using LibHac;
|
||||
using LibHac.Common;
|
||||
using LibHac.Fs;
|
||||
using LibHac.Fs.Fsa;
|
||||
using LibHac.FsSrv.FsCreator;
|
||||
using LibHac.FsSystem;
|
||||
|
||||
namespace Ryujinx.HLE.FileSystem
|
||||
{
|
||||
public class EncryptedFileSystemCreator : IEncryptedFileSystemCreator
|
||||
{
|
||||
public EncryptedFileSystemCreator() { }
|
||||
|
||||
public Result Create(out ReferenceCountedDisposable<IFileSystem> encryptedFileSystem, ReferenceCountedDisposable<IFileSystem> baseFileSystem,
|
||||
EncryptedFsKeyId keyId, in EncryptionSeed encryptionSeed)
|
||||
{
|
||||
UnsafeHelpers.SkipParamInit(out encryptedFileSystem);
|
||||
|
||||
if (keyId < EncryptedFsKeyId.Save || keyId > EncryptedFsKeyId.CustomStorage)
|
||||
{
|
||||
return ResultFs.InvalidArgument.Log();
|
||||
}
|
||||
|
||||
// Force all-zero keys for now since people can open the emulator with different keys or sd seeds sometimes
|
||||
var fs = new AesXtsFileSystem(baseFileSystem, new byte[0x32], 0x4000);
|
||||
var aesFileSystem = new ReferenceCountedDisposable<IFileSystem>(fs);
|
||||
|
||||
// This wrapper will handle deleting files that were created with different keys
|
||||
var wrappedFs = new ChangedEncryptionHandlingFileSystem(aesFileSystem);
|
||||
encryptedFileSystem = new ReferenceCountedDisposable<IFileSystem>(wrappedFs);
|
||||
|
||||
return Result.Success;
|
||||
}
|
||||
}
|
||||
|
||||
public class ChangedEncryptionHandlingFileSystem : ForwardingFileSystem
|
||||
{
|
||||
public ChangedEncryptionHandlingFileSystem(ReferenceCountedDisposable<IFileSystem> baseFileSystem) : base(baseFileSystem) { }
|
||||
|
||||
protected override Result DoOpenFile(out IFile file, U8Span path, OpenMode mode)
|
||||
{
|
||||
UnsafeHelpers.SkipParamInit(out file);
|
||||
|
||||
try
|
||||
{
|
||||
return base.DoOpenFile(out file, path, mode);
|
||||
}
|
||||
catch (HorizonResultException ex)
|
||||
{
|
||||
if (ResultFs.AesXtsFileHeaderInvalidKeys.Includes(ex.ResultValue))
|
||||
{
|
||||
Result rc = DeleteFile(path);
|
||||
if (rc.IsFailure()) return rc;
|
||||
|
||||
return base.DoOpenFile(out file, path, mode);
|
||||
}
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -178,6 +178,9 @@ namespace Ryujinx.HLE.FileSystem
|
|||
|
||||
DefaultFsServerObjects fsServerObjects = DefaultFsServerObjects.GetDefaultEmulatedCreators(serverBaseFs, KeySet, fsServer);
|
||||
|
||||
// Use our own encrypted fs creator that always uses all-zero keys
|
||||
fsServerObjects.FsCreators.EncryptedFileSystemCreator = new EncryptedFileSystemCreator();
|
||||
|
||||
GameCard = fsServerObjects.GameCard;
|
||||
SdCard = fsServerObjects.SdCard;
|
||||
|
||||
|
|
Loading…
Reference in a new issue