diff --git a/src/Core/Models/Business/OrganizationLicense.cs b/src/Core/Models/Business/OrganizationLicense.cs index 75b2229b89..9de23bb164 100644 --- a/src/Core/Models/Business/OrganizationLicense.cs +++ b/src/Core/Models/Business/OrganizationLicense.cs @@ -3,6 +3,8 @@ using Bit.Core.Models.Table; using Bit.Core.Services; using Newtonsoft.Json; using System; +using System.Linq; +using System.Reflection; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -22,6 +24,8 @@ namespace Bit.Core.Models.Business InstallationId = installationId; Id = org.Id; Name = org.Name; + BillingEmail = org.BillingEmail; + BusinessName = org.BusinessName; Enabled = org.Enabled; Plan = org.Plan; PlanType = org.PlanType; @@ -74,6 +78,8 @@ namespace Bit.Core.Models.Business public Guid InstallationId { get; set; } public Guid Id { get; set; } public string Name { get; set; } + public string BillingEmail { get; set; } + public string BusinessName { get; set; } public bool Enabled { get; set; } public string Plan { get; set; } public PlanType PlanType { get; set; } @@ -98,23 +104,13 @@ namespace Bit.Core.Models.Business string data = null; if(Version == 1) { - data = string.Format("organization:{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}_{14}_{15}", - Version, - Utilities.CoreHelpers.ToEpocSeconds(Issued), - Refresh.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Refresh.Value).ToString() : null, - Expires.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Expires.Value).ToString() : null, - LicenseKey, - InstallationId, - Id, - Enabled, - PlanType, - Seats, - MaxCollections, - UseGroups, - UseDirectory, - UseTotp, - MaxStorageGb, - SelfHost); + var props = typeof(OrganizationLicense) + .GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(p => !p.Name.Equals(nameof(Signature)) && !p.Name.Equals(nameof(SignatureBytes))) + .OrderBy(p => p.Name) + .Select(p => $"{p.Name}:{Utilities.CoreHelpers.FormatLicenseSignatureValue(p.GetValue(this, null))}") + .Aggregate((c, n) => $"{c}|{n}"); + data = $"license:organization|{props}"; } else { diff --git a/src/Core/Models/Business/UserLicense.cs b/src/Core/Models/Business/UserLicense.cs index 5ca3099c78..957bf34c17 100644 --- a/src/Core/Models/Business/UserLicense.cs +++ b/src/Core/Models/Business/UserLicense.cs @@ -2,6 +2,8 @@ using Bit.Core.Services; using Newtonsoft.Json; using System; +using System.Linq; +using System.Reflection; using System.Security.Cryptography; using System.Security.Cryptography.X509Certificates; using System.Text; @@ -17,6 +19,7 @@ namespace Bit.Core.Models.Business { LicenseKey = user.LicenseKey; Id = user.Id; + Name = user.Name; Email = user.Email; Version = 1; Premium = user.Premium; @@ -31,6 +34,7 @@ namespace Bit.Core.Models.Business public string LicenseKey { get; set; } public Guid Id { get; set; } + public string Name { get; set; } public string Email { get; set; } public bool Premium { get; set; } public short? MaxStorageGb { get; set; } @@ -48,17 +52,13 @@ namespace Bit.Core.Models.Business string data = null; if(Version == 1) { - data = string.Format("user:{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}", - Version, - Utilities.CoreHelpers.ToEpocSeconds(Issued), - Refresh.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Refresh.Value).ToString() : null, - Expires.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Expires.Value).ToString() : null, - LicenseKey, - Trial, - Id, - Email, - Premium, - MaxStorageGb); + var props = typeof(UserLicense) + .GetProperties(BindingFlags.Public | BindingFlags.Instance) + .Where(p => !p.Name.Equals(nameof(Signature)) && !p.Name.Equals(nameof(SignatureBytes))) + .OrderBy(p => p.Name) + .Select(p => $"{p.Name}:{Utilities.CoreHelpers.FormatLicenseSignatureValue(p.GetValue(this, null))}") + .Aggregate((c, n) => $"{c}|{n}"); + data = $"license:user|{props}"; } else { diff --git a/src/Core/Utilities/CoreHelpers.cs b/src/Core/Utilities/CoreHelpers.cs index 1b88e1e003..f32159e06b 100644 --- a/src/Core/Utilities/CoreHelpers.cs +++ b/src/Core/Utilities/CoreHelpers.cs @@ -351,5 +351,25 @@ namespace Bit.Core.Utilities // Standard base64 decoder 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(); + } } }