mirror of
https://github.com/azaion/annotations.git
synced 2026-04-22 16:06:30 +00:00
bump ImageSharp version vulnerability fix
decouple Loader from Common dll fix current user url in api
This commit is contained in:
@@ -1,3 +1,8 @@
|
||||
using System.Diagnostics;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Azaion.LoaderUI;
|
||||
|
||||
public static class ConstantsLoader
|
||||
@@ -5,4 +10,51 @@ public static class ConstantsLoader
|
||||
public const string SUITE_FOLDER = "suite";
|
||||
public const string SUITE_STAGE_FOLDER = "suite-stage";
|
||||
public const int EXTERNAL_LOADER_PORT = 5020;
|
||||
public const string AZAION_SUITE_EXE = "Azaion.Suite.exe";
|
||||
public const string LOADER_CONFIG_PATH = "loaderconfig.json";
|
||||
|
||||
|
||||
public const string DEFAULT_ZMQ_LOADER_HOST = "127.0.0.1";
|
||||
public const string DEFAULT_API_URL = "https://api.azaion.com";
|
||||
public const string EXTERNAL_LOADER_PATH = "azaion-loader.exe";
|
||||
public const string EXTERNAL_INFERENCE_PATH = "azaion-inference.exe";
|
||||
|
||||
public static Version GetLocalVersion()
|
||||
{
|
||||
var localFileInfo = FileVersionInfo.GetVersionInfo(AZAION_SUITE_EXE);
|
||||
if (string.IsNullOrWhiteSpace(localFileInfo.ProductVersion))
|
||||
throw new Exception($"Can't find {AZAION_SUITE_EXE} and its version");
|
||||
|
||||
return new Version(localFileInfo.FileVersion!);
|
||||
}
|
||||
|
||||
private static string GenDefaultKey()
|
||||
{
|
||||
var date = DateTime.UtcNow;
|
||||
return $"sAzaion_default_dfvkjhg_{date:yyyy}-{date:MM}_{date:dd}_{date:HH}_key";
|
||||
}
|
||||
|
||||
public static string Encrypt<T>(T model, string? key = null) where T : class
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(model);
|
||||
var inputBytes = Encoding.UTF8.GetBytes(json);
|
||||
|
||||
var keyBytes = SHA256.HashData(Encoding.UTF8.GetBytes(key ?? GenDefaultKey()));
|
||||
var iv = RandomNumberGenerator.GetBytes(16);
|
||||
|
||||
using var aes = Aes.Create();
|
||||
aes.Key = keyBytes;
|
||||
aes.IV = iv;
|
||||
aes.Mode = CipherMode.CFB;
|
||||
aes.Padding = PaddingMode.ISO10126;
|
||||
|
||||
using var encryptor = aes.CreateEncryptor();
|
||||
var ciphertext = encryptor.TransformFinalBlock(inputBytes, 0, inputBytes.Length);
|
||||
|
||||
var result = new byte[iv.Length + ciphertext.Length];
|
||||
iv.CopyTo(result, 0);
|
||||
ciphertext.CopyTo(result, iv.Length);
|
||||
|
||||
return Convert.ToBase64String(result);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user