forked from LukeFZ/DragaliaSaveDownloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
1,599 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
|
||
Microsoft Visual Studio Solution File, Format Version 12.00 | ||
# Visual Studio Version 17 | ||
VisualStudioVersion = 17.4.32804.182 | ||
MinimumVisualStudioVersion = 10.0.40219.1 | ||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DragaliaClient", "DragaliaClient\DragaliaClient.csproj", "{5D06E372-560F-4065-AAD8-946617000F39}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibConeshell", "LibConeshell\LibConeshell.csproj", "{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LibConeshell.Test", "LibConeshell.Test\LibConeshell.Test.csproj", "{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}" | ||
EndProject | ||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NintendoAuth.Popup", "NintendoAuth.Popup\NintendoAuth.Popup.csproj", "{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}" | ||
EndProject | ||
Global | ||
GlobalSection(SolutionConfigurationPlatforms) = preSolution | ||
Debug|Any CPU = Debug|Any CPU | ||
Debug|x64 = Debug|x64 | ||
Release|Any CPU = Release|Any CPU | ||
Release|x64 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(ProjectConfigurationPlatforms) = postSolution | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Debug|x64.Build.0 = Debug|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Release|x64.ActiveCfg = Release|Any CPU | ||
{5D06E372-560F-4065-AAD8-946617000F39}.Release|x64.Build.0 = Release|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Debug|x64.Build.0 = Debug|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Release|x64.ActiveCfg = Release|Any CPU | ||
{75DA70E1-C361-4F9F-A1BA-662FA5DC9E55}.Release|x64.Build.0 = Release|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Debug|x64.ActiveCfg = Debug|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Debug|x64.Build.0 = Debug|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Release|x64.ActiveCfg = Release|Any CPU | ||
{A5E164FC-018F-4A9F-88DC-3B6741F8CADF}.Release|x64.Build.0 = Release|Any CPU | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Debug|Any CPU.Build.0 = Debug|Any CPU | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Debug|x64.ActiveCfg = Debug|x64 | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Debug|x64.Build.0 = Debug|x64 | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Release|Any CPU.ActiveCfg = Release|Any CPU | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Release|Any CPU.Build.0 = Release|Any CPU | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Release|x64.ActiveCfg = Release|x64 | ||
{4DD8AC19-4AB8-4E17-BBEF-93874B30012C}.Release|x64.Build.0 = Release|x64 | ||
EndGlobalSection | ||
GlobalSection(SolutionProperties) = preSolution | ||
HideSolutionNode = FALSE | ||
EndGlobalSection | ||
GlobalSection(ExtensibilityGlobals) = postSolution | ||
SolutionGuid = {FF7E4F24-D784-49EF-89AD-77F4A028D238} | ||
EndGlobalSection | ||
EndGlobal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
using System.Net.Sockets; | ||
using System.Security.Cryptography; | ||
using System.Text; | ||
using DragaliaClient.Models; | ||
using LibConeshell; | ||
using MessagePack; | ||
using Org.BouncyCastle.Crypto.Parameters; | ||
|
||
namespace DragaliaClient; | ||
|
||
public class ConeshellClient | ||
{ | ||
private readonly HttpClient _client; | ||
private long _requestId; | ||
private readonly X25519PublicKeyParameters _serverPublicKey; | ||
private readonly string _idToken; | ||
private readonly byte[] _clientId; | ||
private string _sessionId; | ||
private string _deployHash; | ||
private string _resourceVersion; | ||
|
||
public ConeshellClient(X25519PublicKeyParameters serverPublicKey, string idToken, string userId) | ||
{ | ||
_client = new HttpClient(); | ||
_serverPublicKey = serverPublicKey; | ||
_idToken = idToken; | ||
_sessionId = ""; | ||
_deployHash = ""; | ||
_resourceVersion = ""; | ||
_clientId = MD5.HashData(Encoding.UTF8.GetBytes(userId)); | ||
_requestId = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(); | ||
|
||
_client.DefaultRequestHeaders.Accept.ParseAdd("*/*"); | ||
_client.DefaultRequestHeaders.AcceptEncoding.ParseAdd("deflate, gzip"); | ||
_client.DefaultRequestHeaders.UserAgent.ParseAdd(Constants.UnityUserAgent); | ||
_client.DefaultRequestHeaders.Add("Device", Constants.Device); | ||
_client.DefaultRequestHeaders.Add("Platform", Constants.Platform); | ||
_client.DefaultRequestHeaders.Add("App-Ver", Constants.AppVer); | ||
_client.DefaultRequestHeaders.Add("OS-Version", Constants.OsVersion); | ||
_client.DefaultRequestHeaders.Add("GraphicsDeviceName", Constants.Graphics); | ||
_client.DefaultRequestHeaders.Add("X-Unity-Version", Constants.UnityVersion); | ||
_client.DefaultRequestHeaders.Add("DeviceId", ""); | ||
_client.DefaultRequestHeaders.Add("DeviceName", "iPhone"); | ||
_client.DefaultRequestHeaders.Add("Carrier", "Apple"); | ||
} | ||
|
||
public void SetSessionId(string sessionId) | ||
=> _sessionId = sessionId; | ||
|
||
public void SetDeployHash(string deployHash) | ||
=> _deployHash = deployHash; | ||
|
||
public void SetResourceVersion(string resourceVersion) | ||
=> _resourceVersion = resourceVersion; | ||
|
||
public bool Login(string deviceUuid) | ||
{ | ||
try | ||
{ | ||
var pushNotificationUpdateData = | ||
new ConeshellRequests.PushNotificationUpdateSettingRequest("US", deviceUuid, "en_us"); | ||
|
||
var pushNotificationUpdateResponseData = | ||
Send<ConeshellRequests.PushNotificationUpdateSettingRequest, | ||
ConeshellRequests.PushNotificationUpdateSettingResponse>(pushNotificationUpdateData, | ||
Constants.PushNotificationUpdate); | ||
|
||
var toolAuthRequestData = new ConeshellRequests.ToolAuthRequest(deviceUuid, _idToken); | ||
/*var transitionResponseData = | ||
coneshellClient.Send<ConeshellRequests.ToolAuthRequest, ConeshellRequests.TransitionByNAccountResponse>( | ||
toolAuthRequestData, Constants.TransitionByNAccount);*/ | ||
|
||
var toolAuthResponseData = | ||
Send<ConeshellRequests.ToolAuthRequest, ConeshellRequests.ToolAuthResponse>( | ||
toolAuthRequestData, Constants.ToolAuth); | ||
|
||
_sessionId = toolAuthResponseData.data.session_id; | ||
|
||
var deployHashResponse = | ||
Send<ConeshellRequests.RequestCommon, ConeshellRequests.DeployGetDeployVersionResponse>( | ||
new ConeshellRequests.RequestCommon(), Constants.GetDeployVersion); | ||
|
||
_deployHash = deployHashResponse.data.deploy_hash; | ||
|
||
var resourceVersionRequest = new ConeshellRequests.VersionGetResourceVersionRequest(1, Constants.AppVer); | ||
var resourceVersionResponse = | ||
Send<ConeshellRequests.VersionGetResourceVersionRequest, ConeshellRequests.VersionGetResourceVersionResponse>( | ||
resourceVersionRequest, Constants.GetResourceVersion); | ||
|
||
_resourceVersion = resourceVersionResponse.data.resource_version; | ||
|
||
return true; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Console.WriteLine(ex); | ||
return false; | ||
} | ||
} | ||
|
||
private long GetRequestId() | ||
{ | ||
_requestId++; | ||
var currentTime = DateTimeOffset.UtcNow.ToUnixTimeSeconds(); | ||
return (_requestId & 0xffffff) | currentTime << 24; | ||
} | ||
|
||
public TResponse Send<TRequest, TResponse>(TRequest req, string url, bool shouldEncrypt = true) | ||
where TRequest : ConeshellRequests.RequestCommon | ||
{ | ||
var httpRequest = new HttpRequestMessage(HttpMethod.Post, url); | ||
httpRequest.Headers.Add("Request-Token", GetRequestId().ToString()); | ||
httpRequest.Headers.Add("Request-Time", DateTimeOffset.UtcNow.ToUnixTimeSeconds().ToString()); | ||
|
||
if (_sessionId == "") | ||
httpRequest.Headers.Add("ID-TOKEN", _idToken); | ||
else | ||
httpRequest.Headers.Add("SID", _sessionId); | ||
|
||
if (_deployHash != "") | ||
httpRequest.Headers.Add("Deploy-Hash", _deployHash); | ||
|
||
if (_resourceVersion != "") | ||
httpRequest.Headers.Add("Res-Ver", _resourceVersion); | ||
|
||
var serializedData = MessagePackSerializer.Serialize(req); | ||
|
||
var secret = Array.Empty<byte>(); | ||
|
||
if (shouldEncrypt) | ||
{ | ||
(var encryptedData, secret) = Coneshell.EncryptRequestMessage(serializedData, _serverPublicKey, _clientId); | ||
var base64Data = Convert.ToBase64String(encryptedData); | ||
httpRequest.Content = new StringContent(base64Data, Encoding.UTF8, "application/octet-stream"); | ||
} | ||
else | ||
{ | ||
|
||
httpRequest.Content = new ByteArrayContent(serializedData); | ||
} | ||
|
||
var httpResponse = _client.Send(httpRequest); | ||
httpResponse.EnsureSuccessStatusCode(); | ||
|
||
byte[] serializedResponseData; | ||
|
||
if (shouldEncrypt) | ||
{ | ||
var base64ResponseData = httpResponse.Content.ReadAsStringAsync().Result; | ||
var encryptedResponseData = Convert.FromBase64String(base64ResponseData); | ||
serializedResponseData = Coneshell.DecryptResponseMessage(encryptedResponseData, secret, _clientId); | ||
} | ||
else | ||
{ | ||
serializedResponseData = httpResponse.Content.ReadAsByteArrayAsync().Result; | ||
} | ||
|
||
if (typeof(TResponse) == typeof(byte[])) | ||
return (TResponse)(object)serializedResponseData; | ||
|
||
var responseData = MessagePackSerializer.Deserialize<TResponse>(serializedResponseData); | ||
return responseData; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
namespace DragaliaClient; | ||
|
||
public class Constants | ||
{ | ||
public const string NintendoUserAgent = "com.nintendo.zaga/2.19.0 ONEPLUS A6003/10 NPFSDK/Unity-2.33.0-0a4be7c8"; | ||
public const string UnityUserAgent = "UnityPlayer/2019.4.31f1 (UnityWebRequest/1.0, libcurl/7.75.0-DEV)"; | ||
public const string AcceptLanguage = "en-US; q=1, en; q=0.5, *; q=0.001"; | ||
public const string UnityVersion = "2019.4.31f1"; | ||
public const string Graphics = "Apple A9 GPU"; | ||
public const string OsVersion = "iOS 14.3"; | ||
public const string AppVer = "2.19.0"; | ||
public const string Platform = "1"; | ||
public const string Device = "1"; | ||
|
||
// Nintendo user auth constants | ||
public const string AccountsHost = "https://accounts.nintendo.com/"; | ||
public const string Authorize = $"{AccountsHost}connect/1.0.0/authorize"; | ||
public const string SessionToken = $"{AccountsHost}connect/1.0.0/api/session_token"; | ||
public const string SdkToken = "https://api.accounts.nintendo.com/1.0.0/gateway/sdk/token"; | ||
|
||
// Authorize constants | ||
public const string ClientId = "5192a0623a51561a"; | ||
public const string RedirectUri = $"npf{ClientId}://auth"; | ||
public const string ResponseType = "session_token_code"; | ||
public const string Scope = "user user.birthday openid"; | ||
public const string Language = "en-US"; | ||
public const string SessionCodeChallengeMethod = "S256"; | ||
|
||
// Nintendo device auth constants | ||
public const string BaaSSdkPrefix = "/core/v1/gateway/sdk/"; | ||
public const string BaaSHost = "https://48cc81cdb8de30e061928f56e9bd4b4d.baas.nintendo.com"; | ||
public const string BaaSFederation = $"{BaaSHost}{BaaSSdkPrefix}federation"; | ||
public const string BaaSLogin = $"{BaaSHost}{BaaSSdkPrefix}login"; | ||
|
||
// Coneshell constants | ||
public const string OfficialServerEncPublicKey = "d733a12a53e53153b1ffd8908d28e0e1be2f03b17d9d47deca8285070094d849"; | ||
public const string ProductionEndpoint = "https://production-api.dragalialost.com/2.19.0_20220719103923"; | ||
public const string PushNotificationUpdate = $"{ProductionEndpoint}/push_notification/update_setting"; | ||
public const string ToolAuth = $"{ProductionEndpoint}/tool/auth"; | ||
public const string LoadIndex = $"{ProductionEndpoint}/load/index"; | ||
public const string GetDeployVersion = $"{ProductionEndpoint}/deploy/get_deploy_version"; | ||
public const string GetResourceVersion = $"{ProductionEndpoint}/version/get_resource_version"; | ||
public const string TransitionByNAccount = $"{ProductionEndpoint}/transition/transition_by_n_account"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net6.0-windows</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="MessagePack" Version="2.4.35" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\LibConeshell\LibConeshell.csproj" /> | ||
<ProjectReference Include="..\NintendoAuth.Popup\NintendoAuth.Popup.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
Oops, something went wrong.