-
Notifications
You must be signed in to change notification settings - Fork 278
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
Linwenxuan
authored and
Linwenxuan
committed
Oct 7, 2023
1 parent
7fb9aa0
commit b9db643
Showing
4 changed files
with
128 additions
and
41 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,39 @@ | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core.Utility.Extension; | ||
using Lagrange.Core.Utility.Network; | ||
|
||
namespace Lagrange.Core.Utility.Sign; | ||
|
||
internal class LinuxSigner : SignProvider | ||
{ | ||
private const string Url = "http://cn-chengdu.qwqq.moe:20747/api/sign"; | ||
|
||
public override byte[]? Sign(string cmd, uint seq, byte[] body, out byte[]? ver, out string? token) | ||
{ | ||
ver = null; | ||
token = null; | ||
if (!WhiteListCommand.Contains(cmd)) return null; | ||
if (Available || string.IsNullOrEmpty(Url)) return new byte[20]; // Dummy signature | ||
|
||
try | ||
{ | ||
var payload = new Dictionary<string, string> | ||
{ | ||
{ "cmd", cmd }, | ||
{ "seq", seq.ToString() }, | ||
{ "src", body.Hex() }, | ||
}; | ||
string response = Http.GetAsync(Url, payload).GetAwaiter().GetResult(); | ||
var json = JsonSerializer.Deserialize<JsonObject>(response); | ||
|
||
return json?["value"]?["sign"]?.ToString().UnHex() ?? new byte[20]; | ||
} | ||
catch (Exception) | ||
{ | ||
Available = false; | ||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{nameof(LinuxSigner)}] Failed to get signature, using dummy signature"); | ||
return new byte[20]; // Dummy signature | ||
} | ||
} | ||
} |
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,42 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core.Utility.Extension; | ||
using Lagrange.Core.Utility.Network; | ||
|
||
namespace Lagrange.Core.Utility.Sign; | ||
|
||
internal class MacSigner : SignProvider | ||
{ | ||
private const string MacOsUrl = "http://127.0.0.1:7458/api/sign"; | ||
|
||
public override byte[]? Sign(string cmd, uint seq, byte[] body, out byte[]? ver, out string? token) | ||
{ | ||
ver = null; | ||
token = null; | ||
if (!WhiteListCommand.Contains(cmd)) return null; | ||
if (!Available || string.IsNullOrEmpty(MacOsUrl)) return new byte[35]; // Dummy signature | ||
|
||
try | ||
{ | ||
var payload = new Dictionary<string, string> | ||
{ | ||
{ "cmd", cmd }, | ||
{ "seq", seq.ToString() }, | ||
{ "src", body.Hex() }, | ||
}; | ||
string response = Http.GetAsync(MacOsUrl, payload).GetAwaiter().GetResult(); | ||
var json = JsonSerializer.Deserialize<JsonObject>(response); | ||
|
||
ver = json?["value"]?["extra"]?.ToString().UnHex() ?? Array.Empty<byte>(); | ||
token = Encoding.ASCII.GetString(json?["value"]?["token"]?.ToString().UnHex() ?? Array.Empty<byte>()); | ||
return json?["value"]?["sign"]?.ToString().UnHex() ?? new byte[35]; | ||
} | ||
catch (Exception) | ||
{ | ||
Available = false; | ||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{nameof(MacSigner)}] Failed to get signature, using dummy signature"); | ||
return new byte[35]; // Dummy signature | ||
} | ||
} | ||
} |
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
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,42 @@ | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Text.Json.Nodes; | ||
using Lagrange.Core.Utility.Extension; | ||
using Lagrange.Core.Utility.Network; | ||
|
||
namespace Lagrange.Core.Utility.Sign; | ||
|
||
internal class WindowsSigner : SignProvider | ||
{ | ||
private const string WindowsUrl = ""; | ||
|
||
public override byte[]? Sign(string cmd, uint seq, byte[] body, out byte[]? ver, out string? token) | ||
{ | ||
ver = null; | ||
token = null; | ||
if (!WhiteListCommand.Contains(cmd)) return null; | ||
if (!Available || string.IsNullOrEmpty(WindowsUrl)) return new byte[35]; // Dummy signature | ||
|
||
try | ||
{ | ||
var payload = new Dictionary<string, string> | ||
{ | ||
{ "cmd", cmd }, | ||
{ "seq", seq.ToString() }, | ||
{ "src", body.Hex() }, | ||
}; | ||
string response = Http.GetAsync(WindowsUrl, payload).GetAwaiter().GetResult(); | ||
var json = JsonSerializer.Deserialize<JsonObject>(response); | ||
|
||
ver = json?["value"]?["extra"]?.ToString().UnHex() ?? Array.Empty<byte>(); | ||
token = Encoding.ASCII.GetString(json?["value"]?["token"]?.ToString().UnHex() ?? Array.Empty<byte>()); | ||
return json?["value"]?["sign"]?.ToString().UnHex() ?? new byte[35]; | ||
} | ||
catch (Exception) | ||
{ | ||
Available = false; | ||
Console.WriteLine($"[{DateTime.Now:yyyy-MM-dd HH:mm:ss}] [{nameof(WindowsSigner)}] Failed to get signature, using dummy signature"); | ||
return new byte[35]; // Dummy signature | ||
} | ||
} | ||
} |