1
0
mirror of https://github.com/bitwarden/server.git synced 2025-05-22 12:04:27 -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.X509Certificates;
using System.Text.Json.Serialization;
using Bit.Core.Billing.Licenses.Attributes;
using Bit.Core.Enums;
namespace Bit.Core.Models.Business;
public abstract class BaseLicense : ILicense
{
[LicenseVersion(1)]
public string LicenseKey { get; set; }
[LicenseVersion(1)]
public Guid Id { get; set; }
[LicenseVersion(1)]
public string Name { get; set; }
[LicenseVersion(1)]
public int Version { get; set; }
[LicenseIgnore(includeInHash: false)]
public DateTime Issued { get; set; }
[LicenseIgnore(includeInHash: false)]
public DateTime? Refresh { get; set; }
[LicenseVersion(1)]
public DateTime? Expires { get; set; }
[LicenseVersion(1)]
public bool Trial { get; set; }
[LicenseIgnore]
public LicenseType? LicenseType { get; set; }
[LicenseIgnore(includeInHash: false)]
public string Hash { get; set; }
[LicenseVersion(1)]
[LicenseIgnore]
public string Signature { get; set; }
[LicenseIgnore]
public string Token { get; set; }
[JsonIgnore]
[LicenseIgnore]
public byte[] SignatureBytes => Convert.FromBase64String(Signature);
public abstract byte[] GetDataBytes(bool forHash = false);

View File

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

View File

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