0
0
Fork 0
mirror of https://github.com/GreemDev/Ryujinx.git synced 2024-12-22 22:45:46 +00:00

Switch to Microsoft.IdentityModel.JsonWebTokens (#6108)

* Switch to `Microsoft.IdentityModel.JsonWebTokens`

* Formatting
This commit is contained in:
Isaac Marovitz 2024-01-13 10:39:00 +00:00 committed by GitHub
parent 1a45dc8df8
commit 4fbc978e73
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 23 deletions

View file

@ -21,6 +21,7 @@
<PackageVersion Include="LibHac" Version="0.19.0" /> <PackageVersion Include="LibHac" Version="0.19.0" />
<PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" /> <PackageVersion Include="Microsoft.CodeAnalysis.Analyzers" Version="3.3.4" />
<PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" /> <PackageVersion Include="Microsoft.CodeAnalysis.CSharp" Version="4.7.0" />
<PackageVersion Include="Microsoft.IdentityModel.JsonWebTokens" Version="7.2.0" />
<PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" /> <PackageVersion Include="Microsoft.NET.Test.Sdk" Version="17.8.0" />
<PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" /> <PackageVersion Include="Microsoft.IO.RecyclableMemoryStream" Version="2.3.2" />
<PackageVersion Include="MsgPack.Cli" Version="1.0.1" /> <PackageVersion Include="MsgPack.Cli" Version="1.0.1" />
@ -46,7 +47,6 @@
<PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" /> <PackageVersion Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
<PackageVersion Include="SPB" Version="0.0.4-build28" /> <PackageVersion Include="SPB" Version="0.0.4-build28" />
<PackageVersion Include="System.Drawing.Common" Version="8.0.0" /> <PackageVersion Include="System.Drawing.Common" Version="8.0.0" />
<PackageVersion Include="System.IdentityModel.Tokens.Jwt" Version="7.0.3" />
<PackageVersion Include="System.IO.Hashing" Version="8.0.0" /> <PackageVersion Include="System.IO.Hashing" Version="8.0.0" />
<PackageVersion Include="System.Management" Version="8.0.0" /> <PackageVersion Include="System.Management" Version="8.0.0" />
<PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" /> <PackageVersion Include="UnicornEngine.Unicorn" Version="2.0.2-rc1-fb78016" />

View file

@ -1,10 +1,12 @@
using Microsoft.IdentityModel.JsonWebTokens;
using Microsoft.IdentityModel.Tokens; using Microsoft.IdentityModel.Tokens;
using Ryujinx.Common.Logging; using Ryujinx.Common.Logging;
using Ryujinx.HLE.HOS.Kernel.Threading; using Ryujinx.HLE.HOS.Kernel.Threading;
using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext; using Ryujinx.HLE.HOS.Services.Account.Acc.AsyncContext;
using System; using System;
using System.IdentityModel.Tokens.Jwt; using System.Collections.Generic;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Principal;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
@ -37,11 +39,6 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
credentials.Key.KeyId = parameters.ToString(); 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]; byte[] rawUserId = new byte[0x10];
RandomNumberGenerator.Fill(rawUserId); RandomNumberGenerator.Fill(rawUserId);
@ -51,23 +48,25 @@ namespace Ryujinx.HLE.HOS.Services.Account.Acc.AccountService
byte[] deviceAccountId = new byte[0x10]; byte[] deviceAccountId = new byte[0x10];
RandomNumberGenerator.Fill(deviceId); RandomNumberGenerator.Fill(deviceId);
var payload = new JwtPayload var descriptor = new SecurityTokenDescriptor
{ {
{ "sub", Convert.ToHexString(rawUserId).ToLower() }, Subject = new GenericIdentity(Convert.ToHexString(rawUserId).ToLower()),
{ "aud", "ed9e2f05d286f7b8" }, SigningCredentials = credentials,
{ "di", Convert.ToHexString(deviceId).ToLower() }, Audience = "ed9e2f05d286f7b8",
{ "sn", "XAW10000000000" }, Issuer = "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com",
{ "bs:did", Convert.ToHexString(deviceAccountId).ToLower() }, TokenType = "id_token",
{ "iss", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com" }, IssuedAt = DateTime.UtcNow,
{ "typ", "id_token" }, Expires = DateTime.UtcNow + TimeSpan.FromHours(3),
{ "iat", DateTimeOffset.UtcNow.ToUnixTimeSeconds() }, Claims = new Dictionary<string, object>
{ "jti", Guid.NewGuid().ToString() }, {
{ "exp", (DateTimeOffset.UtcNow + TimeSpan.FromHours(3)).ToUnixTimeSeconds() }, { "jku", "https://e0d67c509fb203858ebcb2fe3f88c2aa.baas.nintendo.com/1.0.0/certificates" },
{ "di", Convert.ToHexString(deviceId).ToLower() },
{ "sn", "XAW10000000000" },
{ "bs:did", Convert.ToHexString(deviceAccountId).ToLower() }
}
}; };
JwtSecurityToken securityToken = new(header, payload); return new JsonWebTokenHandler().CreateToken(descriptor);
return new JwtSecurityTokenHandler().WriteToken(securityToken);
} }
public ResultCode CheckAvailability(ServiceCtx context) public ResultCode CheckAvailability(ServiceCtx context)

View file

@ -23,10 +23,10 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Concentus" /> <PackageReference Include="Concentus" />
<PackageReference Include="LibHac" /> <PackageReference Include="LibHac" />
<PackageReference Include="Microsoft.IdentityModel.JsonWebTokens" />
<PackageReference Include="MsgPack.Cli" /> <PackageReference Include="MsgPack.Cli" />
<PackageReference Include="SixLabors.ImageSharp" /> <PackageReference Include="SixLabors.ImageSharp" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" /> <PackageReference Include="SixLabors.ImageSharp.Drawing" />
<PackageReference Include="System.IdentityModel.Tokens.Jwt" />
<PackageReference Include="NetCoreServer" /> <PackageReference Include="NetCoreServer" />
</ItemGroup> </ItemGroup>