Files
Samuele Locatelli 5ced0fec53 LAND:
- fix warning compilazione
- fix auth windows x login
2022-11-15 18:08:19 +01:00

106 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Egw.Core
{
/// <summary>
/// Gestione licenze applicativi GLS (Legacy SteamWare)
/// </summary>
public class licenseManGLS
{
#region Public Methods
/// <summary>
/// restituisce data decodificata da authKey + applicazione + cliente...
/// </summary>
/// <param name="cliente">The cliente.</param>
/// <param name="applicativo">The applicativo.</param>
/// <param name="licenze">The licenze.</param>
/// <param name="authKey">The authentication key.</param>
/// <returns></returns>
public static DateTime expiryDateByAuthKey(string cliente, string applicativo, int licenze, string authKey)
{
DateTime answ = DateTime.Today.AddYears(-10);
string plainAuthKey = "";
try
{
string passPhrase = string.Format("{0}|{1}", cliente.PadLeft(50, ':'), applicativo);
plainAuthKey = SteamCrypto.DecryptString(authKey, passPhrase); // uso combinazione cliente+applicativo come passphrase!
string datePart = plainAuthKey.Replace($"{cliente}#{applicativo.PadLeft(20, '-')}-", "").Replace($"%{licenze}%", "");
//string datePart = plainAuthKey.Replace(string.Format("{0}#{1}-", cliente, applicativo.PadLeft(20, '-')), "").Replace(string.Format("%{0}%", licenze), "");
// se non avesse "bonificato" la parte num licenze (es non corrisponde al max) forzo il trim
if (datePart.Contains("%"))
{
datePart = datePart.Substring(0, datePart.IndexOf("%"));
}
answ = Convert.ToDateTime(datePart);
}
catch //(Exception exc)
{
//logger.lg.scriviLog(string.Format("Errore decodifica auth key:{0}AuthKey: {1}{0}cliente:{2}{0}applicativo:{3}{0}errore:{4}", Environment.NewLine, authKey, cliente, applicativo, exc), tipoLog.EXCEPTION);
}
return answ;
}
/// <summary>
/// Fornisce chiave MD5 x un cliente/applicativo/expiryDate
/// </summary>
/// <param name="cliente"></param>
/// <param name="applicativo"></param>
/// <param name="licenze"></param>
/// <param name="expiryDate"></param>
/// <returns></returns>
public static string getAuthKey(string cliente, string applicativo, int licenze, DateTime expiryDate)
{
string answ = "";
// algoritmo MD5 formato cliente#applicativo#expDate, via SQLdiventa
// SELECT CONVERT(VARCHAR(32), HashBytes('MD5', 'ETS#GPW#2013/12/31'), 2)
string plainAuthKey = string.Format("{0}#{1}-{2}%{3}%", cliente, applicativo.PadLeft(20, '-'), expiryDate.ToString("yyyy/MM/dd"), licenze);
string passPhrase = string.Format("{0}|{1}", cliente.PadLeft(50, ':'), applicativo);
answ = SteamCrypto.EncryptString(plainAuthKey, passPhrase); // uso combinazione cliente+applicativo come passphrase!
return answ;
}
/// <summary>
/// Fornisce chiave MD5 x una chiave secondaria/di checksum data dai parametri in ingresso
/// MasterKey/string[] chiavi singole child/expiryDate
/// </summary>
/// <param name="MasterKey">Chiave master da cui si parte</param>
/// <param name="Payload">Payload che contiene le chiavi SUB (child) riferite alla master in formato JSon (compresso/no indent)</param>
/// <returns></returns>
public static string getChecksumKey(string MasterKey, string Payload)
{
string answ = "";
answ = SteamCrypto.EncryptString(Payload, MasterKey);
return answ;
}
/// <summary>
/// numero di licenze attive per cliente/applicativo
/// </summary>
/// <param name="cliente"></param>
/// <param name="applicativo"></param>
/// <returns></returns>
public static int getLicenseNum(string cliente, string applicativo)
{
// !!!FARE!!! chiamata a webservice 1/mese
int answ = 1;
// molto hard-coded e discutibile... licenze "perenni"
switch (cliente)
{
default:
answ = 1;
break;
}
return answ;
}
#endregion Public Methods
}
}