aboutsummaryrefslogtreecommitdiff
path: root/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
diff options
context:
space:
mode:
authorTSR Berry <20988865+TSRBerry@users.noreply.github.com>2023-04-08 01:22:00 +0200
committerMary <thog@protonmail.com>2023-04-27 23:51:14 +0200
commitcee712105850ac3385cd0091a923438167433f9f (patch)
tree4a5274b21d8b7f938c0d0ce18736d3f2993b11b1 /src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService
parentcd124bda587ef09668a971fa1cac1c3f0cfc9f21 (diff)
Move solution and projects to src
Diffstat (limited to 'src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService')
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs75
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs47
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs40
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs54
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs187
-rw-r--r--src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs114
6 files changed, 517 insertions, 0 deletions
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs
new file mode 100644
index 00000000..9c058cb5
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForApplication.cs
@@ -0,0 +1,75 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IManagerForApplication : IpcService
+ {
+ private ManagerServer _managerServer;
+
+ public IManagerForApplication(UserId userId)
+ {
+ _managerServer = new ManagerServer(userId);
+ }
+
+ [CommandCmif(0)]
+ // CheckAvailability()
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ return _managerServer.CheckAvailability(context);
+ }
+
+ [CommandCmif(1)]
+ // GetAccountId() -> nn::account::NetworkServiceAccountId
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ return _managerServer.GetAccountId(context);
+ }
+
+ [CommandCmif(2)]
+ // EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context)
+ {
+ ResultCode resultCode = _managerServer.EnsureIdTokenCacheAsync(context, out IAsyncContext asyncContext);
+
+ if (resultCode == ResultCode.Success)
+ {
+ MakeObject(context, asyncContext);
+ }
+
+ return resultCode;
+ }
+
+ [CommandCmif(3)]
+ // LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ return _managerServer.LoadIdTokenCache(context);
+ }
+
+ [CommandCmif(130)]
+ // GetNintendoAccountUserResourceCacheForApplication() -> (nn::account::NintendoAccountId, nn::account::nas::NasUserBaseForApplication, buffer<bytes, 6>)
+ public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
+ {
+ return _managerServer.GetNintendoAccountUserResourceCacheForApplication(context);
+ }
+
+ [CommandCmif(160)] // 5.0.0+
+ // StoreOpenContext()
+ public ResultCode StoreOpenContext(ServiceCtx context)
+ {
+ return _managerServer.StoreOpenContext(context);
+ }
+
+ [CommandCmif(170)] // 6.0.0+
+ // LoadNetworkServiceLicenseKindAsync() -> object<nn::account::detail::IAsyncNetworkServiceLicenseKindContext>
+ public ResultCode LoadNetworkServiceLicenseKindAsync(ServiceCtx context)
+ {
+ ResultCode resultCode = _managerServer.LoadNetworkServiceLicenseKindAsync(context, out IAsyncNetworkServiceLicenseKindContext asyncContext);
+
+ if (resultCode == ResultCode.Success)
+ {
+ MakeObject(context, asyncContext);
+ }
+
+ return resultCode;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs
new file mode 100644
index 00000000..ecd51687
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IManagerForSystemService.cs
@@ -0,0 +1,47 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IManagerForSystemService : IpcService
+ {
+ private ManagerServer _managerServer;
+
+ public IManagerForSystemService(UserId userId)
+ {
+ _managerServer = new ManagerServer(userId);
+ }
+
+ [CommandCmif(0)]
+ // CheckAvailability()
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ return _managerServer.CheckAvailability(context);
+ }
+
+ [CommandCmif(1)]
+ // GetAccountId() -> nn::account::NetworkServiceAccountId
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ return _managerServer.GetAccountId(context);
+ }
+
+ [CommandCmif(2)]
+ // EnsureIdTokenCacheAsync() -> object<nn::account::detail::IAsyncContext>
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context)
+ {
+ ResultCode resultCode = _managerServer.EnsureIdTokenCacheAsync(context, out IAsyncContext asyncContext);
+
+ if (resultCode == ResultCode.Success)
+ {
+ MakeObject(context, asyncContext);
+ }
+
+ return resultCode;
+ }
+
+ [CommandCmif(3)]
+ // LoadIdTokenCache() -> (u32 id_token_cache_size, buffer<bytes, 6>)
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ return _managerServer.LoadIdTokenCache(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs
new file mode 100644
index 00000000..14911dfb
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfile.cs
@@ -0,0 +1,40 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IProfile : IpcService
+ {
+ private ProfileServer _profileServer;
+
+ public IProfile(UserProfile profile)
+ {
+ _profileServer = new ProfileServer(profile);
+ }
+
+ [CommandCmif(0)]
+ // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
+ public ResultCode Get(ServiceCtx context)
+ {
+ return _profileServer.Get(context);
+ }
+
+ [CommandCmif(1)]
+ // GetBase() -> nn::account::profile::ProfileBase
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ return _profileServer.GetBase(context);
+ }
+
+ [CommandCmif(10)]
+ // GetImageSize() -> u32
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ return _profileServer.GetImageSize(context);
+ }
+
+ [CommandCmif(11)]
+ // LoadImage() -> (u32, buffer<bytes, 6>)
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ return _profileServer.LoadImage(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs
new file mode 100644
index 00000000..64b6070f
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/IProfileEditor.cs
@@ -0,0 +1,54 @@
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class IProfileEditor : IpcService
+ {
+ private ProfileServer _profileServer;
+
+ public IProfileEditor(UserProfile profile)
+ {
+ _profileServer = new ProfileServer(profile);
+ }
+
+ [CommandCmif(0)]
+ // Get() -> (nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x1a>)
+ public ResultCode Get(ServiceCtx context)
+ {
+ return _profileServer.Get(context);
+ }
+
+ [CommandCmif(1)]
+ // GetBase() -> nn::account::profile::ProfileBase
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ return _profileServer.GetBase(context);
+ }
+
+ [CommandCmif(10)]
+ // GetImageSize() -> u32
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ return _profileServer.GetImageSize(context);
+ }
+
+ [CommandCmif(11)]
+ // LoadImage() -> (u32, buffer<bytes, 6>)
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ return _profileServer.LoadImage(context);
+ }
+
+ [CommandCmif(100)]
+ // Store(nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x19>)
+ public ResultCode Store(ServiceCtx context)
+ {
+ return _profileServer.Store(context);
+ }
+
+ [CommandCmif(101)]
+ // StoreWithImage(nn::account::profile::ProfileBase, buffer<nn::account::profile::UserData, 0x19>, buffer<bytes, 5>)
+ public ResultCode StoreWithImage(ServiceCtx context)
+ {
+ return _profileServer.StoreWithImage(context);
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs
new file mode 100644
index 00000000..97240311
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ManagerServer.cs
@@ -0,0 +1,187 @@
+using Microsoft.IdentityModel.Tokens;
+using Ryujinx.Common.Logging;
+using Ryujinx.HLE.HOS.Kernel.Threading;
+using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
+using System;
+using System.IdentityModel.Tokens.Jwt;
+using System.Security.Cryptography;
+using System.Text;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class ManagerServer
+ {
+ // TODO: Determine where and how NetworkServiceAccountId is set.
+ private const long NetworkServiceAccountId = 0xcafe;
+
+ private UserId _userId;
+
+ public ManagerServer(UserId userId)
+ {
+ _userId = userId;
+ }
+
+ private static string GenerateIdToken()
+ {
+ using RSA provider = RSA.Create(2048);
+
+ RSAParameters parameters = provider.ExportParameters(true);
+
+ RsaSecurityKey secKey = new RsaSecurityKey(parameters);
+
+ SigningCredentials credentials = new SigningCredentials(secKey, "RS256");
+
+ credentials.Key.KeyId = parameters.ToString();
+
+ var header = new JwtHeader(credentials)
+ {
+ { "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" }
+ };
+
+ byte[] rawUserId = new byte[0x10];
+ RandomNumberGenerator.Fill(rawUserId);
+
+ byte[] deviceId = new byte[0x10];
+ RandomNumberGenerator.Fill(deviceId);
+
+ byte[] deviceAccountId = new byte[0x10];
+ RandomNumberGenerator.Fill(deviceId);
+
+ var payload = new JwtPayload
+ {
+ { "sub", Convert.ToHexString(rawUserId).ToLower() },
+ { "aud", "ed9e2f05d286f7b8" },
+ { "di", Convert.ToHexString(deviceId).ToLower() },
+ { "sn", "XAW10000000000" },
+ { "bs:did", Convert.ToHexString(deviceAccountId).ToLower() },
+ { "iss", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com" },
+ { "typ", "id_token" },
+ { "iat", DateTimeOffset.UtcNow.ToUnixTimeSeconds() },
+ { "jti", Guid.NewGuid().ToString() },
+ { "exp", (DateTimeOffset.UtcNow + TimeSpan.FromHours(3)).ToUnixTimeSeconds() }
+ };
+
+ JwtSecurityToken securityToken = new JwtSecurityToken(header, payload);
+
+ return new JwtSecurityTokenHandler().WriteToken(securityToken);
+ }
+
+ public ResultCode CheckAvailability(ServiceCtx context)
+ {
+ // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x".
+ // Then it searches the Availability of Online Services related to the UserId in this file and returns it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ // NOTE: Even if we try to return different error codes here, the guest still needs other calls.
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetAccountId(ServiceCtx context)
+ {
+ // NOTE: This opens the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted
+ // as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the account:/ savedata.
+ // Then it searches the NetworkServiceAccountId related to the UserId in this file and returns it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
+
+ context.ResponseData.Write(NetworkServiceAccountId);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode EnsureIdTokenCacheAsync(ServiceCtx context, out IAsyncContext asyncContext)
+ {
+ KEvent asyncEvent = new KEvent(context.Device.System.KernelContext);
+ AsyncExecution asyncExecution = new AsyncExecution(asyncEvent);
+
+ asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl);
+
+ asyncContext = new IAsyncContext(asyncExecution);
+
+ // return ResultCode.NullObject if the IAsyncContext pointer is null. Doesn't occur in our case.
+
+ return ResultCode.Success;
+ }
+
+ private async Task EnsureIdTokenCacheAsyncImpl(CancellationToken token)
+ {
+ // NOTE: This open the file at "su/baas/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
+ // in the "account:/" savedata.
+ // Then its read data, use dauth API with this data to get the Token Id and probably store the dauth response
+ // in "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x") in the "account:/" savedata.
+ // Since we don't support online services, we can stub it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ // TODO: Use a real function instead, with the CancellationToken.
+ await Task.CompletedTask;
+ }
+
+ public ResultCode LoadIdTokenCache(ServiceCtx context)
+ {
+ ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
+ ulong bufferSize = context.Request.ReceiveBuff[0].Size;
+
+ // NOTE: This opens the file at "su/cache/USERID_IN_UUID_STRING.dat" (where USERID_IN_UUID_STRING is formatted as "%08x-%04x-%04x-%02x%02x-%08x%04x")
+ // in the "account:/" savedata and writes some data in the buffer.
+ // Since we don't support online services, we can stub it.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ /*
+ if (internal_object != null)
+ {
+ if (bufferSize > 0xC00)
+ {
+ return ResultCode.InvalidIdTokenCacheBufferSize;
+ }
+ }
+ */
+
+ byte[] tokenData = Encoding.ASCII.GetBytes(GenerateIdToken());
+
+ context.Memory.Write(bufferPosition, tokenData);
+ context.ResponseData.Write(tokenData.Length);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetNintendoAccountUserResourceCacheForApplication(ServiceCtx context)
+ {
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { NetworkServiceAccountId });
+
+ context.ResponseData.Write(NetworkServiceAccountId);
+
+ // TODO: determine and fill the output IPC buffer.
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode StoreOpenContext(ServiceCtx context)
+ {
+ context.Device.System.AccountManager.StoreOpenedUsers();
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode LoadNetworkServiceLicenseKindAsync(ServiceCtx context, out IAsyncNetworkServiceLicenseKindContext asyncContext)
+ {
+ KEvent asyncEvent = new KEvent(context.Device.System.KernelContext);
+ AsyncExecution asyncExecution = new AsyncExecution(asyncEvent);
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ // NOTE: This is an extension of the data retrieved from the id token cache.
+ asyncExecution.Initialize(1000, EnsureIdTokenCacheAsyncImpl);
+
+ asyncContext = new IAsyncNetworkServiceLicenseKindContext(asyncExecution, NetworkServiceLicenseKind.Subscribed);
+
+ // return ResultCode.NullObject if the IAsyncNetworkServiceLicenseKindContext pointer is null. Doesn't occur in our case.
+
+ return ResultCode.Success;
+ }
+ }
+} \ No newline at end of file
diff --git a/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
new file mode 100644
index 00000000..8e29f94b
--- /dev/null
+++ b/src/Ryujinx.HLE/HOS/Services/Account/Acc/AccountService/ProfileServer.cs
@@ -0,0 +1,114 @@
+using Ryujinx.Common.Logging;
+using Ryujinx.Cpu;
+using Ryujinx.HLE.Utilities;
+using System.Text;
+
+namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
+{
+ class ProfileServer
+ {
+ private UserProfile _profile;
+
+ public ProfileServer(UserProfile profile)
+ {
+ _profile = profile;
+ }
+
+ public ResultCode Get(ServiceCtx context)
+ {
+ context.Response.PtrBuff[0] = context.Response.PtrBuff[0].WithSize(0x80UL);
+
+ ulong bufferPosition = context.Request.RecvListBuff[0].Position;
+
+ MemoryHelper.FillWithZeros(context.Memory, bufferPosition, 0x80);
+
+ // TODO: Determine the struct.
+ context.Memory.Write(bufferPosition, 0); // Unknown
+ context.Memory.Write(bufferPosition + 4, 1); // Icon ID. 0 = Mii, the rest are character icon IDs.
+ context.Memory.Write(bufferPosition + 8, (byte)1); // Profile icon background color ID
+ // 0x07 bytes - Unknown
+ // 0x10 bytes - Some ID related to the Mii? All zeros when a character icon is used.
+ // 0x60 bytes - Usually zeros?
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc);
+
+ return GetBase(context);
+ }
+
+ public ResultCode GetBase(ServiceCtx context)
+ {
+ _profile.UserId.Write(context.ResponseData);
+
+ context.ResponseData.Write(_profile.LastModifiedTimestamp);
+
+ byte[] username = StringUtils.GetFixedLengthBytes(_profile.Name, 0x20, Encoding.UTF8);
+
+ context.ResponseData.Write(username);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode GetImageSize(ServiceCtx context)
+ {
+ context.ResponseData.Write(_profile.Image.Length);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode LoadImage(ServiceCtx context)
+ {
+ ulong bufferPosition = context.Request.ReceiveBuff[0].Position;
+ ulong bufferLen = context.Request.ReceiveBuff[0].Size;
+
+ if ((ulong)_profile.Image.Length > bufferLen)
+ {
+ return ResultCode.InvalidBufferSize;
+ }
+
+ context.Memory.Write(bufferPosition, _profile.Image);
+
+ context.ResponseData.Write(_profile.Image.Length);
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode Store(ServiceCtx context)
+ {
+ ulong userDataPosition = context.Request.PtrBuff[0].Position;
+ ulong userDataSize = context.Request.PtrBuff[0].Size;
+
+ byte[] userData = new byte[userDataSize];
+
+ context.Memory.Read(userDataPosition, userData);
+
+ // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize });
+
+ return ResultCode.Success;
+ }
+
+ public ResultCode StoreWithImage(ServiceCtx context)
+ {
+ ulong userDataPosition = context.Request.PtrBuff[0].Position;
+ ulong userDataSize = context.Request.PtrBuff[0].Size;
+
+ byte[] userData = new byte[userDataSize];
+
+ context.Memory.Read(userDataPosition, userData);
+
+ ulong profileImagePosition = context.Request.SendBuff[0].Position;
+ ulong profileImageSize = context.Request.SendBuff[0].Size;
+
+ byte[] profileImageData = new byte[profileImageSize];
+
+ context.Memory.Read(profileImagePosition, profileImageData);
+
+ // TODO: Read the nn::account::profile::ProfileBase and store everything in the savedata.
+
+ Logger.Stub?.PrintStub(LogClass.ServiceAcc, new { userDataSize, profileImageSize });
+
+ return ResultCode.Success;
+ }
+ }
+} \ No newline at end of file