96 lines
3.8 KiB
C#
96 lines
3.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace 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!
|
|
answ = Convert.ToDateTime(plainAuthKey.Replace(string.Format("{0}#{1}-", cliente, applicativo.PadLeft(20, '-')), "").Replace(string.Format("%{0}%", licenze), ""));
|
|
}
|
|
catch
|
|
{ }
|
|
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
|
|
}
|
|
} |