mirror of
https://github.com/bitwarden/server.git
synced 2025-04-09 07:08:15 -05:00
Log user premium license disabled reason
This commit is contained in:
parent
3f5a0a8249
commit
cce4969094
@ -161,11 +161,32 @@ namespace Bit.Core.Services
|
|||||||
private async Task<bool> ProcessUserValidationAsync(User user)
|
private async Task<bool> ProcessUserValidationAsync(User user)
|
||||||
{
|
{
|
||||||
var license = ReadUserLicense(user);
|
var license = ReadUserLicense(user);
|
||||||
var valid = license != null && license.VerifyData(user) && license.VerifySignature(_certificate);
|
if(license == null)
|
||||||
if(!valid)
|
{
|
||||||
|
await DisablePremiumAsync(user, null, "No license file.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!license.VerifyData(user))
|
||||||
|
{
|
||||||
|
await DisablePremiumAsync(user, license, "Invalid data.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!license.VerifySignature(_certificate))
|
||||||
|
{
|
||||||
|
await DisablePremiumAsync(user, license, "Invalid signature.");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private async Task DisablePremiumAsync(User user, ILicense license, string reason)
|
||||||
{
|
{
|
||||||
_logger.LogInformation(Constants.BypassFiltersEventId, null,
|
_logger.LogInformation(Constants.BypassFiltersEventId, null,
|
||||||
"User {0}({1}) has an invalid license and premium is being disabled.", user.Id, user.Email);
|
"User {0}({1}) has an invalid license and premium is being disabled. Reason: {2}",
|
||||||
|
user.Id, user.Email, reason);
|
||||||
|
|
||||||
user.Premium = false;
|
user.Premium = false;
|
||||||
user.PremiumExpirationDate = license?.Expires ?? DateTime.UtcNow;
|
user.PremiumExpirationDate = license?.Expires ?? DateTime.UtcNow;
|
||||||
@ -173,9 +194,6 @@ namespace Bit.Core.Services
|
|||||||
await _userRepository.ReplaceAsync(user);
|
await _userRepository.ReplaceAsync(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
return valid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool VerifyLicense(ILicense license)
|
public bool VerifyLicense(ILicense license)
|
||||||
{
|
{
|
||||||
return license.VerifySignature(_certificate);
|
return license.VerifySignature(_certificate);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user