diff --git a/src/Core/Billing/Licenses/Extensions/LicenseExtensions.cs b/src/Core/Billing/Licenses/Extensions/LicenseExtensions.cs index 31569f02ac..f36af856df 100644 --- a/src/Core/Billing/Licenses/Extensions/LicenseExtensions.cs +++ b/src/Core/Billing/Licenses/Extensions/LicenseExtensions.cs @@ -1,5 +1,6 @@ using System.Reflection; using System.Security.Claims; +using System.Security.Cryptography; using System.Text; using Bit.Core.AdminConsole.Entities; using Bit.Core.Billing.Enums; @@ -12,6 +13,14 @@ namespace Bit.Core.Billing.Licenses.Extensions; public static class LicenseExtensions { + public static byte[] ComputeHash(this ILicense license) + { + using (var alg = SHA256.Create()) + { + return alg.ComputeHash(license.GetDataBytes(true)); + } + } + public static byte[] GetDataBytesWithAttributes(this ILicense license, bool forHash = false) { var props = license.GetType() diff --git a/src/Core/Models/Business/BaseLicense.cs b/src/Core/Models/Business/BaseLicense.cs index e1e62a17f2..5bd5ad19c5 100644 --- a/src/Core/Models/Business/BaseLicense.cs +++ b/src/Core/Models/Business/BaseLicense.cs @@ -49,14 +49,6 @@ public abstract class BaseLicense : ILicense public abstract byte[] GetDataBytes(bool forHash = false); - public byte[] ComputeHash() - { - using (var alg = SHA256.Create()) - { - return alg.ComputeHash(GetDataBytes(true)); - } - } - public bool VerifySignature(X509Certificate2 certificate) { using (var rsa = certificate.GetRSAPublicKey()) diff --git a/src/Core/Models/Business/ILicense.cs b/src/Core/Models/Business/ILicense.cs index 8d968bee15..815ab7d5bc 100644 --- a/src/Core/Models/Business/ILicense.cs +++ b/src/Core/Models/Business/ILicense.cs @@ -16,7 +16,6 @@ public interface ILicense string Signature { get; set; } string Token { get; set; } byte[] GetDataBytes(bool forHash = false); - byte[] ComputeHash(); bool VerifySignature(X509Certificate2 certificate); byte[] Sign(X509Certificate2 certificate); } diff --git a/src/Core/Models/Business/OrganizationLicense.cs b/src/Core/Models/Business/OrganizationLicense.cs index b802a02bc1..3a7424058f 100644 --- a/src/Core/Models/Business/OrganizationLicense.cs +++ b/src/Core/Models/Business/OrganizationLicense.cs @@ -94,7 +94,7 @@ public class OrganizationLicense : BaseLicense Trial = org.IsTrialing(subscriptionInfo); UseAdminSponsoredFamilies = org.UseAdminSponsoredFamilies; - Hash = Convert.ToBase64String(ComputeHash()); + Hash = Convert.ToBase64String(this.ComputeHash()); Signature = Convert.ToBase64String(licenseService.SignLicense(this)); } diff --git a/src/Core/Models/Business/UserLicense.cs b/src/Core/Models/Business/UserLicense.cs index cb36d53a52..1621767562 100644 --- a/src/Core/Models/Business/UserLicense.cs +++ b/src/Core/Models/Business/UserLicense.cs @@ -28,7 +28,7 @@ public class UserLicense : BaseLicense Refresh = user.CalculateFreshRefreshDate(subscriptionInfo); Trial = user.IsTrialing(subscriptionInfo); - Hash = Convert.ToBase64String(ComputeHash()); + Hash = Convert.ToBase64String(this.ComputeHash()); Signature = Convert.ToBase64String(licenseService.SignLicense(this)); } @@ -47,7 +47,7 @@ public class UserLicense : BaseLicense Refresh = user.CalculateFreshRefreshDate(null); Trial = user.IsTrialing(null); - Hash = Convert.ToBase64String(ComputeHash()); + Hash = Convert.ToBase64String(this.ComputeHash()); Signature = Convert.ToBase64String(licenseService.SignLicense(this)); }