mirror of
https://github.com/Thealexbarney/LibHac.git
synced 2024-11-14 10:49:41 +01:00
Add external key methods to FS client/server
This commit is contained in:
parent
d291500b28
commit
fdd7eebb4b
6 changed files with 82 additions and 14 deletions
38
src/LibHac/Fs/ExternalKeys.cs
Normal file
38
src/LibHac/Fs/ExternalKeys.cs
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
using LibHac.FsService;
|
||||||
|
using LibHac.Ncm;
|
||||||
|
using LibHac.Spl;
|
||||||
|
|
||||||
|
namespace LibHac.Fs
|
||||||
|
{
|
||||||
|
public static class ExternalKeys
|
||||||
|
{
|
||||||
|
public static Result GetRightsId(this FileSystemClient fs, out RightsId rightsId, TitleId programId,
|
||||||
|
StorageId storageId)
|
||||||
|
{
|
||||||
|
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||||
|
|
||||||
|
return fsProxy.GetRightsId(out rightsId, programId, storageId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result RegisterExternalKey(this FileSystemClient fs, ref RightsId rightsId, ref AccessKey key)
|
||||||
|
{
|
||||||
|
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||||
|
|
||||||
|
return fsProxy.RegisterExternalKey(ref rightsId, ref key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result UnregisterExternalKey(this FileSystemClient fs, ref RightsId rightsId)
|
||||||
|
{
|
||||||
|
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||||
|
|
||||||
|
return fsProxy.UnregisterExternalKey(ref rightsId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result UnregisterAllExternalKey(this FileSystemClient fs)
|
||||||
|
{
|
||||||
|
IFileSystemProxy fsProxy = fs.GetFileSystemProxyServiceObject();
|
||||||
|
|
||||||
|
return fsProxy.UnregisterAllExternalKey();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -451,18 +451,25 @@ namespace LibHac.FsService
|
||||||
|
|
||||||
public Result RegisterExternalKey(ref RightsId rightsId, ref AccessKey externalKey)
|
public Result RegisterExternalKey(ref RightsId rightsId, ref AccessKey externalKey)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// Missing permission check
|
||||||
|
|
||||||
|
return FsProxyCore.RegisterExternalKey(ref rightsId, ref externalKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result UnregisterExternalKey(ref RightsId rightsId)
|
public Result UnregisterExternalKey(ref RightsId rightsId)
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// Missing permission check
|
||||||
|
|
||||||
|
return FsProxyCore.UnregisterExternalKey(ref rightsId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result UnregisterAllExternalKey()
|
public Result UnregisterAllExternalKey()
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
// Missing permission check
|
||||||
|
|
||||||
|
return FsProxyCore.UnregisterAllExternalKey();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
||||||
{
|
{
|
||||||
// todo: use struct instead of byte span
|
// todo: use struct instead of byte span
|
||||||
|
|
|
@ -3,12 +3,14 @@ using LibHac.Fs;
|
||||||
using LibHac.FsSystem;
|
using LibHac.FsSystem;
|
||||||
using LibHac.FsSystem.Save;
|
using LibHac.FsSystem.Save;
|
||||||
using LibHac.FsService.Creators;
|
using LibHac.FsService.Creators;
|
||||||
|
using LibHac.Spl;
|
||||||
|
|
||||||
namespace LibHac.FsService
|
namespace LibHac.FsService
|
||||||
{
|
{
|
||||||
public class FileSystemProxyCore
|
public class FileSystemProxyCore
|
||||||
{
|
{
|
||||||
private FileSystemCreators FsCreators { get; }
|
private FileSystemCreators FsCreators { get; }
|
||||||
|
private ExternalKeySet ExternalKeys { get; }
|
||||||
private byte[] SdEncryptionSeed { get; } = new byte[0x10];
|
private byte[] SdEncryptionSeed { get; } = new byte[0x10];
|
||||||
|
|
||||||
private const string NintendoDirectoryName = "Nintendo";
|
private const string NintendoDirectoryName = "Nintendo";
|
||||||
|
@ -16,9 +18,10 @@ namespace LibHac.FsService
|
||||||
|
|
||||||
private GlobalAccessLogMode LogMode { get; set; }
|
private GlobalAccessLogMode LogMode { get; set; }
|
||||||
|
|
||||||
public FileSystemProxyCore(FileSystemCreators fsCreators)
|
public FileSystemProxyCore(FileSystemCreators fsCreators, ExternalKeySet externalKeys)
|
||||||
{
|
{
|
||||||
FsCreators = fsCreators;
|
FsCreators = fsCreators;
|
||||||
|
ExternalKeys = externalKeys ?? new ExternalKeySet();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Result OpenBisFileSystem(out IFileSystem fileSystem, string rootPath, BisPartitionId partitionId)
|
public Result OpenBisFileSystem(out IFileSystem fileSystem, string rootPath, BisPartitionId partitionId)
|
||||||
|
@ -122,6 +125,25 @@ namespace LibHac.FsService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Result RegisterExternalKey(ref RightsId rightsId, ref AccessKey externalKey)
|
||||||
|
{
|
||||||
|
return ExternalKeys.Add(rightsId, externalKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result UnregisterExternalKey(ref RightsId rightsId)
|
||||||
|
{
|
||||||
|
ExternalKeys.Remove(rightsId);
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result UnregisterAllExternalKey()
|
||||||
|
{
|
||||||
|
ExternalKeys.Clear();
|
||||||
|
|
||||||
|
return Result.Success;
|
||||||
|
}
|
||||||
|
|
||||||
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
public Result SetSdCardEncryptionSeed(ReadOnlySpan<byte> seed)
|
||||||
{
|
{
|
||||||
seed.CopyTo(SdEncryptionSeed);
|
seed.CopyTo(SdEncryptionSeed);
|
||||||
|
|
|
@ -15,16 +15,17 @@ namespace LibHac.FsService
|
||||||
/// Creates a new <see cref="FileSystemServer"/> with a new default <see cref="ITimeSpanGenerator"/>.
|
/// Creates a new <see cref="FileSystemServer"/> with a new default <see cref="ITimeSpanGenerator"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
|
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
|
||||||
public FileSystemServer(FileSystemCreators fsCreators) : this(fsCreators, new StopWatchTimeSpanGenerator()) { }
|
public FileSystemServer(FileSystemCreators fsCreators) : this(fsCreators, null, new StopWatchTimeSpanGenerator()) { }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a new <see cref="FileSystemServer"/>.
|
/// Creates a new <see cref="FileSystemServer"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
|
/// <param name="fsCreators">The <see cref="FileSystemCreators"/> used for creating filesystems.</param>
|
||||||
|
/// <param name="externalKeys">A keyset containing rights IDs and title keys. If null, an empty set will be created.</param>
|
||||||
/// <param name="timer">The <see cref="ITimeSpanGenerator"/> to use for access log timestamps.</param>
|
/// <param name="timer">The <see cref="ITimeSpanGenerator"/> to use for access log timestamps.</param>
|
||||||
public FileSystemServer(FileSystemCreators fsCreators, ITimeSpanGenerator timer)
|
public FileSystemServer(FileSystemCreators fsCreators, ExternalKeySet externalKeys, ITimeSpanGenerator timer)
|
||||||
{
|
{
|
||||||
FsProxyCore = new FileSystemProxyCore(fsCreators);
|
FsProxyCore = new FileSystemProxyCore(fsCreators, externalKeys);
|
||||||
FsClient = new FileSystemClient(this, timer);
|
FsClient = new FileSystemClient(this, timer);
|
||||||
Timer = timer;
|
Timer = timer;
|
||||||
}
|
}
|
||||||
|
|
|
@ -382,7 +382,7 @@ namespace LibHac
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class ExternalKeys
|
public static class ExternalKeyReader
|
||||||
{
|
{
|
||||||
private const int TitleKeySize = 0x10;
|
private const int TitleKeySize = 0x10;
|
||||||
|
|
||||||
|
@ -390,7 +390,7 @@ namespace LibHac
|
||||||
public static readonly Dictionary<string, KeyValue> UniqueKeyDict;
|
public static readonly Dictionary<string, KeyValue> UniqueKeyDict;
|
||||||
public static readonly Dictionary<string, KeyValue> AllKeyDict;
|
public static readonly Dictionary<string, KeyValue> AllKeyDict;
|
||||||
|
|
||||||
static ExternalKeys()
|
static ExternalKeyReader()
|
||||||
{
|
{
|
||||||
List<KeyValue> commonKeys = CreateCommonKeyList();
|
List<KeyValue> commonKeys = CreateCommonKeyList();
|
||||||
List<KeyValue> uniqueKeys = CreateUniqueKeyList();
|
List<KeyValue> uniqueKeys = CreateUniqueKeyList();
|
||||||
|
|
|
@ -174,7 +174,7 @@ namespace hactoolnet
|
||||||
consoleKeyFile = homeConsoleKeyFile;
|
consoleKeyFile = homeConsoleKeyFile;
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.Keyset = ExternalKeys.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile, ctx.Logger);
|
ctx.Keyset = ExternalKeyReader.ReadKeyFile(keyFile, titleKeyFile, consoleKeyFile, ctx.Logger);
|
||||||
if (ctx.Options.SdSeed != null)
|
if (ctx.Options.SdSeed != null)
|
||||||
{
|
{
|
||||||
ctx.Keyset.SetSdSeed(ctx.Options.SdSeed.ToBytes());
|
ctx.Keyset.SetSdSeed(ctx.Options.SdSeed.ToBytes());
|
||||||
|
@ -185,15 +185,15 @@ namespace hactoolnet
|
||||||
string dir = ctx.Options.OutDir;
|
string dir = ctx.Options.OutDir;
|
||||||
Directory.CreateDirectory(dir);
|
Directory.CreateDirectory(dir);
|
||||||
|
|
||||||
File.WriteAllText(Path.Combine(dir, keyFileName), ExternalKeys.PrintCommonKeys(ctx.Keyset));
|
File.WriteAllText(Path.Combine(dir, keyFileName), ExternalKeyReader.PrintCommonKeys(ctx.Keyset));
|
||||||
File.WriteAllText(Path.Combine(dir, "console.keys"), ExternalKeys.PrintUniqueKeys(ctx.Keyset));
|
File.WriteAllText(Path.Combine(dir, "console.keys"), ExternalKeyReader.PrintUniqueKeys(ctx.Keyset));
|
||||||
File.WriteAllText(Path.Combine(dir, "title.keys"), ExternalKeys.PrintTitleKeys(ctx.Keyset));
|
File.WriteAllText(Path.Combine(dir, "title.keys"), ExternalKeyReader.PrintTitleKeys(ctx.Keyset));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ProcessKeygen(Context ctx)
|
private static void ProcessKeygen(Context ctx)
|
||||||
{
|
{
|
||||||
Console.WriteLine(ExternalKeys.PrintCommonKeys(ctx.Keyset));
|
Console.WriteLine(ExternalKeyReader.PrintCommonKeys(ctx.Keyset));
|
||||||
}
|
}
|
||||||
|
|
||||||
// For running random stuff
|
// For running random stuff
|
||||||
|
|
Loading…
Reference in a new issue