mirror of
https://github.com/bitwarden/server.git
synced 2025-07-01 08:02:49 -05:00
updates for license validation
This commit is contained in:
@ -12,9 +12,10 @@ namespace Bit.Core.Models.Business
|
||||
public OrganizationLicense()
|
||||
{ }
|
||||
|
||||
public OrganizationLicense(Organization org)
|
||||
public OrganizationLicense(Organization org, Guid installationId)
|
||||
{
|
||||
LicenseKey = "";
|
||||
InstallationId = installationId;
|
||||
Id = org.Id;
|
||||
Name = org.Name;
|
||||
Enabled = org.Enabled;
|
||||
@ -29,6 +30,7 @@ namespace Bit.Core.Models.Business
|
||||
}
|
||||
|
||||
public string LicenseKey { get; set; }
|
||||
public Guid InstallationId { get; set; }
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public bool Enabled { get; set; }
|
||||
@ -53,11 +55,12 @@ 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}",
|
||||
data = string.Format("organization:{0}_{1}_{2}_{3}_{4}_{5}_{6}_{7}_{8}_{9}_{10}_{11}_{12}_{13}_{14}",
|
||||
Version,
|
||||
Utilities.CoreHelpers.ToEpocSeconds(Issued),
|
||||
Expires.HasValue ? Utilities.CoreHelpers.ToEpocSeconds(Expires.Value).ToString() : null,
|
||||
LicenseKey,
|
||||
InstallationId,
|
||||
Id,
|
||||
Enabled,
|
||||
PlanType,
|
||||
@ -76,7 +79,29 @@ namespace Bit.Core.Models.Business
|
||||
|
||||
return Encoding.UTF8.GetBytes(data);
|
||||
}
|
||||
|
||||
|
||||
public bool CanUse(Guid installationId)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
{
|
||||
return InstallationId == installationId;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"Version {Version} is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public bool VerifyData(Organization organization)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow)
|
||||
@ -99,7 +124,7 @@ namespace Bit.Core.Models.Business
|
||||
organization.MaxCollections == MaxCollections &&
|
||||
organization.UseGroups == UseGroups &&
|
||||
organization.UseDirectory == UseDirectory &&
|
||||
organization.UseTotp == UseTotp &&
|
||||
organization.UseTotp == UseTotp &&
|
||||
organization.SelfHost == SelfHost;
|
||||
}
|
||||
else
|
||||
|
@ -65,6 +65,28 @@ namespace Bit.Core.Models.Business
|
||||
return Encoding.UTF8.GetBytes(data);
|
||||
}
|
||||
|
||||
public bool CanUse(User user)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Expires < DateTime.UtcNow)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
{
|
||||
return user.Email.Equals(Email, StringComparison.InvariantCultureIgnoreCase);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new NotSupportedException($"Version {Version} is not supported.");
|
||||
}
|
||||
}
|
||||
|
||||
public bool VerifyData(User user)
|
||||
{
|
||||
if(Issued > DateTime.UtcNow)
|
||||
|
Reference in New Issue
Block a user