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

Decorated license properties with newly created attributes

This commit is contained in:
Conner Turnbull 2025-05-20 14:43:57 -04:00
parent 59c1994fde
commit 3c40646d9f
No known key found for this signature in database
3 changed files with 97 additions and 0 deletions

View File

@ -1,26 +1,52 @@
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates; using System.Security.Cryptography.X509Certificates;
using System.Text.Json.Serialization; using System.Text.Json.Serialization;
using Bit.Core.Billing.Licenses.Attributes;
using Bit.Core.Enums; using Bit.Core.Enums;
namespace Bit.Core.Models.Business; namespace Bit.Core.Models.Business;
public abstract class BaseLicense : ILicense public abstract class BaseLicense : ILicense
{ {
[LicenseVersion(1)]
public string LicenseKey { get; set; } public string LicenseKey { get; set; }
[LicenseVersion(1)]
public Guid Id { get; set; } public Guid Id { get; set; }
[LicenseVersion(1)]
public string Name { get; set; } public string Name { get; set; }
[LicenseVersion(1)]
public int Version { get; set; } public int Version { get; set; }
[LicenseIgnore(includeInHash: false)]
public DateTime Issued { get; set; } public DateTime Issued { get; set; }
[LicenseIgnore(includeInHash: false)]
public DateTime? Refresh { get; set; } public DateTime? Refresh { get; set; }
[LicenseVersion(1)]
public DateTime? Expires { get; set; } public DateTime? Expires { get; set; }
[LicenseVersion(1)]
public bool Trial { get; set; } public bool Trial { get; set; }
[LicenseIgnore]
public LicenseType? LicenseType { get; set; } public LicenseType? LicenseType { get; set; }
[LicenseIgnore(includeInHash: false)]
public string Hash { get; set; } public string Hash { get; set; }
[LicenseVersion(1)]
[LicenseIgnore]
public string Signature { get; set; } public string Signature { get; set; }
[LicenseIgnore]
public string Token { get; set; } public string Token { get; set; }
[JsonIgnore] [JsonIgnore]
[LicenseIgnore]
public byte[] SignatureBytes => Convert.FromBase64String(Signature); public byte[] SignatureBytes => Convert.FromBase64String(Signature);
public abstract byte[] GetDataBytes(bool forHash = false); public abstract byte[] GetDataBytes(bool forHash = false);

View File

@ -3,6 +3,7 @@ using System.Security.Claims;
using System.Text; using System.Text;
using Bit.Core.AdminConsole.Entities; using Bit.Core.AdminConsole.Entities;
using Bit.Core.Billing.Enums; using Bit.Core.Billing.Enums;
using Bit.Core.Billing.Licenses.Attributes;
using Bit.Core.Billing.Licenses.Extensions; using Bit.Core.Billing.Licenses.Extensions;
using Bit.Core.Enums; using Bit.Core.Enums;
using Bit.Core.Services; using Bit.Core.Services;
@ -136,42 +137,105 @@ public class OrganizationLicense : BaseLicense
Signature = Convert.ToBase64String(licenseService.SignLicense(this)); Signature = Convert.ToBase64String(licenseService.SignLicense(this));
} }
[LicenseVersion(1)]
public Guid InstallationId { get; set; } public Guid InstallationId { get; set; }
[LicenseVersion(1)]
public string BillingEmail { get; set; } public string BillingEmail { get; set; }
[LicenseVersion(1)]
public string BusinessName { get; set; } public string BusinessName { get; set; }
[LicenseVersion(1)]
public bool Enabled { get; set; } public bool Enabled { get; set; }
[LicenseVersion(1)]
public string Plan { get; set; } public string Plan { get; set; }
[LicenseVersion(1)]
public PlanType PlanType { get; set; } public PlanType PlanType { get; set; }
[LicenseVersion(1)]
public int? Seats { get; set; } public int? Seats { get; set; }
[LicenseVersion(1)]
public short? MaxCollections { get; set; } public short? MaxCollections { get; set; }
[LicenseVersion(6)]
public bool UsePolicies { get; set; } public bool UsePolicies { get; set; }
[LicenseVersion(7)]
public bool UseSso { get; set; } public bool UseSso { get; set; }
[LicenseVersion(9)]
public bool UseKeyConnector { get; set; } public bool UseKeyConnector { get; set; }
[LicenseVersion(10)]
public bool UseScim { get; set; } public bool UseScim { get; set; }
[LicenseVersion(1)]
public bool UseGroups { get; set; } public bool UseGroups { get; set; }
[LicenseVersion(3)]
public bool UseEvents { get; set; } public bool UseEvents { get; set; }
[LicenseVersion(1)]
public bool UseDirectory { get; set; } public bool UseDirectory { get; set; }
[LicenseVersion(1)]
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
[LicenseVersion(4)]
public bool Use2fa { get; set; } public bool Use2fa { get; set; }
[LicenseVersion(5)]
public bool UseApi { get; set; } public bool UseApi { get; set; }
[LicenseVersion(8)]
public bool UseResetPassword { get; set; } public bool UseResetPassword { get; set; }
[LicenseVersion(1)]
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
[LicenseVersion(1)]
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
[LicenseVersion(2)]
public bool UsersGetPremium { get; set; } public bool UsersGetPremium { get; set; }
[LicenseVersion(11)]
public bool UseCustomPermissions { get; set; } public bool UseCustomPermissions { get; set; }
[LicenseVersion(12)]
public DateTime? ExpirationWithoutGracePeriod { get; set; } public DateTime? ExpirationWithoutGracePeriod { get; set; }
[LicenseVersion(13)]
public bool UsePasswordManager { get; set; } public bool UsePasswordManager { get; set; }
[LicenseVersion(13)]
public bool UseSecretsManager { get; set; } public bool UseSecretsManager { get; set; }
[LicenseVersion(13)]
public int? SmSeats { get; set; } public int? SmSeats { get; set; }
[LicenseVersion(13)]
public int? SmServiceAccounts { get; set; } public int? SmServiceAccounts { get; set; }
[LicenseIgnore]
public bool UseRiskInsights { get; set; } public bool UseRiskInsights { get; set; }
// Deprecated. Left for backwards compatibility with old license versions. // Deprecated. Left for backwards compatibility with old license versions.
[LicenseVersion(14)]
public bool LimitCollectionCreationDeletion { get; set; } = true; public bool LimitCollectionCreationDeletion { get; set; } = true;
[LicenseVersion(15)]
public bool AllowAdminAccessToAllCollectionItems { get; set; } = true; public bool AllowAdminAccessToAllCollectionItems { get; set; } = true;
// //
[LicenseVersion(16)]
public bool UseOrganizationDomains { get; set; } public bool UseOrganizationDomains { get; set; }
[LicenseIgnore]
public bool UseAdminSponsoredFamilies { get; set; } public bool UseAdminSponsoredFamilies { get; set; }
/// <summary> /// <summary>
@ -181,6 +245,7 @@ public class OrganizationLicense : BaseLicense
/// getting out of date license errors /// getting out of date license errors
/// </remarks> /// </remarks>
public const int CurrentLicenseFileVersion = 15; public const int CurrentLicenseFileVersion = 15;
private bool ValidLicenseVersion private bool ValidLicenseVersion
{ {
get => Version is >= 1 and <= 16; get => Version is >= 1 and <= 16;

View File

@ -1,6 +1,7 @@
using System.Reflection; using System.Reflection;
using System.Security.Claims; using System.Security.Claims;
using System.Text; using System.Text;
using Bit.Core.Billing.Licenses.Attributes;
using Bit.Core.Billing.Licenses.Extensions; using Bit.Core.Billing.Licenses.Extensions;
using Bit.Core.Entities; using Bit.Core.Entities;
using Bit.Core.Services; using Bit.Core.Services;
@ -54,8 +55,13 @@ public class UserLicense : BaseLicense
Signature = Convert.ToBase64String(licenseService.SignLicense(this)); Signature = Convert.ToBase64String(licenseService.SignLicense(this));
} }
[LicenseVersion(1)]
public string Email { get; set; } public string Email { get; set; }
[LicenseVersion(1)]
public bool Premium { get; set; } public bool Premium { get; set; }
[LicenseVersion(1)]
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
public override byte[] GetDataBytes(bool forHash = false) public override byte[] GetDataBytes(bool forHash = false)