This commit is contained in:
@@ -240,7 +240,7 @@ namespace Sockeye.Biz
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static string GenFetchCode()
|
private static string GenFetchCode()
|
||||||
{
|
{
|
||||||
|
|
||||||
//sufficient for this purpose
|
//sufficient for this purpose
|
||||||
@@ -304,7 +304,7 @@ namespace Sockeye.Biz
|
|||||||
/// This is called by both regular and trial license key routes
|
/// This is called by both regular and trial license key routes
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
private static void genKey(License l)
|
internal static void GenerateAndSetV7Key(License l)
|
||||||
{
|
{
|
||||||
|
|
||||||
StringBuilder sbKey = new StringBuilder();
|
StringBuilder sbKey = new StringBuilder();
|
||||||
|
|||||||
@@ -493,18 +493,14 @@ namespace Sockeye.Biz
|
|||||||
|
|
||||||
switch(l.PGroup){
|
switch(l.PGroup){
|
||||||
case ProductGroup.RavenPerpetual:
|
case ProductGroup.RavenPerpetual:
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ProductGroup.RavenSubscription:
|
case ProductGroup.RavenSubscription:
|
||||||
{
|
{
|
||||||
|
RavenKeyFactory.GenerateAndSetRavenKey(l);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case ProductGroup.AyaNova7:
|
case ProductGroup.AyaNova7:
|
||||||
{
|
{
|
||||||
|
KeyFactory.GenerateAndSetV7Key(l);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Org.BouncyCastle.Security;
|
|||||||
using Org.BouncyCastle.Crypto;
|
using Org.BouncyCastle.Crypto;
|
||||||
using Org.BouncyCastle.OpenSsl;
|
using Org.BouncyCastle.OpenSsl;
|
||||||
using Sockeye.Util;
|
using Sockeye.Util;
|
||||||
|
using Sockeye.Models;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -41,217 +42,379 @@ namespace Sockeye.Biz
|
|||||||
//This feature name means it's a trial key
|
//This feature name means it's a trial key
|
||||||
private const string TRIAL_FEATURE_NAME = "TrialMode";
|
private const string TRIAL_FEATURE_NAME = "TrialMode";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// RAVEN key generator
|
||||||
|
/// </summary>
|
||||||
|
/// <returns></returns>
|
||||||
|
internal static void GenerateAndSetRavenKey(License l)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(l.RegTo))
|
||||||
|
throw new ArgumentException("RegisteredTo is required", "RegisteredTo");
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(l.DbId))
|
||||||
|
throw new ArgumentException("DBId is required", "DbId");
|
||||||
|
|
||||||
|
//license serial number
|
||||||
|
var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
|
||||||
|
string sId = vv.ToString();
|
||||||
|
if (sId.Contains(","))
|
||||||
|
sId = sId.Split('.')[0];
|
||||||
|
|
||||||
|
StringBuilder sbKey = new StringBuilder();
|
||||||
|
StringWriter sw = new StringWriter(sbKey);
|
||||||
|
|
||||||
|
using (Newtonsoft.Json.JsonWriter w = new Newtonsoft.Json.JsonTextWriter(sw))
|
||||||
|
{
|
||||||
|
w.Formatting = Newtonsoft.Json.Formatting.Indented;
|
||||||
|
|
||||||
|
//outer object start
|
||||||
|
w.WriteStartObject();
|
||||||
|
|
||||||
|
w.WritePropertyName("Key");
|
||||||
|
|
||||||
|
w.WriteStartObject();//start of key object
|
||||||
|
|
||||||
|
w.WritePropertyName("LicenseFormat");
|
||||||
|
w.WriteValue("8");
|
||||||
|
|
||||||
|
w.WritePropertyName("Id");
|
||||||
|
w.WriteValue(sId);
|
||||||
|
|
||||||
|
w.WritePropertyName("RegisteredTo");
|
||||||
|
w.WriteValue(l.RegTo);
|
||||||
|
|
||||||
|
w.WritePropertyName("DBID");
|
||||||
|
w.WriteValue(l.DbId);
|
||||||
|
|
||||||
|
w.WritePropertyName("Perpetual");
|
||||||
|
w.WriteValue(l.PGroup == ProductGroup.RavenPerpetual);
|
||||||
|
|
||||||
|
w.WritePropertyName("LicenseExpiration");
|
||||||
|
w.WriteValue(l.LicenseExpire);
|
||||||
|
|
||||||
|
w.WritePropertyName("MaintenanceExpiration");
|
||||||
|
w.WriteValue(l.MaintenanceExpire);
|
||||||
|
|
||||||
|
//FEATURES
|
||||||
|
w.WritePropertyName("Features");
|
||||||
|
w.WriteStartArray();
|
||||||
|
|
||||||
|
if (l.TrialMode)
|
||||||
|
{
|
||||||
|
w.WriteStartObject();
|
||||||
|
w.WritePropertyName("Name");
|
||||||
|
w.WriteValue(TRIAL_FEATURE_NAME);
|
||||||
|
w.WriteEndObject();
|
||||||
|
}
|
||||||
|
|
||||||
|
//USERS
|
||||||
|
w.WriteStartObject();
|
||||||
|
w.WritePropertyName("Name");
|
||||||
|
w.WriteValue(ACTIVE_INTERNAL_USERS_FEATURE_NAME);
|
||||||
|
w.WritePropertyName("Count");
|
||||||
|
w.WriteValue(l.Users);
|
||||||
|
w.WriteEndObject();
|
||||||
|
|
||||||
|
if (l.PGroup == ProductGroup.RavenSubscription)
|
||||||
|
{
|
||||||
|
//CUSTOMER USERS
|
||||||
|
w.WriteStartObject();
|
||||||
|
w.WritePropertyName("Name");
|
||||||
|
w.WriteValue(ACTIVE_CUSTOMER_USERS_FEATURE_NAME);
|
||||||
|
w.WritePropertyName("Count");
|
||||||
|
w.WriteValue(l.CustomerUsers);
|
||||||
|
w.WriteEndObject();
|
||||||
|
|
||||||
|
//MAX DATA GB
|
||||||
|
w.WriteStartObject();
|
||||||
|
w.WritePropertyName("Name");
|
||||||
|
w.WriteValue(MAXIMUM_DATA_GB_FEATURE_NAME);
|
||||||
|
w.WritePropertyName("Count");
|
||||||
|
w.WriteValue(l.MaxDataGB);
|
||||||
|
w.WriteEndObject();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//end of features array
|
||||||
|
w.WriteEnd();
|
||||||
|
|
||||||
|
//End of "Key" property
|
||||||
|
w.WriteEndObject();
|
||||||
|
|
||||||
|
//close outer 'wrapper' object brace }
|
||||||
|
w.WriteEndObject();
|
||||||
|
|
||||||
|
}//end of using statement
|
||||||
|
|
||||||
|
|
||||||
|
// ## CALCULATE SIGNATURE
|
||||||
|
|
||||||
|
//GET JSON as a string with whitespace stripped outside of delimited strings
|
||||||
|
//http://stackoverflow.com/questions/8913138/minify-indented-json-string-in-net
|
||||||
|
string keyNoWS = System.Text.RegularExpressions.Regex.Replace(sbKey.ToString(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
|
||||||
|
|
||||||
|
|
||||||
|
//**** Note this is our real 2016 private key
|
||||||
|
var privatePEM = @"-----BEGIN RSA PRIVATE KEY-----
|
||||||
|
MIIEpAIBAAKCAQEAz7wrvLDcKVMZ31HFGBnLWL08IodYIV5VJkKy1Z0n2snprhSi
|
||||||
|
u3izxTyz+SLpftvKHJpky027ii7l/pL9Bo3JcjU5rKrxXavnE7TuYPjXn16dNLd0
|
||||||
|
K/ERSU+pXLmUaVN0nUWuGuUMoGJMEXoulS6pJiG11yu3BM9fL2Nbj0C6a+UwzEHF
|
||||||
|
mns3J/daZOb4gAzMUdJfh9OJ0+wRGzR8ZxyC99Na2gDmqYglUkSMjwLTL/HbgwF4
|
||||||
|
OwmoQYJBcET0Wa6Gfb17SaF8XRBV5ZtpCsbStkthGeoXZkFriB9c1eFQLKpBYQo2
|
||||||
|
DW3H1MPG2nAlQZLbkJj5cSh7/t1bRF08m6P+EQIDAQABAoIBAQCGvTpxLRXgB/Kk
|
||||||
|
EtmQBEsMx9EVZEwZeKIqKuDsBP8wvf4/10ql5mhT6kehtK9WhSDW5J2z8DtQKZMs
|
||||||
|
SBKuCZE77qH2CPp9E17SPWzQoRbaW/gDlWpYhgf8URs89XH5zxO4XtXKw/4omRlV
|
||||||
|
zLYiNR2pifv0EHqpOAg5KGzewdEo4VgXgtRWpHZLMpH2Q0/5ZIKMhstI6vFHP1p7
|
||||||
|
jmU4YI6uxiu7rVrZDmIUsAGoTdMabNqK/N8hKaoBiIto0Jn1ck26g+emLg8m160y
|
||||||
|
Xciu5yFUU+PP1SJMUs+k1UnAWf4p46X9jRLQCBRue9o0Ntiq/75aljRoDvgdwDsR
|
||||||
|
mg4ZANqxAoGBAPBoM5KoMZ4sv8ZFv8V+V8hgL5xiLgGoiwQl91mRsHRM/NQU5A/w
|
||||||
|
tH8nmwUrJOrksV7kX9228smKmoliTptyGGyi1NPmSkA7cN9YYnENoOEBHCVNK9vh
|
||||||
|
P+bkbMYUDNMW4fgOj09oXtQtMl5E2B3OTGoNwZ2w13YQJ8RIniLPsX7nAoGBAN01
|
||||||
|
eQNcUzQk9YrFGTznOs8udDLBfigDxaNnawvPueulJdBy6ZXDDrKmkQQA7xxl8YPr
|
||||||
|
dNtBq2lOgnb6+smC15TaAfV/fb8BLmkSwdn4Fy0FApIXIEOnLq+wjkte98nuezl8
|
||||||
|
9KXDzaqNI9hPuk2i36tJuLLMH8hzldveWbWjSlRHAoGBAKRPE7CQtBjfjNL+qOta
|
||||||
|
RrT0yJWhpMANabYUHNJi+K8ET2jEPnuGkFa3wwPtUPYaCABLJhprB9Unnid3wTIM
|
||||||
|
8RSO1ddd9jGgbqy3w9Bw+BvQnmQAMpG9iedNB+r5mSpM4XSgvuIO+4EYwuwbMXpt
|
||||||
|
nVx+um4Eh75xnDxTRYGVYkLRAoGAaZVpUlpR+HSfooHbPv+bSWKB4ewLPCw4vHrT
|
||||||
|
VErtEfW8q9b9eRcmP81TMFcFykc6VN4g47pfh58KlKHM7DwAjDLWdohIy89TiKGE
|
||||||
|
V3acEUfv5y0UoFX+6ara8Ey+9upWdKUY3Lotw3ckoc3EPeQ84DQK7YSSswnAgLaL
|
||||||
|
mS/8fWcCgYBjRefVbEep161d2DGruk4X7eNI9TFJ278h6ydW5kK9aTJuxkrtKIp4
|
||||||
|
CYf6emoB4mLXFPvAmnsalkhN2iB29hUZCXXSUjpKZrpijL54Wdu2S6ynm7aT97NF
|
||||||
|
oArP0E2Vbow3JMxq/oeXmHbrLMLQfYyXwFmciLFigOtkd45bfHdrbA==
|
||||||
|
-----END RSA PRIVATE KEY-----";
|
||||||
|
|
||||||
|
PemReader pr = new PemReader(new StringReader(privatePEM));
|
||||||
|
AsymmetricCipherKeyPair keys = (AsymmetricCipherKeyPair)pr.ReadObject();
|
||||||
|
var encoder = new UTF8Encoding(false, true);
|
||||||
|
var inputData = encoder.GetBytes(keyNoWS);
|
||||||
|
var signer = SignerUtilities.GetSigner("SHA256WITHRSA");
|
||||||
|
signer.Init(true, keys.Private);
|
||||||
|
signer.BlockUpdate(inputData, 0, inputData.Length);
|
||||||
|
var sign = signer.GenerateSignature();
|
||||||
|
var signature = Convert.ToBase64String(sign);
|
||||||
|
|
||||||
|
System.Text.StringBuilder sbOut = new StringBuilder();
|
||||||
|
sbOut.AppendLine("[KEY");
|
||||||
|
sbOut.AppendLine(sbKey.ToString());
|
||||||
|
sbOut.AppendLine("KEY]");
|
||||||
|
sbOut.AppendLine("[SIGNATURE");
|
||||||
|
sbOut.AppendLine(signature);
|
||||||
|
sbOut.AppendLine("SIGNATURE]");
|
||||||
|
|
||||||
|
l.Key = sbOut.ToString();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#region old stuff
|
||||||
#region license classes
|
#region license classes
|
||||||
|
|
||||||
//DTO object returned on license query
|
// //DTO object returned on license query
|
||||||
public class LicenseFeature
|
// public class LicenseFeature
|
||||||
{
|
// {
|
||||||
//name of feature / product
|
// //name of feature / product
|
||||||
public string Feature { get; set; }
|
// public string Feature { get; set; }
|
||||||
|
|
||||||
//Optional count for items that require it
|
// //Optional count for items that require it
|
||||||
public long Count { get; set; }
|
// public long Count { get; set; }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
//DTO object for parsed key
|
// //DTO object for parsed key
|
||||||
internal class AyaNovaLicenseKey
|
// internal class AyaNovaLicenseKey
|
||||||
{
|
// {
|
||||||
public AyaNovaLicenseKey()
|
// public AyaNovaLicenseKey()
|
||||||
{
|
// {
|
||||||
Features = new List<LicenseFeature>();
|
// Features = new List<LicenseFeature>();
|
||||||
RegisteredTo = UNLICENSED_TOKEN;
|
// RegisteredTo = UNLICENSED_TOKEN;
|
||||||
//Id = RegisteredTo;
|
// //Id = RegisteredTo;
|
||||||
LicenseFormat = "8";
|
// LicenseFormat = "8";
|
||||||
|
|
||||||
var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
|
// var vv = Math.Truncate((DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds);
|
||||||
string sId = vv.ToString();
|
// string sId = vv.ToString();
|
||||||
if (sId.Contains(","))
|
// if (sId.Contains(","))
|
||||||
sId = sId.Split('.')[0];
|
// sId = sId.Split('.')[0];
|
||||||
Id = sId;
|
// Id = sId;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public override string ToString()
|
// public override string ToString()
|
||||||
{
|
// {
|
||||||
|
|
||||||
System.Text.StringBuilder sb = new StringBuilder();
|
// System.Text.StringBuilder sb = new StringBuilder();
|
||||||
sb.AppendLine($"Registered to: {RegisteredTo}");
|
// sb.AppendLine($"Registered to: {RegisteredTo}");
|
||||||
sb.AppendLine($"Database id: {DbId}");
|
// sb.AppendLine($"Database id: {DbId}");
|
||||||
sb.AppendLine($"Type: {(Perpetual ? "Perpetual" : "Subscription")}");
|
// sb.AppendLine($"Type: {(Perpetual ? "Perpetual" : "Subscription")}");
|
||||||
if (WillExpire)
|
// if (WillExpire)
|
||||||
sb.AppendLine($"Available for use until: {LicenseExpiration.ToLongDateString()}");
|
// sb.AppendLine($"Available for use until: {LicenseExpiration.ToLongDateString()}");
|
||||||
if (Perpetual)
|
// if (Perpetual)
|
||||||
sb.AppendLine($"Support and updates available until: {MaintenanceExpiration.ToLongDateString()}");
|
// sb.AppendLine($"Support and updates available until: {MaintenanceExpiration.ToLongDateString()}");
|
||||||
foreach (LicenseFeature f in Features)
|
// foreach (LicenseFeature f in Features)
|
||||||
{
|
// {
|
||||||
if (f.Feature == TRIAL_FEATURE_NAME)
|
// if (f.Feature == TRIAL_FEATURE_NAME)
|
||||||
{
|
// {
|
||||||
sb.AppendLine("Temporary license for evaluation");
|
// sb.AppendLine("Temporary license for evaluation");
|
||||||
continue;
|
// continue;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
//default for items added later not tokenized
|
// //default for items added later not tokenized
|
||||||
if (f.Count > 0)
|
// if (f.Count > 0)
|
||||||
sb.AppendLine($"{f.Feature}: {f.Count}");
|
// sb.AppendLine($"{f.Feature}: {f.Count}");
|
||||||
else
|
// else
|
||||||
sb.AppendLine($"{f.Feature}");
|
// sb.AppendLine($"{f.Feature}");
|
||||||
}
|
// }
|
||||||
return sb.ToString();
|
// return sb.ToString();
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public bool IsEmpty
|
// public bool IsEmpty
|
||||||
{
|
// {
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
//Key is empty if it's not registered to anyone or there are no features in it
|
// //Key is empty if it's not registered to anyone or there are no features in it
|
||||||
return string.IsNullOrWhiteSpace(RegisteredTo) || (Features == null || Features.Count == 0);
|
// return string.IsNullOrWhiteSpace(RegisteredTo) || (Features == null || Features.Count == 0);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Fetch the license status of the feature in question
|
// /// Fetch the license status of the feature in question
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <param name="Feature"></param>
|
// /// <param name="Feature"></param>
|
||||||
/// <returns>LicenseFeature object or null if there is no license</returns>
|
// /// <returns>LicenseFeature object or null if there is no license</returns>
|
||||||
public LicenseFeature GetLicenseFeature(string Feature)
|
// public LicenseFeature GetLicenseFeature(string Feature)
|
||||||
{
|
// {
|
||||||
if (IsEmpty)
|
// if (IsEmpty)
|
||||||
return null;
|
// return null;
|
||||||
|
|
||||||
string lFeature = Feature.ToLowerInvariant();
|
// string lFeature = Feature.ToLowerInvariant();
|
||||||
|
|
||||||
foreach (LicenseFeature l in Features)
|
// foreach (LicenseFeature l in Features)
|
||||||
{
|
// {
|
||||||
if (l.Feature.ToLowerInvariant() == lFeature)
|
// if (l.Feature.ToLowerInvariant() == lFeature)
|
||||||
{
|
// {
|
||||||
return l;
|
// return l;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return null;
|
// return null;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
// /// <summary>
|
||||||
/// Check for the existance of license feature
|
// /// Check for the existance of license feature
|
||||||
/// </summary>
|
// /// </summary>
|
||||||
/// <param name="Feature"></param>
|
// /// <param name="Feature"></param>
|
||||||
/// <returns>bool</returns>
|
// /// <returns>bool</returns>
|
||||||
public bool HasLicenseFeature(string Feature)
|
// public bool HasLicenseFeature(string Feature)
|
||||||
{
|
// {
|
||||||
if (IsEmpty)
|
// if (IsEmpty)
|
||||||
return false;
|
// return false;
|
||||||
|
|
||||||
string lFeature = Feature.ToLowerInvariant();
|
// string lFeature = Feature.ToLowerInvariant();
|
||||||
|
|
||||||
foreach (LicenseFeature l in Features)
|
// foreach (LicenseFeature l in Features)
|
||||||
{
|
// {
|
||||||
if (l.Feature.ToLowerInvariant() == lFeature)
|
// if (l.Feature.ToLowerInvariant() == lFeature)
|
||||||
{
|
// {
|
||||||
return true;
|
// return true;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return false;
|
// return false;
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public bool WillExpire
|
// public bool WillExpire
|
||||||
{
|
// {
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
return LicenseExpiration < DateUtil.EmptyDateValue;
|
// return LicenseExpiration < DateUtil.EmptyDateValue;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public bool LicenseExpired
|
// public bool LicenseExpired
|
||||||
{
|
// {
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
return LicenseExpiration > DateTime.Now;
|
// return LicenseExpiration > DateTime.Now;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
public bool MaintenanceExpired
|
// public bool MaintenanceExpired
|
||||||
{
|
// {
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
return MaintenanceExpiration > DateTime.Now;
|
// return MaintenanceExpiration > DateTime.Now;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
public bool TrialLicense
|
// public bool TrialLicense
|
||||||
{
|
// {
|
||||||
get
|
// get
|
||||||
{
|
// {
|
||||||
return HasLicenseFeature(TRIAL_FEATURE_NAME);
|
// return HasLicenseFeature(TRIAL_FEATURE_NAME);
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public string LicenseFormat { get; set; }
|
// public string LicenseFormat { get; set; }
|
||||||
public string Id { get; set; }
|
// public string Id { get; set; }
|
||||||
public string RegisteredTo { get; set; }
|
// public string RegisteredTo { get; set; }
|
||||||
public string DbId { get; set; }
|
// public string DbId { get; set; }
|
||||||
public bool Perpetual { get; set; }
|
// public bool Perpetual { get; set; }
|
||||||
public DateTime LicenseExpiration { get; set; }
|
// public DateTime LicenseExpiration { get; set; }
|
||||||
public DateTime MaintenanceExpiration { get; set; }
|
// public DateTime MaintenanceExpiration { get; set; }
|
||||||
public List<LicenseFeature> Features { get; set; }
|
// public List<LicenseFeature> Features { get; set; }
|
||||||
|
|
||||||
|
|
||||||
}
|
// }
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// public static string GetRavenTrialKey(License l)//string dbid, string CompanyName, bool Perpetual)
|
||||||
|
// {
|
||||||
|
|
||||||
public static string GetRavenTrialKey(string dbid, string CompanyName, bool Perpetual)
|
// //Build a sample test key, sign it and return it
|
||||||
{
|
// AyaNovaLicenseKey k = new AyaNovaLicenseKey();
|
||||||
|
// k.LicenseFormat = "8";
|
||||||
|
// k.RegisteredTo = l.RegTo;
|
||||||
|
// k.DbId = l.DbId;
|
||||||
|
// k.Perpetual = l.PGroup == ProductGroup.RavenPerpetual;
|
||||||
|
|
||||||
//Build a sample test key, sign it and return it
|
// //flag as trial key not regular key
|
||||||
AyaNovaLicenseKey k = new AyaNovaLicenseKey();
|
// k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 });
|
||||||
k.LicenseFormat = "8";
|
// if (k.Perpetual)
|
||||||
k.RegisteredTo = CompanyName;
|
// {
|
||||||
k.DbId = dbid;
|
// //trial period time limit
|
||||||
k.Perpetual = Perpetual;
|
|
||||||
|
|
||||||
//flag as trial key not regular key
|
// //Normal code, uncomment this when done testing expiration dates of perpetual
|
||||||
k.Features.Add(new LicenseFeature() { Feature = TRIAL_FEATURE_NAME, Count = 0 });
|
// k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS);
|
||||||
if (Perpetual)
|
|
||||||
{
|
|
||||||
//trial period time limit
|
|
||||||
|
|
||||||
|
// //Testing code for 3 minute long evaluation license in case need to test with a key that expires
|
||||||
|
// // #warning FYI ROCKFISH is SET TO GENERATE A VERY SHORT TEST KEY
|
||||||
|
// // k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddMinutes(3); //TEST VALUE FOR DIAGNOSING LICENSE EXPIRATION ISSUES
|
||||||
|
|
||||||
//Normal code, uncomment this when done testing expiration dates of perpetual
|
// //5k inside staff users will cover huge seeding level easily
|
||||||
k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS);
|
// k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 });
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// //SUBSCRIPTION
|
||||||
|
// //trial period time limit
|
||||||
|
// k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS);//NOTE: this preserves the current time, should it be set to midnight or something?
|
||||||
|
|
||||||
//Testing code for 3 minute long evaluation license in case need to test with a key that expires
|
// //20k customer contacts will cover huge seeding level easily
|
||||||
// #warning FYI ROCKFISH is SET TO GENERATE A VERY SHORT TEST KEY
|
// //5k inside staff users will cover huge seeding level easily
|
||||||
// k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddMinutes(3); //TEST VALUE FOR DIAGNOSING LICENSE EXPIRATION ISSUES
|
// k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 });
|
||||||
|
// k.Features.Add(new LicenseFeature() { Feature = ACTIVE_CUSTOMER_USERS_FEATURE_NAME, Count = 20000 });
|
||||||
//5k inside staff users will cover huge seeding level easily
|
// k.Features.Add(new LicenseFeature() { Feature = MAXIMUM_DATA_GB_FEATURE_NAME, Count = 20 });
|
||||||
k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 });
|
// }
|
||||||
}
|
// return GenerateRavenKey(k);
|
||||||
else
|
// }
|
||||||
{
|
|
||||||
//SUBSCRIPTION
|
|
||||||
//trial period time limit
|
|
||||||
k.MaintenanceExpiration = k.LicenseExpiration = DateTime.UtcNow.AddDays(TRIAL_PERIOD_DAYS);//NOTE: this preserves the current time, should it be set to midnight or something?
|
|
||||||
|
|
||||||
//20k customer contacts will cover huge seeding level easily
|
|
||||||
//5k inside staff users will cover huge seeding level easily
|
|
||||||
k.Features.Add(new LicenseFeature() { Feature = ACTIVE_INTERNAL_USERS_FEATURE_NAME, Count = 5000 });
|
|
||||||
k.Features.Add(new LicenseFeature() { Feature = ACTIVE_CUSTOMER_USERS_FEATURE_NAME, Count = 20000 });
|
|
||||||
k.Features.Add(new LicenseFeature() { Feature = MAXIMUM_DATA_GB_FEATURE_NAME, Count = 20 });
|
|
||||||
}
|
|
||||||
return GenerateRavenKey(k);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// //TESTING ONLY this is for development purposes only
|
// //TESTING ONLY this is for development purposes only
|
||||||
@@ -287,172 +450,7 @@ namespace Sockeye.Biz
|
|||||||
// return GenerateRavenKey(k);
|
// return GenerateRavenKey(k);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
#endregion old stuff
|
||||||
/// <summary>
|
|
||||||
/// RAVEN key generator
|
|
||||||
/// </summary>
|
|
||||||
/// <returns></returns>
|
|
||||||
internal static string GenerateRavenKey(AyaNovaLicenseKey k)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
if (string.IsNullOrWhiteSpace(k.RegisteredTo))
|
|
||||||
throw new ArgumentException("RegisteredTo is required", "RegisteredTo");
|
|
||||||
|
|
||||||
// if (k.DbId == Guid.Empty)
|
|
||||||
if (string.IsNullOrWhiteSpace(k.DbId))
|
|
||||||
throw new ArgumentException("DBId is required", "RegisteredTo");
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
|
|
||||||
StringBuilder sbKey = new StringBuilder();
|
|
||||||
StringWriter sw = new StringWriter(sbKey);
|
|
||||||
|
|
||||||
using (Newtonsoft.Json.JsonWriter w = new Newtonsoft.Json.JsonTextWriter(sw))
|
|
||||||
{
|
|
||||||
w.Formatting = Newtonsoft.Json.Formatting.Indented;
|
|
||||||
|
|
||||||
//outer object start
|
|
||||||
w.WriteStartObject();
|
|
||||||
|
|
||||||
w.WritePropertyName("Key");
|
|
||||||
|
|
||||||
w.WriteStartObject();//start of key object
|
|
||||||
|
|
||||||
w.WritePropertyName("LicenseFormat");
|
|
||||||
w.WriteValue(k.LicenseFormat);
|
|
||||||
|
|
||||||
w.WritePropertyName("Id");
|
|
||||||
w.WriteValue(k.Id);
|
|
||||||
|
|
||||||
w.WritePropertyName("RegisteredTo");
|
|
||||||
w.WriteValue(k.RegisteredTo);
|
|
||||||
|
|
||||||
w.WritePropertyName("DBID");
|
|
||||||
w.WriteValue(k.DbId);
|
|
||||||
|
|
||||||
w.WritePropertyName("Perpetual");
|
|
||||||
w.WriteValue(k.Perpetual);
|
|
||||||
|
|
||||||
w.WritePropertyName("LicenseExpiration");
|
|
||||||
w.WriteValue(k.LicenseExpiration);
|
|
||||||
|
|
||||||
w.WritePropertyName("MaintenanceExpiration");
|
|
||||||
w.WriteValue(k.MaintenanceExpiration);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//FEATURES
|
|
||||||
// w.WritePropertyName("Features");
|
|
||||||
// w.WriteStartObject();
|
|
||||||
w.WritePropertyName("Features");
|
|
||||||
w.WriteStartArray();
|
|
||||||
|
|
||||||
foreach (LicenseFeature lf in k.Features)
|
|
||||||
{
|
|
||||||
|
|
||||||
w.WriteStartObject();
|
|
||||||
|
|
||||||
w.WritePropertyName("Name");
|
|
||||||
w.WriteValue(lf.Feature);
|
|
||||||
|
|
||||||
if (lf.Count > 0)
|
|
||||||
{
|
|
||||||
w.WritePropertyName("Count");
|
|
||||||
w.WriteValue(lf.Count);
|
|
||||||
}
|
|
||||||
|
|
||||||
w.WriteEndObject();
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//end of features array
|
|
||||||
w.WriteEnd();
|
|
||||||
|
|
||||||
//end of features object
|
|
||||||
// w.WriteEndObject();
|
|
||||||
|
|
||||||
//end of AyaNova/AyaNovaLite key object
|
|
||||||
w.WriteEndObject();
|
|
||||||
|
|
||||||
//close outer 'wrapper' object brace }
|
|
||||||
w.WriteEndObject();
|
|
||||||
|
|
||||||
}//end of using statement
|
|
||||||
|
|
||||||
|
|
||||||
// ## CALCULATE SIGNATURE
|
|
||||||
|
|
||||||
//GET JSON as a string with whitespace stripped outside of delimited strings
|
|
||||||
//http://stackoverflow.com/questions/8913138/minify-indented-json-string-in-net
|
|
||||||
string keyNoWS = System.Text.RegularExpressions.Regex.Replace(sbKey.ToString(), "(\"(?:[^\"\\\\]|\\\\.)*\")|\\s+", "$1");
|
|
||||||
|
|
||||||
|
|
||||||
//**** Note this is our real 2016 private key
|
|
||||||
var privatePEM = @"-----BEGIN RSA PRIVATE KEY-----
|
|
||||||
MIIEpAIBAAKCAQEAz7wrvLDcKVMZ31HFGBnLWL08IodYIV5VJkKy1Z0n2snprhSi
|
|
||||||
u3izxTyz+SLpftvKHJpky027ii7l/pL9Bo3JcjU5rKrxXavnE7TuYPjXn16dNLd0
|
|
||||||
K/ERSU+pXLmUaVN0nUWuGuUMoGJMEXoulS6pJiG11yu3BM9fL2Nbj0C6a+UwzEHF
|
|
||||||
mns3J/daZOb4gAzMUdJfh9OJ0+wRGzR8ZxyC99Na2gDmqYglUkSMjwLTL/HbgwF4
|
|
||||||
OwmoQYJBcET0Wa6Gfb17SaF8XRBV5ZtpCsbStkthGeoXZkFriB9c1eFQLKpBYQo2
|
|
||||||
DW3H1MPG2nAlQZLbkJj5cSh7/t1bRF08m6P+EQIDAQABAoIBAQCGvTpxLRXgB/Kk
|
|
||||||
EtmQBEsMx9EVZEwZeKIqKuDsBP8wvf4/10ql5mhT6kehtK9WhSDW5J2z8DtQKZMs
|
|
||||||
SBKuCZE77qH2CPp9E17SPWzQoRbaW/gDlWpYhgf8URs89XH5zxO4XtXKw/4omRlV
|
|
||||||
zLYiNR2pifv0EHqpOAg5KGzewdEo4VgXgtRWpHZLMpH2Q0/5ZIKMhstI6vFHP1p7
|
|
||||||
jmU4YI6uxiu7rVrZDmIUsAGoTdMabNqK/N8hKaoBiIto0Jn1ck26g+emLg8m160y
|
|
||||||
Xciu5yFUU+PP1SJMUs+k1UnAWf4p46X9jRLQCBRue9o0Ntiq/75aljRoDvgdwDsR
|
|
||||||
mg4ZANqxAoGBAPBoM5KoMZ4sv8ZFv8V+V8hgL5xiLgGoiwQl91mRsHRM/NQU5A/w
|
|
||||||
tH8nmwUrJOrksV7kX9228smKmoliTptyGGyi1NPmSkA7cN9YYnENoOEBHCVNK9vh
|
|
||||||
P+bkbMYUDNMW4fgOj09oXtQtMl5E2B3OTGoNwZ2w13YQJ8RIniLPsX7nAoGBAN01
|
|
||||||
eQNcUzQk9YrFGTznOs8udDLBfigDxaNnawvPueulJdBy6ZXDDrKmkQQA7xxl8YPr
|
|
||||||
dNtBq2lOgnb6+smC15TaAfV/fb8BLmkSwdn4Fy0FApIXIEOnLq+wjkte98nuezl8
|
|
||||||
9KXDzaqNI9hPuk2i36tJuLLMH8hzldveWbWjSlRHAoGBAKRPE7CQtBjfjNL+qOta
|
|
||||||
RrT0yJWhpMANabYUHNJi+K8ET2jEPnuGkFa3wwPtUPYaCABLJhprB9Unnid3wTIM
|
|
||||||
8RSO1ddd9jGgbqy3w9Bw+BvQnmQAMpG9iedNB+r5mSpM4XSgvuIO+4EYwuwbMXpt
|
|
||||||
nVx+um4Eh75xnDxTRYGVYkLRAoGAaZVpUlpR+HSfooHbPv+bSWKB4ewLPCw4vHrT
|
|
||||||
VErtEfW8q9b9eRcmP81TMFcFykc6VN4g47pfh58KlKHM7DwAjDLWdohIy89TiKGE
|
|
||||||
V3acEUfv5y0UoFX+6ara8Ey+9upWdKUY3Lotw3ckoc3EPeQ84DQK7YSSswnAgLaL
|
|
||||||
mS/8fWcCgYBjRefVbEep161d2DGruk4X7eNI9TFJ278h6ydW5kK9aTJuxkrtKIp4
|
|
||||||
CYf6emoB4mLXFPvAmnsalkhN2iB29hUZCXXSUjpKZrpijL54Wdu2S6ynm7aT97NF
|
|
||||||
oArP0E2Vbow3JMxq/oeXmHbrLMLQfYyXwFmciLFigOtkd45bfHdrbA==
|
|
||||||
-----END RSA PRIVATE KEY-----";
|
|
||||||
|
|
||||||
PemReader pr = new PemReader(new StringReader(privatePEM));
|
|
||||||
AsymmetricCipherKeyPair keys = (AsymmetricCipherKeyPair)pr.ReadObject();
|
|
||||||
var encoder = new UTF8Encoding(false, true);
|
|
||||||
var inputData = encoder.GetBytes(keyNoWS);
|
|
||||||
var signer = SignerUtilities.GetSigner("SHA256WITHRSA");
|
|
||||||
signer.Init(true, keys.Private);
|
|
||||||
signer.BlockUpdate(inputData, 0, inputData.Length);
|
|
||||||
var sign = signer.GenerateSignature();
|
|
||||||
var signature = Convert.ToBase64String(sign);
|
|
||||||
|
|
||||||
|
|
||||||
System.Text.StringBuilder sbOut = new StringBuilder();
|
|
||||||
sbOut.AppendLine("[KEY");
|
|
||||||
sbOut.AppendLine(sbKey.ToString());
|
|
||||||
sbOut.AppendLine("KEY]");
|
|
||||||
sbOut.AppendLine("[SIGNATURE");
|
|
||||||
sbOut.AppendLine(signature);
|
|
||||||
sbOut.AppendLine("SIGNATURE]");
|
|
||||||
|
|
||||||
|
|
||||||
return sbOut.ToString();
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
return (ex.Message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//eoc
|
//eoc
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user