Add token expiry (bump minor)
Temp remove genuine patch for unity product name Exporting and importing tokens (not tested very well) Insecure HTTP warning on auth
This commit is contained in:
40
Galvanic.cs
40
Galvanic.cs
@@ -4,6 +4,7 @@ using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using System.Text.Json;
|
||||
using System.IO;
|
||||
|
||||
// this entire file could be better
|
||||
|
||||
@@ -70,6 +71,28 @@ namespace undead_universal_patch_il2cpp
|
||||
return Convert.ToBase64String(signature);
|
||||
}
|
||||
}
|
||||
public static void Export()
|
||||
{
|
||||
File.WriteAllText("./galvanic_keys_export.txt", $"{GetPubKey()}\n{Convert.ToBase64String(GetPrivKey().ExportPkcs8PrivateKey())}");
|
||||
Plugin.Log.LogWarning("Galvanic Authentication keys were exported.");
|
||||
}
|
||||
public static void Import()
|
||||
{
|
||||
try
|
||||
{
|
||||
string imported = File.ReadAllText("./galvanic_keys_export.txt").ToString();
|
||||
string privkey = imported.Split("\n")[1];
|
||||
string pubkey = imported.Split("\n")[0];
|
||||
if (privkey == null || pubkey == null) throw new Exception("Either imported key was null");
|
||||
|
||||
PlayerPrefs.SetString("GalvanicPrivateKey", privkey);
|
||||
PlayerPrefs.SetString("GalvanicPublicKey", pubkey);
|
||||
PlayerPrefs.Save();
|
||||
} catch (Exception err)
|
||||
{
|
||||
Plugin.Log.LogError($"Could not import Galvanic Authentication keys: {err}");
|
||||
}
|
||||
}
|
||||
public static ServerInfoRes GetServerInfo()
|
||||
{
|
||||
UriBuilder nameserver = new(NameserverConfig.NewUrl.Value);
|
||||
@@ -103,6 +126,22 @@ namespace undead_universal_patch_il2cpp
|
||||
public static class GalvanicWebAuth
|
||||
{
|
||||
public static string Token { get; private set; } = null;
|
||||
public static void TokenExpiry()
|
||||
{
|
||||
string url = NameserverConfig.NewUrl.Value;
|
||||
UriBuilder uri = new(url);
|
||||
uri.Path = "/user/checkExpired";
|
||||
uri.Query = "";
|
||||
|
||||
HttpClient client = new();
|
||||
client.DefaultRequestHeaders.Add("GalvanicAuth", Token);
|
||||
HttpResponseMessage res = client.GetAsync(uri.ToString()).Result;
|
||||
if (res.IsSuccessStatusCode)
|
||||
{
|
||||
bool expired = JsonSerializer.Deserialize<bool>(res.Content.ReadAsStringAsync().Result.ToString());
|
||||
if (expired) GetToken();
|
||||
}
|
||||
}
|
||||
|
||||
public static void GetToken()
|
||||
{
|
||||
@@ -113,6 +152,7 @@ namespace undead_universal_patch_il2cpp
|
||||
|
||||
var info = GalvanicAuth.GetServerInfo();
|
||||
Plugin.Log.LogInfo($"Sending authentication request to server ID '{info.id}'");
|
||||
if (uri.Scheme == "http") Plugin.Log.LogWarning("The server is not secure! Please use HTTPS.");
|
||||
|
||||
UserAuthPayload payload = new UserAuthPayload
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user