1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-22 21:45:15 -05:00

licensing signature refactor

This commit is contained in:
Kyle Spearrin 2017-08-16 13:55:01 -04:00
parent 593cfe1f71
commit 912e875a33
3 changed files with 44 additions and 28 deletions

View File

@ -3,6 +3,8 @@ using Bit.Core.Models.Table;
using Bit.Core.Services; using Bit.Core.Services;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
@ -22,6 +24,8 @@ namespace Bit.Core.Models.Business
InstallationId = installationId; InstallationId = installationId;
Id = org.Id; Id = org.Id;
Name = org.Name; Name = org.Name;
BillingEmail = org.BillingEmail;
BusinessName = org.BusinessName;
Enabled = org.Enabled; Enabled = org.Enabled;
Plan = org.Plan; Plan = org.Plan;
PlanType = org.PlanType; PlanType = org.PlanType;
@ -74,6 +78,8 @@ namespace Bit.Core.Models.Business
public Guid InstallationId { get; set; } public Guid InstallationId { get; set; }
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; } public string Name { get; set; }
public string BillingEmail { get; set; }
public string BusinessName { get; set; }
public bool Enabled { get; set; } public bool Enabled { get; set; }
public string Plan { get; set; } public string Plan { get; set; }
public PlanType PlanType { get; set; } public PlanType PlanType { get; set; }
@ -98,23 +104,13 @@ namespace Bit.Core.Models.Business
string data = null; string data = null;
if(Version == 1) if(Version == 1)
{ {
data = string.Format("organization:{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}_{14}_{15}", var props = typeof(OrganizationLicense)
Version, .GetProperties(BindingFlags.Public | BindingFlags.Instance)
Utilities.CoreHelpers.ToEpocSeconds(Issued), .Where(p => !p.Name.Equals(nameof(Signature)) && !p.Name.Equals(nameof(SignatureBytes)))
Refresh.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Refresh.Value).ToString() : null, .OrderBy(p => p.Name)
Expires.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Expires.Value).ToString() : null, .Select(p => $"{p.Name}:{Utilities.CoreHelpers.FormatLicenseSignatureValue(p.GetValue(this, null))}")
LicenseKey, .Aggregate((c, n) => $"{c}|{n}");
InstallationId, data = $"license:organization|{props}";
Id,
Enabled,
PlanType,
Seats,
MaxCollections,
UseGroups,
UseDirectory,
UseTotp,
MaxStorageGb,
SelfHost);
} }
else else
{ {

View File

@ -2,6 +2,8 @@
using Bit.Core.Services; using Bit.Core.Services;
using Newtonsoft.Json; using Newtonsoft.Json;
using System; using System;
using System.Linq;
using System.Reflection;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text; using System.Text;
@ -17,6 +19,7 @@ namespace Bit.Core.Models.Business
{ {
LicenseKey = user.LicenseKey; LicenseKey = user.LicenseKey;
Id = user.Id; Id = user.Id;
Name = user.Name;
Email = user.Email; Email = user.Email;
Version = 1; Version = 1;
Premium = user.Premium; Premium = user.Premium;
@ -31,6 +34,7 @@ namespace Bit.Core.Models.Business
public string LicenseKey { get; set; } public string LicenseKey { get; set; }
public Guid Id { get; set; } public Guid Id { get; set; }
public string Name { get; set; }
public string Email { get; set; } public string Email { get; set; }
public bool Premium { get; set; } public bool Premium { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
@ -48,17 +52,13 @@ namespace Bit.Core.Models.Business
string data = null; string data = null;
if(Version == 1) if(Version == 1)
{ {
data = string.Format("user:{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}", var props = typeof(UserLicense)
Version, .GetProperties(BindingFlags.Public | BindingFlags.Instance)
Utilities.CoreHelpers.ToEpocSeconds(Issued), .Where(p => !p.Name.Equals(nameof(Signature)) && !p.Name.Equals(nameof(SignatureBytes)))
Refresh.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Refresh.Value).ToString() : null, .OrderBy(p => p.Name)
Expires.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Expires.Value).ToString() : null, .Select(p => $"{p.Name}:{Utilities.CoreHelpers.FormatLicenseSignatureValue(p.GetValue(this, null))}")
LicenseKey, .Aggregate((c, n) => $"{c}|{n}");
Trial, data = $"license:user|{props}";
Id,
Email,
Premium,
MaxStorageGb);
} }
else else
{ {

View File

@ -351,5 +351,25 @@ namespace Bit.Core.Utilities
// Standard base64 decoder // Standard base64 decoder
return Convert.FromBase64String(output); return Convert.FromBase64String(output);
} }
public static string FormatLicenseSignatureValue(object val)
{
if(val == null)
{
return string.Empty;
}
if(val.GetType() == typeof(DateTime))
{
return ToEpocSeconds((DateTime)val).ToString();
}
if(val.GetType() == typeof(bool))
{
return val.ToString().ToLowerInvariant();
}
return val.ToString();
}
} }
} }